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
@@ -14,14 +14,14 @@ module Fog
14
14
 
15
15
  # 'folder' => '/Datacenters/vm/Jeff/Templates' will be MUCH faster.
16
16
  # than simply listing everything.
17
- def all(filters = { })
17
+ def all(filters = {})
18
18
  f = {
19
- :datacenter => datacenter,
20
- :cluster => cluster,
21
- :network => network,
22
- :resource_pool => resource_pool,
23
- :folder => folder,
24
- :recursive => recursive,
19
+ datacenter: datacenter,
20
+ cluster: cluster,
21
+ network: network,
22
+ resource_pool: resource_pool,
23
+ folder: folder,
24
+ recursive: recursive
25
25
  }.merge(filters)
26
26
 
27
27
  load service.list_virtual_machines(f)
@@ -32,17 +32,16 @@ module Fog
32
32
  rescue Fog::Compute::Vsphere::NotFound
33
33
  nil
34
34
  end
35
-
35
+
36
36
  # Pass attributes we know about down to any VM we're creating
37
37
  def new(attributes = {})
38
38
  super({
39
- :datacenter => datacenter,
40
- :path => folder,
41
- :cluster => cluster,
42
- :resource_pool => resource_pool,
39
+ datacenter: datacenter,
40
+ path: folder,
41
+ cluster: cluster,
42
+ resource_pool: resource_pool
43
43
  }.merge(attributes))
44
44
  end
45
-
46
45
  end
47
46
  end
48
47
  end
@@ -9,7 +9,7 @@ module Fog
9
9
  attribute :datacenter
10
10
  attribute :interfacetypes
11
11
 
12
- def initialize(attributes={} )
12
+ def initialize(attributes = {})
13
13
  super defaults.merge(attributes)
14
14
  end
15
15
 
@@ -17,17 +17,17 @@ module Fog
17
17
  id
18
18
  end
19
19
 
20
- def interfacetypes filters={}
21
- attributes[:interfacetypes] ||= service.interfacetypes({ :datacenter => datacenter, :servertype => self }.merge(filters))
20
+ def interfacetypes(filters = {})
21
+ attributes[:interfacetypes] ||= service.interfacetypes({ datacenter: datacenter, servertype: self }.merge(filters))
22
22
  end
23
23
 
24
24
  private
25
25
 
26
26
  def defaults
27
27
  {
28
- :id=>"otherGuest64",
29
- :family=>"otherGuestFamily",
30
- :interfacetypes => nil,
28
+ id: 'otherGuest64',
29
+ family: 'otherGuestFamily',
30
+ interfacetypes: nil
31
31
  }
32
32
  end
33
33
  end
@@ -7,8 +7,8 @@ module Fog
7
7
  model Fog::Compute::Vsphere::Servertype
8
8
  attr_accessor :datacenter, :id, :fullname
9
9
 
10
- def all(filters = { })
11
- load service.list_server_types(filters.merge({:datacenter => datacenter}))
10
+ def all(filters = {})
11
+ load service.list_server_types(filters.merge(datacenter: datacenter))
12
12
  end
13
13
 
14
14
  def get(id)
@@ -4,15 +4,14 @@ module Fog
4
4
  module Compute
5
5
  class Vsphere
6
6
  class Snapshot < Fog::Model
7
-
8
7
  identity :ref
9
8
  attribute :server_id
10
9
 
11
10
  attribute :name
12
- attribute :quiescedi, :default => false
13
- attribute :description, :default => ''
11
+ attribute :quiescedi, default: false
12
+ attribute :description, default: ''
14
13
  attribute :create_time
15
- attribute :power_state, :default => 'none'
14
+ attribute :power_state, default: 'none'
16
15
  attribute :ref
17
16
  attribute :mo_ref
18
17
  attribute :tree_node
@@ -21,13 +20,13 @@ module Fog
21
20
 
22
21
  def child_snapshots(filters = {})
23
22
  service.snapshots(
24
- { :server_id => server_id, :parent_snapshot => self }.update(filters)
23
+ { server_id: server_id, parent_snapshot: self }.update(filters)
25
24
  )
26
25
  end
27
26
 
