Class: Fog::Compute::XenServer::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::XenServer::Server
- Defined in:
- lib/fog/xenserver/models/compute/server.rb
Instance Method Summary collapse
- #affinity ⇒ Object
- #clean_reboot ⇒ Object
- #clean_shutdown ⇒ Object
- #consoles ⇒ Object
- #destroy ⇒ Object
-
#guest_metrics ⇒ Object
This is not always present in XenServer VMs Guest needs XenTools installed to report this AFAIK.
- #halted? ⇒ Boolean
- #hard_reboot ⇒ Object
- #hard_shutdown ⇒ Object
- #home_hypervisor ⇒ Object
- #mac_address ⇒ Object
-
#networks ⇒ Object
associations.
- #provision ⇒ Object
- #reboot(stype = 'clean') ⇒ Object
- #refresh ⇒ Object
- #resident_on ⇒ Object
- #revert(snapshot_ref) ⇒ Object
- #running? ⇒ Boolean
- #save(params = {}) ⇒ Object
- #set_attribute(name, *val) ⇒ Object
- #snapshot(name) ⇒ Object
-
#start ⇒ Object
operations.
- #stop(stype = 'clean') ⇒ Object
- #tools_installed? ⇒ Boolean
- #vbds ⇒ Object
- #vifs ⇒ Object
Instance Method Details
#affinity ⇒ Object
95 96 97 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 95 def affinity service.hosts.get __affinity end |
#clean_reboot ⇒ Object
218 219 220 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 218 def clean_reboot reboot 'clean' end |
#clean_shutdown ⇒ Object
233 234 235 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 233 def clean_shutdown stop 'clean' end |
#consoles ⇒ Object
99 100 101 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 99 def consoles __consoles.map {|console| service.consoles.get console } end |
#destroy ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 103 def destroy # Make sure it's halted stop('hard') vbds.each do |vbd| if vbd.type == "Disk" vbd.unplug \ if vbd.allowed_operations.include?("unplug") vbd.vdi.destroy \ if vbd.vdi.allowed_operations.include?("destroy") end end service.destroy_server( reference ) true end |
#guest_metrics ⇒ Object
This is not always present in XenServer VMs Guest needs XenTools installed to report this AFAIK
151 152 153 154 155 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 151 def guest_metrics return nil unless __guest_metrics rec = service.get_record( __guest_metrics, 'VM_guest_metrics' ) Fog::Compute::XenServer::GuestMetrics.new(rec) end |
#halted? ⇒ Boolean
174 175 176 177 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 174 def halted? reload power_state == "Halted" end |
#hard_reboot ⇒ Object
214 215 216 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 214 def hard_reboot reboot 'hard' end |
#hard_shutdown ⇒ Object
229 230 231 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 229 def hard_shutdown stop 'hard' end |
#home_hypervisor ⇒ Object
161 162 163 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 161 def home_hypervisor service.hosts.first end |
#mac_address ⇒ Object
165 166 167 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 165 def mac_address networks.first.MAC end |
#networks ⇒ Object
associations
140 141 142 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 140 def networks vifs.map { |v| v.network } end |
#provision ⇒ Object
237 238 239 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 237 def provision service.provision_server reference end |
#reboot(stype = 'clean') ⇒ Object
209 210 211 212 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 209 def reboot(stype = 'clean') service.reboot_server(reference, stype) true end |
#refresh ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 126 def refresh Fog::Logger.deprecation( 'This method is deprecated. Use #reload instead.' ) data = service.get_record( reference, 'VM' ) merge_attributes( data ) true end |
#resident_on ⇒ Object
144 145 146 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 144 def resident_on service.hosts.get __resident_on end |
#revert(snapshot_ref) ⇒ Object
245 246 247 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 245 def revert(snapshot_ref) service.snapshot_revert(snapshot_ref) end |
#running? ⇒ Boolean
169 170 171 172 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 169 def running? reload power_state == "Running" end |
#save(params = {}) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 186 def save(params = {}) requires :name nets = attributes[:networks] || [] if params[:auto_start].nil? auto_start = true else auto_start = params[:auto_start] end if template_name attr = service.get_record( service.create_server( name, template_name, nets, :auto_start => auto_start), 'VM' ) else attr = service.get_record( service.create_server_raw(attributes), 'VM' ) end merge_attributes attr true end |
#set_attribute(name, *val) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 118 def set_attribute(name, *val) data = service.set_attribute( 'VM', reference, name, *val ) # Do not reload automatically for performance reasons # We can set multiple attributes at the same time and # then reload manually #reload end |
#snapshot(name) ⇒ Object
241 242 243 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 241 def snapshot(name) service.snapshot_server(reference, name) end |
#start ⇒ Object
operations
180 181 182 183 184 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 180 def start return false if running? service.start_server( reference ) true end |
#stop(stype = 'clean') ⇒ Object
222 223 224 225 226 227 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 222 def stop(stype = 'clean') return false if !running? service.shutdown_server( reference, stype ) wait_for { power_state == 'Halted' } true end |
#tools_installed? ⇒ Boolean
157 158 159 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 157 def tools_installed? !guest_metrics.nil? end |
#vbds ⇒ Object
91 92 93 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 91 def vbds __vbds.map {|vbd| service.vbds.get vbd } end |
#vifs ⇒ Object
135 136 137 |
# File 'lib/fog/xenserver/models/compute/server.rb', line 135 def vifs __vifs.map { |vif| service.vifs.get vif } end |