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, #username
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
Methods inherited from Server
#scp, #scp_download, #ssh, #ssh_port, #sshable?
Methods inherited from Model
#inspect, #reload, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_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
#affinity ⇒ Object
62
63
64
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 62
def affinity
connection.hosts.get __affinity
end
|
#clean_reboot ⇒ Object
178
179
180
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 178
def clean_reboot
reboot 'clean'
end
|
#clean_shutdown ⇒ Object
193
194
195
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 193
def clean_shutdown
stop 'clean'
end
|
#destroy ⇒ Object
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
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_metrics ⇒ Object
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
134
135
136
137
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 134
def halted?
reload
power_state == "Halted"
end
|
#hard_reboot ⇒ Object
174
175
176
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 174
def hard_reboot
reboot 'hard'
end
|
#hard_shutdown ⇒ Object
189
190
191
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 189
def hard_shutdown
stop 'hard'
end
|
#home_hypervisor ⇒ Object
121
122
123
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 121
def home_hypervisor
connection.hosts.first
end
|
#mac_address ⇒ Object
125
126
127
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 125
def mac_address
networks.first.MAC
end
|
#networks ⇒ Object
100
101
102
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 100
def networks
vifs.collect { |v| v.network }
end
|
#provision ⇒ Object
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
|
#refresh ⇒ Object
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_on ⇒ Object
104
105
106
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 104
def resident_on
connection.hosts.get __resident_on
end
|
#running? ⇒ 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 )
end
|
#start ⇒ Object
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
|
117
118
119
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 117
def tools_installed?
!guest_metrics.nil?
end
|
#vbds ⇒ Object
58
59
60
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 58
def vbds
__vbds.collect {|vbd| connection.vbds.get vbd }
end
|
#vifs ⇒ Object
95
96
97
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 95
def vifs
__vifs.collect { |vif| connection.vifs.get vif }
end
|