Class: Fog::Compute::VcloudDirector::Vm
- Defined in:
- lib/fog/vcloud_director/models/compute/vm.rb
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
- #cpu=(new_cpu) ⇒ Object
- #customization ⇒ Object
- #disks ⇒ Object
- #memory=(new_memory) ⇒ Object
- #network ⇒ Object
-
#power_off ⇒ Object
Power off the VM.
-
#power_on ⇒ Object
Power on the VM.
- #ready? ⇒ Boolean
-
#reboot ⇒ Object
Reboot the VM.
- #reload ⇒ Object
- #reload_single_vm ⇒ Object
-
#reset ⇒ Object
Reset the VM.
-
#shutdown ⇒ Object
Shut down the VM.
-
#suspend ⇒ Object
Suspend the VM.
- #tags ⇒ Object
- #vapp ⇒ Object
Methods inherited from Model
#initialize, #inspect, #lazy_load_attrs, #make_attr_loaded_method, #make_lazy_load_method
Methods inherited from Model
#initialize, #inspect, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Fog::Core::DeprecatedConnectionAccessors
#connection, #connection=, #prepare_service_value
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Compute::VcloudDirector::Model
Instance Method Details
#cpu=(new_cpu) ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 150 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_cpu(id, cpu) service.process_task(response.body) end end |
#customization ⇒ Object
123 124 125 126 127 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 123 def customization requires :id data = service.get_vm_customization(id).body service.vm_customizations.new(data) end |
#disks ⇒ Object
135 136 137 138 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 135 def disks requires :id service.disks(:vm => self) end |
#memory=(new_memory) ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 140 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_memory(id, memory) service.process_task(response.body) end end |
#network ⇒ Object
129 130 131 132 133 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 129 def network requires :id data = service.get_vm_network(id).body service.vm_networks.new(data) end |
#power_off ⇒ Object
Power off the VM.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 46 def power_off requires :id begin response = service.post_power_off_vapp(id) rescue Fog::Compute::VcloudDirector::BadRequest => ex Fog::Logger.debug(ex.) return false end service.process_task(response.body) end |
#power_on ⇒ Object
Power on the VM.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 58 def power_on requires :id begin response = service.post_power_on_vapp(id) rescue Fog::Compute::VcloudDirector::BadRequest => ex Fog::Logger.debug(ex.) return false end service.process_task(response.body) end |
#ready? ⇒ Boolean
160 161 162 163 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 160 def ready? reload status == 'on' end |
#reboot ⇒ Object
Reboot the VM.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 71 def reboot requires :id begin response = service.post_reboot_vapp(id) rescue Fog::Compute::VcloudDirector::BadRequest => ex Fog::Logger.debug(ex.) return false end service.process_task(response.body) end |
#reload ⇒ Object
23 24 25 26 27 28 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 23 def reload # when collection.vapp is nil, it means it's fatherless, # vms from different vapps are loaded in the same collection. # This situation comes from a "query" result collection.vapp.nil? ? reload_single_vm : super end |
#reload_single_vm ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 30 def reload_single_vm return unless data = begin collection.get_single_vm(identity) rescue Excon::Errors::SocketError nil end # these two attributes don't exists in the get_single_vm response # that's why i use the old attributes data.attributes[:vapp_id] = attributes[:vapp_id] data.attributes[:vapp_name] = attributes[:vapp_name] new_attributes = data.attributes merge_attributes(new_attributes) self end |
#reset ⇒ Object
Reset the VM.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 83 def reset requires :id begin response = service.post_reset_vapp(id) rescue Fog::Compute::VcloudDirector::BadRequest => ex Fog::Logger.debug(ex.) return false end service.process_task(response.body) end |
#shutdown ⇒ Object
Shut down the VM.
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 95 def shutdown requires :id begin response = service.post_shutdown_vapp(id) rescue Fog::Compute::VcloudDirector::BadRequest => ex Fog::Logger.debug(ex.) return false end service.process_task(response.body) end |
#suspend ⇒ Object
Suspend the VM.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 107 def suspend requires :id begin response = service.post_suspend_vapp(id) rescue Fog::Compute::VcloudDirector::BadRequest => ex Fog::Logger.debug(ex.) return false end service.process_task(response.body) end |
#tags ⇒ Object
118 119 120 121 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 118 def requires :id service.(:vm => self) end |
#vapp ⇒ Object
165 166 167 168 |
# File 'lib/fog/vcloud_director/models/compute/vm.rb', line 165 def vapp # get_by_metadata returns a vm collection where every vapp parent is orpahn collection.vapp ||= service.vapps.get(vapp_id) end |