28
27
  def get_child(snapshot_ref)
29
28
  return self if ref == snapshot_ref
30
- child_snapshots().get(snapshot_ref)
29
+ child_snapshots.get(snapshot_ref)
31
30
  end
32
31
 
33
32
  def revert
@@ -5,7 +5,7 @@ module Fog
5
5
  module Compute
6
6
  class Vsphere
7
7
  class Snapshots < Fog::Collection
8
- attribute :server_id, :alias => :instance_uuid
8
+ attribute :server_id, alias: :instance_uuid
9
9
  attribute :parent_snapshot
10
10
  model Fog::Compute::Vsphere::Snapshot
11
11
 
@@ -4,7 +4,6 @@ module Fog
4
4
  module Compute
5
5
  class Vsphere
6
6
  class Ticket < Fog::Model
7
-
8
7
  attribute :server_id
9
8
 
10
9
  attribute :ticket
@@ -2,7 +2,7 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Volume < Fog::Model
5
- DISK_SIZE_TO_GB = 1048576
5
+ DISK_SIZE_TO_GB = 1_048_576
6
6
  identity :id
7
7
 
8
8
  has_one :server, Server
@@ -17,9 +17,9 @@ module Fog
17
17
  attribute :size_gb
18
18
  attribute :key
19
19
  attribute :unit_number
20
- attribute :controller_key, :type => :integer
20
+ attribute :controller_key, type: :integer
21
21
 
22
- def initialize(attributes={})
22
+ def initialize(attributes = {})
23
23
  super defaults.merge(attributes)
24
24
  end
25
25
 
@@ -27,7 +27,7 @@ module Fog
27
27
  attributes[:size_gb] ||= attributes[:size].to_i / DISK_SIZE_TO_GB if attributes[:size]
28
28
  end
29
29
 
30
- def size_gb= s
30
+ def size_gb=(s)
31
31
  attributes[:size] = s.to_i * DISK_SIZE_TO_GB if s
32
32
  attributes[:size_gb] = s.to_i if s
33
33
  end
@@ -52,7 +52,7 @@ module Fog
52
52
  end
53
53
 
54
54
  def save
55
- raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
55
+ raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted?
56
56
  requires :server_id, :size, :datastore
57
57
 
58
58
  set_unit_number
@@ -60,9 +60,7 @@ module Fog
60
60
  data = service.add_vm_volume(self)
61
61
 
62
62
  if data['task_state'] == 'success'
63
- if self.unit_number >= 7
64
- self.unit_number += 1
65
- end
63
+ self.unit_number += 1 if unit_number >= 7
66
64
 
67
65
  # We have to query vSphere to get the volume attributes since the task handle doesn't include that info.
68
66
  created = server.volumes.all.find { |volume| volume.unit_number == self.unit_number }
@@ -106,7 +104,7 @@ module Fog
106
104
  if unit_number.nil?
107
105
  self.unit_number = calculate_free_unit_number
108
106
  else
109
- if server.volumes.select { |vol| vol.controller_key == controller_key }.any? { |volume| volume.unit_number == self.unit_number && volume.id != self.id }
107
+ if server.volumes.select { |vol| vol.controller_key == controller_key }.any? { |volume| volume.unit_number == self.unit_number && volume.id != id }
110
108
  raise "A volume already exists with that unit_number, so we can't save the new volume"
111
109
  end
112
110
  end
@@ -127,10 +125,10 @@ module Fog
127
125
 
128
126
  def defaults
129
127
  {
130
- :thin => true,
131
- :name => "Hard disk",
132
- :mode => "persistent",
133
- :controller_key => 1000
128
+ thin: true,
129
+ name: 'Hard disk',
130
+ mode: 'persistent',
131
+ controller_key: 1000
134
132
  }
135
133
  end
136
134
 
@@ -139,7 +137,7 @@ module Fog
139
137
 
140
138
  # Vsphere maps unit_numbers 7 and greater to a higher SCSI ID since the pvscsi driver reserves SCSI ID 7
141
139
  used_unit_numbers = server.volumes
