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

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Server

#private_key=, #scp, #scp_download, #ssh, #ssh_port, #sshable?

Methods inherited from Model

#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 Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server.



54
55
56
# File 'lib/fog/xenserver/models/compute/server.rb', line 54

def initialize(attributes={})
  super
end

Instance Method Details

#affinityObject



62
63
64
# File 'lib/fog/xenserver/models/compute/server.rb', line 62

def affinity
  connection.hosts.get __affinity
end

#clean_rebootObject



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

def clean_reboot
  reboot 'clean'
end

#clean_shutdownObject



193
194
195
# File 'lib/fog/xenserver/models/compute/server.rb', line 193

def clean_shutdown
  stop 'clean'
end

#destroyObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fog/xenserver/models/compute/server.rb', line 66

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
  connection.destroy_server( reference )
  true
end

#guest_metricsObject

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



111
112
113
114
115
# File 'lib/fog/xenserver/models/compute/server.rb', line 111

def guest_metrics
  return nil unless __guest_metrics
  rec = connection.get_record( __guest_metrics, 'VM_guest_metrics' )
  Fog::Compute::XenServer::GuestMetrics.new(rec)
end

#halted?Boolean

Returns:

  • (Boolean)


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

def halted?
  reload
  power_state == "Halted"
end

#hard_rebootObject



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

def hard_reboot
  reboot 'hard'
end

#hard_shutdownObject



189
190
191
# File 'lib/fog/xenserver/models/compute/server.rb', line 189

def hard_shutdown
  stop 'hard'
end

#home_hypervisorObject



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

def home_hypervisor
  connection.hosts.first
end

#mac_addressObject



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

def mac_address
  networks.first.MAC
end

#networksObject

associations



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

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

#provisionObject



197
198
199
# File 'lib/fog/xenserver/models/compute/server.rb', line 197

def provision
  connection.provision_server reference
end

#reboot(stype = 'clean') ⇒ Object



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

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

#refreshObject



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

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

#resident_onObject



104
105
106
# File 'lib/fog/xenserver/models/compute/server.rb', line 104

def resident_on
  connection.hosts.get __resident_on
end

#running?Boolean

Returns:

  • (Boolean)


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

def running?
  reload
  power_state == "Running"
end

#save(params = {}) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/fog/xenserver/models/compute/server.rb', line 146

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 = connection.get_record(
      connection.create_server( name, template_name, nets, :auto_start => auto_start),
      'VM'
    )
  else
    attr = connection.get_record(
      connection.create_server_raw(attributes),
      'VM'
    )
  end
  merge_attributes attr 
  true
end

#set_attribute(name, *val) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/fog/xenserver/models/compute/server.rb', line 81

def set_attribute(name, *val)
  data = connection.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

#startObject

operations



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

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

#stop(stype = 'clean') ⇒ Object



182
183
184
185
186
187
# File 'lib/fog/xenserver/models/compute/server.rb', line 182

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

#tools_installed?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/fog/xenserver/models/compute/server.rb', line 117

def tools_installed?
  !guest_metrics.nil?
end

#vbdsObject



58
59
60
# File 'lib/fog/xenserver/models/compute/server.rb', line 58

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

#vifsObject



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

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