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.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.rubocop_todo.yml +217 -0
  4. data/.travis.yml +1 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Rakefile +10 -1
  7. data/fog-vsphere.gemspec +2 -2
  8. data/lib/fog/bin/vsphere.rb +1 -1
  9. data/lib/fog/vsphere/compute.rb +320 -301
  10. data/lib/fog/vsphere/models/compute/cdrom.rb +10 -10
  11. data/lib/fog/vsphere/models/compute/cdroms.rb +2 -2
  12. data/lib/fog/vsphere/models/compute/cluster.rb +20 -20
  13. data/lib/fog/vsphere/models/compute/clusters.rb +1 -1
  14. data/lib/fog/vsphere/models/compute/customfields.rb +4 -4
  15. data/lib/fog/vsphere/models/compute/customvalues.rb +8 -8
  16. data/lib/fog/vsphere/models/compute/datacenter.rb +16 -16
  17. data/lib/fog/vsphere/models/compute/datastores.rb +1 -1
  18. data/lib/fog/vsphere/models/compute/folder.rb +2 -2
  19. data/lib/fog/vsphere/models/compute/folders.rb +2 -2
  20. data/lib/fog/vsphere/models/compute/hosts.rb +4 -4
  21. data/lib/fog/vsphere/models/compute/interface.rb +12 -12
  22. data/lib/fog/vsphere/models/compute/interfaces.rb +14 -16
  23. data/lib/fog/vsphere/models/compute/interfacetype.rb +2 -2
  24. data/lib/fog/vsphere/models/compute/interfacetypes.rb +6 -8
  25. data/lib/fog/vsphere/models/compute/networks.rb +1 -1
  26. data/lib/fog/vsphere/models/compute/resource_pools.rb +1 -1
  27. data/lib/fog/vsphere/models/compute/rule.rb +8 -9
  28. data/lib/fog/vsphere/models/compute/rules.rb +9 -10
  29. data/lib/fog/vsphere/models/compute/scsicontroller.rb +1 -1
  30. data/lib/fog/vsphere/models/compute/server.rb +68 -80
  31. data/lib/fog/vsphere/models/compute/servers.rb +12 -13
  32. data/lib/fog/vsphere/models/compute/servertype.rb +6 -6
  33. data/lib/fog/vsphere/models/compute/servertypes.rb +2 -2
  34. data/lib/fog/vsphere/models/compute/snapshot.rb +5 -6
  35. data/lib/fog/vsphere/models/compute/snapshots.rb +1 -1
  36. data/lib/fog/vsphere/models/compute/ticket.rb +0 -1
  37. data/lib/fog/vsphere/models/compute/volume.rb +12 -14
  38. data/lib/fog/vsphere/models/compute/volumes.rb +10 -10
  39. data/lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb +8 -8
  40. data/lib/fog/vsphere/requests/compute/create_folder.rb +5 -5
  41. data/lib/fog/vsphere/requests/compute/create_group.rb +16 -16
  42. data/lib/fog/vsphere/requests/compute/create_rule.rb +13 -13
  43. data/lib/fog/vsphere/requests/compute/create_vm.rb +117 -119
  44. data/lib/fog/vsphere/requests/compute/destroy_group.rb +8 -8
  45. data/lib/fog/vsphere/requests/compute/destroy_rule.rb +8 -8
  46. data/lib/fog/vsphere/requests/compute/folder_destroy.rb +3 -3
  47. data/lib/fog/vsphere/requests/compute/get_cluster.rb +2 -2
  48. data/lib/fog/vsphere/requests/compute/get_compute_resource.rb +16 -16
  49. data/lib/fog/vsphere/requests/compute/get_datacenter.rb +7 -7
  50. data/lib/fog/vsphere/requests/compute/get_datastore.rb +1 -2
  51. data/lib/fog/vsphere/requests/compute/get_folder.rb +24 -24
  52. data/lib/fog/vsphere/requests/compute/get_host.rb +2 -3
  53. data/lib/fog/vsphere/requests/compute/get_interface_type.rb +6 -6
  54. data/lib/fog/vsphere/requests/compute/get_network.rb +7 -10
  55. data/lib/fog/vsphere/requests/compute/get_resource_pool.rb +1 -2
  56. data/lib/fog/vsphere/requests/compute/get_server_type.rb +14 -14
  57. data/lib/fog/vsphere/requests/compute/get_storage_pod.rb +2 -2
  58. data/lib/fog/vsphere/requests/compute/get_template.rb +1 -2
  59. data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +26 -26
  60. data/lib/fog/vsphere/requests/compute/get_vm_first_scsi_controller.rb +6 -7
  61. data/lib/fog/vsphere/requests/compute/host_finish_maintenance.rb +1 -1
  62. data/lib/fog/vsphere/requests/compute/host_shutdown.rb +1 -1
  63. data/lib/fog/vsphere/requests/compute/host_start_maintenance.rb +1 -1
  64. data/lib/fog/vsphere/requests/compute/list_child_snapshots.rb +37 -39
  65. data/lib/fog/vsphere/requests/compute/list_clusters.rb +8 -9
  66. data/lib/fog/vsphere/requests/compute/list_compute_resources.rb +57 -59
  67. data/lib/fog/vsphere/requests/compute/list_customfields.rb +5 -6
  68. data/lib/fog/vsphere/requests/compute/list_datacenters.rb +17 -17
  69. data/lib/fog/vsphere/requests/compute/list_datastores.rb +16 -15
  70. data/lib/fog/vsphere/requests/compute/list_folders.rb +4 -4
  71. data/lib/fog/vsphere/requests/compute/list_groups.rb +5 -5
  72. data/lib/fog/vsphere/requests/compute/list_hosts.rb +30 -14
  73. data/lib/fog/vsphere/requests/compute/list_interface_types.rb +7 -7
  74. data/lib/fog/vsphere/requests/compute/list_networks.rb +12 -16
  75. data/lib/fog/vsphere/requests/compute/list_processes.rb +14 -14
  76. data/lib/fog/vsphere/requests/compute/list_resource_pools.rb +13 -14
  77. data/lib/fog/vsphere/requests/compute/list_rules.rb +4 -4
  78. data/lib/fog/vsphere/requests/compute/list_server_types.rb +24 -26
  79. data/lib/fog/vsphere/requests/compute/list_storage_pods.rb +8 -8
  80. data/lib/fog/vsphere/requests/compute/list_templates.rb +4 -5
  81. data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +15 -15
  82. data/lib/fog/vsphere/requests/compute/list_vm_cdroms.rb +16 -12
  83. data/lib/fog/vsphere/requests/compute/list_vm_customvalues.rb +3 -4
  84. data/lib/fog/vsphere/requests/compute/list_vm_interfaces.rb +54 -56
  85. data/lib/fog/vsphere/requests/compute/list_vm_scsi_controllers.rb +7 -7
  86. data/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb +36 -36
  87. data/lib/fog/vsphere/requests/compute/list_vm_volumes.rb +43 -36
  88. data/lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb +4 -4
  89. data/lib/fog/vsphere/requests/compute/modify_vm_controller.rb +2 -2
  90. data/lib/fog/vsphere/requests/compute/modify_vm_interface.rb +26 -19
  91. data/lib/fog/vsphere/requests/compute/modify_vm_volume.rb +7 -7
  92. data/lib/fog/vsphere/requests/compute/revert_to_snapshot.rb +2 -2
  93. data/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb +2 -2
  94. data/lib/fog/vsphere/requests/compute/update_vm.rb +111 -0
  95. data/lib/fog/vsphere/requests/compute/upload_iso.rb +10 -10
  96. data/lib/fog/vsphere/requests/compute/vm_acquire_ticket.rb +3 -3
  97. data/lib/fog/vsphere/requests/compute/vm_clone.rb +245 -247
  98. data/lib/fog/vsphere/requests/compute/vm_config_vnc.rb +15 -15
  99. data/lib/fog/vsphere/requests/compute/vm_destroy.rb +2 -2
  100. data/lib/fog/vsphere/requests/compute/vm_execute.rb +16 -16
  101. data/lib/fog/vsphere/requests/compute/vm_migrate.rb +11 -11
  102. data/lib/fog/vsphere/requests/compute/vm_power_off.rb +8 -8
  103. data/lib/fog/vsphere/requests/compute/vm_power_on.rb +2 -2
  104. data/lib/fog/vsphere/requests/compute/vm_reboot.rb +5 -5
  105. data/lib/fog/vsphere/requests/compute/vm_reconfig_cdrom.rb +11 -11
  106. data/lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb +8 -8
  107. data/lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb +6 -6
  108. data/lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb +8 -8
  109. data/lib/fog/vsphere/requests/compute/vm_reconfig_volumes.rb +14 -16
  110. data/lib/fog/vsphere/requests/compute/vm_relocate.rb +8 -8
  111. data/lib/fog/vsphere/requests/compute/vm_remove_snapshot.rb +2 -2
  112. data/lib/fog/vsphere/requests/compute/vm_rename.rb +5 -5
  113. data/lib/fog/vsphere/requests/compute/vm_revert_snapshot.rb +1 -1
  114. data/lib/fog/vsphere/requests/compute/vm_take_snapshot.rb +8 -8
  115. data/lib/fog/vsphere/version.rb +1 -1
  116. data/tests/compute_tests.rb +16 -17
  117. data/tests/helpers/mock_helper.rb +3 -3
  118. data/tests/models/compute/cluster_tests.rb +4 -5
  119. data/tests/models/compute/hosts_tests.rb +2 -4
  120. data/tests/models/compute/rules_tests.rb +10 -16
  121. data/tests/models/compute/server_tests.rb +30 -31
  122. data/tests/models/compute/servers_tests.rb +2 -4
  123. data/tests/models/compute/ticket_tests.rb +4 -6
  124. data/tests/models/compute/tickets_tests.rb +1 -3
  125. data/tests/requests/compute/current_time_tests.rb +2 -4
  126. data/tests/requests/compute/folder_destroy_tests.rb +5 -7
  127. data/tests/requests/compute/get_network_tests.rb +20 -23
  128. data/tests/requests/compute/list_child_snapshots_tests.rb +1 -2
  129. data/tests/requests/compute/list_clusters_tests.rb +5 -6
  130. data/tests/requests/compute/list_datastores_tests.rb +6 -7
  131. data/tests/requests/compute/list_hosts_tests.rb +3 -4
  132. data/tests/requests/compute/list_networks_tests.rb +6 -7
  133. data/tests/requests/compute/list_storage_pods_test.rb +3 -4
  134. data/tests/requests/compute/list_virtual_machines_tests.rb +16 -20
  135. data/tests/requests/compute/list_vm_cdroms_tests.rb +1 -2
  136. data/tests/requests/compute/list_vm_snapshots_tests.rb +1 -2
  137. data/tests/requests/compute/modify_vm_cdrom_tests.rb +3 -4
  138. data/tests/requests/compute/revert_to_snapshot_tests.rb +2 -4
  139. data/tests/requests/compute/set_vm_customvalue_tests.rb +0 -2
  140. data/tests/requests/compute/update_vm_tests.rb +13 -0
  141. data/tests/requests/compute/vm_clone_tests.rb +20 -20
  142. data/tests/requests/compute/vm_config_vnc_tests.rb +3 -4
  143. data/tests/requests/compute/vm_destroy_tests.rb +1 -4
  144. data/tests/requests/compute/vm_migrate_tests.rb +1 -2
  145. data/tests/requests/compute/vm_power_off_tests.rb +2 -4
  146. data/tests/requests/compute/vm_power_on_tests.rb +1 -3
  147. data/tests/requests/compute/vm_reboot_tests.rb +2 -4
  148. data/tests/requests/compute/vm_reconfig_cdrom_tests.rb +2 -3
  149. data/tests/requests/compute/vm_reconfig_cpus_tests.rb +1 -3
  150. data/tests/requests/compute/vm_reconfig_hardware_tests.rb +2 -4
  151. data/tests/requests/compute/vm_reconfig_memory_tests.rb +1 -3
  152. data/tests/requests/compute/vm_take_snapshot_tests.rb +1 -3
  153. 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 attributes = { }