142
- .select { |vol| vol.unit_number && vol.controller_key == controller_key }.map(&:unit_number) + [7]
140
+ .select { |vol| vol.unit_number && vol.controller_key == controller_key }.map(&:unit_number) + [7]
143
141
  free_unit_numbers = (0..15).to_a - used_unit_numbers
144
142
 
145
143
  free_unit_numbers.first
@@ -8,19 +8,19 @@ module Fog
8
8
 
9
9
  model Fog::Compute::Vsphere::Volume
10
10
 
11
- def all(filters = {})
11
+ def all(_filters = {})
12
12
  requires :server_id
13
13
 
14
14
  case server
15
- when Fog::Compute::Vsphere::Server
16
- load service.list_vm_volumes(server.id)
17
- when Fog::Compute::Vsphere::Template
18
- load service.list_template_volumes(server.id)
19
- else
20
- raise 'volumes should have vm or template'
15
+ when Fog::Compute::Vsphere::Server
16
+ load service.list_vm_volumes(server.id)
17
+ when Fog::Compute::Vsphere::Template
18
+ load service.list_template_volumes(server.id)
19
+ else
20
+ raise 'volumes should have vm or template'
21
21
  end
22
22
 
23
- self.each { |volume| volume.server = server }
23
+ each { |volume| volume.server = server }
24
24
  self
25
25
  end
26
26
 
@@ -31,9 +31,9 @@ module Fog
31
31
  def new(attributes = {})
32
32
  if server_id
33
33
  # Default to the root volume datastore if one is not configured.
34
- datastore = ! attributes.key?(:datastore) && self.any? ? self.first.datastore : nil
34
+ datastore = !attributes.key?(:datastore) && any? ? first.datastore : nil
35
35
 
36
- super({ :server_id => server_id, :datastore => datastore }.merge!(attributes))
36
+ super({ server_id: server_id, datastore: datastore }.merge!(attributes))
37
37
  else
38
38
  super
39
39
  end
@@ -4,8 +4,8 @@ module Fog
4
4
  class Real
5
5
  def cloudinit_to_customspec(user_data)
6
6
  raise ArgumentError, "user_data can't be nil" if user_data.nil?
7
- custom_spec = { 'customization_spec' => Hash.new }
8
- user_data = YAML.load(user_data)
7
+ custom_spec = { 'customization_spec' => {} }
8
+ user_data = YAML.safe_load(user_data)
9
9
  # https://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.vm.customization.Specification.html
10
10
  # encryptionKey expects an array
11
11
  # globalIPSettings expects a hash, REQUIRED
@@ -16,10 +16,10 @@ module Fog
16
16
  custom_spec['encryptionKey'] = user_data['encryptionKey'] if user_data.key?('encryptionKey')
17
17
  custom_spec['globalIPSettings'] = user_data['globalIPSettings'] if user_data.key?('globalIPSettings')
18
18
  custom_spec['identity'] = user_data['identity'] if user_data.key?('identity')
19
- custom_spec['identity'] = {"Sysprep"=>{"guiRunOnce"=>{"commandList"=>user_data['runcmd']}}} if user_data.key?('runcmd') and not user_data.key?('identity')
19
+ custom_spec['identity'] = { 'Sysprep' => { 'guiRunOnce' => { 'commandList' => user_data['runcmd'] } } } if user_data.key?('runcmd') && !user_data.key?('identity')
20
20
  custom_spec['nicSettingMap'] = user_data['nicSettingMap'] if user_data.key?('nicSettingMap')
21
21
  custom_spec['options'] = user_data['options'] if user_data.key?('options')
22
-
22
+
23
23
  # for backwards compatability
24
24
  # hostname expects a string, REQUIRED
25
25
  # netmask expects a string
@@ -36,15 +36,15 @@ module Fog
36
36
  custom_spec['domain'] = user_data['domain'] if user_data.key?('domain')
37
37
  custom_spec['dnsSuffixList'] = user_data['domainsuffixlist'] if user_data.key?('domainsuffixlist')
38
38
  custom_spec['time_zone'] = user_data['timezone'] if user_data.key?('timezone')
39
- custom_spec
39
+ custom_spec
40
40
  end
41
41
  end
42
42
 
43
43
  class Mock
44
44
  def cloudinit_to_customspec(user_data)
