-
Notifications
You must be signed in to change notification settings - Fork 4
/
virtual_disk.yml
242 lines (209 loc) · 8.38 KB
/
virtual_disk.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
---
- name: test virtual disk upload using hypercore_virtual_disk module
hosts: all
become: false
gather_facts: false
connection: ansible.builtin.local
strategy: host_pinned
environment: #if set here - hypercore modules will automatically use this for each remote cluster - avoiding need to specify cluster_instance for each test
SC_HOST: "https://{{ inventory_hostname }}"
SC_USERNAME: "{{ scale_user | default('admin') }}"
SC_PASSWORD: "{{ scale_pass | default('admin') }}"
SC_TIMEOUT: 2000000
SC_AUTH_METHOD: oidc #or local
vars:
image_url:
- "https://github.com/ddemlow/RestAPIExamples/raw/master/ubuntu20_04-cloud-init/ubuntu20cloudimage.qcow2"
- "https://github.lab.local/ddemlow/k8sdeploy/raw/master/ubuntu18_04-cloud-init/ubuntu18cloudimage.qcow2"
- "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.vmdk"
- "https://github.com/ddemlow/RestAPIExamples/raw/master/RHEL9/RHEL9-disk.qcow2"
- "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-disk-kvm.img"
image_filename: "{{ image_url[0] | split('/') | last }}" #only works for first in list
image_path: "/Users/davedemlow/Downloads/"
image_remove_old: true
template_remove_old: false
tasks:
# - name: check if "{{ image_filename }}" exists #fail will stop playbook
# stat:
# path: "{{image_path}}{{ image_url[0] | split('/') | last }}"
# register: filename
- name: Download Virtual Disks from URL list
ansible.builtin.get_url: #TODO: what if file doesn't download completely?
url: "{{ item }}"
dest: "{{image_path}}{{ item | split('/') | last }}"
timeout: 10000
validate_certs: false
# when: not "{{image_path}}{{ item | split('/') | last }}"
register: download
loop: "{{ image_url }}"
- name: delete template vm #for debugging only
scale_computing.hypercore.vm:
vm_name: template
state: absent
when: template_remove_old
- name: Get Information About the uploaded Virtual Disk in HyperCore
scale_computing.hypercore.virtual_disk_info:
register: diskmedia
- name: Show uploaded disk info
debug:
var: diskmedia
- name: Delete existing virtual disk "{{ item | split('/') | last }}"
scale_computing.hypercore.virtual_disk:
name: "{{ item | split('/') | last }}"
state: absent
when: image_remove_old
register: deleted
loop: "{{ image_url }}"
- name: Delete existing uploading-"{{ item | split('/') | last }}" virtual disk
scale_computing.hypercore.virtual_disk:
name: "uploading-{{ item | split('/') | last }}"
state: absent
when: image_remove_old
register: deleted
loop: "{{ image_url }}"
- name: Upload Virtual Disk {{ item | split('/') | last }}" to HyperCore "{{ inventory_hostname }}"
scale_computing.hypercore.virtual_disk:
name: "{{ item | split('/') | last }}"
source: "{{image_path}}{{ item | split('/') | last }}"
state: present
register: uploadResult
loop: "{{ image_url }}"
ignore_errors: true
- name: search for uploadable virtual disk files in "{{ image_path }}"
ansible.builtin.find:
paths: "{{ image_path }}"
hidden: false
recurse: false
file_type: any
patterns:
- '*.qcow2'
- '*.vmdk'
- '*.vhd'
- '*.img'
- '*.vhdx'
register: uploadable_files
- name: delete uploading- from "{{ image_path }}"" search for HyperCore "{{ inventory_hostname }}" #
scale_computing.hypercore.virtual_disk:
name: "uploading-{{ item.path | split('/') | last }}"
source: "{{ item.path }}"
state: absent
register: uploadResult
loop: "{{ uploadable_files.files }}"
ignore_errors: true
- name: delete existing virtual disks - from "{{ image_path }}" forHyperCore "{{ inventory_hostname }}" #500 error if previous upload still converting
scale_computing.hypercore.virtual_disk:
name: "{{ item.path | split('/') | last }}"
source: "{{ item.path }}"
state: absent
register: uploadResult
loop: "{{ uploadable_files.files }}"
when: image_remove_old
ignore_errors: true
- name: Upload local Virtual Disk from path search {{ image_path }}" to HyperCore "{{ inventory_hostname }}"
scale_computing.hypercore.virtual_disk:
name: "{{ item.path | split('/') | last }}"
source: "{{ item.path }}"
state: present
register: uploadResult
loop: "{{ uploadable_files.files }}"
ignore_errors: true
- name: search for uploadable virtual disk files in "/Volumes/Samsung USB"
ansible.builtin.find:
paths: "/Volumes/Samsung USB"
hidden: false
recurse: false
file_type: any
patterns:
- '*.qcow2'
- '*.vmdk'
- '*.vhd'
- '*.img'
- '*.vhdx'
register: uploadable_files
- name: delete uploading- from "/Volumes/Samsung USB" search for HyperCore "{{ inventory_hostname }}" #
scale_computing.hypercore.virtual_disk:
name: "uploading-{{ item.path | split('/') | last }}"
source: "{{ item.path }}"
state: absent
register: uploadResult
loop: "{{ uploadable_files.files }}"
ignore_errors: true
- name: delete existing virtual disks - from "/Volumes/Samsung USB" forHyperCore "{{ inventory_hostname }}" #500 error if previous upload still converting
scale_computing.hypercore.virtual_disk:
name: "{{ item.path | split('/') | last }}"
source: "{{ item.path }}"
state: absent
register: uploadResult
loop: "{{ uploadable_files.files }}"
when: image_remove_old
ignore_errors: true
- name: Upload local Virtual Disk from path search "/Volumes/Samsung USB" to HyperCore "{{ inventory_hostname }}"
scale_computing.hypercore.virtual_disk:
name: "{{ item.path | split('/') | last }}"
source: "{{ item.path }}"
state: present
register: uploadResult
loop: "{{ uploadable_files.files }}"
ignore_errors: true
# - name: Set diskmedia_uuid to uploaded UUID
# ansible.builtin.set_fact:
# diskmedia: "{{ uploadResult.record.createdUUID }}"
# when: uploadResult.changed
# - name: Get Information about the uploaded Virtual Disk in HyperCore
# scale_computing.hypercore.api:
# action: get
# endpoint: "/rest/v1/VirtualDisk/{{ uploadResult.record.createdUUID }}"
# register: result
# when: uploadResult.changed
# - name: Show uploaded disk info
# ansible.builtin.debug:
# var: result
# when: uploadResult.changed
# - name: Create template vm and will delete attached disks not specified below
# scale_computing.hypercore.vm:
# vm_name: template
# description: Demo VM
# state: present
# tags:
# - vsdupload
# memory: "{{ '1 GB' | human_to_bytes }}"
# vcpu: 2
# power_state: stop
# disks:
# - type: ide_cdrom
# disk_slot: 0
# nics:
# - vlan: 0
# type: virtio
# register: template
# - name: show template data
# ansible.builtin.debug:
# var: template
# - name: show diskmedia data
# ansible.builtin.debug:
# var: diskmedia
# - name: Attach Virtual Disk
# scale_computing.hypercore.api:
# action: post
# endpoint: "/rest/v1/VirtualDisk/{{ diskmedia }}/attach"
# data:
# options:
# regenerateDiskID: true
# readOnly: false
# template:
# virDomainUUID: "{{ template.record[0].uuid }}"
# type: "VIRTIO_DISK"
# slot: -1
# capacity: 200000000000
# tieringPriorityFactor: 8
# register: diskattached
# # capacity 0 should be documented? just preserves existing size - useful since capacity is required
# # slot -1 is default - what is that?
# - name: display template vm
# scale_computing.hypercore.vm_info:
# vm_name: template
# register: template
# # HYPERCORE BUG? appears we boot off disk even though "boot_devices": [],
# - name: show template data
# ansible.builtin.debug:
# var: template