2012-04-02 07:25:03 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class XenServer
|
|
|
|
|
|
|
|
class Host < Fog::Model
|
|
|
|
# API Reference here:
|
2013-12-10 20:05:42 -05:00
|
|
|
# http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=host
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
identity :reference
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :name, :aliases => :name_label
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :uuid
|
|
|
|
attribute :address
|
|
|
|
attribute :allowed_operations
|
2013-12-10 20:05:42 -05:00
|
|
|
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 :__crash_dump_sr, :aliases => :crash_dump_sr
|
|
|
|
attribute :__crashdumps, :aliases => :crashdumps
|
|
|
|
attribute :current_operations
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :enabled
|
2013-12-10 20:05:42 -05:00
|
|
|
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
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :hostname
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :license_params
|
|
|
|
attribute :license_server
|
|
|
|
attribute :__local_cache_sr, :aliases => :local_cache_sr
|
|
|
|
attribute :logging
|
|
|
|
attribute :memory_overhead
|
|
|
|
attribute :__metrics, :aliases => :metrics
|
|
|
|
attribute :description, :aliases => :name_description
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :other_config
|
2013-12-10 20:05:42 -05:00
|
|
|
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 :supported_bootloaders
|
|
|
|
attribute :suspend_image_sr
|
|
|
|
attribute :tags
|
|
|
|
attribute :__host_cpus, :aliases => :host_CPUs
|
2013-01-07 16:47:55 -05:00
|
|
|
attribute :edition
|
|
|
|
attribute :software_version
|
2014-02-19 07:30:59 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
def pifs
|
2012-12-22 18:21:33 -05:00
|
|
|
__pifs.collect { |pif| service.pifs.get pif }
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def pbds
|
2012-12-22 18:21:33 -05:00
|
|
|
__pbds.collect { |pbd| service.pbds.get pbd }
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def resident_servers
|
2012-12-22 18:21:33 -05:00
|
|
|
__resident_vms.collect { |ref| service.servers.get ref }
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def resident_vms
|
|
|
|
resident_servers
|
|
|
|
end
|
|
|
|
|
2013-01-07 16:35:53 -05:00
|
|
|
def host_cpus
|
|
|
|
cpus = []
|
|
|
|
(__host_cpus || []).each do |ref|
|
2013-01-07 18:14:13 -05:00
|
|
|
cpu_ref = service.get_record(ref, 'host_cpu' )
|
|
|
|
cpu_ref[:service] = service
|
2013-01-07 16:35:53 -05:00
|
|
|
cpus << Fog::Compute::XenServer::HostCpu.new(cpu_ref)
|
|
|
|
end
|
|
|
|
cpus
|
|
|
|
end
|
|
|
|
|
Added missing HostMetrics model
Added missing HostMetrics model that wraps Host.metrics OpaqueRef.
conn = Fog::Compute.new({
:provider => 'XenServer',
:xenserver_url => 'xenserver-test',
:xenserver_username => 'root',
:xenserver_password => 'secret',
})
pp conn.hosts.first.metrics # => yields
# <Fog::Compute::XenServer::HostMetrics
# reference="OpaqueRef:161923b3-47e4-7f8c-8995-3030be9d58f8",
# uuid="00d47697-3682-1e91-154b-00116a5b7878",
# live=true,
# memory_free="3311230976",
# memory_total="4217688064",
# other_config={},
# last_updated=2012-12-06 21:19:59 UTC
# >
2012-12-06 17:39:50 -05:00
|
|
|
def metrics
|
|
|
|
return nil unless __metrics
|
2012-12-22 18:21:33 -05:00
|
|
|
rec = service.get_record(__metrics, 'host_metrics' )
|
Added missing HostMetrics model
Added missing HostMetrics model that wraps Host.metrics OpaqueRef.
conn = Fog::Compute.new({
:provider => 'XenServer',
:xenserver_url => 'xenserver-test',
:xenserver_username => 'root',
:xenserver_password => 'secret',
})
pp conn.hosts.first.metrics # => yields
# <Fog::Compute::XenServer::HostMetrics
# reference="OpaqueRef:161923b3-47e4-7f8c-8995-3030be9d58f8",
# uuid="00d47697-3682-1e91-154b-00116a5b7878",
# live=true,
# memory_free="3311230976",
# memory_total="4217688064",
# other_config={},
# last_updated=2012-12-06 21:19:59 UTC
# >
2012-12-06 17:39:50 -05:00
|
|
|
Fog::Compute::XenServer::HostMetrics.new(rec)
|
|
|
|
end
|
|
|
|
|
2013-01-06 10:12:38 -05:00
|
|
|
#
|
2014-02-19 07:30:59 -05:00
|
|
|
# Reboot the host disabling it first unless auto_disable is
|
2013-01-06 10:12:38 -05:00
|
|
|
# set to false
|
2014-02-19 07:30:59 -05:00
|
|
|
#
|
|
|
|
# This function can only be called if there are no currently running
|
2013-01-06 10:12:38 -05:00
|
|
|
# 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
|
2013-01-07 18:14:13 -05:00
|
|
|
service.reboot_host(reference)
|
2013-01-06 10:12:38 -05:00
|
|
|
end
|
2014-02-19 07:30:59 -05:00
|
|
|
|
2013-01-06 10:12:38 -05:00
|
|
|
#
|
2014-02-19 07:30:59 -05:00
|
|
|
# Puts the host into a state in which no new VMs can be started.
|
2013-01-06 10:12:38 -05:00
|
|
|
# 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
|
|
|
|
#
|
2014-02-19 07:30:59 -05:00
|
|
|
def disable
|
2013-01-07 18:14:13 -05:00
|
|
|
service.disable_host(reference)
|
2013-01-06 10:12:38 -05:00
|
|
|
end
|
2014-02-19 07:30:59 -05:00
|
|
|
|
2013-01-06 10:12:38 -05:00
|
|
|
#
|
2014-02-19 07:30:59 -05:00
|
|
|
# Puts the host into a state in which new VMs can be started.
|
2013-01-06 10:12:38 -05:00
|
|
|
#
|
|
|
|
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
|
|
|
|
#
|
|
|
|
def enable
|
2013-01-07 18:14:13 -05:00
|
|
|
service.enable_host(reference)
|
2013-01-06 10:12:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2014-02-19 07:30:59 -05:00
|
|
|
# Shutdown the host disabling it first unless auto_disable is
|
2013-01-06 10:12:38 -05:00
|
|
|
# set to false.
|
|
|
|
#
|
2014-02-19 07:30:59 -05:00
|
|
|
# This function can only be called if there are no currently running
|
2013-01-06 10:12:38 -05:00
|
|
|
# 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
|
2013-01-07 18:14:13 -05:00
|
|
|
service.shutdown_host(reference)
|
2013-01-06 10:12:38 -05:00
|
|
|
end
|
2014-02-19 07:30:59 -05:00
|
|
|
|
2013-01-06 10:12:38 -05:00
|
|
|
def set_attribute(name, *val)
|
2013-01-07 18:14:13 -05:00
|
|
|
data = service.set_attribute( 'host', reference, name, *val )
|
2013-01-06 10:12:38 -05:00
|
|
|
# Do not reload automatically for performance reasons
|
|
|
|
# We can set multiple attributes at the same time and
|
|
|
|
# then reload manually
|
|
|
|
#reload
|
|
|
|
end
|
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|