1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/xenserver/compute.rb

178 lines
4.5 KiB
Ruby
Raw Normal View History

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
recognizes :xenserver_timeout
2013-07-30 13:01:35 -04:00
2012-04-02 07:25:03 -04:00
model_path 'fog/xenserver/models/compute'
model :blob
collection :blobs
model :bond
collection :bonds
model :crash_dump
collection :crash_dumps
model :dr_task
collection :dr_tasks
model :gpu_group
collection :gpu_groups
model :host_crash_dump
collection :host_crash_dumps
model :host_patch
collection :host_patchs
model :pci
collection :pcis
model :pgpu
collection :pgpus
model :pif_metrics
collection :pifs_metrics
model :pool_patch
collection :pool_patchs
model :role
collection :roles
2012-04-02 07:25:03 -04:00
model :server
collection :servers
model :server_appliance
collection :server_appliances
model :storage_manager
collection :storage_managers
model :tunnel
collection :tunnels
model :vmpp
collection :vmpps
model :vtpm
collection :vtpms
2012-04-02 07:25:03 -04:00
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
model :guest_metrics
2012-04-10 02:01:17 -04:00
model :vbd_metrics
model :host_metrics
model :host_cpu
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
request :create_vdi
request :create_vbd
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
request :set_attribute
2012-04-02 07:25:03 -04:00
request :reboot_server
request :provision_server
request :scan_sr
request :unplug_pbd
request :destroy_sr
request :create_sr
request :reboot_host
request :disable_host
request :enable_host
request :shutdown_host
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] || {}
@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?
(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