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

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

Instance Attribute Summary

Attributes inherited from Server

#private_key, #private_key_path, #public_key, #public_key_path, #ssh_options, #ssh_port, #username

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Server

#scp, #scp_download, #ssh, #ssh_ip_address, #ssh_ip_address=, #sshable?

Methods inherited from Model

#initialize, #inspect, #reload, #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::Model

Instance Method Details

#affinityObject



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

def affinity
  service.hosts.get __affinity
end

#clean_rebootObject



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

def clean_reboot
  reboot 'clean'
end

#clean_shutdownObject



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

def clean_shutdown
  stop 'clean'
end

#consolesObject



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

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

#destroyObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/fog/xenserver/models/compute/server.rb', line 104

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



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

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)


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

def halted?
  reload
  power_state == "Halted"
end

#hard_rebootObject



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

def hard_reboot
  reboot 'hard'
end

#hard_shutdownObject



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

def hard_shutdown
  stop 'hard'
end

#home_hypervisorObject



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

def home_hypervisor
  service.hosts.first
end

#mac_addressObject



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

def mac_address
  networks.first.MAC
end

#networksObject

associations



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

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

#provisionObject



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

def provision
  service.provision_server reference
end

#reboot(stype = 'clean') ⇒ Object



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

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

#refreshObject



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

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

#resident_onObject



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

def resident_on
  service.hosts.get __resident_on
end

#revert(snapshot_ref) ⇒ Object



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

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

#running?Boolean

Returns:

  • (Boolean)


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

def running?
  reload
  power_state == "Running"
end

#save(params = {}) ⇒ Object



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

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



119
120
121
122
123
124
125
# File 'lib/fog/xenserver/models/compute/server.rb', line 119

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



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

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

#startObject

operations



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

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

#stop(stype = 'clean') ⇒ Object



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

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)


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

def tools_installed?
  !guest_metrics.nil?
end

#vbdsObject



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

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

#vifsObject



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

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