fog-vsphere 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +217 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/Rakefile +10 -1
- data/fog-vsphere.gemspec +2 -2
- data/lib/fog/bin/vsphere.rb +1 -1
- data/lib/fog/vsphere/compute.rb +320 -301
- data/lib/fog/vsphere/models/compute/cdrom.rb +10 -10
- data/lib/fog/vsphere/models/compute/cdroms.rb +2 -2
- data/lib/fog/vsphere/models/compute/cluster.rb +20 -20
- data/lib/fog/vsphere/models/compute/clusters.rb +1 -1
- data/lib/fog/vsphere/models/compute/customfields.rb +4 -4
- data/lib/fog/vsphere/models/compute/customvalues.rb +8 -8
- data/lib/fog/vsphere/models/compute/datacenter.rb +16 -16
- data/lib/fog/vsphere/models/compute/datastores.rb +1 -1
- data/lib/fog/vsphere/models/compute/folder.rb +2 -2
- data/lib/fog/vsphere/models/compute/folders.rb +2 -2
- data/lib/fog/vsphere/models/compute/hosts.rb +4 -4
- data/lib/fog/vsphere/models/compute/interface.rb +12 -12
- data/lib/fog/vsphere/models/compute/interfaces.rb +14 -16
- data/lib/fog/vsphere/models/compute/interfacetype.rb +2 -2
- data/lib/fog/vsphere/models/compute/interfacetypes.rb +6 -8
- data/lib/fog/vsphere/models/compute/networks.rb +1 -1
- data/lib/fog/vsphere/models/compute/resource_pools.rb +1 -1
- data/lib/fog/vsphere/models/compute/rule.rb +8 -9
- data/lib/fog/vsphere/models/compute/rules.rb +9 -10
- data/lib/fog/vsphere/models/compute/scsicontroller.rb +1 -1
- data/lib/fog/vsphere/models/compute/server.rb +68 -80
- data/lib/fog/vsphere/models/compute/servers.rb +12 -13
- data/lib/fog/vsphere/models/compute/servertype.rb +6 -6
- data/lib/fog/vsphere/models/compute/servertypes.rb +2 -2
- data/lib/fog/vsphere/models/compute/snapshot.rb +5 -6
- data/lib/fog/vsphere/models/compute/snapshots.rb +1 -1
- data/lib/fog/vsphere/models/compute/ticket.rb +0 -1
- data/lib/fog/vsphere/models/compute/volume.rb +12 -14
- data/lib/fog/vsphere/models/compute/volumes.rb +10 -10
- data/lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb +8 -8
- data/lib/fog/vsphere/requests/compute/create_folder.rb +5 -5
- data/lib/fog/vsphere/requests/compute/create_group.rb +16 -16
- data/lib/fog/vsphere/requests/compute/create_rule.rb +13 -13
- data/lib/fog/vsphere/requests/compute/create_vm.rb +117 -119
- data/lib/fog/vsphere/requests/compute/destroy_group.rb +8 -8
- data/lib/fog/vsphere/requests/compute/destroy_rule.rb +8 -8
- data/lib/fog/vsphere/requests/compute/folder_destroy.rb +3 -3
- data/lib/fog/vsphere/requests/compute/get_cluster.rb +2 -2
- data/lib/fog/vsphere/requests/compute/get_compute_resource.rb +16 -16
- data/lib/fog/vsphere/requests/compute/get_datacenter.rb +7 -7
- data/lib/fog/vsphere/requests/compute/get_datastore.rb +1 -2
- data/lib/fog/vsphere/requests/compute/get_folder.rb +24 -24
- data/lib/fog/vsphere/requests/compute/get_host.rb +2 -3
- data/lib/fog/vsphere/requests/compute/get_interface_type.rb +6 -6
- data/lib/fog/vsphere/requests/compute/get_network.rb +7 -10
- data/lib/fog/vsphere/requests/compute/get_resource_pool.rb +1 -2
- data/lib/fog/vsphere/requests/compute/get_server_type.rb +14 -14
- data/lib/fog/vsphere/requests/compute/get_storage_pod.rb +2 -2
- data/lib/fog/vsphere/requests/compute/get_template.rb +1 -2
- data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +26 -26
- data/lib/fog/vsphere/requests/compute/get_vm_first_scsi_controller.rb +6 -7
- data/lib/fog/vsphere/requests/compute/host_finish_maintenance.rb +1 -1
- data/lib/fog/vsphere/requests/compute/host_shutdown.rb +1 -1
- data/lib/fog/vsphere/requests/compute/host_start_maintenance.rb +1 -1
- data/lib/fog/vsphere/requests/compute/list_child_snapshots.rb +37 -39
- data/lib/fog/vsphere/requests/compute/list_clusters.rb +8 -9
- data/lib/fog/vsphere/requests/compute/list_compute_resources.rb +57 -59
- data/lib/fog/vsphere/requests/compute/list_customfields.rb +5 -6
- data/lib/fog/vsphere/requests/compute/list_datacenters.rb +17 -17
- data/lib/fog/vsphere/requests/compute/list_datastores.rb +16 -15
- data/lib/fog/vsphere/requests/compute/list_folders.rb +4 -4
- data/lib/fog/vsphere/requests/compute/list_groups.rb +5 -5
- data/lib/fog/vsphere/requests/compute/list_hosts.rb +30 -14
- data/lib/fog/vsphere/requests/compute/list_interface_types.rb +7 -7
- data/lib/fog/vsphere/requests/compute/list_networks.rb +12 -16
- data/lib/fog/vsphere/requests/compute/list_processes.rb +14 -14
- data/lib/fog/vsphere/requests/compute/list_resource_pools.rb +13 -14
- data/lib/fog/vsphere/requests/compute/list_rules.rb +4 -4
- data/lib/fog/vsphere/requests/compute/list_server_types.rb +24 -26
- data/lib/fog/vsphere/requests/compute/list_storage_pods.rb +8 -8
- data/lib/fog/vsphere/requests/compute/list_templates.rb +4 -5
- data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +15 -15
- data/lib/fog/vsphere/requests/compute/list_vm_cdroms.rb +16 -12
- data/lib/fog/vsphere/requests/compute/list_vm_customvalues.rb +3 -4
- data/lib/fog/vsphere/requests/compute/list_vm_interfaces.rb +54 -56
- data/lib/fog/vsphere/requests/compute/list_vm_scsi_controllers.rb +7 -7
- data/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb +36 -36
- data/lib/fog/vsphere/requests/compute/list_vm_volumes.rb +43 -36
- data/lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb +4 -4
- data/lib/fog/vsphere/requests/compute/modify_vm_controller.rb +2 -2
- data/lib/fog/vsphere/requests/compute/modify_vm_interface.rb +26 -19
- data/lib/fog/vsphere/requests/compute/modify_vm_volume.rb +7 -7
- data/lib/fog/vsphere/requests/compute/revert_to_snapshot.rb +2 -2
- data/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb +2 -2
- data/lib/fog/vsphere/requests/compute/update_vm.rb +111 -0
- data/lib/fog/vsphere/requests/compute/upload_iso.rb +10 -10
- data/lib/fog/vsphere/requests/compute/vm_acquire_ticket.rb +3 -3
- data/lib/fog/vsphere/requests/compute/vm_clone.rb +245 -247
- data/lib/fog/vsphere/requests/compute/vm_config_vnc.rb +15 -15
- data/lib/fog/vsphere/requests/compute/vm_destroy.rb +2 -2
- data/lib/fog/vsphere/requests/compute/vm_execute.rb +16 -16
- data/lib/fog/vsphere/requests/compute/vm_migrate.rb +11 -11
- data/lib/fog/vsphere/requests/compute/vm_power_off.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_power_on.rb +2 -2
- data/lib/fog/vsphere/requests/compute/vm_reboot.rb +5 -5
- data/lib/fog/vsphere/requests/compute/vm_reconfig_cdrom.rb +11 -11
- data/lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb +6 -6
- data/lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_reconfig_volumes.rb +14 -16
- data/lib/fog/vsphere/requests/compute/vm_relocate.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_remove_snapshot.rb +2 -2
- data/lib/fog/vsphere/requests/compute/vm_rename.rb +5 -5
- data/lib/fog/vsphere/requests/compute/vm_revert_snapshot.rb +1 -1
- data/lib/fog/vsphere/requests/compute/vm_take_snapshot.rb +8 -8
- data/lib/fog/vsphere/version.rb +1 -1
- data/tests/compute_tests.rb +16 -17
- data/tests/helpers/mock_helper.rb +3 -3
- data/tests/models/compute/cluster_tests.rb +4 -5
- data/tests/models/compute/hosts_tests.rb +2 -4
- data/tests/models/compute/rules_tests.rb +10 -16
- data/tests/models/compute/server_tests.rb +30 -31
- data/tests/models/compute/servers_tests.rb +2 -4
- data/tests/models/compute/ticket_tests.rb +4 -6
- data/tests/models/compute/tickets_tests.rb +1 -3
- data/tests/requests/compute/current_time_tests.rb +2 -4
- data/tests/requests/compute/folder_destroy_tests.rb +5 -7
- data/tests/requests/compute/get_network_tests.rb +20 -23
- data/tests/requests/compute/list_child_snapshots_tests.rb +1 -2
- data/tests/requests/compute/list_clusters_tests.rb +5 -6
- data/tests/requests/compute/list_datastores_tests.rb +6 -7
- data/tests/requests/compute/list_hosts_tests.rb +3 -4
- data/tests/requests/compute/list_networks_tests.rb +6 -7
- data/tests/requests/compute/list_storage_pods_test.rb +3 -4
- data/tests/requests/compute/list_virtual_machines_tests.rb +16 -20
- data/tests/requests/compute/list_vm_cdroms_tests.rb +1 -2
- data/tests/requests/compute/list_vm_snapshots_tests.rb +1 -2
- data/tests/requests/compute/modify_vm_cdrom_tests.rb +3 -4
- data/tests/requests/compute/revert_to_snapshot_tests.rb +2 -4
- data/tests/requests/compute/set_vm_customvalue_tests.rb +0 -2
- data/tests/requests/compute/update_vm_tests.rb +13 -0
- data/tests/requests/compute/vm_clone_tests.rb +20 -20
- data/tests/requests/compute/vm_config_vnc_tests.rb +3 -4
- data/tests/requests/compute/vm_destroy_tests.rb +1 -4
- data/tests/requests/compute/vm_migrate_tests.rb +1 -2
- data/tests/requests/compute/vm_power_off_tests.rb +2 -4
- data/tests/requests/compute/vm_power_on_tests.rb +1 -3
- data/tests/requests/compute/vm_reboot_tests.rb +2 -4
- data/tests/requests/compute/vm_reconfig_cdrom_tests.rb +2 -3
- data/tests/requests/compute/vm_reconfig_cpus_tests.rb +1 -3
- data/tests/requests/compute/vm_reconfig_hardware_tests.rb +2 -4
- data/tests/requests/compute/vm_reconfig_memory_tests.rb +1 -3
- data/tests/requests/compute/vm_take_snapshot_tests.rb +1 -3
- metadata +9 -4
@@ -2,20 +2,20 @@ module Fog
|
|
2
2
|
module Compute
|
3
3
|
class Vsphere
|
4
4
|
class Real
|
5
|
-
def create_vm
|
5
|
+
def create_vm(attributes = {})
|
6
6
|
# build up vm configuration
|
7
7
|
|
8
|
-
vm_cfg
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
8
|
+
vm_cfg = {
|
9
|
+
name: attributes[:name],
|
10
|
+
annotation: attributes[:annotation],
|
11
|
+
guestId: attributes[:guest_id],
|
12
|
+
version: attributes[:hardware_version],
|
13
|
+
files: { vmPathName: vm_path_name(attributes) },
|
14
|
+
numCPUs: attributes[:cpus],
|
15
|
+
numCoresPerSocket: attributes[:corespersocket],
|
16
|
+
memoryMB: attributes[:memory_mb],
|
17
|
+
deviceChange: device_change(attributes),
|
18
|
+
extraConfig: extra_config(attributes)
|
19
19
|
}
|
20
20
|
vm_cfg[:cpuHotAddEnabled] = attributes[:cpuHotAddEnabled] if attributes.key?(:cpuHotAddEnabled)
|
21
21
|
vm_cfg[:memoryHotAddEnabled] = attributes[:memoryHotAddEnabled] if attributes.key?(:memoryHotAddEnabled)
|
@@ -27,77 +27,75 @@ module Fog
|
|
27
27
|
get_raw_cluster(attributes[:cluster], attributes[:datacenter]).resourcePool
|
28
28
|
end
|
29
29
|
vmFolder = get_raw_vmfolder(attributes[:path], attributes[:datacenter])
|
30
|
-
if attributes.key?(:host)
|
31
|
-
|
32
|
-
|
33
|
-
host = nil
|
34
|
-
end
|
30
|
+
host = if attributes.key?(:host)
|
31
|
+
get_raw_host(attributes[:host], attributes[:cluster], attributes[:datacenter])
|
32
|
+
end
|
35
33
|
# if any volume has a storage_pod set, we deploy the vm on a storage pod instead of the defined datastores
|
36
34
|
pod = get_storage_pod(attributes)
|
37
|
-
if pod
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
vm = if pod
|
36
|
+
create_vm_on_storage_pod(pod, vm_cfg, vmFolder, resource_pool, attributes[:datacenter], host)
|
37
|
+
else
|
38
|
+
create_vm_on_datastore(vm_cfg, vmFolder, resource_pool, host)
|
39
|
+
end
|
42
40
|
vm.config.instanceUuid
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
46
44
|
|
47
45
|
def create_vm_on_datastore(vm_cfg, vmFolder, resource_pool, host = nil)
|
48
|
-
vm = vmFolder.CreateVM_Task(:
|
46
|
+
vm = vmFolder.CreateVM_Task(config: vm_cfg, pool: resource_pool, host: host).wait_for_completion
|
49
47
|
end
|
50
48
|
|
51
49
|
def create_vm_on_storage_pod(storage_pod, vm_cfg, vmFolder, resource_pool, datacenter, host = nil)
|
52
|
-
pod_spec
|
53
|
-
:
|
50
|
+
pod_spec = RbVmomi::VIM::StorageDrsPodSelectionSpec.new(
|
51
|
+
storagePod: get_raw_storage_pod(storage_pod, datacenter)
|
54
52
|
)
|
55
53
|
storage_spec = RbVmomi::VIM::StoragePlacementSpec.new(
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
54
|
+
type: 'create',
|
55
|
+
folder: vmFolder,
|
56
|
+
resourcePool: resource_pool,
|
57
|
+
podSelectionSpec: pod_spec,
|
58
|
+
configSpec: vm_cfg,
|
59
|
+
host: host
|
62
60
|
)
|
63
61
|
srm = connection.serviceContent.storageResourceManager
|
64
|
-
result = srm.RecommendDatastores(:
|
62
|
+
result = srm.RecommendDatastores(storageSpec: storage_spec)
|
65
63
|
|
66
64
|
# if result array contains recommendation, we can apply it
|
67
65
|
if key = result.recommendations.first.key
|
68
|
-
result = srm.ApplyStorageDrsRecommendation_Task(:
|
66
|
+
result = srm.ApplyStorageDrsRecommendation_Task(key: [key]).wait_for_completion
|
69
67
|
vm = result.vm
|
70
68
|
else
|
71
|
-
raise
|
69
|
+
raise 'Could not create vm on storage pod, did not get a storage recommendation'
|
72
70
|
end
|
73
71
|
vm
|
74
72
|
end
|
75
73
|
|
76
74
|
# check if a storage pool is set on any of the volumes and return the first result found or nil
|
77
75
|
# return early if vsphere revision is lower than 5 as this is not supported
|
78
|
-
def get_storage_pod
|
76
|
+
def get_storage_pod(attributes)
|
79
77
|
return unless @vsphere_rev.to_f >= 5
|
80
|
-
volume = attributes[:volumes].detect {|volume| !(
|
78
|
+
volume = attributes[:volumes].detect { |volume| !(volume.storage_pod.nil? || volume.storage_pod.empty?) }
|
81
79
|
volume.storage_pod if volume
|
82
80
|
end
|
83
81
|
|
84
82
|
# this methods defines where the vm config files would be located,
|
85
83
|
# by default we prefer to keep it at the same place the (first) vmdk is located
|
86
84
|
# if we deploy the vm on a storage pool, we have to return an empty string
|
87
|
-
def vm_path_name
|
85
|
+
def vm_path_name(attributes)
|
88
86
|
return '' if get_storage_pod(attributes)
|
89
87
|
datastore = attributes[:volumes].first.datastore unless attributes[:volumes].empty?
|
90
88
|
datastore ||= 'datastore1'
|
91
89
|
"[#{datastore}]"
|
92
90
|
end
|
93
91
|
|
94
|
-
def device_change
|
92
|
+
def device_change(attributes)
|
95
93
|
devices = []
|
96
94
|
if (nics = attributes[:interfaces])
|
97
95
|
devices << nics.map { |nic| create_interface(nic, nics.index(nic), :add, attributes) }
|
98
96
|
end
|
99
97
|
|
100
|
-
if (scsi_controllers = (attributes[:scsi_controllers] || attributes[
|
98
|
+
if (scsi_controllers = (attributes[:scsi_controllers] || attributes['scsi_controller']))
|
101
99
|
devices << scsi_controllers.each_with_index.map { |controller, index| create_controller(controller, index) }
|
102
100
|
end
|
103
101
|
|
@@ -115,7 +113,7 @@ module Fog
|
|
115
113
|
# NOTE: you must be using vsphere_rev 5.0 or greater to set boot_order
|
116
114
|
# e.g. Fog::Compute.new(provider: "vsphere", vsphere_rev: "5.5", etc)
|
117
115
|
options = {}
|
118
|
-
if @vsphere_rev.to_f >= 5
|
116
|
+
if (@vsphere_rev.to_f >= 5) && attributes[:boot_order]
|
119
117
|
options[:bootOrder] = boot_order(attributes, vm_cfg)
|
120
118
|
end
|
121
119
|
|
@@ -140,16 +138,16 @@ module Fog
|
|
140
138
|
# we allow booting from all network interfaces, the first interface has the highest priority
|
141
139
|
nics.each do |nic|
|
142
140
|
boot_order << RbVmomi::VIM::VirtualMachineBootOptionsBootableEthernetDevice.new(
|
143
|
-
:
|
141
|
+
deviceKey: 4000 + nics.index(nic)
|
144
142
|
)
|
145
143
|
end
|
146
144
|
end
|
147
145
|
when 'disk'
|
148
|
-
disks = vm_cfg[:deviceChange].map {|dev| dev[:device]}.select { |dev| dev.is_a? RbVmomi::VIM::VirtualDisk }
|
146
|
+
disks = vm_cfg[:deviceChange].map { |dev| dev[:device] }.select { |dev| dev.is_a? RbVmomi::VIM::VirtualDisk }
|
149
147
|
disks.each do |disk|
|
150
148
|
# we allow booting from all harddisks, the first disk has the highest priority
|
151
149
|
boot_order << RbVmomi::VIM::VirtualMachineBootOptionsBootableDiskDevice.new(
|
152
|
-
:
|
150
|
+
deviceKey: disk.key
|
153
151
|
)
|
154
152
|
end
|
155
153
|
when 'cdrom'
|
@@ -163,65 +161,63 @@ module Fog
|
|
163
161
|
boot_order
|
164
162
|
end
|
165
163
|
|
166
|
-
def create_nic_backing
|
164
|
+
def create_nic_backing(nic, attributes)
|
167
165
|
raw_network = get_raw_network(nic.network, attributes[:datacenter], if nic.virtualswitch then nic.virtualswitch end)
|
168
166
|
|
169
|
-
if raw_network.
|
167
|
+
if raw_network.is_a? RbVmomi::VIM::DistributedVirtualPortgroup
|
170
168
|
RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
|
171
|
-
:
|
172
|
-
:
|
173
|
-
:
|
169
|
+
port: RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
|
170
|
+
portgroupKey: raw_network.key,
|
171
|
+
switchUuid: raw_network.config.distributedVirtualSwitch.uuid
|
174
172
|
)
|
175
173
|
)
|
176
174
|
else
|
177
|
-
RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(:
|
175
|
+
RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(deviceName: nic.network)
|
178
176
|
end
|
179
177
|
end
|
180
178
|
|
181
|
-
def create_interface
|
179
|
+
def create_interface(nic, index = 0, operation = :add, attributes = {})
|
182
180
|
{
|
183
|
-
:
|
184
|
-
:
|
185
|
-
:
|
186
|
-
:
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
:
|
192
|
-
|
181
|
+
operation: operation,
|
182
|
+
device: nic.type.new(
|
183
|
+
key: index,
|
184
|
+
deviceInfo: {
|
185
|
+
label: nic.name,
|
186
|
+
summary: nic.summary
|
187
|
+
},
|
188
|
+
backing: create_nic_backing(nic, attributes),
|
189
|
+
addressType: 'generated'
|
190
|
+
)
|
193
191
|
}
|
194
192
|
end
|
195
193
|
|
196
|
-
def create_controller(controller=nil, index = 0)
|
197
|
-
options=if controller
|
198
|
-
|
199
|
-
|
200
|
-
|
194
|
+
def create_controller(controller = nil, index = 0)
|
195
|
+
options = if controller
|
196
|
+
controller_default_options.merge(controller.attributes)
|
197
|
+
else
|
198
|
+
controller_default_options
|
201
199
|
end
|
202
|
-
controller_class=if options[:type].is_a? String
|
203
|
-
|
204
|
-
|
205
|
-
|
200
|
+
controller_class = if options[:type].is_a? String
|
201
|
+
Fog::Vsphere.class_from_string options[:type], 'RbVmomi::VIM'
|
202
|
+
else
|
203
|
+
options[:type]
|
206
204
|
end
|
207
205
|
{
|
208
|
-
:
|
209
|
-
:
|
210
|
-
|
211
|
-
|
212
|
-
:sharedBus => controller_get_shared_from_options(options),
|
213
|
-
})
|
206
|
+
operation: options[:operation],
|
207
|
+
device: controller_class.new(key: options[:key] || (1000 + index),
|
208
|
+
busNumber: options[:bus_id] || index,
|
209
|
+
sharedBus: controller_get_shared_from_options(options))
|
214
210
|
}
|
215
211
|
end
|
216
212
|
|
217
213
|
def controller_default_options
|
218
|
-
{:
|
214
|
+
{ operation: :add, type: RbVmomi::VIM.VirtualLsiLogicController.class, shared: false }
|
219
215
|
end
|
220
216
|
|
221
|
-
def controller_get_shared_from_options
|
222
|
-
if (options.key?
|
217
|
+
def controller_get_shared_from_options(options)
|
218
|
+
if (options.key?(:shared) && (options[:shared] == false)) || (!options.key? :shared)
|
223
219
|
:noSharing
|
224
|
-
elsif options[:shared]==true
|
220
|
+
elsif options[:shared] == true
|
225
221
|
:virtualSharing
|
226
222
|
elsif options[:shared].is_a? String
|
227
223
|
options[:shared]
|
@@ -232,27 +228,27 @@ module Fog
|
|
232
228
|
|
233
229
|
def create_disk(disk, operation = :add, options = {})
|
234
230
|
# If we deploy the vm on a storage pod, datastore has to be an empty string
|
235
|
-
if options[:storage_pod]
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
231
|
+
datastore = if options[:storage_pod]
|
232
|
+
''
|
233
|
+
else
|
234
|
+
"[#{disk.datastore}]"
|
235
|
+
end
|
240
236
|
|
241
237
|
disk.set_unit_number
|
242
238
|
disk.set_key
|
243
239
|
|
244
240
|
payload = {
|
245
|
-
:
|
246
|
-
:
|
247
|
-
:
|
248
|
-
:
|
249
|
-
:
|
250
|
-
:
|
251
|
-
:
|
241
|
+
operation: operation,
|
242
|
+
device: RbVmomi::VIM.VirtualDisk(
|
243
|
+
key: disk.key,
|
244
|
+
backing: RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
|
245
|
+
fileName: options[:filename] || datastore,
|
246
|
+
diskMode: disk.mode.to_sym,
|
247
|
+
thinProvisioned: disk.thin
|
252
248
|
),
|
253
|
-
:
|
254
|
-
:
|
255
|
-
:
|
249
|
+
controllerKey: disk.controller_key,
|
250
|
+
unitNumber: disk.unit_number,
|
251
|
+
capacityInKB: disk.size
|
256
252
|
)
|
257
253
|
}
|
258
254
|
file_operation = options[:file_operation] || (:create if operation == :add)
|
@@ -265,58 +261,60 @@ module Fog
|
|
265
261
|
payload
|
266
262
|
end
|
267
263
|
|
268
|
-
def create_cdrom
|
264
|
+
def create_cdrom(cdrom, index = 0, operation = :add, controller_key = 200)
|
269
265
|
{
|
270
|
-
:
|
271
|
-
:
|
272
|
-
:
|
273
|
-
:
|
274
|
-
:
|
266
|
+
operation: operation,
|
267
|
+
device: RbVmomi::VIM.VirtualCdrom(
|
268
|
+
key: cdrom.key || index,
|
269
|
+
backing: RbVmomi::VIM::VirtualCdromRemoteAtapiBackingInfo(deviceName: ''),
|
270
|
+
controllerKey: controller_key,
|
275
271
|
connectable: RbVmomi::VIM::VirtualDeviceConnectInfo(
|
276
272
|
startConnected: false,
|
277
273
|
connected: false,
|
278
|
-
allowGuestControl: true
|
279
|
-
)
|
274
|
+
allowGuestControl: true
|
275
|
+
)
|
280
276
|
)
|
281
277
|
}
|
282
278
|
end
|
283
279
|
|
284
|
-
def extra_config
|
285
|
-
extra_config = attributes[:extra_config] || {'bios.bootOrder' => 'ethernet0'}
|
286
|
-
extra_config.map {|k,v| {:
|
280
|
+
def extra_config(attributes)
|
281
|
+
extra_config = attributes[:extra_config] || { 'bios.bootOrder' => 'ethernet0' }
|
282
|
+
extra_config.map { |k, v| { key: k, value: v.to_s } }
|
287
283
|
end
|
288
284
|
end
|
289
285
|
|
290
286
|
class Mock
|
291
|
-
def create_vm
|
287
|
+
def create_vm(attributes = {})
|
292
288
|
id = SecureRandom.uuid
|
293
289
|
vm = {
|
294
290
|
'id' => id,
|
295
291
|
'uuid' => id,
|
296
292
|
'instance_uuid' => id,
|
297
|
-
'mo_ref' => "vm-#{rand
|
293
|
+
'mo_ref' => "vm-#{rand 99_999}",
|
298
294
|
'datacenter' => attributes[:datacenter],
|
299
295
|
'name' => attributes[:name],
|
300
|
-
'interfaces' => attributes[:interfaces].map
|
301
|
-
|
302
|
-
|
296
|
+
'interfaces' => attributes[:interfaces].map do
|
297
|
+
{
|
298
|
+
'mac' => 'f2:b5:46:b5:d8:d7'
|
299
|
+
}
|
300
|
+
end
|
303
301
|
}
|
304
|
-
|
302
|
+
data[:servers][id] = vm
|
305
303
|
id
|
306
304
|
end
|
307
305
|
|
308
|
-
def create_cdrom
|
306
|
+
def create_cdrom(cdrom, index = 0, operation = :add, controller_key = 200)
|
309
307
|
{
|
310
|
-
:
|
311
|
-
:
|
312
|
-
:
|
313
|
-
:
|
314
|
-
:
|
308
|
+
operation: operation,
|
309
|
+
device: {
|
310
|
+
key: cdrom.key || index,
|
311
|
+
backing: { deviceName: '' },
|
312
|
+
controllerKey: controller_key,
|
315
313
|
connectable: {
|
316
314
|
startConnected: false,
|
317
315
|
connected: false,
|
318
|
-
allowGuestControl: true
|
319
|
-
}
|
316
|
+
allowGuestControl: true
|
317
|
+
}
|
320
318
|
}
|
321
319
|
}
|
322
320
|
end
|
@@ -4,22 +4,22 @@ module Fog
|
|
4
4
|
class Real
|
5
5
|
def destroy_group(attributes = {})
|
6
6
|
cluster = get_raw_cluster(attributes[:cluster], attributes[:datacenter])
|
7
|
-
group = cluster.configurationEx.group.find {|g| g.name == attributes[:name]}
|
7
|
+
group = cluster.configurationEx.group.find { |g| g.name == attributes[:name] }
|
8
8
|
raise Fog::Vsphere::Error::NotFound, "group #{attributes[:name]} not found" unless group
|
9
9
|
delete_spec = RbVmomi::VIM.ClusterConfigSpecEx(groupSpec: [
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
RbVmomi::VIM.ClusterGroupSpec(
|
11
|
+
operation: RbVmomi::VIM.ArrayUpdateOperation('remove'),
|
12
|
+
removeKey: group.name
|
13
|
+
)
|
14
|
+
])
|
15
15
|
cluster.ReconfigureComputeResource_Task(spec: delete_spec, modify: true).wait_for_completion
|
16
16
|
end
|
17
17
|
end
|
18
18
|
class Mock
|
19
19
|
def destroy_group(attributes = {})
|
20
|
-
group =
|
20
|
+
group = data[:groups][attributes[:name]]
|
21
21
|
raise Fog::Vsphere::Error::NotFound unless group
|
22
|
-
|
22
|
+
data[:groups].delete(attributes[:name])
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -4,22 +4,22 @@ module Fog
|
|
4
4
|
class Real
|
5
5
|
def destroy_rule(attributes = {})
|
6
6
|
cluster = get_raw_cluster(attributes[:cluster], attributes[:datacenter])
|
7
|
-
rule = cluster.configurationEx.rule.find {|rule| rule.key == attributes[:key]}
|
7
|
+
rule = cluster.configurationEx.rule.find { |rule| rule.key == attributes[:key] }
|
8
8
|
raise Fog::Vsphere::Error::NotFound, "rule #{attributes[:key]} not found" unless rule
|
9
9
|
delete_spec = RbVmomi::VIM.ClusterConfigSpecEx(rulesSpec: [
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
RbVmomi::VIM.ClusterRuleSpec(
|
11
|
+
operation: RbVmomi::VIM.ArrayUpdateOperation('remove'),
|
12
|
+
removeKey: rule.key
|
13
|
+
)
|
14
|
+
])
|
15
15
|
cluster.ReconfigureComputeResource_Task(spec: delete_spec, modify: true).wait_for_completion
|
16
16
|
end
|
17
17
|
end
|
18
18
|
class Mock
|
19
19
|
def destroy_rule(attributes = {})
|
20
|
-
rule =
|
20
|
+
rule = data[:rules][attributes[:name]]
|
21
21
|
raise Fog::Vsphere::Error::NotFound unless rule
|
22
|
-
|
22
|
+
data[:rules].delete(attributes[:name])
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|