45
45
  raise ArgumentError, "user_data can't be nil" if user_data.nil?
46
- custom_spec = { 'customization_spec' => Hash.new }
47
- user_data = YAML.load(user_data)
46
+ custom_spec = { 'customization_spec' => {} }
47
+ user_data = YAML.safe_load(user_data)
48
48
  custom_spec['encryptionKey'] = user_data['encryptionKey'] if user_data.key?('encryptionKey')
49
49
  custom_spec['globalIPSettings'] = user_data['globalIPSettings'] if user_data.key?('globalIPSettings')
50
50
  custom_spec['identity'] = user_data['identity'] if user_data.key?('identity')
@@ -58,7 +58,7 @@ module Fog
58
58
  custom_spec['domain'] = user_data['domain'] if user_data.key?('domain')
59
59
  custom_spec['dnsSuffixList'] = user_data['domainsuffixlist'] if user_data.key?('domainsuffixlist')
60
60
  custom_spec['time_zone'] = user_data['timezone'] if user_data.key?('timezone')
61
- custom_spec
61
+ custom_spec
62
62
  end
63
63
  end
64
64
  end
@@ -3,21 +3,21 @@ module Fog
3
3
  class Vsphere
4
4
  class Real
5
5
  def create_folder(datacenter, path, name)
6
- #Path cannot be nil but it can be an empty string
7
- raise ArgumentError, "Path cannot be nil" if path.nil?
6
+ # Path cannot be nil but it can be an empty string
7
+ raise ArgumentError, 'Path cannot be nil' if path.nil?
8
8
 
9
9
  parent_folder = get_raw_vmfolder(path, datacenter)
10
10
  begin
11
- new_folder = parent_folder.CreateFolder(:name => name)
11
+ new_folder = parent_folder.CreateFolder(name: name)
12
12
  # output is cleaned up to return the new path
13
13
  # new path will be path/name, example: "Production/Pool1"
