lib/fog/vcloud_director/models/compute/vm.rb in fog-maestrodev-1.15.0.20130927082724 vs lib/fog/vcloud_director/models/compute/vm.rb in fog-maestrodev-1.18.0.20131111203459
- old
+ new
@@ -15,11 +15,11 @@
attribute :href
attribute :status
attribute :operating_system
attribute :ip_address
attribute :cpu, :type => :integer
- attribute :memory
+ attribute :memory, :type => :integer
attribute :hard_disks, :aliases => :disks
def reload
# when collection.vapp is nil, it means it's fatherless,
# vms from different vapps are loaded in the same collection.
@@ -40,32 +40,96 @@
new_attributes = data.attributes
merge_attributes(new_attributes)
self
end
+ # Power off the VM.
+ def power_off
+ requires :id
+ begin
+ response = service.post_power_off_vapp(id)
+ rescue Fog::Compute::VcloudDirector::BadRequest => ex
+ Fog::Logger.debug(ex.message)
+ return false
+ end
+ service.process_task(response.body)
+ end
+ # Power on the VM.
def power_on
- response = service.post_vm_poweron(id)
+ requires :id
+ begin
+ response = service.post_power_on_vapp(id)
+ rescue Fog::Compute::VcloudDirector::BadRequest => ex
+ Fog::Logger.debug(ex.message)
+ return false
+ end
service.process_task(response.body)
end
- def power_off
- response = service.post_vm_poweroff(id)
+
+ # Reboot the VM.
+ def reboot
+ requires :id
+ begin
+ response = service.post_reboot_vapp(id)
+ rescue Fog::Compute::VcloudDirector::BadRequest => ex
+ Fog::Logger.debug(ex.message)
+ return false
+ end
service.process_task(response.body)
end
+ # Reset the VM.
+ def reset
+ requires :id
+ begin
+ response = service.post_reset_vapp(id)
+ rescue Fog::Compute::VcloudDirector::BadRequest => ex
+ Fog::Logger.debug(ex.message)
+ return false
+ end
+ service.process_task(response.body)
+ end
+
+ # Shut down the VM.
+ def shutdown
+ requires :id
+ begin
+ response = service.post_shutdown_vapp(id)
+ rescue Fog::Compute::VcloudDirector::BadRequest => ex
+ Fog::Logger.debug(ex.message)
+ return false
+ end
+ service.process_task(response.body)
+ end
+
+ # Suspend the VM.
+ def suspend
+ requires :id
+ begin
+ response = service.post_suspend_vapp(id)
+ rescue Fog::Compute::VcloudDirector::BadRequest => ex
+ Fog::Logger.debug(ex.message)
+ return false
+ end
+ service.process_task(response.body)
+ end
+
def tags
requires :id
service.tags(:vm => self)
end
def customization
+ requires :id
data = service.get_vm_customization(id).body
service.vm_customizations.new(data)
end
def network
+ requires :id
data = service.get_vm_network(id).body
service.vm_networks.new(data)
end
def disks
@@ -76,22 +140,32 @@
def memory=(new_memory)
has_changed = ( memory != new_memory.to_i )
not_first_set = !memory.nil?
attributes[:memory] = new_memory.to_i
if not_first_set && has_changed
- response = service.put_vm_memory(id, memory)
+ response = service.put_memory(id, memory)
service.process_task(response.body)
end
end
def cpu=(new_cpu)
has_changed = ( cpu != new_cpu.to_i )
not_first_set = !cpu.nil?
attributes[:cpu] = new_cpu.to_i
if not_first_set && has_changed
- response = service.put_vm_cpu(id, cpu)
+ response = service.put_cpu(id, cpu)
service.process_task(response.body)
end
+ end
+
+ def ready?
+ reload
+ status == 'on'
+ end
+
+ def vapp
+ # get_by_metadata returns a vm collection where every vapp parent is orpahn
+ collection.vapp ||= service.vapps.get(vapp_id)
end
end
end
end