fog-vsphere 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.travis.yml +32 -0
  4. data/CONTRIBUTING.md +18 -0
  5. data/CONTRIBUTORS.md +59 -0
  6. data/Gemfile +5 -0
  7. data/LICENSE.md +20 -0
  8. data/README.md +31 -0
  9. data/Rakefile +8 -0
  10. data/fog-vsphere.gemspec +32 -0
  11. data/gemfiles/Gemfile.1.9.2+ +8 -0
  12. data/gemfiles/Gemfile.1.9.2- +11 -0
  13. data/lib/fog/vsphere.rb +41 -0
  14. data/lib/fog/vsphere/compute.rb +473 -0
  15. data/lib/fog/vsphere/models/compute/cluster.rb +28 -0
  16. data/lib/fog/vsphere/models/compute/clusters.rb +22 -0
  17. data/lib/fog/vsphere/models/compute/customfield.rb +16 -0
  18. data/lib/fog/vsphere/models/compute/customfields.rb +23 -0
  19. data/lib/fog/vsphere/models/compute/customvalue.rb +14 -0
  20. data/lib/fog/vsphere/models/compute/customvalues.rb +33 -0
  21. data/lib/fog/vsphere/models/compute/datacenter.rb +44 -0
  22. data/lib/fog/vsphere/models/compute/datacenters.rb +19 -0
  23. data/lib/fog/vsphere/models/compute/datastore.rb +21 -0
  24. data/lib/fog/vsphere/models/compute/datastores.rb +21 -0
  25. data/lib/fog/vsphere/models/compute/folder.rb +24 -0
  26. data/lib/fog/vsphere/models/compute/folders.rb +23 -0
  27. data/lib/fog/vsphere/models/compute/interface.rb +91 -0
  28. data/lib/fog/vsphere/models/compute/interfaces.rb +66 -0
  29. data/lib/fog/vsphere/models/compute/interfacetype.rb +22 -0
  30. data/lib/fog/vsphere/models/compute/interfacetypes.rb +34 -0
  31. data/lib/fog/vsphere/models/compute/network.rb +18 -0
  32. data/lib/fog/vsphere/models/compute/networks.rb +22 -0
  33. data/lib/fog/vsphere/models/compute/process.rb +17 -0
  34. data/lib/fog/vsphere/models/compute/resource_pool.rb +19 -0
  35. data/lib/fog/vsphere/models/compute/resource_pools.rb +22 -0
  36. data/lib/fog/vsphere/models/compute/scsicontroller.rb +16 -0
  37. data/lib/fog/vsphere/models/compute/server.rb +325 -0
  38. data/lib/fog/vsphere/models/compute/servers.rb +36 -0
  39. data/lib/fog/vsphere/models/compute/servertype.rb +36 -0
  40. data/lib/fog/vsphere/models/compute/servertypes.rb +23 -0
  41. data/lib/fog/vsphere/models/compute/snapshot.rb +35 -0
  42. data/lib/fog/vsphere/models/compute/snapshots.rb +27 -0
  43. data/lib/fog/vsphere/models/compute/template.rb +11 -0
  44. data/lib/fog/vsphere/models/compute/templates.rb +19 -0
  45. data/lib/fog/vsphere/models/compute/volume.rb +99 -0
  46. data/lib/fog/vsphere/models/compute/volumes.rb +53 -0
  47. data/lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb +65 -0
  48. data/lib/fog/vsphere/requests/compute/create_folder.rb +22 -0
  49. data/lib/fog/vsphere/requests/compute/create_vm.rb +169 -0
  50. data/lib/fog/vsphere/requests/compute/current_time.rb +18 -0
  51. data/lib/fog/vsphere/requests/compute/get_cluster.rb +25 -0
  52. data/lib/fog/vsphere/requests/compute/get_compute_resource.rb +41 -0
  53. data/lib/fog/vsphere/requests/compute/get_datacenter.rb +31 -0
  54. data/lib/fog/vsphere/requests/compute/get_datastore.rb +30 -0
  55. data/lib/fog/vsphere/requests/compute/get_folder.rb +74 -0
  56. data/lib/fog/vsphere/requests/compute/get_interface_type.rb +15 -0
  57. data/lib/fog/vsphere/requests/compute/get_network.rb +59 -0
  58. data/lib/fog/vsphere/requests/compute/get_resource_pool.rb +26 -0
  59. data/lib/fog/vsphere/requests/compute/get_server_type.rb +32 -0
  60. data/lib/fog/vsphere/requests/compute/get_template.rb +16 -0
  61. data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +57 -0
  62. data/lib/fog/vsphere/requests/compute/get_vm_first_scsi_controller.rb +26 -0
  63. data/lib/fog/vsphere/requests/compute/list_child_snapshots.rb +71 -0
  64. data/lib/fog/vsphere/requests/compute/list_clusters.rb +72 -0
  65. data/lib/fog/vsphere/requests/compute/list_compute_resources.rb +92 -0
  66. data/lib/fog/vsphere/requests/compute/list_customfields.rb +21 -0
  67. data/lib/fog/vsphere/requests/compute/list_datacenters.rb +53 -0
  68. data/lib/fog/vsphere/requests/compute/list_datastores.rb +40 -0
  69. data/lib/fog/vsphere/requests/compute/list_folders.rb +44 -0
  70. data/lib/fog/vsphere/requests/compute/list_interface_types.rb +25 -0
  71. data/lib/fog/vsphere/requests/compute/list_networks.rb +38 -0
  72. data/lib/fog/vsphere/requests/compute/list_processes.rb +40 -0
  73. data/lib/fog/vsphere/requests/compute/list_resource_pools.rb +38 -0
  74. data/lib/fog/vsphere/requests/compute/list_server_types.rb +54 -0
  75. data/lib/fog/vsphere/requests/compute/list_templates.rb +48 -0
  76. data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +80 -0
  77. data/lib/fog/vsphere/requests/compute/list_vm_customvalues.rb +20 -0
  78. data/lib/fog/vsphere/requests/compute/list_vm_interfaces.rb +63 -0
  79. data/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb +66 -0
  80. data/lib/fog/vsphere/requests/compute/list_vm_volumes.rb +52 -0
  81. data/lib/fog/vsphere/requests/compute/modify_vm_interface.rb +59 -0
  82. data/lib/fog/vsphere/requests/compute/modify_vm_volume.rb +25 -0
  83. data/lib/fog/vsphere/requests/compute/revert_to_snapshot.rb +30 -0
  84. data/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb +17 -0
  85. data/lib/fog/vsphere/requests/compute/vm_clone.rb +727 -0
  86. data/lib/fog/vsphere/requests/compute/vm_config_vnc.rb +45 -0
  87. data/lib/fog/vsphere/requests/compute/vm_destroy.rb +23 -0
  88. data/lib/fog/vsphere/requests/compute/vm_execute.rb +47 -0
  89. data/lib/fog/vsphere/requests/compute/vm_migrate.rb +33 -0
  90. data/lib/fog/vsphere/requests/compute/vm_power_off.rb +39 -0
  91. data/lib/fog/vsphere/requests/compute/vm_power_on.rb +26 -0
  92. data/lib/fog/vsphere/requests/compute/vm_reboot.rb +31 -0
  93. data/lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb +23 -0
  94. data/lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb +24 -0
  95. data/lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb +23 -0
  96. data/lib/fog/vsphere/requests/compute/vm_take_snapshot.rb +37 -0
  97. data/lib/fog/vsphere/version.rb +5 -0
  98. data/tests/compute_tests.rb +53 -0
  99. data/tests/helper.rb +8 -0
  100. data/tests/helpers/mock_helper.rb +9 -0
  101. data/tests/helpers/succeeds_helper.rb +9 -0
  102. data/tests/models/compute/server_tests.rb +70 -0
  103. data/tests/models/compute/servers_tests.rb +15 -0
  104. data/tests/requests/compute/current_time_tests.rb +12 -0
  105. data/tests/requests/compute/get_network_tests.rb +50 -0
  106. data/tests/requests/compute/list_child_snapshots_tests.rb +10 -0
  107. data/tests/requests/compute/list_clusters_tests.rb +11 -0
  108. data/tests/requests/compute/list_virtual_machines_tests.rb +38 -0
  109. data/tests/requests/compute/list_vm_snapshots_tests.rb +10 -0
  110. data/tests/requests/compute/revert_to_snapshot_tests.rb +15 -0
  111. data/tests/requests/compute/set_vm_customvalue_tests.rb +20 -0
  112. data/tests/requests/compute/vm_clone_tests.rb +50 -0
  113. data/tests/requests/compute/vm_config_vnc_tests.rb +19 -0
  114. data/tests/requests/compute/vm_destroy_tests.rb +17 -0
  115. data/tests/requests/compute/vm_migrate_tests.rb +16 -0
  116. data/tests/requests/compute/vm_power_off_tests.rb +26 -0
  117. data/tests/requests/compute/vm_power_on_tests.rb +17 -0
  118. data/tests/requests/compute/vm_reboot_tests.rb +26 -0
  119. data/tests/requests/compute/vm_reconfig_cpus_tests.rb +19 -0
  120. data/tests/requests/compute/vm_reconfig_hardware_tests.rb +19 -0
  121. data/tests/requests/compute/vm_reconfig_memory_tests.rb +19 -0
  122. data/tests/requests/compute/vm_take_snapshot_tests.rb +19 -0
  123. metadata +289 -0
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Interfacetype < Fog::Model
5
+ identity :id
6
+
7
+ # attribute :class
8
+ attribute :name
9
+ attribute :datacenter
10
+ attribute :servertype
11
+
12
+ def initialize(attributes={} )
13
+ super attributes
14
+ end
15
+
16
+ def to_s
17
+ name
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Interfacetypes < Fog::Collection
5
+ autoload :Interfacetype, File.expand_path('../interfacetype', __FILE__)
6
+
7
+ model Fog::Compute::Vsphere::Interfacetype
8
+ attr_accessor :datacenter
9
+ attr_accessor :servertype
10
+
11
+ def all(filters = { })
12
+ requires :servertype
13
+ case servertype
14
+ when Fog::Compute::Vsphere::Servertype
15
+ load service.list_interface_types(filters.merge({
16
+ :datacenter => datacenter,
17
+ :servertype => servertype.id
18
+ }))
19
+ else
20
+ raise 'interfacetypes should have a servertype'
21
+ end
22
+ end
23
+
24
+ def get(id)
25
+ requires :servertype
26
+ requires :datacenter
27
+ new service.get_interface_type id, servertype, datacenter
28
+ rescue Fog::Compute::Vsphere::NotFound
29
+ nil
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Network < Fog::Model
5
+ identity :id
6
+
7
+ attribute :name
8
+ attribute :datacenter
9
+ attribute :accessible # reachable by at least one hypervisor
10
+ attribute :virtualswitch
11
+
12
+ def to_s
13
+ name
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Networks < Fog::Collection
5
+ autoload :Network, File.expand_path('../network', __FILE__)
6
+
7
+ model Fog::Compute::Vsphere::Network
8
+ attr_accessor :datacenter
9
+
10
+ def all(filters = {})
11
+ f = { :datacenter => datacenter }.merge(filters)
12
+ load service.list_networks(f)
13
+ end
14
+
15
+ def get(id)
16
+ requires :datacenter
17
+ new service.get_network(id, datacenter)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ require 'fog/compute/models/server'
2
+
3
+ module Fog
4
+ module Compute
5
+ class Vsphere
6
+ class Process < Fog::Model
7
+ attribute :cmd_line
8
+ attribute :end_time
9
+ attribute :exit_code
10
+ attribute :name
11
+ attribute :owner
12
+ attribute :pid
13
+ attribute :start_time
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class ResourcePool < Fog::Model
5
+ identity :id
6
+
7
+ attribute :name
8
+ attribute :cluster
9
+ attribute :datacenter
10
+ attribute :configured_memory_mb
11
+ attribute :overall_status
12
+
13
+ def to_s
14
+ name
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class ResourcePools < Fog::Collection
5
+ autoload :ResourcePool, File.expand_path('../resource_pool', __FILE__)
6
+
7
+ model Fog::Compute::Vsphere::ResourcePool
8
+ attr_accessor :datacenter, :cluster
9
+
10
+ def all(filters = {})
11
+ load service.list_resource_pools(filters.merge(:datacenter => datacenter, :cluster => cluster))
12
+ end
13
+
14
+ def get(id)
15
+ requires :datacenter
16
+ requires :cluster
17
+ new service.get_resource_pool(id, cluster, datacenter)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class SCSIController < Fog::Model
5
+ attribute :shared_bus
6
+ attribute :type
7
+ attribute :unit_number
8
+ attribute :key
9
+
10
+ def to_s
11
+ "#{type} ##{key}: shared: #{shared_bus}, unit_number: #{unit_number}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,325 @@
1
+ require 'fog/compute/models/server'
2
+
3
+ module Fog
4
+ module Compute
5
+ class Vsphere
6
+ class Server < Fog::Compute::Server
7
+ extend Fog::Deprecation
8
+ deprecate(:ipaddress, :public_ip_address)
9
+
10
+ # This will be the instance uuid which is globally unique across
11
+ # a vSphere deployment.
12
+ identity :id
13
+
14
+ # JJM REVISIT (Extend the model of a vmware server)
15
+ # SEE: http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.VirtualMachine.html
16
+ # (Take note of the See also section.)
17
+ # In particular:
18
+ # GuestInfo: information about the guest operating system
19
+ # VirtualMachineConfigInfo: Access to the VMX file and configuration
20
+
21
+ attribute :name
22
+ # UUID may be the same from VM to VM if the user does not select (I copied it)
23
+ attribute :uuid
24
+ attribute :hostname
25
+ attribute :operatingsystem
26
+ attribute :public_ip_address, :aliases => 'ipaddress'
27
+ attribute :power_state, :aliases => 'power'
28
+ attribute :tools_state, :aliases => 'tools'
29
+ attribute :tools_version
30
+ attribute :mac_addresses, :aliases => 'macs'
31
+ attribute :hypervisor, :aliases => 'host'
32
+ attribute :connection_state
33
+ attribute :mo_ref
34
+ attribute :path
35
+ attribute :memory_mb
36
+ attribute :cpus
37
+ attribute :corespersocket
38
+ attribute :interfaces
39
+ attribute :volumes
40
+ attribute :customvalues
41
+ attribute :overall_status, :aliases => 'status'
42
+ attribute :cluster
43
+ attribute :datacenter
44
+ attribute :resource_pool
45
+ attribute :instance_uuid # move this --> id
46
+ attribute :guest_id
47
+ attribute :hardware_version
48
+ attribute :scsi_controller # this is the first scsi controller. Right now no more of them can be used.
49
+ attribute :cpuHotAddEnabled
50
+ attribute :memoryHotAddEnabled
51
+ attribute :firmware
52
+
53
+ def initialize(attributes={} )
54
+ super defaults.merge(attributes)
55
+ self.instance_uuid ||= id # TODO: remvoe instance_uuid as it can be replaced with simple id
56
+ initialize_interfaces
57
+ initialize_volumes
58
+ initialize_customvalues
59
+ initialize_scsi_controller
60
+ end
61
+
62
+ # Lazy Loaded Attributes
63
+ [:datacenter, :cluster, :hypervisor, :resource_pool, :mac_addresses].each do |attr|
64
+ define_method attr do
65
+ attributes[attr] = attributes[attr].call if attributes[attr].is_a?(Proc)
66
+ attributes[attr]
67
+ end
68
+ end
69
+ # End Lazy Loaded Attributes
70
+
71
+ def vm_reconfig_memory(options = {})
72
+ requires :instance_uuid, :memory
73
+ service.vm_reconfig_memory('instance_uuid' => instance_uuid, 'memory' => memory_mb)
74
+ end
75
+
76
+ def vm_reconfig_cpus(options = {})
77
+ requires :instance_uuid, :cpus, :corespersocket
78
+ service.vm_reconfig_cpus('instance_uuid' => instance_uuid, 'cpus' => cpus, 'corespersocket' => corespersocket)
79
+ end
80
+
81
+ def vm_reconfig_hardware(hardware_spec, options = {})
82
+ requires :instance_uuid
83
+ service.vm_reconfig_hardware('instance_uuid' => instance_uuid, 'hardware_spec' => hardware_spec)
84
+ end
85
+
86
+ def start(options = {})
87
+ requires :instance_uuid
88
+ service.vm_power_on('instance_uuid' => instance_uuid)
89
+ end
90
+
91
+ def stop(options = {})
92
+ options = { :force => !tools_installed? || !tools_running? }.merge(options)
93
+ requires :instance_uuid
94
+ service.vm_power_off('instance_uuid' => instance_uuid, 'force' => options[:force])
95
+ end
96
+
97
+ def reboot(options = {})
98
+ options = { :force => false }.merge(options)
99
+ requires :instance_uuid
100
+ service.vm_reboot('instance_uuid' => instance_uuid, 'force' => options[:force])
101
+ end
102
+
103
+ def destroy(options = {})
104
+ requires :instance_uuid
105
+ if ready?
106
+ # need to turn it off before destroying
107
+ stop(options)
108
+ wait_for { !ready? }
109
+ end
110
+ service.vm_destroy('instance_uuid' => instance_uuid)
111
+ end
112
+
113
+ def migrate(options = {})
114
+ options = { :priority => 'defaultPriority' }.merge(options)
115
+ requires :instance_uuid
116
+ service.vm_migrate('instance_uuid' => instance_uuid, 'priority' => options[:priority])
117
+ end
118
+
119
+ # Clone from a server object
120
+ #
121
+ # ==== Parameters
122
+ # *<~Hash>:
123
+ # * 'name'<~String> - *REQUIRED* Name of the _new_ VirtualMachine
124
+ # * See more options in vm_clone request/compute/vm_clone.rb
125
+ #
126
+ def clone(options = {})
127
+ requires :name, :datacenter, :path
128
+
129
+ # Convert symbols to strings
130
+ req_options = options.reduce({}) { |hsh, (k,v)| hsh[k.to_s] = v; hsh }
131
+
132
+ # Give our path to the request
133
+ req_options['template_path'] ="#{relative_path}/#{name}"
134
+ req_options['datacenter'] = "#{datacenter}"
135
+
136
+ # Perform the actual clone
137
+ clone_results = service.vm_clone(req_options)
138
+
139
+ # We need to assign the service, otherwise we can't reload the model
140
+ # Create the new VM model. TODO This only works when "wait=true"
141
+ new_vm = self.class.new(clone_results['new_vm'].merge(:service => self.service))
142
+
143
+ # We need to assign the collection otherwise we
144
+ # cannot reload the model.
145
+ new_vm.collection = self.collection
146
+
147
+ # Return the new VM model.
148
+ new_vm
149
+ end
150
+
151
+ def take_snapshot(options = {})
152
+ requires :instance_uuid
153
+ service.vm_take_snapshot(options.merge('instance_uuid' => instance_uuid))
154
+ end
155
+
156
+ def ready?
157
+ power_state == "poweredOn"
158
+ end
159
+
160
+ def tools_installed?
161
+ tools_state != "toolsNotInstalled"
162
+ end
163
+
164
+ def tools_running?
165
+ ["toolsOk","toolsOld"].include? tools_state
166
+ end
167
+
168
+ # defines VNC attributes on the hypervisor
169
+ def config_vnc(options = {})
170
+ requires :instance_uuid
171
+ service.vm_config_vnc(options.merge('instance_uuid' => instance_uuid))
172
+ end
173
+
174
+ # returns a hash of VNC attributes required for service
175
+ def vnc
176
+ requires :instance_uuid
177
+ service.vm_get_vnc(instance_uuid)
178
+ end
179
+
180
+ def memory
181
+ memory_mb * 1024 * 1024
182
+ end
183
+
184
+ def sockets
185
+ cpus / corespersocket
186
+ end
187
+
188
+ def mac
189
+ interfaces.first.mac unless interfaces.empty?
190
+ end
191
+
192
+ def interfaces
193
+ attributes[:interfaces] ||= id.nil? ? [] : service.interfaces( :server_id => self.id )
194
+ end
195
+
196
+ def interface_ready? attrs
197
+ (attrs.is_a? Hash and attrs[:blocking]) or attrs.is_a? Fog::Compute::Vsphere::Interface
198
+ end
199
+
200
+ def add_interface attrs
201
+ Fog::Logger.deprecation("<server>.add_interface is deprecated. Call <server>.interfaces.create instead.")
202
+
203
+ interfaces.create(attrs)
204
+ end
205
+
206
+ def update_interface attrs
207
+ wait_for { not ready? } if interface_ready? attrs
208
+ service.update_vm_interface(id, attrs)
209
+ end
210
+
211
+ def destroy_interface attrs
212
+ Fog::Logger.deprecation("<server>.destroy_vm_interface is deprecated. Call <server>.interfaces.get(:key => <nic_key>).destroy instead.")
213
+
214
+ interfaces.get(attrs[:key] || attrs['key']).destroy
215
+ end
216
+
217
+ def volumes
218
+ attributes[:volumes] ||= id.nil? ? [] : service.volumes(:server_id => self.id)
219
+ end
220
+
221
+ def snapshots(opts = {})
222
+ service.snapshots(:server_id => self.id).all(opts)
223
+ end
224
+
225
+ def find_snapshot(snapshot_ref)
226
+ snapshots.get(snapshot_ref)
227
+ end
228
+
229
+ def revert_snapshot(snapshot)
230
+ case snapshot
231
+ when Snapshot
232
+ service.revert_to_snapshot(snapshot)
233
+ when String
234
+ service.revert_to_snapshot(find_snapshot(snapshot))
235
+ else
236
+ fail ArgumentError, "snapshot has to be kind of Snapshot or String class"
237
+ end
238
+ end
239
+
240
+ def guest_processes(opts = {})
241
+ fail 'VM tools must be running' unless tools_running?
242
+ service.list_processes(self.id, opts)
243
+ end
244
+
245
+ def customvalues
246
+ attributes[:customvalues] ||= id.nil? ? [] : service.customvalues( :vm => self )
247
+ end
248
+
249
+ def scsi_controller
250
+ self.attributes[:scsi_controller] ||= service.get_vm_first_scsi_controller(id)
251
+ end
252
+
253
+ def folder
254
+ return nil unless datacenter and path
255
+ attributes[:folder] ||= service.folders(:datacenter => datacenter, :type => :vm).get(path)
256
+ end
257
+
258
+ def save
259
+ requires :name, :cluster, :datacenter
260
+ if persisted?
261
+ raise "update is not supported yet"
262
+ # service.update_vm(attributes)
263
+ else
264
+ self.id = service.create_vm(attributes)
265
+ end
266
+ reload
267
+ end
268
+
269
+ def new?
270
+ id.nil?
271
+ end
272
+
273
+ def reload
274
+ # reload does not re-read assoiciated attributes, so we clear it manually
275
+ [:interfaces, :volumes].each do |attr|
276
+ self.attributes.delete(attr)
277
+ end
278
+ super
279
+ end
280
+
281
+ def relative_path
282
+ requires :path, :datacenter
283
+
284
+ (path.split('/').reject {|e| e.empty?} - ["Datacenters", datacenter, "vm"]).join("/")
285
+ end
286
+
287
+ private
288
+
289
+ def defaults
290
+ {
291
+ :cpus => 1,
292
+ # :corespersocket => 1,
293
+ :memory_mb => 512,
294
+ :guest_id => 'otherGuest',
295
+ :path => '/'
296
+ }
297
+ end
298
+
299
+ def initialize_interfaces
300
+ if attributes[:interfaces] and attributes[:interfaces].is_a?(Array)
301
+ self.attributes[:interfaces].map! { |nic| nic.is_a?(Hash) ? service.interfaces.new(nic) : nic }
302
+ end
303
+ end
304
+
305
+ def initialize_volumes
306
+ if attributes[:volumes] and attributes[:volumes].is_a?(Array)
307
+ self.attributes[:volumes].map! { |vol| vol.is_a?(Hash) ? service.volumes.new(vol) : vol }
308
+ end
309
+ end
310
+
311
+ def initialize_customvalues
312
+ if attributes[:customvalues] and attributes[:customvalues].is_a?(Array)
313
+ self.attributes[:customvalues].map { |cfield| cfield.is_a?(Hash) ? service.customvalue.new(cfield) : cfield}
314
+ end
315
+ end
316
+
317
+ def initialize_scsi_controller
318
+ if attributes[:scsi_controller] and attributes[:scsi_controller].is_a?(Hash)
319
+ Fog::Compute::Vsphere::SCSIController.new(self.attributes[:scsi_controller])
320
+ end
321
+ end
322
+ end
323
+ end
324
+ end
325
+ end