14
- new_folder.path.reject { |a| a.first.class == "Folder" }.map { |a| a.first.name }.join("/").sub(/^\/?Datacenters\/#{datacenter}\/vm\/?/, '')
14
+ new_folder.path.reject { |a| a.first.class == 'Folder' }.map { |a| a.first.name }.join('/').sub(/^\/?Datacenters\/#{datacenter}\/vm\/?/, '')
15
15
  end
16
16
  end
17
17
  end
18
18
  class Mock
19
19
  def create_folder(datacenter, path, name)
20
- self.data[:folders][name] = {
20
+ data[:folders][name] = {
21
21
  'name' => name,
22
22
  'datacenter' => datacenter,
23
23
  'path' => "#{path}/#{name}",
@@ -2,21 +2,21 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
- def create_group(attributes={})
5
+ def create_group(attributes = {})
6
6
  cluster = get_raw_cluster(attributes[:cluster], attributes[:datacenter])
7
- group = cluster.configurationEx.group.find {|n| n[:name] == attributes[:name]}
7
+ group = cluster.configurationEx.group.find { |n| n[:name] == attributes[:name] }
8
8
  if group
9
9
  raise ArgumentError, "Group #{attributes[:name]} already exists!"
10
10
  end
11
11
  spec = get_group_spec attributes
12
12
  cluster_spec = RbVmomi::VIM.ClusterConfigSpecEx(groupSpec: [
13
- RbVmomi::VIM.ClusterGroupSpec(
14
- operation: RbVmomi::VIM.ArrayUpdateOperation('add'),
15
- info: spec
16
- )
17
- ])
13
+ RbVmomi::VIM.ClusterGroupSpec(
14
+ operation: RbVmomi::VIM.ArrayUpdateOperation('add'),
15
+ info: spec
16
+ )
17
+ ])
18
18
  cluster.ReconfigureComputeResource_Task(spec: cluster_spec, modify: true).wait_for_completion
19
- group = cluster.configurationEx.group.find {|n| n[:name] == attributes[:name]}
19
+ group = cluster.configurationEx.group.find { |n| n[:name] == attributes[:name] }
20
20
  if group
21
21
  return group[:name]
22
22
  else
@@ -26,25 +26,25 @@ module Fog
26
26
 
27
27
  private
28
28
 
29
- def get_group_spec(attributes={})
29
+ def get_group_spec(attributes = {})
30
30
  if attributes[:type].to_s == 'ClusterVmGroup'
31
- vms = attributes[:vm_ids].to_a.map {|id| get_vm_ref(id, attributes[:datacenter])}
31
+ vms = attributes[:vm_ids].to_a.map { |id| get_vm_ref(id, attributes[:datacenter]) }
32
32
  attributes[:type].new(
33
- name: attributes[:name],
34
- vm: vms
33
+ name: attributes[:name],
34
+ vm: vms
35
35
  )
36
36
  elsif attributes[:type].to_s == 'ClusterHostGroup'
37
37
  attributes[:type].new(
38
- name: attributes[:name],
39
- host: attributes[:host_refs]
38
+ name: attributes[:name],
39
+ host: attributes[:host_refs]
40
40
  )
41
41
  end
42
42
  end
43
43
  end
44
44
 
45
45
  class Mock
46
- def create_group(attributes={})
47
- self.data[:groups][attributes[:name]] = attributes
46
+ def create_group(attributes = {})
47
+ data[:groups][attributes[:name]] = attributes
48
48
  end
49
49
  end
50
50
  end
@@ -2,22 +2,22 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
- def create_rule(attributes={})
5
+ def create_rule(attributes = {})
6
6
  cluster = get_raw_cluster(attributes[:cluster], attributes[:datacenter])
7
- rule = cluster.configurationEx.rule.find {|n| n[:name] == attributes[:name]}
7
+ rule = cluster.configurationEx.rule.find { |n| n[:name] == attributes[:name] }
8
8
  if rule
9
9
  raise ArgumentError, "Rule #{attributes[:name]} already exists!"
10
10
  end
11
11
  spec = get_rule_spec attributes
12
12
  # Now, attach it to the cluster
13
13
  cluster_spec = RbVmomi::VIM.ClusterConfigSpecEx(rulesSpec: [
14
- RbVmomi::VIM.ClusterRuleSpec(
15
- operation: RbVmomi::VIM.ArrayUpdateOperation('add'),
16
- info: spec
17
- )
18
- ])
14
+ RbVmomi::VIM.ClusterRuleSpec(
15
+ operation: RbVmomi::VIM.ArrayUpdateOperation('add'),
16
+ info: spec
17
+ )
18
+ ])
19
19
  ret = cluster.ReconfigureComputeResource_Task(spec: cluster_spec, modify: true).wait_for_completion
20
- rule = cluster.configurationEx.rule.find {|n| n[:name] == attributes[:name]}
20
+ rule = cluster.configurationEx.rule.find { |n| n[:name] == attributes[:name] }
21
21
  if rule
22
22
  return rule[:key]
23
23
  else
@@ -27,9 +27,9 @@ module Fog
27
27
 
28
28
  private
29
29
 
30
- def get_rule_spec(attributes={})
31
- if (attributes[:type].to_s == 'ClusterAntiAffinityRuleSpec' || attributes[:type].to_s == 'ClusterAffinityRuleSpec')
32
- vms = attributes[:vm_ids].to_a.map {|id| get_vm_ref(id, attributes[:datacenter])}
30
+ def get_rule_spec(attributes = {})
31
+ if attributes[:type].to_s == 'ClusterAntiAffinityRuleSpec' || attributes[:type].to_s == 'ClusterAffinityRuleSpec'
32
+ vms = attributes[:vm_ids].to_a.map { |id| get_vm_ref(id, attributes[:datacenter]) }
33
33
  attributes[:type].new(
34
34
  name: attributes[:name],
35
35
  enabled: attributes[:enabled],
@@ -48,9 +48,9 @@ module Fog
48
48
  end
49
49
 
50
50
  class Mock
51
- def create_rule(attributes={})
51
+ def create_rule(attributes = {})
52
52
  attributes[:key] = rand(9999)
53
- self.data[:rules][attributes[:name]] = attributes
53
+ data[:rules][attributes[:name]] = attributes
54
54
  attributes[:key]
55
55
  end
56
56
  end