/
host.rb
158 lines (144 loc) · 5.76 KB
/
host.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
require 'fog/core/model'
module Fog
module Compute
class XenServer
module Models
class Host < Fog::Model
# API Reference here:
# http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=host
identity :reference
attribute :address
attribute :allowed_operations
attribute :api_version_major, :aliases => :API_version_major
attribute :api_version_minor, :aliases => :API_version_minor
attribute :api_version_vendor, :aliases => :API_version_vendor
attribute :api_version_vendor_implementation, :aliases => :API_version_vendor_implementation
attribute :bios_strings
attribute :blobs
attribute :capabilities
attribute :chipset_info
attribute :cpu_configuration
attribute :cpu_info
attribute :__crashdumps, :aliases => :crashdumps
attribute :__crash_dump_sr, :aliases => :crash_dump_sr
attribute :current_operations
attribute :description, :aliases => :name_description
attribute :edition
attribute :enabled
attribute :external_auth_configuration
attribute :external_auth_service_name
attribute :external_auth_type
attribute :guest_vcpus_params, :aliases => :guest_VCPUs_params
attribute :ha_network_peers
attribute :ha_statefiles
attribute :hostname
attribute :__host_cpus, :aliases => :host_CPUs
attribute :license_params
attribute :license_server
attribute :__local_cache_sr, :aliases => :local_cache_sr
attribute :logging
attribute :memory_overhead
attribute :__metrics, :aliases => :metrics
attribute :name, :aliases => :name_label
attribute :other_config
attribute :patches
attribute :__pbds, :aliases => :PBDs
attribute :__pcis, :aliases => :PCIs
attribute :__pgpus, :aliases => :PGPUs
attribute :__pifs, :aliases => :PIFs
attribute :power_on_config
attribute :power_on_mode
attribute :__resident_vms, :aliases => :resident_VMs
attribute :sched_policy
attribute :software_version
attribute :supported_bootloaders
attribute :suspend_image_sr
attribute :tags
attribute :uuid
def pifs
__pifs.collect { |pif| service.pifs.get pif }
end
def pbds
__pbds.collect { |pbd| service.pbds.get pbd }
end
def resident_servers
__resident_vms.collect { |ref| service.servers.get ref }
end
def resident_vms
resident_servers
end
def host_cpus
cpus = []
(__host_cpus || []).each do |ref|
cpu_ref = service.get_record(ref, 'host_cpu' )
cpu_ref[:service] = service
cpus << Fog::Compute::XenServer::HostCpu.new(cpu_ref)
end
cpus
end
def metrics
return nil unless __metrics
rec = service.get_record(__metrics, 'host_metrics' )
Fog::Compute::XenServer::HostMetrics.new(rec)
end
#
# Reboot the host disabling it first unless auto_disable is
# set to false
#
# This function can only be called if there are no currently running
# VMs on the host and it is disabled. If there are running VMs, it will
# raise an exception.
#
# @param [Boolean] auto_disable disable the host first
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def reboot(auto_disable = true)
disable if auto_disable
service.reboot_host(reference)
end
#
# Puts the host into a state in which no new VMs can be started.
# Currently active VMs on the host continue to execute.
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def disable
service.disable_host(reference)
end
#
# Puts the host into a state in which new VMs can be started.
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def enable
service.enable_host(reference)
end
#
# Shutdown the host disabling it first unless auto_disable is
# set to false.
#
# This function can only be called if there are no currently running
# VMs on the host and it is disabled. If there are running VMs, it will
# raise an exception.
#
# @param [Boolean] auto_disable disable the host first
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def shutdown(auto_disable = true)
disable if auto_disable
service.shutdown_host(reference)
end
def set_attribute(name, *val)
data = service.set_attribute( 'host', 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
end
end
end
end
end