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
@@ -8,7 +8,7 @@ module Fog
8
8
  attr_accessor :datacenter, :cluster
9
9
 
10
10
  def all(filters = {})
11
- f = { :datacenter => datacenter, :cluster => cluster }.merge(filters)
11
+ f = { datacenter: datacenter, cluster: cluster }.merge(filters)
12
12
  load service.list_networks(f)
13
13
  end
14
14
 
@@ -8,7 +8,7 @@ module Fog
8
8
  attr_accessor :datacenter, :cluster
9
9
 
10
10
  def all(filters = {})
11
- load service.list_resource_pools(filters.merge(:datacenter => datacenter, :cluster => cluster))
11
+ load service.list_resource_pools(filters.merge(datacenter: datacenter, cluster: cluster))
12
12
  end
13
13
 
14
14
  def get(id)
@@ -4,7 +4,7 @@ module Fog
4
4
  # ClusterRuleInfo
5
5
  class Rule < Fog::Model
6
6
  identity :key
7
-
7
+
8
8
  attribute :datacenter
9
9
  attribute :cluster
10
10
  attribute :name
@@ -15,32 +15,31 @@ module Fog
15
15
  # - RbVmomi::VIM::ClusterVmHostRuleInfo
16
16
  attribute :type
17
17
  attribute :vm_ids
18
-
18
+
19
19
  def vms
20
- vm_ids.map {|id| service.servers.get(id, datacenter) }
20
+ vm_ids.map { |id| service.servers.get(id, datacenter) }
21
21
  end
22
-
22
+
23
23
  def vms=(vms)
24
24
  self.vm_ids = vms.map(&:instance_uuid)
25
25
  end
26
-
26
+
27
27
  def save
28
28
  requires :datacenter, :cluster, :name, :enabled, :type, :vm_ids
29
29
  if vm_ids.length < 2
30
- raise ArgumentError, "A rule must have at least 2 VMs"
30
+ raise ArgumentError, 'A rule must have at least 2 VMs'
31
31
  end
32
32
  if persisted?
33
- raise "Update is not supported yet"
33
+ raise 'Update is not supported yet'
34
34
  else
35
35
  self.key = service.create_rule(attributes)
36
36
  end
37
37
  reload
38
38
  end
39
-
39
+
40
40
  def destroy
41
41
  service.destroy_rule(attributes)
42
42
  end
43
-
44
43
  end
45
44
  end
46
45
  end
@@ -3,27 +3,26 @@ module Fog
3
3
  class Vsphere
4
4
  class Rules < Fog::Collection
5
5
  autoload :Rule, File.expand_path('../rule', __FILE__)
6
-
6
+
7
7
  model Fog::Compute::Vsphere::Rule
8
8
  attribute :datacenter
9
9
  attribute :cluster
10
-
11
- def all(filters = {})
10
+
11
+ def all(_filters = {})
12
12
  requires :datacenter, :cluster
13
- load service.list_rules(:datacenter => datacenter, :cluster => cluster)
13
+ load service.list_rules(datacenter: datacenter, cluster: cluster)
14
14
  end
15
-
15
+
16
16
  def get(key_or_name)
17
- all.find {|rule| [rule.key, rule.name].include? key_or_name } or
18
- raise Fog::Compute::Vsphere::NotFound, "no such rule #{key_or_name}"
17
+ all.find { |rule| [rule.key, rule.name].include? key_or_name } ||
18
+ raise(Fog::Compute::Vsphere::NotFound, "no such rule #{key_or_name}")
19
19
  end
20
-
20
+
21
21
  # Pass datacenter/cluster to every new rule
22
- def new(attributes={})
22
+ def new(attributes = {})
23
23
  requires :datacenter, :cluster
24
24
  super(attributes.merge(datacenter: datacenter, cluster: cluster))
25
25
  end
26
-
27
26
  end
28
27
  end
29
28
  end
@@ -5,7 +5,7 @@ module Fog
5
5
  attribute :shared_bus
6
6
  attribute :type
7
7
  attribute :unit_number
8
- attribute :key, :type => :integer
8
+ attribute :key, type: :integer
9
9
  attribute :server_id
10
10
 
11
11
  def initialize(attributes = {})
@@ -24,12 +24,12 @@ module Fog
24
24
  attribute :uuid
25
25
  attribute :hostname
26
26
  attribute :operatingsystem
27
- attribute :public_ip_address, :aliases => 'ipaddress'
28
- attribute :power_state, :aliases => 'power'
29
- attribute :tools_state, :aliases => 'tools'
27
+ attribute :public_ip_address, aliases: 'ipaddress'
28
+ attribute :power_state, aliases: 'power'
29
+ attribute :tools_state, aliases: 'tools'
30
30
  attribute :tools_version
31
- attribute :mac_addresses, :aliases => 'macs'
32
- attribute :hypervisor, :aliases => 'host'
31
+ attribute :mac_addresses, aliases: 'macs'
32
+ attribute :hypervisor, aliases: 'host'
33
33
  attribute :connection_state
34
34
  attribute :mo_ref
35
35
  attribute :path
@@ -39,20 +39,20 @@ module Fog
39
39
  attribute :interfaces
40
40
  attribute :volumes
41
41
  attribute :customvalues
42
- attribute :overall_status, :aliases => 'status'
42
+ attribute :overall_status, aliases: 'status'
43
43
  attribute :cluster
44
44
  attribute :datacenter
45
45
  attribute :resource_pool
46
46
  attribute :instance_uuid # move this --> id
47
47
  attribute :guest_id
48
48
  attribute :hardware_version
49
- attribute :scsi_controllers, :type => :array
49
+ attribute :scsi_controllers, type: :array
50
50
  attribute :cpuHotAddEnabled
51
51
  attribute :memoryHotAddEnabled
52
52
  attribute :firmware
53
53
  attribute :annotation
54
54
 
55
- def initialize(attributes={} )
55
+ def initialize(attributes = {})
56
56
  super defaults.merge(attributes)
57
57
  self.instance_uuid ||= id # TODO: remvoe instance_uuid as it can be replaced with simple id
58
58
  initialize_interfaces
@@ -62,7 +62,7 @@ module Fog
62
62
  end
63
63
 
64
64
  # Lazy Loaded Attributes
65
- [:datacenter, :cluster, :hypervisor, :resource_pool, :mac_addresses].each do |attr|
65
+ %i[datacenter cluster hypervisor resource_pool mac_addresses].each do |attr|
66
66
  define_method attr do
67
67
  attributes[attr] = attributes[attr].call if attributes[attr].is_a?(Proc)
68
68
  attributes[attr]
@@ -75,45 +75,45 @@ module Fog
75
75
  service.vm_rename('instance_uuid' => instance_uuid, 'name' => name)
76
76
  end
77
77
 
78
- def vm_reconfig_memory(options = {})
78
+ def vm_reconfig_memory(_options = {})
79
79
  requires :instance_uuid, :memory
80
80
  service.vm_reconfig_memory('instance_uuid' => instance_uuid, 'memory' => memory_mb)
81
81
  end
82
82
 
83
- def vm_reconfig_cpus(options = {})
83
+ def vm_reconfig_cpus(_options = {})
84
84
  requires :instance_uuid, :cpus, :corespersocket
85
85
  service.vm_reconfig_cpus('instance_uuid' => instance_uuid, 'cpus' => cpus, 'corespersocket' => corespersocket)
86
86
  end
87
87
 
88
- def vm_reconfig_volumes(options = {})
88
+ def vm_reconfig_volumes(_options = {})
89
89
  requires :instance_uuid, :volumes
90
90
  service.vm_reconfig_volumes('instance_uuid' => instance_uuid, 'volumes' => volumes)
91
91
  end
92
92
 
93
- def vm_reconfig_hardware(hardware_spec, options = {})
93
+ def vm_reconfig_hardware(hardware_spec, _options = {})
94
94
  requires :instance_uuid
95
95
  service.vm_reconfig_hardware('instance_uuid' => instance_uuid, 'hardware_spec' => hardware_spec)
96
96
  end
97
97
 
98
- def start(options = {})
98
+ def start(_options = {})
99
99
  requires :instance_uuid
100
100
  service.vm_power_on('instance_uuid' => instance_uuid) unless ready?
101
101
  end
102
102
 
103
103
  def stop(options = {})
104
- options = { :force => !tools_installed? || !tools_running? }.merge(options)
104
+ options = { force: !tools_installed? || !tools_running? }.merge(options)
105
105
  requires :instance_uuid
106
106
  service.vm_power_off('instance_uuid' => instance_uuid, 'force' => options[:force]) unless power_state == 'poweredOff'
107
107
  end
108
108
 
109
109
  def suspend(options = {})
110
- options = { :force => !tools_installed? || !tools_running? }.merge(options)
110
+ options = { force: !tools_installed? || !tools_running? }.merge(options)
111
111
  requires :instance_uuid
112
112
  service.vm_suspend('instance_uuid' => instance_uuid, 'force' => options[:force])
113
113
  end
114
114
 
115
115
  def reboot(options = {})
116
- options = { :force => false }.merge(options)
116
+ options = { force: false }.merge(options)
117
117
  requires :instance_uuid
118
118
  service.vm_reboot('instance_uuid' => instance_uuid, 'force' => options[:force])
119
119
  end
@@ -129,15 +129,15 @@ module Fog
129
129
  end
130
130
 
131
131
  def migrate(options = {})
132
- options = { :priority => 'defaultPriority' }.merge(options)
132
+ options = { priority: 'defaultPriority' }.merge(options)
133
133
  requires :instance_uuid
134
134
 
135
135
  # Convert symbols to strings
136
- req_options = options.reduce({}) { |hsh, (k,v)| hsh[k.to_s] = v; hsh }
136
+ req_options = options.each_with_object({}) { |(k, v), hsh| hsh[k.to_s] = v; }
137
137
  req_options['cluster'] ||= cluster
138
- req_options['datacenter'] = "#{datacenter}"
138
+ req_options['datacenter'] = datacenter.to_s
139
139
  req_options['instance_uuid'] = instance_uuid
140
-
140
+
141
141
  service.vm_migrate(req_options)
142
142
  end
143
143
 
@@ -152,22 +152,22 @@ module Fog
152
152
  requires :name, :datacenter, :path
153
153
 
154
154
  # Convert symbols to strings
155
- req_options = options.reduce({}) { |hsh, (k,v)| hsh[k.to_s] = v; hsh }
155
+ req_options = options.each_with_object({}) { |(k, v), hsh| hsh[k.to_s] = v; }
156
156
 
157
157
  # Give our path to the request
158
- req_options['template_path'] ="#{relative_path}/#{name}"
159
- req_options['datacenter'] = "#{datacenter}"
158
+ req_options['template_path'] = "#{relative_path}/#{name}"
159
+ req_options['datacenter'] = datacenter.to_s
160
160
 
161
161
  # Perform the actual clone
162
162
  clone_results = service.vm_clone(req_options)
163
163
 
164
164
  # We need to assign the service, otherwise we can't reload the model
165
165
  # Create the new VM model. TODO This only works when "wait=true"
166
- new_vm = self.class.new(clone_results['new_vm'].merge(:service => self.service))
166
+ new_vm = self.class.new(clone_results['new_vm'].merge(service: service))
167
167
 
168
168
  # We need to assign the collection otherwise we
169
169
  # cannot reload the model.
170
- new_vm.collection = self.collection
170
+ new_vm.collection = collection
171
171
 
172
172
  # Return the new VM model.
173
173
  new_vm
@@ -179,7 +179,7 @@ module Fog
179
179
  end
180
180
 
181
181
  def ready?
182
- power_state == "poweredOn"
182
+ power_state == 'poweredOn'
183
183
  end
184
184
 
185
185
  def tools_installed?
@@ -187,7 +187,7 @@ module Fog
187
187
  end
188
188
 
189
189
  def tools_running?
190
- ["toolsOk","toolsOld"].include? tools_state
190
+ %w[toolsOk toolsOld].include? tools_state
191
191
  end
192
192
 
193
193
  # defines VNC attributes on the hypervisor
@@ -215,36 +215,36 @@ module Fog
215
215
  end
216
216
 
217
217
  def interfaces
218
- attributes[:interfaces] ||= id.nil? ? [] : service.interfaces( :server_id => self.id )
218
+ attributes[:interfaces] ||= id.nil? ? [] : service.interfaces(server_id: id)
219
219
  end
220
220
 
221
- def interface_ready? attrs
222
- (attrs.is_a? Hash and attrs[:blocking]) or attrs.is_a? Fog::Compute::Vsphere::Interface
221
+ def interface_ready?(attrs)
222
+ (attrs.is_a?(Hash) && attrs[:blocking]) || attrs.is_a?(Fog::Compute::Vsphere::Interface)
223
223
  end
224
224
 
225
- def add_interface attrs
226
- Fog::Logger.deprecation("<server>.add_interface is deprecated. Call <server>.interfaces.create instead.")
225
+ def add_interface(attrs)
226
+ Fog::Logger.deprecation('<server>.add_interface is deprecated. Call <server>.interfaces.create instead.')
227
227
 
