2012-04-02 07:25:03 -04:00
|
|
|
require 'fog/compute/models/server'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class XenServer
|
|
|
|
class Server < Fog::Compute::Server
|
|
|
|
# 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=VM
|
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
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :uuid
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :name, :aliases => :name_label
|
|
|
|
attribute :description, :aliases => :name_description
|
|
|
|
attribute :__affinity, :aliases => :affinity
|
|
|
|
attribute :actions_after_crash
|
|
|
|
attribute :actions_after_reboot
|
|
|
|
attribute :actions_after_shutdown
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :allowed_operations
|
2013-12-11 14:01:19 -05:00
|
|
|
attribute :__consoles, :aliases => :consoles
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :__attached_pcis, :aliases => :attached_PCIs
|
|
|
|
attribute :bios_strings
|
|
|
|
attribute :blobs
|
|
|
|
attribute :blocked_operations
|
|
|
|
attribute :__children, :aliases => :children
|
|
|
|
attribute :__crash_dumps, :aliases => :crash_dumps
|
|
|
|
attribute :current_operations
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :domarch
|
|
|
|
attribute :domid
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :generation_id
|
2012-06-07 13:26:47 -04:00
|
|
|
attribute :tags
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :__guest_metrics, :aliases => :guest_metrics
|
|
|
|
attribute :ha_always_run
|
|
|
|
attribute :ha_restart_priority
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :is_a_snapshot
|
|
|
|
attribute :is_a_template
|
|
|
|
attribute :is_control_domain
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :is_snapshot_from_vmpp
|
|
|
|
attribute :last_boot_cpu_flags, :aliases => :last_boot_CPU_flags
|
|
|
|
attribute :last_booted_record
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :memory_dynamic_max
|
|
|
|
attribute :memory_dynamic_min
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :memory_overhead
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :memory_static_max
|
|
|
|
attribute :memory_static_min
|
|
|
|
attribute :memory_target
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :__metrics, :aliases => :metrics
|
|
|
|
attribute :order
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :other_config
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :__parent, :aliases => :parent
|
|
|
|
attribute :platform
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :power_state
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :protection_policy
|
|
|
|
attribute :pv_args, :aliases => :PV_args
|
|
|
|
attribute :pv_bootloader, :aliases => :PV_bootloader
|
|
|
|
attribute :pv_bootloader_args, :aliases => :PV_bootloader_args
|
|
|
|
attribute :pv_kernel, :aliases => :PV_kernel
|
|
|
|
attribute :pv_ramdisk, :aliases => :PV_ramdisk
|
|
|
|
attribute :pv_legacy_args, :aliases => :PV_legacy_args
|
|
|
|
attribute :recommendations
|
|
|
|
attribute :__resident_on, :aliases => :resident_on
|
|
|
|
attribute :shutdown_delay
|
|
|
|
attribute :snapshot_info
|
|
|
|
attribute :snapshot_metadata
|
|
|
|
attribute :__snapshot_of, :aliases => :snapshot_of
|
|
|
|
attribute :snapshot_time
|
|
|
|
attribute :start_delay
|
|
|
|
attribute :__suspend_sr, :aliases => :suspend_sr
|
|
|
|
attribute :__suspend_vdi, :aliases => :suspend_VDI
|
|
|
|
attribute :transportable_snapshot_id
|
|
|
|
attribute :user_version
|
|
|
|
attribute :version
|
|
|
|
attribute :__vgpus, :aliases => :VGPUs
|
|
|
|
attribute :__vtpms, :aliases => :VTPMs
|
|
|
|
attribute :xenstore_data
|
2012-04-02 07:25:03 -04:00
|
|
|
# Virtual Block Devices
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :__vbds, :aliases => :VBDs
|
2012-04-02 07:25:03 -04:00
|
|
|
# Virtual CPUs
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :vcpus_at_startup, :aliases => :VCPUs_at_startup
|
|
|
|
attribute :vcpus_max, :aliases => :VCPUs_max
|
|
|
|
attribute :vcpus_params, :aliases => :VCPUs_params
|
2012-04-02 07:25:03 -04:00
|
|
|
# Virtual Interfaces (NIC)
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :__vifs, :aliases => :VIFs
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :template_name
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :hvm_boot_policy, :aliases => :HVM_boot_policy
|
|
|
|
attribute :hvm_boot_params, :aliases => :HVM_boot_params
|
|
|
|
attribute :hvm_shadow_multiplier, :aliases => :HVM_shadow_multiplier
|
|
|
|
attribute :pci_bus, :aliases => :PCI_bus
|
2013-06-25 00:33:44 -04:00
|
|
|
attribute :snapshots
|
2012-04-02 07:25:03 -04:00
|
|
|
|
|
|
|
def vbds
|
2014-05-22 21:40:43 -04:00
|
|
|
__vbds.map {|vbd| service.vbds.get vbd }
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
|
2012-04-13 06:44:49 -04:00
|
|
|
def affinity
|
2012-12-22 18:21:33 -05:00
|
|
|
service.hosts.get __affinity
|
2012-04-13 06:44:49 -04:00
|
|
|
end
|
|
|
|
|
2013-12-11 13:49:49 -05:00
|
|
|
def consoles
|
2014-05-22 21:40:43 -04:00
|
|
|
__consoles.map {|console| service.consoles.get console }
|
2013-07-30 13:01:35 -04:00
|
|
|
end
|
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
def destroy
|
2012-04-04 13:48:21 -04:00
|
|
|
# Make sure it's halted
|
|
|
|
stop('hard')
|
2012-04-02 07:25:03 -04:00
|
|
|
vbds.each do |vbd|
|
2012-04-04 13:48:21 -04:00
|
|
|
if vbd.type == "Disk"
|
2012-04-10 02:01:17 -04:00
|
|
|
vbd.unplug \
|
2012-04-04 13:48:21 -04:00
|
|
|
if vbd.allowed_operations.include?("unplug")
|
2012-04-10 02:01:17 -04:00
|
|
|
vbd.vdi.destroy \
|
2012-04-04 13:48:21 -04:00
|
|
|
if vbd.vdi.allowed_operations.include?("destroy")
|
|
|
|
end
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
2012-12-22 18:21:33 -05:00
|
|
|
service.destroy_server( reference )
|
2012-04-02 07:25:03 -04:00
|
|
|
true
|
|
|
|
end
|
2012-04-12 07:17:58 -04:00
|
|
|
|
2012-04-19 04:53:56 -04:00
|
|
|
def set_attribute(name, *val)
|
2012-12-22 18:21:33 -05:00
|
|
|
data = service.set_attribute( 'VM', reference, name, *val )
|
2012-04-12 07:17:58 -04:00
|
|
|
# Do not reload automatically for performance reasons
|
|
|
|
# We can set multiple attributes at the same time and
|
|
|
|
# then reload manually
|
|
|
|
#reload
|
|
|
|
end
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
def refresh
|
2014-12-21 21:08:44 -05:00
|
|
|
Fog::Logger.deprecation(
|
|
|
|
'This method is deprecated. Use #reload instead.'
|
|
|
|
)
|
2012-12-22 18:21:33 -05:00
|
|
|
data = service.get_record( reference, 'VM' )
|
2012-04-02 07:25:03 -04:00
|
|
|
merge_attributes( data )
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def vifs
|
2014-05-22 21:40:43 -04:00
|
|
|
__vifs.map { |vif| service.vifs.get vif }
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# associations
|
|
|
|
def networks
|
2014-05-22 21:40:43 -04:00
|
|
|
vifs.map { |v| v.network }
|
2012-04-04 03:01:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def resident_on
|
2012-12-22 18:21:33 -05:00
|
|
|
service.hosts.get __resident_on
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-04 03:01:55 -04:00
|
|
|
#
|
|
|
|
# This is not always present in XenServer VMs
|
|
|
|
# Guest needs XenTools installed to report this AFAIK
|
|
|
|
def guest_metrics
|
2012-04-13 12:17:19 -04:00
|
|
|
return nil unless __guest_metrics
|
2012-12-22 18:21:33 -05:00
|
|
|
rec = service.get_record( __guest_metrics, 'VM_guest_metrics' )
|
2012-04-13 12:17:19 -04:00
|
|
|
Fog::Compute::XenServer::GuestMetrics.new(rec)
|
2012-04-04 03:01:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tools_installed?
|
|
|
|
!guest_metrics.nil?
|
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
|
|
|
def home_hypervisor
|
2012-12-22 18:21:33 -05:00
|
|
|
service.hosts.first
|
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
|
|
|
def mac_address
|
|
|
|
networks.first.MAC
|
|
|
|
end
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
def running?
|
2012-04-04 13:48:21 -04:00
|
|
|
reload
|
|
|
|
power_state == "Running"
|
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
|
|
|
def halted?
|
2012-04-04 13:48:21 -04:00
|
|
|
reload
|
|
|
|
power_state == "Halted"
|
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
|
|
|
# operations
|
|
|
|
def start
|
|
|
|
return false if running?
|
2012-12-22 18:21:33 -05:00
|
|
|
service.start_server( reference )
|
2012-04-02 07:25:03 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def save(params = {})
|
|
|
|
requires :name
|
2012-04-09 06:36:08 -04:00
|
|
|
nets = attributes[:networks] || []
|
2012-04-09 13:29:17 -04:00
|
|
|
if params[:auto_start].nil?
|
|
|
|
auto_start = true
|
|
|
|
else
|
2012-12-22 18:21:33 -05:00
|
|
|
auto_start = params[:auto_start]
|
2012-04-09 13:29:17 -04:00
|
|
|
end
|
2012-04-13 06:44:49 -04:00
|
|
|
if template_name
|
2012-12-22 18:21:33 -05:00
|
|
|
attr = service.get_record(
|
|
|
|
service.create_server( name, template_name, nets, :auto_start => auto_start),
|
2012-04-13 06:44:49 -04:00
|
|
|
'VM'
|
|
|
|
)
|
|
|
|
else
|
2012-12-22 18:21:33 -05:00
|
|
|
attr = service.get_record(
|
|
|
|
service.create_server_raw(attributes),
|
2012-04-13 06:44:49 -04:00
|
|
|
'VM'
|
|
|
|
)
|
|
|
|
end
|
2012-12-22 18:21:33 -05:00
|
|
|
merge_attributes attr
|
2012-04-02 07:25:03 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def reboot(stype = 'clean')
|
2012-12-22 18:21:33 -05:00
|
|
|
service.reboot_server(reference, stype)
|
2012-04-02 07:25:03 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def hard_reboot
|
|
|
|
reboot 'hard'
|
|
|
|
end
|
|
|
|
|
|
|
|
def clean_reboot
|
|
|
|
reboot 'clean'
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop(stype = 'clean')
|
|
|
|
return false if !running?
|
2012-12-22 18:21:33 -05:00
|
|
|
service.shutdown_server( reference, stype )
|
2012-04-04 13:48:21 -04:00
|
|
|
wait_for { power_state == 'Halted' }
|
2012-04-02 07:25:03 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def hard_shutdown
|
|
|
|
stop 'hard'
|
|
|
|
end
|
|
|
|
|
|
|
|
def clean_shutdown
|
|
|
|
stop 'clean'
|
|
|
|
end
|
|
|
|
|
2012-04-12 08:16:14 -04:00
|
|
|
def provision
|
2012-12-22 18:21:33 -05:00
|
|
|
service.provision_server reference
|
2012-04-12 08:16:14 -04:00
|
|
|
end
|
|
|
|
|
2013-06-25 00:33:44 -04:00
|
|
|
def snapshot(name)
|
|
|
|
service.snapshot_server(reference, name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def revert(snapshot_ref)
|
|
|
|
service.snapshot_revert(snapshot_ref)
|
|
|
|
end
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
end
|