2012-05-15 14:54:20 -04:00
|
|
|
require 'fog/xenserver'
|
2012-04-02 07:25:03 -04:00
|
|
|
require 'fog/compute'
|
|
|
|
|
|
|
|
module Fog
|
2013-07-30 13:01:35 -04:00
|
|
|
module Compute
|
2012-04-02 07:25:03 -04:00
|
|
|
class XenServer < Fog::Service
|
|
|
|
|
|
|
|
require 'fog/xenserver/utilities'
|
|
|
|
require 'fog/xenserver/parser'
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
requires :xenserver_username
|
|
|
|
requires :xenserver_password
|
|
|
|
requires :xenserver_url
|
|
|
|
recognizes :xenserver_defaults
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
model_path 'fog/xenserver/models/compute'
|
|
|
|
model :server
|
|
|
|
collection :servers
|
|
|
|
model :host
|
|
|
|
collection :hosts
|
|
|
|
collection :vifs
|
|
|
|
model :vif
|
|
|
|
collection :storage_repositories
|
|
|
|
model :storage_repository
|
|
|
|
collection :pools
|
|
|
|
model :pool
|
|
|
|
collection :vbds
|
|
|
|
model :vbd
|
|
|
|
collection :vdis
|
|
|
|
model :vdi
|
|
|
|
collection :networks
|
|
|
|
model :network
|
|
|
|
collection :pifs
|
|
|
|
model :pif
|
|
|
|
collection :pbds
|
|
|
|
model :pbd
|
2012-04-04 03:01:55 -04:00
|
|
|
model :guest_metrics
|
2012-04-10 02:01:17 -04:00
|
|
|
model :vbd_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
|
|
|
model :host_metrics
|
2013-01-07 16:35:09 -05:00
|
|
|
model :host_cpu
|
2013-03-26 12:34:58 -04:00
|
|
|
model :vlan
|
|
|
|
collection :vlans
|
2013-07-30 13:01:35 -04:00
|
|
|
model :console
|
|
|
|
collection :consoles
|
2012-04-02 07:25:03 -04:00
|
|
|
|
|
|
|
request_path 'fog/xenserver/requests/compute'
|
|
|
|
request :create_server
|
|
|
|
request :create_vif
|
2012-04-09 15:33:47 -04:00
|
|
|
request :create_vdi
|
2012-04-12 08:16:14 -04:00
|
|
|
request :create_vbd
|
2012-04-09 13:29:17 -04:00
|
|
|
request :destroy_vif
|
2012-04-09 04:36:28 -04:00
|
|
|
request :clone_server
|
2012-04-02 07:25:03 -04:00
|
|
|
request :destroy_server
|
2012-04-10 02:01:17 -04:00
|
|
|
request :unplug_vbd
|
|
|
|
request :eject_vbd
|
|
|
|
request :insert_vbd
|
2012-04-02 07:25:03 -04:00
|
|
|
request :destroy_vdi
|
|
|
|
request :shutdown_server
|
|
|
|
request :start_vm
|
|
|
|
request :start_server
|
|
|
|
request :get_record
|
|
|
|
request :get_records
|
|
|
|
request :set_affinity
|
2012-04-12 07:17:58 -04:00
|
|
|
request :set_attribute
|
2012-04-02 07:25:03 -04:00
|
|
|
request :reboot_server
|
2012-04-12 08:16:14 -04:00
|
|
|
request :provision_server
|
2012-04-16 15:09:52 -04:00
|
|
|
request :scan_sr
|
2012-12-30 18:48:41 -05:00
|
|
|
request :unplug_pbd
|
|
|
|
request :destroy_sr
|
|
|
|
request :create_sr
|
2013-01-06 10:12:38 -05:00
|
|
|
request :reboot_host
|
|
|
|
request :disable_host
|
|
|
|
request :enable_host
|
|
|
|
request :shutdown_host
|
2013-03-26 12:34:58 -04:00
|
|
|
request :create_network
|
|
|
|
request :destroy_network
|
|
|
|
request :create_vlan
|
|
|
|
request :destroy_vlan
|
2013-06-25 00:33:44 -04:00
|
|
|
request :snapshot_server
|
|
|
|
request :snapshot_revert
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
class Real
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
def initialize(options={})
|
|
|
|
@host = options[:xenserver_url]
|
|
|
|
@username = options[:xenserver_username]
|
|
|
|
@password = options[:xenserver_password]
|
|
|
|
@defaults = options[:xenserver_defaults] || {}
|
2013-12-05 06:42:28 -05:00
|
|
|
@timeout = options[:xenserver_timeout] || 30
|
|
|
|
@connection = Fog::XenServer::Connection.new(@host, @timeout)
|
2012-04-02 07:25:03 -04:00
|
|
|
@connection.authenticate(@username, @password)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.authenticate(@username, @password)
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
def default_template=(name)
|
|
|
|
@defaults[:template] = name
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_template
|
|
|
|
return nil if @defaults[:template].nil?
|
2012-04-04 13:48:21 -04:00
|
|
|
(servers.custom_templates + servers.builtin_templates).find do |s|
|
|
|
|
(s.name == @defaults[:template]) or (s.uuid == @defaults[:template])
|
|
|
|
end
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
def default_network
|
2012-05-14 14:41:02 -04:00
|
|
|
networks.find { |n| n.name == (@defaults[:network] || "Pool-wide network associated with eth0") }
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
class Mock
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
def self.reset_data(keys=data.keys)
|
|
|
|
for key in [*keys]
|
|
|
|
data.delete(key)
|
|
|
|
end
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
def initialize(options={})
|
|
|
|
@host = options[:xenserver_pool_master]
|
|
|
|
@username = options[:xenserver_username]
|
|
|
|
@password = options[:xenserver_password]
|
|
|
|
@connection = Fog::Connection.new(@host)
|
|
|
|
@connection.authenticate(@username, @password)
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|