mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
* Added clone_server request
This commit is contained in:
parent
7d0b7d8814
commit
9ea96293e6
4 changed files with 64 additions and 2 deletions
|
@ -39,6 +39,7 @@ module Fog
|
|||
request_path 'fog/xenserver/requests/compute'
|
||||
request :create_server
|
||||
request :create_vif
|
||||
request :clone_server
|
||||
request :destroy_server
|
||||
request :destroy_vbd
|
||||
request :destroy_vdi
|
||||
|
|
31
lib/fog/xenserver/requests/compute/clone_server.rb
Normal file
31
lib/fog/xenserver/requests/compute/clone_server.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class XenServer
|
||||
class Real
|
||||
|
||||
def clone_server( server_name, template_ref )
|
||||
# Clone the VM template
|
||||
if template_ref.kind_of? Fog::Compute::XenServer::Server
|
||||
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
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def clone_server( server_name, template_ref )
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,8 +3,6 @@ module Fog
|
|||
class XenServer
|
||||
class Real
|
||||
|
||||
require 'fog/xenserver/parsers/get_vms'
|
||||
|
||||
def get_vm_by_name(label)
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.get_by_name_label' }, label)
|
||||
end
|
||||
|
|
32
tests/xenserver/requests/compute/clone_server.rb
Normal file
32
tests/xenserver/requests/compute/clone_server.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
Shindo.tests('Fog::Compute[:xenserver] | clone_server request', ['xenserver']) do
|
||||
|
||||
compute = Fog::Compute[:xenserver]
|
||||
servers = compute.servers
|
||||
(servers.all :name_matches => test_ephemeral_vm_name).each do |s|
|
||||
s.destroy
|
||||
end
|
||||
|
||||
tests('clone_server should') do
|
||||
raises(ArgumentError, 'raise exception when template nil') do
|
||||
compute.clone_server 'fooserver', nil
|
||||
end
|
||||
raises(ArgumentError, 'raise exception when name nil') do
|
||||
compute.clone_server nil, 'fooref'
|
||||
end
|
||||
|
||||
compute.default_template = test_template_name
|
||||
tmpl = compute.default_template
|
||||
test('accept a string template ref') do
|
||||
ref = compute.clone_server test_ephemeral_vm_name, tmpl.reference
|
||||
(ref =~ /OpaqueRef:/) == 0 and !(servers.custom_templates.find { |s| s.reference == ref }).nil?
|
||||
end
|
||||
test('accept a Server object') do
|
||||
ref = compute.clone_server test_ephemeral_vm_name, tmpl
|
||||
(ref =~ /OpaqueRef:/) == 0 and !(servers.custom_templates.find { |s| s.reference == ref }).nil?
|
||||
end
|
||||
end
|
||||
|
||||
tests('The expected options') do
|
||||
raises(ArgumentError, 'raises ArgumentError when ref,class missing') { compute.clone_server }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue