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, #sshable?
Methods inherited from Model
#inspect, #reload, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#connection, #connection=, #prepare_service_value
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
55
56
57
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 55
def initialize(attributes={})
super
end
|
Instance Method Details
#affinity ⇒ Object
63
64
65
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 63
def affinity
service.hosts.get __affinity
end
|
#clean_reboot ⇒ Object
183
184
185
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 183
def clean_reboot
reboot 'clean'
end
|
#clean_shutdown ⇒ Object
198
199
200
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 198
def clean_shutdown
stop 'clean'
end
|
#consoles ⇒ Object
67
68
69
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 67
def consoles
__consoles.collect {|console| service.consoles.get console }
end
|
#destroy ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 71
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
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
116
117
118
119
120
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 116
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
139
140
141
142
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 139
def halted?
reload
power_state == "Halted"
end
|
#hard_reboot ⇒ Object
179
180
181
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 179
def hard_reboot
reboot 'hard'
end
|
#hard_shutdown ⇒ Object
194
195
196
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 194
def hard_shutdown
stop 'hard'
end
|
#home_hypervisor ⇒ Object
126
127
128
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 126
def home_hypervisor
service.hosts.first
end
|
#mac_address ⇒ Object
130
131
132
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 130
def mac_address
networks.first.MAC
end
|
#networks ⇒ Object
105
106
107
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 105
def networks
vifs.collect { |v| v.network }
end
|
#provision ⇒ Object
202
203
204
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 202
def provision
service.provision_server reference
end
|
#reboot(stype = 'clean') ⇒ Object
174
175
176
177
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 174
def reboot(stype = 'clean')
service.reboot_server(reference, stype)
true
end
|
#refresh ⇒ Object
94
95
96
97
98
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 94
def refresh
data = service.get_record( reference, 'VM' )
merge_attributes( data )
true
end
|
#resident_on ⇒ Object
109
110
111
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 109
def resident_on
service.hosts.get __resident_on
end
|
#revert(snapshot_ref) ⇒ Object
210
211
212
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 210
def revert(snapshot_ref)
service.snapshot_revert(snapshot_ref)
end
|
#running? ⇒ Boolean
134
135
136
137
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 134
def running?
reload
power_state == "Running"
end
|
#save(params = {}) ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 151
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
86
87
88
89
90
91
92
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 86
def set_attribute(name, *val)
data = service.set_attribute( 'VM', reference, name, *val )
end
|
#snapshot(name) ⇒ Object
206
207
208
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 206
def snapshot(name)
service.snapshot_server(reference, name)
end
|
#start ⇒ Object
145
146
147
148
149
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 145
def start
return false if running?
service.start_server( reference )
true
end
|
#stop(stype = 'clean') ⇒ Object
187
188
189
190
191
192
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 187
def stop(stype = 'clean')
return false if !running?
service.shutdown_server( reference, stype )
wait_for { power_state == 'Halted' }
true
end
|
122
123
124
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 122
def tools_installed?
!guest_metrics.nil?
end
|
#vbds ⇒ Object
59
60
61
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 59
def vbds
__vbds.collect {|vbd| service.vbds.get vbd }
end
|
#vifs ⇒ Object
100
101
102
|
# File 'lib/fog/xenserver/models/compute/server.rb', line 100
def vifs
__vifs.collect { |vif| service.vifs.get vif }
end
|