2012-04-02 13:25:03 +02:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class XenServer
|
|
|
|
class Real
|
|
|
|
|
2012-04-04 09:01:55 +02:00
|
|
|
def get_vm_by_name(label)
|
|
|
|
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.get_by_name_label' }, label)
|
2012-04-02 13:25:03 +02:00
|
|
|
end
|
2012-04-04 09:01:55 +02:00
|
|
|
|
|
|
|
def create_server( name_label, template = nil, network = nil, extra_args = {})
|
|
|
|
template ||= default_template
|
|
|
|
network ||= default_network
|
|
|
|
|
|
|
|
if template.nil?
|
|
|
|
raise "Invalid template"
|
|
|
|
end
|
2012-04-02 13:25:03 +02:00
|
|
|
|
2012-04-04 09:01:55 +02:00
|
|
|
if template.kind_of? String
|
|
|
|
template_string = template
|
|
|
|
template = servers.get get_vm_by_name(template_string)
|
|
|
|
end
|
2012-04-02 13:25:03 +02:00
|
|
|
|
2012-04-04 09:01:55 +02:00
|
|
|
#FIXME: need to check that template exist actually
|
|
|
|
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
|
|
|
|
@connection.request(
|
|
|
|
{:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.clone'},
|
|
|
|
template.reference, name_label
|
|
|
|
)
|
|
|
|
new_vm = servers.get get_vm_by_name( name_label )
|
2012-04-02 13:25:03 +02:00
|
|
|
|
2012-04-04 09:01:55 +02:00
|
|
|
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.provision'}, new_vm.reference)
|
|
|
|
start_vm( new_vm.reference ) unless extra_args[:auto_start] == false
|
|
|
|
|
|
|
|
new_vm
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def create_server( name_label, template = nil, network = nil, extra_args = {})
|
2012-04-02 13:25:03 +02:00
|
|
|
Fog::Mock.not_implemented
|
|
|
|
end
|
2012-04-04 09:01:55 +02:00
|
|
|
|
2012-04-02 13:25:03 +02:00
|
|
|
end
|
2012-04-04 09:01:55 +02:00
|
|
|
|
2012-04-02 13:25:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|