5
+ def create_vm(attributes = {})
6
6
  # build up vm configuration
7
7
 
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),
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
- host = get_raw_host(attributes[:host], attributes[:cluster], attributes[:datacenter])
32
- else
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
- vm = create_vm_on_storage_pod(pod, vm_cfg, vmFolder, resource_pool, attributes[:datacenter], host)
39
- else
40
- vm = create_vm_on_datastore(vm_cfg, vmFolder, resource_pool, host)
41
- end
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(:config => vm_cfg, :pool => resource_pool, :host => host).wait_for_completion
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 = RbVmomi::VIM::StorageDrsPodSelectionSpec.new(
53
- :storagePod => get_raw_storage_pod(storage_pod, datacenter),
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
- :type => 'create',
57
- :folder => vmFolder,
58
- :resourcePool => resource_pool,
59
- :podSelectionSpec => pod_spec,
60
- :configSpec => vm_cfg,
61
- :host => host,
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(:storageSpec => storage_spec)
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(:key => [key]).wait_for_completion
66
+ result = srm.ApplyStorageDrsRecommendation_Task(key: [key]).wait_for_completion
69
67
  vm = result.vm
70
68
  else
71
- raise "Could not create vm on storage pod, did not get a storage recommendation"
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 attributes
76
+ def get_storage_pod(attributes)
79
77
  return unless @vsphere_rev.to_f >= 5
80
- volume = attributes[:volumes].detect {|volume| !( volume.storage_pod.nil? || volume.storage_pod.empty? ) }
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 attributes
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 attributes
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["scsi_controller"]))
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 and attributes[:boot_order]
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
- :deviceKey => 4000 + nics.index(nic),
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
- :deviceKey => disk.key
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 nic, attributes
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.kind_of? RbVmomi::VIM::DistributedVirtualPortgroup
167
+ if raw_network.is_a? RbVmomi::VIM::DistributedVirtualPortgroup
170
168
  RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
