mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-08 20:58:17 +03:00
Feature #4400: New template instantiate --persistent
This commit is contained in:
parent
7855ebd22d
commit
53c5269249
@ -63,25 +63,26 @@ protected:
|
||||
class VMTemplateClone : public RequestManagerClone
|
||||
{
|
||||
public:
|
||||
VMTemplateClone():
|
||||
RequestManagerClone("VMTemplateClone",
|
||||
"Clone an existing virtual machine template",
|
||||
"A:sisb")
|
||||
|
||||
static VMTemplateClone& instance()
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
static VMTemplateClone instance;
|
||||
|
||||
auth_object = PoolObjectSQL::TEMPLATE;
|
||||
auth_op = AuthRequest::USE;
|
||||
return instance;
|
||||
};
|
||||
|
||||
~VMTemplateClone(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
|
||||
ErrorCode request_execute(
|
||||
int source_id,
|
||||
string name,
|
||||
bool recursive,
|
||||
int &new_id,
|
||||
RequestAttributes &att);
|
||||
|
||||
Template * clone_template(PoolObjectSQL* obj)
|
||||
{
|
||||
return static_cast<VMTemplate*>(obj)->clone_template();
|
||||
@ -101,6 +102,21 @@ public:
|
||||
return tpool->allocate(att.uid, att.gid, att.uname, att.gname, att.umask,
|
||||
ttmpl, &id, att.resp_msg);
|
||||
};
|
||||
|
||||
private:
|
||||
VMTemplateClone():
|
||||
RequestManagerClone("VMTemplateClone",
|
||||
"Clone an existing virtual machine template",
|
||||
"A:sisb")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
|
||||
auth_object = PoolObjectSQL::TEMPLATE;
|
||||
auth_op = AuthRequest::USE;
|
||||
};
|
||||
|
||||
~VMTemplateClone(){};
|
||||
};
|
||||
|
||||
|
||||
|
@ -58,6 +58,13 @@ EOT
|
||||
"image defined in DISK"
|
||||
}
|
||||
|
||||
PERSISTENT={
|
||||
:name => "persistent",
|
||||
:large => "--persistent",
|
||||
:description => "Creates a private persistent copy of the template "+
|
||||
"plus any image defined in DISK, and instantiates that copy"
|
||||
}
|
||||
|
||||
def self.rname
|
||||
"VMTEMPLATE"
|
||||
end
|
||||
|
@ -55,7 +55,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
OneTemplateHelper::VM_NAME,
|
||||
OneTemplateHelper::MULTIPLE,
|
||||
OneTemplateHelper::USERDATA,
|
||||
OneVMHelper::HOLD
|
||||
OneVMHelper::HOLD,
|
||||
OneTemplateHelper::PERSISTENT,
|
||||
]
|
||||
|
||||
########################################################################
|
||||
@ -231,7 +232,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
extra_template << "\n" << user_inputs
|
||||
|
||||
res = t.instantiate(name, on_hold, extra_template)
|
||||
persistent = options[:persistent] != nil
|
||||
|
||||
res = t.instantiate(name, on_hold, extra_template, persistent)
|
||||
|
||||
if !OpenNebula.is_error?(res)
|
||||
puts "VM ID: #{res}"
|
||||
|
@ -114,18 +114,22 @@ module OpenNebula
|
||||
# true to create it on hold
|
||||
# @param template [String] User provided Template to merge with the
|
||||
# one being instantiated
|
||||
# @param persistent [true,false] true to create a private persistent
|
||||
# copy of the template plus any image defined in DISK, and instantiate
|
||||
# that copy
|
||||
#
|
||||
# @return [Integer, OpenNebula::Error] The new VM id, Error
|
||||
# otherwise
|
||||
def instantiate(name="", hold=false, template="")
|
||||
def instantiate(name="", hold=false, template="", persistent=false)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
name ||= ""
|
||||
hold = false if hold.nil?
|
||||
template ||= ""
|
||||
persistent = false if persistent.nil?
|
||||
|
||||
rc = @client.call(
|
||||
TEMPLATE_METHODS[:instantiate], @pe_id, name, hold, template)
|
||||
rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id,
|
||||
name, hold, template, persistent)
|
||||
|
||||
return rc
|
||||
end
|
||||
|
@ -370,7 +370,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr vrouter_allocate(new VirtualRouterAllocate());
|
||||
|
||||
// Clone Methods
|
||||
xmlrpc_c::methodPtr template_clone(new VMTemplateClone());
|
||||
xmlrpc_c::methodPtr template_clone( &VMTemplateClone::instance() );
|
||||
xmlrpc_c::methodPtr doc_clone(new DocumentClone());
|
||||
xmlrpc_c::methodPtr secg_clone(new SecurityGroupClone());
|
||||
|
||||
|
@ -124,7 +124,30 @@ void VMTemplateClone::request_execute(
|
||||
recursive = xmlrpc_c::value_boolean(paramList.getBoolean(3));
|
||||
}
|
||||
|
||||
int new_id;
|
||||
int new_id;
|
||||
|
||||
ErrorCode ec = request_execute(source_id, name, recursive, new_id, att);
|
||||
|
||||
if ( ec == SUCCESS )
|
||||
{
|
||||
success_response(new_id, att);
|
||||
}
|
||||
else
|
||||
{
|
||||
failure_response(ec, att);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Request::ErrorCode VMTemplateClone::request_execute(
|
||||
int source_id,
|
||||
string name,
|
||||
bool recursive,
|
||||
int &new_id,
|
||||
RequestAttributes &att)
|
||||
{
|
||||
VMTemplate * vmtmpl;
|
||||
VMTemplatePool* tpool = static_cast<VMTemplatePool*>(pool);
|
||||
ErrorCode ec;
|
||||
@ -141,8 +164,7 @@ void VMTemplateClone::request_execute(
|
||||
|
||||
if ( ec != SUCCESS )
|
||||
{
|
||||
failure_response(ec, att);
|
||||
return;
|
||||
return ec;
|
||||
}
|
||||
|
||||
if (recursive)
|
||||
@ -160,8 +182,7 @@ void VMTemplateClone::request_execute(
|
||||
att.resp_msg = object_name(PoolObjectSQL::TEMPLATE) +
|
||||
" was cloned, but it was deleted before the disks could also be cloned.";
|
||||
|
||||
failure_response(ACTION, att);
|
||||
return;
|
||||
return ACTION;
|
||||
}
|
||||
|
||||
vmtmpl->get_disks(disks);
|
||||
@ -235,9 +256,7 @@ void VMTemplateClone::request_execute(
|
||||
vmtmpl->unlock();
|
||||
}
|
||||
|
||||
success_response(new_id, att);
|
||||
|
||||
return;
|
||||
return SUCCESS;
|
||||
|
||||
error_images:
|
||||
|
||||
@ -254,7 +273,7 @@ error_template:
|
||||
|
||||
for (i = new_img_ids.begin(); i != new_img_ids.end(); i++)
|
||||
{
|
||||
ec = ImageDelete::delete_img(*i, att);
|
||||
ec = ImageDelete::delete_img(*i, img_att);
|
||||
|
||||
if (ec != SUCCESS)
|
||||
{
|
||||
@ -268,9 +287,7 @@ error_template:
|
||||
delete *i;
|
||||
}
|
||||
|
||||
failure_response(ACTION, att);
|
||||
|
||||
return;
|
||||
return ACTION;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "RequestManagerVMTemplate.h"
|
||||
#include "PoolObjectAuth.h"
|
||||
#include "Nebula.h"
|
||||
#include "RequestManagerClone.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -28,6 +29,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
|
||||
string name = xmlrpc_c::value_string(paramList.getString(2));
|
||||
bool on_hold = false; //Optional XML-RPC argument
|
||||
string str_uattrs; //Optional XML-RPC argument
|
||||
bool clone_template = false; //Optional XML-RPC argument
|
||||
|
||||
if ( paramList.size() > 3 )
|
||||
{
|
||||
@ -36,6 +38,11 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
|
||||
str_uattrs = xmlrpc_c::value_string(paramList.getString(4));
|
||||
}
|
||||
|
||||
if ( paramList.size() > 5 )
|
||||
{
|
||||
clone_template = xmlrpc_c::value_boolean(paramList.getBoolean(5));
|
||||
}
|
||||
|
||||
VMTemplate * tmpl = static_cast<VMTemplatePool* > (pool)->get(id,true);
|
||||
|
||||
if ( tmpl == 0 )
|
||||
@ -56,10 +63,27 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
|
||||
return;
|
||||
}
|
||||
|
||||
int instantiate_id = id;
|
||||
|
||||
if (clone_template)
|
||||
{
|
||||
int new_id;
|
||||
|
||||
ErrorCode ec = VMTemplateClone::instance().request_execute(id, name, true, new_id, att);
|
||||
|
||||
if (ec != SUCCESS)
|
||||
{
|
||||
failure_response(ec, att);
|
||||
return;
|
||||
}
|
||||
|
||||
instantiate_id = new_id;
|
||||
}
|
||||
|
||||
int vid;
|
||||
ErrorCode ec;
|
||||
|
||||
ec = instantiate(id, name, on_hold, str_uattrs, 0, vid, att);
|
||||
ec = instantiate(instantiate_id, name, on_hold, str_uattrs, 0, vid, att);
|
||||
|
||||
if ( ec == SUCCESS )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user