Class: Fog::Compute::XenServer::Server

Inherits:
Server
  • Object
show all
Defined in:
lib/fog/xenserver/models/compute/server.rb

Instance Method Summary collapse

Instance Method Details

#affinityObject



95
96
97
# File 'lib/fog/xenserver/models/compute/server.rb', line 95

def affinity
  service.hosts.get __affinity
end

#clean_rebootObject



215
216
217
# File 'lib/fog/xenserver/models/compute/server.rb', line 215

def clean_reboot
  reboot 'clean'
end

#clean_shutdownObject



230
231
232
# File 'lib/fog/xenserver/models/compute/server.rb', line 230

def clean_shutdown
  stop 'clean'
end

#consolesObject



99
100
101
# File 'lib/fog/xenserver/models/compute/server.rb', line 99

def consoles
  __consoles.map {|console| service.consoles.get console }
end

#destroyObject



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_metricsObject

This is not always present in XenServer VMs Guest needs XenTools installed to report this AFAIK



148
149
150
151
152
# File 'lib/fog/xenserver/models/compute/server.rb', line 148

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

Returns:

  • (Boolean)


171
172
173
174
# File 'lib/fog/xenserver/models/compute/server.rb', line 171

def halted?
  reload
  power_state == "Halted"
end

#hard_rebootObject



211
212
213
# File 'lib/fog/xenserver/models/compute/server.rb', line 211

def hard_reboot
  reboot 'hard'
end

#hard_shutdownObject



226
227
228
# File 'lib/fog/xenserver/models/compute/server.rb', line 226

def hard_shutdown
  stop 'hard'
end

#home_hypervisorObject



158
159
160
# File 'lib/fog/xenserver/models/compute/server.rb', line 158

def home_hypervisor
  service.hosts.first
end

#mac_addressObject



162
163
164
# File 'lib/fog/xenserver/models/compute/server.rb', line 162

def mac_address
  networks.first.MAC
end

#networksObject

associations



137
138
139
# File 'lib/fog/xenserver/models/compute/server.rb', line 137

def networks
  vifs.map { |v| v.network }
end

#provisionObject



234
235
236
# File 'lib/fog/xenserver/models/compute/server.rb', line 234

def provision
  service.provision_server reference
end

#reboot(stype = 'clean') ⇒ Object



206
207
208
209
# File 'lib/fog/xenserver/models/compute/server.rb', line 206

def reboot(stype = 'clean')
  service.reboot_server(reference, stype)
  true
end

#refreshObject



126
127
128
129
130
# File 'lib/fog/xenserver/models/compute/server.rb', line 126

def refresh
  data = service.get_record( reference, 'VM' )
  merge_attributes( data )
  true
end

#resident_onObject



141
142
143
# File 'lib/fog/xenserver/models/compute/server.rb', line 141

def resident_on
  service.hosts.get __resident_on
end

#revert(snapshot_ref) ⇒ Object



242
243
244
# File 'lib/fog/xenserver/models/compute/server.rb', line 242

def revert(snapshot_ref)
  service.snapshot_revert(snapshot_ref)
end

#running?Boolean

Returns:

  • (Boolean)


166
167
168
169
# File 'lib/fog/xenserver/models/compute/server.rb', line 166

def running?
  reload
  power_state == "Running"
end

#save(params = {}) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/fog/xenserver/models/compute/server.rb', line 183

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



238
239
240
# File 'lib/fog/xenserver/models/compute/server.rb', line 238

def snapshot(name)
  service.snapshot_server(reference, name)
end

#startObject

operations



177
178
179
180
181
# File 'lib/fog/xenserver/models/compute/server.rb', line 177

def start
  return false if running?
  service.start_server( reference )
  true
end

#stop(stype = 'clean') ⇒ Object



219
220
221
222
223
224
# File 'lib/fog/xenserver/models/compute/server.rb', line 219

def stop(stype = 'clean')
  return false if !running?
  service.shutdown_server( reference, stype )
  wait_for { power_state == 'Halted' }
  true
end

#tools_installed?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/fog/xenserver/models/compute/server.rb', line 154

def tools_installed?
  !guest_metrics.nil?
end

#vbdsObject



91
92
93
# File 'lib/fog/xenserver/models/compute/server.rb', line 91

def vbds
  __vbds.map {|vbd| service.vbds.get vbd }
end

#vifsObject



132
133
134
# File 'lib/fog/xenserver/models/compute/server.rb', line 132

def vifs
  __vifs.map { |vif| service.vifs.get vif }
end