228
228
  interfaces.create(attrs)
229
229
  end
230
230
 
231
- def update_interface attrs
232
- wait_for { not ready? } if interface_ready? attrs
231
+ def update_interface(attrs)
232
+ wait_for { !ready? } if interface_ready? attrs
233
233
  service.update_vm_interface(id, attrs)
234
234
  end
235
235
 
236
- def destroy_interface attrs
237
- Fog::Logger.deprecation("<server>.destroy_vm_interface is deprecated. Call <server>.interfaces.get(:key => <nic_key>).destroy instead.")
236
+ def destroy_interface(attrs)
237
+ Fog::Logger.deprecation('<server>.destroy_vm_interface is deprecated. Call <server>.interfaces.get(:key => <nic_key>).destroy instead.')
238
238
 
239
239
  interfaces.get(attrs[:key] || attrs['key']).destroy
240
240
  end
241
241
 
242
242
  def volumes
243
- attributes[:volumes] ||= id.nil? ? [] : service.volumes(:server_id => self.id)
243
+ attributes[:volumes] ||= id.nil? ? [] : service.volumes(server_id: id)
244
244
  end
245
245
 
246
246
  def snapshots(opts = {})
247
- service.snapshots(:server_id => self.id).all(opts)
247
+ service.snapshots(server_id: id).all(opts)
248
248
  end
249
249
 
250
250
  def find_snapshot(snapshot_ref)
@@ -258,12 +258,12 @@ module Fog
258
258
  when String
259
259
  service.revert_to_snapshot(find_snapshot(snapshot))
260
260
  else
261
- fail ArgumentError, "snapshot has to be kind of Snapshot or String class"
261
+ raise ArgumentError, 'snapshot has to be kind of Snapshot or String class'
262
262
  end
263
263
  end
264
264
 
265
265
  def cdroms(opts = {})
266
- service.cdroms(:instance_uuid => self.id).all(opts)
266
+ service.cdroms(instance_uuid: id).all(opts)
267
267
  end
268
268
 
269
269
  def cdrom(key)
@@ -271,16 +271,16 @@ module Fog
271
271
  end
272
272
 
273
273
  def guest_processes(opts = {})
274
- fail 'VM tools must be running' unless tools_running?
275
- service.list_processes(self.id, opts)
274
+ raise 'VM tools must be running' unless tools_running?
275
+ service.list_processes(id, opts)
276
276
  end
277
277
 
278
278
  def customvalues
279
- attributes[:customvalues] ||= id.nil? ? [] : service.customvalues( :vm => self )
279
+ attributes[:customvalues] ||= id.nil? ? [] : service.customvalues(vm: self)
280
280
  end
281
281
 
282
282
  def scsi_controllers
283
- self.attributes[:scsi_controllers] ||= service.list_vm_scsi_controllers(id)
283
+ attributes[:scsi_controllers] ||= service.list_vm_scsi_controllers(id)
284
284
  end
285
285
 
286
286
  def scsi_controller
@@ -288,21 +288,17 @@ module Fog
288
288
  end
289
289
 
290
290
  def folder
291
- return nil unless datacenter and path
292
- attributes[:folder] ||= service.folders(:datacenter => datacenter, :type => :vm).get(path)
291
+ return nil unless datacenter && path
292
+ attributes[:folder] ||= service.folders(datacenter: datacenter, type: :vm).get(path)
293
293
  end
294
294
 
295
295
  def save
296
296
  requires :name, :cluster, :datacenter
297
297
  if persisted?
298
- vm_rename if attribute_changed?(:name)
299
- vm_reconfig_cpus if attribute_changed?(:cpus) || attribute_changed?(:corespersocket)
300
- vm_reconfig_memory if attribute_changed?(:memory_mb)
301
- vm_reconfig_volumes if attribute_changed?(:volumes)
298
+ service.update_vm(self)
302
299
  else
303
300
  self.id = service.create_vm(attributes)
304
301
  end
305
- @old = nil
306
302
  reload
307
303
  end
308
304
 
@@ -312,8 +308,8 @@ module Fog
312
308
 
313
309
  def reload
314
310
  # reload does not re-read assoiciated attributes, so we clear it manually
