mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
First batch of deprecation of requests in Xenserver
This commit is contained in:
parent
393874f4a1
commit
8892d189d5
5 changed files with 181 additions and 110 deletions
|
@ -5,14 +5,17 @@ module Fog
|
|||
def clone_server( server_name, template_ref )
|
||||
# Clone the VM template
|
||||
if template_ref.kind_of? Fog::Compute::XenServer::Server
|
||||
Fog::Logger.deprecation(
|
||||
'Passing an object to #clone_server is deprecated. Pass the reference instead.'
|
||||
)
|
||||
template_ref = template_ref.reference
|
||||
end
|
||||
raise ArgumentError.new("Invalid template_ref") if template_ref.nil?
|
||||
raise ArgumentError.new("Invalid template_ref") if server_name.nil?
|
||||
|
||||
ref = @connection.request(
|
||||
{:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.clone'},
|
||||
template_ref, server_name
|
||||
{:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.clone'},
|
||||
template_ref, server_name
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,15 +7,24 @@ module Fog
|
|||
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=network
|
||||
#
|
||||
def create_network( name, config = {} )
|
||||
config.reject! { |k,v| v.nil? }
|
||||
if name.is_a?(Hash)
|
||||
default_config = name
|
||||
default_config.reject! { |_k,v| v.nil? }
|
||||
else
|
||||
Fog::Logger.deprecation(
|
||||
'This api is deprecated. The only expected param is a hash with the attributes.'
|
||||
)
|
||||
|
||||
default_config = {
|
||||
:name_label => name,
|
||||
# Description is mandatory in XenAPI but we default to empty
|
||||
:name_description => config[:description] || '',
|
||||
# Mandatory, but can be empty
|
||||
:other_config => {}
|
||||
}.merge config
|
||||
config.reject! { |k,v| v.nil? }
|
||||
|
||||
default_config = {
|
||||
:name_label => name,
|
||||
# Description is mandatory in XenAPI but we default to empty
|
||||
:name_description => config[:description] || '',
|
||||
# Mandatory, but can be empty
|
||||
:other_config => {}
|
||||
}.merge config
|
||||
end
|
||||
|
||||
@connection.request(
|
||||
{
|
||||
|
|
|
@ -3,14 +3,32 @@ module Fog
|
|||
class XenServer
|
||||
class Real
|
||||
def get_vm_by_name(label)
|
||||
Fog::Logger.deprecation(
|
||||
'This method is deprecated. Use #get_by_name instead.'
|
||||
)
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.get_by_name_label' }, label)
|
||||
end
|
||||
|
||||
def get_vm_by_uuid(uuid)
|
||||
Fog::Logger.deprecation(
|
||||
'This method is deprecated. Use #get_by_uuid instead.'
|
||||
)
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.get_by_uuid' }, uuid)
|
||||
end
|
||||
|
||||
def get_by_name(name, provider_class)
|
||||
@connection.request({ :parser => Fog::Parsers::XenServer::Base.new, :method => "#{provider_class}.get_by_name_label" }, name)
|
||||
end
|
||||
|
||||
def get_by_uuid(uuid, provider_class)
|
||||
@connection.request({ :parser => Fog::Parsers::XenServer::Base.new, :method => "#{provider_class}.get_by_uuid" }, uuid)
|
||||
end
|
||||
|
||||
def create_server_raw(config = {})
|
||||
Fog::Logger.deprecation(
|
||||
'This method is deprecated. To create a server from scratch, use #create_server.'
|
||||
)
|
||||
|
||||
config[:name_label] = config[:name] if config[:name]
|
||||
config.delete :name
|
||||
config[:affinity] = config[:__affinity] if config[:__affinity]
|
||||
|
@ -39,71 +57,81 @@ module Fog
|
|||
end
|
||||
end
|
||||
vm_record = {
|
||||
:name_label => '',
|
||||
:name_description => 'description',
|
||||
:user_version => '0',
|
||||
:affinity => '',
|
||||
:is_a_template => true,
|
||||
:auto_power_on => false,
|
||||
:memory_static_max => '536870912',
|
||||
:memory_static_min => '536870912',
|
||||
:memory_dynamic_max => '536870912',
|
||||
:memory_dynamic_min => '536870912',
|
||||
:VCPUs_params => {},
|
||||
:VCPUs_max => '1',
|
||||
:VCPUs_at_startup => '1',
|
||||
:actions_after_shutdown => 'Destroy',
|
||||
:actions_after_reboot => 'Restart',
|
||||
:actions_after_crash => 'Restart',
|
||||
:platform => { :'nx' => 'true', :'acpi' => 'true', :'apic' => 'true', :'pae' => 'true', :'viridian' => 'true' },
|
||||
:other_config => {},
|
||||
:pool_name => '',
|
||||
:PV_bootloader => 'pygrub', #pvgrub, eliloader
|
||||
:PV_kernel => '',
|
||||
:PV_ramdisk => '',
|
||||
:PV_args => '-- quiet console=hvc0',
|
||||
:PV_bootloader_args => '',
|
||||
:PV_legacy_args => '',
|
||||
:HVM_boot_policy => '',
|
||||
:HVM_boot_params => {},
|
||||
:PCI_bus => '',
|
||||
:recommendations => '',
|
||||
:name_label => '',
|
||||
:name_description => 'description',
|
||||
:user_version => '0',
|
||||
:affinity => '',
|
||||
:is_a_template => true,
|
||||
:auto_power_on => false,
|
||||
:memory_static_max => '536870912',
|
||||
:memory_static_min => '536870912',
|
||||
:memory_dynamic_max => '536870912',
|
||||
:memory_dynamic_min => '536870912',
|
||||
:VCPUs_params => {},
|
||||
:VCPUs_max => '1',
|
||||
:VCPUs_at_startup => '1',
|
||||
:actions_after_shutdown => 'Destroy',
|
||||
:actions_after_reboot => 'Restart',
|
||||
:actions_after_crash => 'Restart',
|
||||
:platform => { :'nx' => 'true', :'acpi' => 'true', :'apic' => 'true', :'pae' => 'true', :'viridian' => 'true' },
|
||||
:other_config => {},
|
||||
:pool_name => '',
|
||||
:PV_bootloader => 'pygrub', #pvgrub, eliloader
|
||||
:PV_kernel => '',
|
||||
:PV_ramdisk => '',
|
||||
:PV_args => '-- quiet console=hvc0',
|
||||
:PV_bootloader_args => '',
|
||||
:PV_legacy_args => '',
|
||||
:HVM_boot_policy => '',
|
||||
:HVM_boot_params => {},
|
||||
:PCI_bus => '',
|
||||
:recommendations => '',
|
||||
}.merge config
|
||||
ref = @connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.create' }, vm_record)
|
||||
ref
|
||||
end
|
||||
|
||||
def create_server( name_label, template = nil, networks = [], extra_args = {})
|
||||
if !networks.kind_of? Array
|
||||
raise "Invalid networks argument"
|
||||
end
|
||||
if name_label.is_a?(Hash)
|
||||
config = name_label.reject! { |_k,v| v.nil? }
|
||||
ref = @connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.create' }, config)
|
||||
else
|
||||
Fog::Logger.deprecation(
|
||||
'This api is deprecated. The only expected param is a hash with the attributes.' + "\n" +
|
||||
'To create a server from a template, use #clone_server instead.'
|
||||
)
|
||||
|
||||
if template.kind_of? String
|
||||
template_string = template
|
||||
# try template by UUID
|
||||
template = servers.templates.find { |s| s.uuid == template_string }
|
||||
if template.nil?
|
||||
# Try with the template name just in case
|
||||
template = servers.get get_vm_by_name(template_string)
|
||||
if !networks.kind_of? Array
|
||||
raise "Invalid networks argument"
|
||||
end
|
||||
end
|
||||
|
||||
if template.nil?
|
||||
raise "Invalid template"
|
||||
end
|
||||
if template.kind_of? String
|
||||
template_string = template
|
||||
# try template by UUID
|
||||
template = servers.templates.find { |s| s.uuid == template_string }
|
||||
if template.nil?
|
||||
# Try with the template name just in case
|
||||
template = servers.get get_vm_by_name(template_string)
|
||||
end
|
||||
end
|
||||
|
||||
raise "Template #{template_string} does not exist" if template.allowed_operations.nil?
|
||||
raise 'Clone Operation not Allowed' unless template.allowed_operations.include?('clone')
|
||||
if template.nil?
|
||||
raise "Invalid template"
|
||||
end
|
||||
|
||||
# Clone the VM template
|
||||
ref = clone_server name_label, template.reference
|
||||
# Add additional NICs
|
||||
networks.each do |n|
|
||||
create_vif ref, n.reference
|
||||
end
|
||||
if !extra_args[:auto_start] == false
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.provision'}, ref)
|
||||
start_vm( ref )
|
||||
raise "Template #{template_string} does not exist" if template.allowed_operations.nil?
|
||||
raise 'Clone Operation not Allowed' unless template.allowed_operations.include?('clone')
|
||||
|
||||
# Clone the VM template
|
||||
ref = clone_server name_label, template.reference
|
||||
# Add additional NICs
|
||||
networks.each do |n|
|
||||
create_vif ref, n.reference
|
||||
end
|
||||
if !extra_args[:auto_start] == false
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.provision'}, ref)
|
||||
start_vm( ref )
|
||||
end
|
||||
end
|
||||
|
||||
ref
|
||||
|
|
|
@ -24,40 +24,63 @@ module Fog
|
|||
#
|
||||
# @return [String] an OpaqueRef to the storage repository
|
||||
def create_sr( host_ref,
|
||||
name_label,
|
||||
type,
|
||||
name_description = '',
|
||||
device_config = {},
|
||||
physical_size = '0',
|
||||
content_type = 'user',
|
||||
shared = false,
|
||||
sm_config = {} )
|
||||
|
||||
@connection.request(
|
||||
{:parser => Fog::Parsers::XenServer::Base.new, :method => 'SR.create'},
|
||||
host_ref,
|
||||
device_config || {},
|
||||
physical_size || '0',
|
||||
name_label,
|
||||
name_description || '',
|
||||
type,
|
||||
content_type,
|
||||
shared || false,
|
||||
sm_config || {}
|
||||
)
|
||||
type = '',
|
||||
name_description = '',
|
||||
device_config = {},
|
||||
physical_size = '0',
|
||||
content_type = 'user',
|
||||
shared = false,
|
||||
sm_config = {} )
|
||||
|
||||
if host_ref.is_a?(Hash)
|
||||
config = host_ref
|
||||
extra_params = name_label
|
||||
|
||||
%i(physical_size name description type content_type shared sm_config).each do |attribute|
|
||||
raise "Missing Argument in first param: #{attribute}" if config[attribute].nil?
|
||||
end
|
||||
|
||||
%i(host_ref device_config).each do |attribute|
|
||||
raise "Missing Argument in second param: #{attribute}" if extra_params[attribute].nil?
|
||||
end
|
||||
|
||||
@connection.request({ :parser => Fog::Parsers::XenServer::Base.new, :method => 'SR.create' },
|
||||
extra_params[:host_ref], extra_params[:device_config], config[:physical_size],
|
||||
config[:name], config[:description], config[:type], config[:content_type],
|
||||
config[:shared], config[:sm_config])
|
||||
else
|
||||
Fog::Logger.deprecation(
|
||||
'This api is deprecated. The expected params are two hashes of attributes.' + "\n" +
|
||||
'To create a server from a template, use #clone_server instead.'
|
||||
)
|
||||
|
||||
@connection.request(
|
||||
{:parser => Fog::Parsers::XenServer::Base.new, :method => 'SR.create'},
|
||||
host_ref,
|
||||
device_config || {},
|
||||
physical_size || '0',
|
||||
name_label,
|
||||
name_description || '',
|
||||
type,
|
||||
content_type,
|
||||
shared || false,
|
||||
sm_config || {}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_sr( host_ref,
|
||||
name_label,
|
||||
type,
|
||||
name_description = nil,
|
||||
device_config = {},
|
||||
physical_size = '0',
|
||||
content_type = nil,
|
||||
shared = false,
|
||||
sm_config = {} )
|
||||
name_label,
|
||||
type,
|
||||
name_description = nil,
|
||||
device_config = {},
|
||||
physical_size = '0',
|
||||
content_type = nil,
|
||||
shared = false,
|
||||
sm_config = {} )
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,24 +2,32 @@ module Fog
|
|||
module Compute
|
||||
class XenServer
|
||||
class Real
|
||||
def create_vbd( vm_ref, vdi_ref, config = {} )
|
||||
raise ArgumentError.new('Invalid config') if config.nil?
|
||||
vm_ref = vm_ref.reference if vm_ref.kind_of? Fog::Compute::XenServer::Server
|
||||
vdi_ref = vdi_ref.reference if vdi_ref.kind_of? Fog::Compute::XenServer::VDI
|
||||
config.reject! { |k,v| (k == :server) or (k == :vdi) }
|
||||
default_config = {
|
||||
:VM => vm_ref,
|
||||
:VDI => vdi_ref,
|
||||
:empty => false,
|
||||
:other_config => {'owner' => ''},
|
||||
:userdevice => "0",
|
||||
:bootable => true,
|
||||
:mode => 'RW',
|
||||
:qos_algorithm_type=> '',
|
||||
:qos_algorithm_params=> {},
|
||||
:qos_supported_algorithms=> [],
|
||||
:type => 'Disk'
|
||||
}.merge config
|
||||
def create_vbd( vm_ref, vdi_ref = '', config = {} )
|
||||
if vm_ref.is_a?(Hash)
|
||||
default_config = vm_ref.reject! { |_k,v| v.nil? }
|
||||
else
|
||||
Fog::Logger.deprecation(
|
||||
'This api is deprecated. The only expected param is a hash of attributes.'
|
||||
)
|
||||
|
||||
raise ArgumentError.new('Invalid config') if config.nil?
|
||||
vm_ref = vm_ref.reference if vm_ref.kind_of? Fog::Compute::XenServer::Server
|
||||
vdi_ref = vdi_ref.reference if vdi_ref.kind_of? Fog::Compute::XenServer::VDI
|
||||
config.reject! { |k,v| (k == :server) or (k == :vdi) }
|
||||
default_config = {
|
||||
:VM => vm_ref,
|
||||
:VDI => vdi_ref,
|
||||
:empty => false,
|
||||
:other_config => {'owner' => ''},
|
||||
:userdevice => "0",
|
||||
:bootable => true,
|
||||
:mode => 'RW',
|
||||
:qos_algorithm_type=> '',
|
||||
:qos_algorithm_params=> {},
|
||||
:qos_supported_algorithms=> [],
|
||||
:type => 'Disk'
|
||||
}.merge config
|
||||
end
|
||||
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VBD.create'}, default_config )
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue