mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-26 06:50:09 +03:00
Feature #487: Small auth and DB bugfixes, and support to allocate a VM from a template using its TEMPLATE_ID
This commit is contained in:
parent
77f861a2b5
commit
b27c9372f5
@ -321,10 +321,12 @@ private:
|
||||
VirtualMachinePool * _vmpool,
|
||||
VirtualNetworkPool * _vnpool,
|
||||
ImagePool * _ipool,
|
||||
VMTemplatePool * _tpool,
|
||||
UserPool * _upool):
|
||||
vmpool(_vmpool),
|
||||
vnpool(_vnpool),
|
||||
ipool(_ipool),
|
||||
tpool(_tpool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:ss";
|
||||
@ -340,6 +342,7 @@ private:
|
||||
VirtualMachinePool * vmpool;
|
||||
VirtualNetworkPool * vnpool;
|
||||
ImagePool * ipool;
|
||||
VMTemplatePool * tpool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
|
@ -161,8 +161,10 @@ public:
|
||||
* @param name the attribute name.
|
||||
* @param value the attribute value, an int, 0 if the attribute is not
|
||||
* defined or not Single
|
||||
*
|
||||
* @returns True if the Single attribute was found
|
||||
*/
|
||||
virtual void get(
|
||||
virtual bool get(
|
||||
string& name,
|
||||
int& value) const;
|
||||
|
||||
|
@ -74,6 +74,11 @@ public:
|
||||
// Template Contents
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
VirtualMachineTemplate * get_template_contents() const
|
||||
{
|
||||
return new VirtualMachineTemplate(*template_contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the values of a template attribute
|
||||
* @param name of the attribute
|
||||
@ -178,12 +183,16 @@ private:
|
||||
*/
|
||||
VirtualMachineTemplate* template_contents;
|
||||
|
||||
|
||||
/**
|
||||
* Public scope of the VMTemplate
|
||||
*/
|
||||
int public_template;
|
||||
|
||||
/**
|
||||
* Registration time
|
||||
*/
|
||||
time_t regtime;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
|
@ -148,7 +148,7 @@ void AuthRequest::add_auth(Object ob,
|
||||
switch (op)
|
||||
{
|
||||
case CREATE:
|
||||
if ( ob == VM || ob == NET || ob == IMAGE )
|
||||
if ( ob == VM || ob == NET || ob == IMAGE || ob == TEMPLATE )
|
||||
{
|
||||
auth = true;
|
||||
}
|
||||
@ -159,7 +159,7 @@ void AuthRequest::add_auth(Object ob,
|
||||
break;
|
||||
|
||||
case USE:
|
||||
if (ob == NET || ob == IMAGE)
|
||||
if (ob == NET || ob == IMAGE || ob == TEMPLATE)
|
||||
{
|
||||
auth = (owner == uid) || pub;
|
||||
}
|
||||
|
@ -70,14 +70,8 @@ ShowTableTemplate={
|
||||
:proc => lambda {|d,e|
|
||||
if d["PUBLIC"].to_i == 1 then "Yes" else "No" end}
|
||||
},
|
||||
:runningvms => {
|
||||
:name => "#VMS",
|
||||
:desc => "Number of VMs currently running from this Template",
|
||||
:size => 5,
|
||||
:proc => lambda {|d,e| d['RUNNING_VMS'] }
|
||||
},
|
||||
|
||||
:default => [:id, :user, :name, :regtime, :public, :runningvms]
|
||||
:default => [:id, :user, :name, :regtime, :public]
|
||||
}
|
||||
|
||||
|
||||
@ -377,8 +371,6 @@ when "show"
|
||||
end
|
||||
puts str % ["PUBLIC", public_str]
|
||||
|
||||
puts str % ["RUNNING_VMS", template['RUNNING_VMS']]
|
||||
|
||||
puts
|
||||
|
||||
print_header(str_h1,"TEMPLATE CONTENTS",false)
|
||||
@ -400,7 +392,7 @@ when "delete"
|
||||
OpenNebula::Template.build_xml(template_id),
|
||||
get_one_client)
|
||||
|
||||
result = img_repo.delete(template)
|
||||
result = template.delete
|
||||
if is_successful?(result)
|
||||
puts "Template correctly deleted" if ops[:verbose]
|
||||
end
|
||||
|
@ -214,7 +214,7 @@ void RequestManager::do_action(
|
||||
void RequestManager::register_xml_methods()
|
||||
{
|
||||
xmlrpc_c::methodPtr vm_allocate(new
|
||||
RequestManager::VirtualMachineAllocate(vmpool, vnpool, ipool, upool));
|
||||
RequestManager::VirtualMachineAllocate(vmpool,vnpool,ipool,tpool,upool));
|
||||
|
||||
xmlrpc_c::methodPtr vm_deploy(new
|
||||
RequestManager::VirtualMachineDeploy(vmpool,hpool,upool));
|
||||
|
@ -30,10 +30,11 @@ void RequestManager::VirtualMachineAllocate::execute(
|
||||
string str_template;
|
||||
string error_str;
|
||||
string user_name;
|
||||
string att_name;
|
||||
|
||||
const string method_name = "VirtualMachineAllocate";
|
||||
|
||||
int vid, uid;
|
||||
int vid, uid, tid;
|
||||
int rc;
|
||||
|
||||
ostringstream oss;
|
||||
@ -43,6 +44,11 @@ void RequestManager::VirtualMachineAllocate::execute(
|
||||
|
||||
VirtualMachineTemplate * vm_template;
|
||||
User * user;
|
||||
VMTemplate * registered_template;
|
||||
bool using_template_pool;
|
||||
int template_owner;
|
||||
bool template_public;
|
||||
|
||||
char * error_msg = 0;
|
||||
|
||||
int num;
|
||||
@ -77,11 +83,46 @@ void RequestManager::VirtualMachineAllocate::execute(
|
||||
goto error_parse;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Look for a template id
|
||||
//--------------------------------------------------------------------------
|
||||
att_name = "TEMPLATE_ID";
|
||||
using_template_pool = vm_template->get(att_name, tid);
|
||||
|
||||
if( using_template_pool )
|
||||
{
|
||||
// Get the registered template
|
||||
registered_template = VirtualMachineAllocate::tpool->get(tid, true);
|
||||
|
||||
if( registered_template == 0 )
|
||||
{
|
||||
goto error_template_get;
|
||||
}
|
||||
|
||||
delete vm_template;
|
||||
|
||||
// Use the template contents
|
||||
vm_template = registered_template->get_template_contents();
|
||||
template_owner = registered_template->get_uid();
|
||||
template_public = registered_template->isPublic();
|
||||
|
||||
registered_template->unlock();
|
||||
}
|
||||
|
||||
if ( uid != 0 )
|
||||
{
|
||||
AuthRequest ar(uid);
|
||||
string t64;
|
||||
|
||||
if( using_template_pool )
|
||||
{
|
||||
ar.add_auth(AuthRequest::TEMPLATE,
|
||||
tid,
|
||||
AuthRequest::USE,
|
||||
template_owner,
|
||||
template_public);
|
||||
}
|
||||
|
||||
num = vm_template->get("DISK",vectors);
|
||||
|
||||
for(int i=0; i<num; i++)
|
||||
@ -165,6 +206,11 @@ void RequestManager::VirtualMachineAllocate::execute(
|
||||
|
||||
return;
|
||||
|
||||
error_template_get:
|
||||
oss.str(get_error(method_name, "TEMPLATE", tid));
|
||||
|
||||
delete vm_template;
|
||||
goto error_common;
|
||||
|
||||
error_user_get:
|
||||
oss.str(get_error(method_name, "USER", uid));
|
||||
|
@ -309,7 +309,7 @@ void Template::get(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void Template::get(
|
||||
bool Template::get(
|
||||
string& name,
|
||||
int& value) const
|
||||
{
|
||||
@ -320,12 +320,13 @@ void Template::get(
|
||||
if ( sval == "" )
|
||||
{
|
||||
value = 0;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
istringstream iss(sval);
|
||||
|
||||
iss >> value;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -28,7 +28,8 @@ VMTemplate::VMTemplate(int id,
|
||||
string _user_name,
|
||||
VirtualMachineTemplate * _template_contents):
|
||||
PoolObjectSQL(id,"",_uid,table),
|
||||
user_name(_user_name)
|
||||
user_name(_user_name),
|
||||
regtime(time(0))
|
||||
{
|
||||
if (_template_contents != 0)
|
||||
{
|
||||
@ -61,7 +62,7 @@ const char * VMTemplate::db_names = "oid, name, body, uid, public";
|
||||
|
||||
const char * VMTemplate::db_bootstrap =
|
||||
"CREATE TABLE IF NOT EXISTS template_pool (oid INTEGER PRIMARY KEY, "
|
||||
"name VARCHAR(256), body TEXT, uid INTEGER, public INTEGER, UNIQUE(name))";
|
||||
"name VARCHAR(256), body TEXT, uid INTEGER, public INTEGER)";
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
@ -197,6 +198,7 @@ string& VMTemplate::to_xml(string& xml) const
|
||||
<< "<USERNAME>" << user_name << "</USERNAME>"
|
||||
<< "<NAME>" << name << "</NAME>"
|
||||
<< "<PUBLIC>" << public_template << "</PUBLIC>"
|
||||
<< "<REGTIME>" << regtime << "</REGTIME>"
|
||||
<< template_contents->to_xml(template_xml)
|
||||
<< "</VMTEMPLATE>";
|
||||
|
||||
@ -222,6 +224,7 @@ int VMTemplate::from_xml(const string& xml)
|
||||
rc += xpath(user_name, "/VMTEMPLATE/USERNAME", "not_found");
|
||||
rc += xpath(name, "/VMTEMPLATE/NAME", "not_found");
|
||||
rc += xpath(public_template,"/VMTEMPLATE/PUBLIC", 0);
|
||||
rc += xpath(regtime, "/VMTEMPLATE/REGTIME", 0);
|
||||
|
||||
// Get associated classes
|
||||
ObjectXML::get_nodes("/VMTEMPLATE/TEMPLATE", content);
|
||||
|
Loading…
x
Reference in New Issue
Block a user