315
- [:interfaces, :volumes].each do |attr|
316
- self.attributes.delete(attr)
311
+ %i[interfaces volumes].each do |attr|
312
+ attributes.delete(attr)
317
313
  end
318
314
  super
319
315
  end
@@ -321,67 +317,59 @@ module Fog
321
317
  def relative_path
322
318
  requires :path, :datacenter
323
319
 
324
- (path.split('/').reject {|e| e.empty?} - ["Datacenters", datacenter, "vm"]).join("/")
320
+ (path.split('/').reject(&:empty?) - ['Datacenters', datacenter, 'vm']).join('/')
325
321
  end
326
322
 
327
- def acquire_ticket(type = nil)
328
- service.tickets(:server => self).create
323
+ def acquire_ticket(_type = nil)
324
+ service.tickets(server: self).create
329
325
  end
330
326
 
331
327
  private
332
328
 
333
329
  def defaults
334
330
  {
335
- :cpus => 1,
336
- # :corespersocket => 1,
337
- :memory_mb => 512,
338
- :guest_id => 'otherGuest',
339
- :path => '/'
331
+ cpus: 1,
332
+ # :corespersocket => 1,
333
+ memory_mb: 512,
334
+ guest_id: 'otherGuest',
335
+ path: '/'
340
336
  }
341
337
  end
342
338
 
343
339
  def initialize_interfaces
344
- if attributes[:interfaces] and attributes[:interfaces].is_a?(Array)
345
- self.attributes[:interfaces].map! { |nic| nic.is_a?(Hash) ? service.interfaces.new(nic) : nic }
340
+ if attributes[:interfaces] && attributes[:interfaces].is_a?(Array)
341
+ attributes[:interfaces].map! { |nic| nic.is_a?(Hash) ? service.interfaces.new(nic) : nic }
346
342
  end
347
343
  end
348
344
 
349
345
  def initialize_volumes
350
- if attributes[:volumes] and attributes[:volumes].is_a?(Array)
351
- self.attributes[:volumes].map! { |vol| vol.is_a?(Hash) ? service.volumes.new({:server => self}.merge(vol)) : vol }
346
+ if attributes[:volumes] && attributes[:volumes].is_a?(Array)
347
+ attributes[:volumes].map! { |vol| vol.is_a?(Hash) ? service.volumes.new({ server: self }.merge(vol)) : vol }
352
348
  end
353
349
  end
354
350
 
355
351
  def initialize_customvalues
356
- if attributes[:customvalues] and attributes[:customvalues].is_a?(Array)
357
- self.attributes[:customvalues].map { |cfield| cfield.is_a?(Hash) ? service.customvalue.new(cfield) : cfield}
352
+ if attributes[:customvalues] && attributes[:customvalues].is_a?(Array)
353
+ attributes[:customvalues].map { |cfield| cfield.is_a?(Hash) ? service.customvalue.new(cfield) : cfield }
358
354
  end
359
355
  end
360
356
 
361
357
  def initialize_scsi_controllers
362
358
  if attributes[:scsi_controllers] && attributes[:scsi_controllers].is_a?(Array)
363
- self.attributes[:scsi_controllers].map! do |controller|
359
+ attributes[:scsi_controllers].map! do |controller|
364
360
  controller.is_a?(Hash) ? Fog::Compute::Vsphere::SCSIController.new(controller) : controller
365
361
  end
366
362
  elsif attributes[:scsi_controller] && attributes[:scsi_controller].is_a?(Hash)
367
- self.attributes[:scsi_controllers] = [
368
- Fog::Compute::Vsphere::SCSIController.new(self.attributes[:scsi_controller])
363
+ attributes[:scsi_controllers] = [
364
+ Fog::Compute::Vsphere::SCSIController.new(attributes[:scsi_controller])
369
365
  ]
370
366
  elsif attributes[:volumes] && attributes[:volumes].is_a?(Array) && !attributes[:volumes].empty?
371
367
  # Create a default scsi controller if there are any disks but no controller defined
372
- self.attributes[:scsi_controllers] = [
368
+ attributes[:scsi_controllers] = [
373
369
  Fog::Compute::Vsphere::SCSIController.new
374
370
  ]
375
371
  end
376
372
  end
377
-
378
- def attribute_changed?(attr)
379
- self.attributes.select { |k, v| old.attributes[k] != v }.key?(attr)
380
- end
381
-
382
- def old
383
- @old ||= self.dup.reload
384
- end
385
373
  end
386
374
  end
387
375
  end