Class: Fog::Ovirt::Compute::Server
- Inherits:
-
Compute::Server
- Object
- Compute::Server
- Fog::Ovirt::Compute::Server
- Defined in:
- lib/fog/ovirt/models/compute/server.rb
Instance Method Summary collapse
- #add_interface(attrs) ⇒ Object
- #add_to_affinity_group(attrs) ⇒ Object
- #add_volume(attrs) ⇒ Object
- #attach_volume(attrs) ⇒ Object
- #destroy(_options = {}) ⇒ Object
- #destroy_interface(attrs) ⇒ Object
- #destroy_volume(attrs) ⇒ Object
- #detach_volume(attrs) ⇒ Object
- #interfaces ⇒ Object
- #locked? ⇒ Boolean
- #mac ⇒ Object
- #ready? ⇒ Boolean
- #reboot(options = {}) ⇒ Object
- #remove_from_affinity_group(attrs) ⇒ Object
- #save ⇒ Object
- #start(options = {}) ⇒ Object
- #start_with_cloudinit(options = {}) ⇒ Object
- #stop(_options = {}) ⇒ Object
- #stopped? ⇒ Boolean
- #suspend(_options = {}) ⇒ Object
- #ticket(options = {}) ⇒ Object
- #to_s ⇒ Object
- #update_interface(attrs) ⇒ Object
- #update_volume(attrs) ⇒ Object
- #vm_power_action(action) ⇒ Object
- #volumes ⇒ Object
Instance Method Details
#add_interface(attrs) ⇒ Object
62 63 64 65 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 62 def add_interface(attrs) wait_for { stopped? } if attrs[:blocking] service.add_interface(id, attrs) end |
#add_to_affinity_group(attrs) ⇒ Object
109 110 111 112 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 109 def add_to_affinity_group(attrs) wait_for { stopped? } if attrs[:blocking] service.add_to_affinity_group(id, attrs) end |
#add_volume(attrs) ⇒ Object
84 85 86 87 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 84 def add_volume(attrs) wait_for { stopped? } if attrs[:blocking] service.add_volume(id, attrs) end |
#attach_volume(attrs) ⇒ Object
99 100 101 102 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 99 def attach_volume(attrs) wait_for { stopped? } if attrs[:blocking] service.attach_volume(id, attrs) end |
#destroy(_options = {}) ⇒ Object
158 159 160 161 162 163 164 165 166 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 158 def destroy( = {}) begin (stop unless stopped?) rescue StandardError nil end # ignore failure, destroy the machine anyway. wait_for { stopped? } service.destroy_vm(:id => id) end |
#destroy_interface(attrs) ⇒ Object
72 73 74 75 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 72 def destroy_interface(attrs) wait_for { stopped? } if attrs[:blocking] service.destroy_interface(id, attrs) end |
#destroy_volume(attrs) ⇒ Object
89 90 91 92 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 89 def destroy_volume(attrs) wait_for { stopped? } if attrs[:blocking] service.destroy_volume(id, attrs) end |
#detach_volume(attrs) ⇒ Object
104 105 106 107 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 104 def detach_volume(attrs) wait_for { stopped? } if attrs[:blocking] service.detach_volume(id, attrs) end |
#interfaces ⇒ Object
55 56 57 58 59 60 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 55 def interfaces @interfaces ||= id.nil? ? [] : Fog::Ovirt::Compute::Interfaces.new( :service => service, :vm => self ) end |
#locked? ⇒ Boolean
42 43 44 45 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 42 def locked? @volumes = nil # force reload volumes !!(status =~ /locked/i) || (attributes[:volumes] = nil) || volumes.any? { |v| !!(v.status =~ /locked/i) } end |
#mac ⇒ Object
51 52 53 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 51 def mac interfaces.first.mac unless interfaces.empty? end |
#ready? ⇒ Boolean
38 39 40 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 38 def ready? status !~ /down/i end |
#reboot(options = {}) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 140 def reboot( = {}) unless stopped? stop wait_for { stopped? } end start .merge(:blocking => true) end |
#remove_from_affinity_group(attrs) ⇒ Object
114 115 116 117 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 114 def remove_from_affinity_group(attrs) wait_for { stopped? } if attrs[:blocking] service.remove_from_affinity_group(id, attrs) end |
#save ⇒ Object
173 174 175 176 177 178 179 180 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 173 def save if persisted? service.update_vm(attributes) else self.id = service.create_vm(attributes).id end reload end |
#start(options = {}) ⇒ Object
119 120 121 122 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 119 def start( = {}) wait_for { !locked? } if [:blocking] vm_power_action(:start) end |
#start_with_cloudinit(options = {}) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 124 def start_with_cloudinit( = {}) wait_for { !locked? } if [:blocking] user_data = if [:use_custom_script] { :custom_script => [:user_data] } else Hash[YAML.safe_load([:user_data]).map { |a| [a.first.to_sym, a.last] }] end action_status = service.vm_start_with_cloudinit(:id => id, :user_data => user_data) reload action_status end |
#stop(_options = {}) ⇒ Object
136 137 138 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 136 def stop( = {}) vm_power_action(:stop) end |
#stopped? ⇒ Boolean
47 48 49 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 47 def stopped? status.casecmp("down").zero? end |
#suspend(_options = {}) ⇒ Object
148 149 150 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 148 def suspend( = {}) vm_power_action(:suspend) end |
#ticket(options = {}) ⇒ Object
168 169 170 171 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 168 def ticket( = {}) raise ::Fog::Ovirt::Errors::OvirtError, "Can not set console ticket, Server is not ready. Server status: #{status}" unless ready? service.vm_ticket(id, ) end |
#to_s ⇒ Object
182 183 184 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 182 def to_s name end |
#update_interface(attrs) ⇒ Object
67 68 69 70 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 67 def update_interface(attrs) wait_for { stopped? } if attrs[:blocking] service.update_interface(id, attrs) end |
#update_volume(attrs) ⇒ Object
94 95 96 97 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 94 def update_volume(attrs) wait_for { stopped? } if attrs[:blocking] service.update_volume(id, attrs) end |
#vm_power_action(action) ⇒ Object
152 153 154 155 156 |
# File 'lib/fog/ovirt/models/compute/server.rb', line 152 def vm_power_action(action) action_status = service.vm_action(:id => id, :action => action) reload action_status end |