171
- :port => RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
172
- :portgroupKey => raw_network.key,
173
- :switchUuid => raw_network.config.distributedVirtualSwitch.uuid
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(:deviceName => nic.network)
175
+ RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(deviceName: nic.network)
178
176
  end
179
177
  end
180
178
 
181
- def create_interface nic, index = 0, operation = :add, attributes = {}
179
+ def create_interface(nic, index = 0, operation = :add, attributes = {})
182
180
  {
183
- :operation => operation,
184
- :device => nic.type.new(
185
- :key => index,
186
- :deviceInfo =>
187
- {
188
- :label => nic.name,
189
- :summary => nic.summary,
190
- },
191
- :backing => create_nic_backing(nic, attributes),
192
- :addressType => 'generated')
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
- controller_default_options.merge(controller.attributes)
199
- else
200
- controller_default_options
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 then
203
- Fog::Vsphere.class_from_string options[:type], "RbVmomi::VIM"
204
- else
205
- options[:type]
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
- :operation => options[:operation],
209
- :device => controller_class.new({
210
- :key => options[:key] || (1000 + index),
211
- :busNumber => options[:bus_id] || index,
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
- {:operation => :add, :type => RbVmomi::VIM.VirtualLsiLogicController.class, :shared => false }
214
+ { operation: :add, type: RbVmomi::VIM.VirtualLsiLogicController.class, shared: false }
219
215
  end
220
216
 
221
- def controller_get_shared_from_options options
222
- if (options.key? :shared and options[:shared]==false) or not options.key? :shared then
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 then
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
- datastore = ''
237
- else
238
- datastore = "[#{disk.datastore}]"
239
- end
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
- :operation => operation,
246
- :device => RbVmomi::VIM.VirtualDisk(
247
- :key => disk.key,
248
- :backing => RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
249
- :fileName => options[:filename] || datastore,
250
- :diskMode => disk.mode.to_sym,
251
- :thinProvisioned => disk.thin
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
- :controllerKey => disk.controller_key,
254
- :unitNumber => disk.unit_number,
255
- :capacityInKB => disk.size
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 cdrom, index = 0, operation = :add, controller_key = 200
264
+ def create_cdrom(cdrom, index = 0, operation = :add, controller_key = 200)
269
265
  {
270
- :operation => operation,
271
- :device => RbVmomi::VIM.VirtualCdrom(
272
- :key => cdrom.key || index,
273
- :backing => RbVmomi::VIM::VirtualCdromRemoteAtapiBackingInfo(deviceName: ''),
274
- :controllerKey => controller_key,
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 attributes
285
- extra_config = attributes[:extra_config] || {'bios.bootOrder' => 'ethernet0'}
286
- extra_config.map {|k,v| {:key => k, :value => v.to_s} }
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 attributes = { }
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 99999}",
293
+ 'mo_ref' => "vm-#{rand 99_999}",
298
294
  'datacenter' => attributes[:datacenter],
299
295
  'name' => attributes[:name],
300
- 'interfaces' => attributes[:interfaces].map {{
301
- 'mac' => 'f2:b5:46:b5:d8:d7'
302
- }}
296
+ 'interfaces' => attributes[:interfaces].map do
297
+ {
298
+ 'mac' => 'f2:b5:46:b5:d8:d7'
299
+ }
300
+ end
303
301
  }
304
- self.data[:servers][id] = vm
302
+ data[:servers][id] = vm
305
303
  id
306
304
  end
307
305
 
308
- def create_cdrom cdrom, index = 0, operation = :add, controller_key = 200
306
+ def create_cdrom(cdrom, index = 0, operation = :add, controller_key = 200)
309
307
  {
310
- :operation => operation,
311
- :device => {
312
- :key => cdrom.key || index,
313
- :backing => { deviceName: '' },
314
- :controllerKey => controller_key,
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
- RbVmomi::VIM.ClusterGroupSpec(
11
- operation: RbVmomi::VIM.ArrayUpdateOperation('remove'),
12
- removeKey: group.name
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 = self.data[:groups][attributes[:name]]
20
+ group = data[:groups][attributes[:name]]
21
21
  raise Fog::Vsphere::Error::NotFound unless group
22
- self.data[:groups].delete(attributes[:name])
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
- RbVmomi::VIM.ClusterRuleSpec(
11
- operation: RbVmomi::VIM.ArrayUpdateOperation('remove'),
12
- removeKey: rule.key
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 = self.data[:rules][attributes[:name]]
20
+ rule = data[:rules][attributes[:name]]
21
21
  raise Fog::Vsphere::Error::NotFound unless rule
22
- self.data[:rules].delete(attributes[:name])
22
+ data[:rules].delete(attributes[:name])
23
23
  end
24
24
  end
25
25
  end