mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
Feature #1304: Add new methods one.generic.*. VMTemplates have a new 'type' attribute.
As things are right now, VMTemplates with different types share the "namespace", meaning that you can't have two templtes with the same name even if their type is different
This commit is contained in:
parent
3c9b00173b
commit
04940ff188
@ -217,7 +217,7 @@ public:
|
||||
class TemplateAllocate : public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
TemplateAllocate():
|
||||
TemplateAllocate(int type):
|
||||
RequestManagerAllocate("TemplateAllocate",
|
||||
"Allocates a new virtual machine template",
|
||||
"A:ss",
|
||||
@ -226,6 +226,8 @@ public:
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = PoolObjectSQL::TEMPLATE;
|
||||
|
||||
this->type = type;
|
||||
};
|
||||
|
||||
~TemplateAllocate(){};
|
||||
@ -233,7 +235,7 @@ public:
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
Template * get_object_template()
|
||||
{
|
||||
{
|
||||
return new VirtualMachineTemplate;
|
||||
};
|
||||
|
||||
@ -242,6 +244,10 @@ public:
|
||||
int& id,
|
||||
string& error_str,
|
||||
RequestAttributes& att);
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
private:
|
||||
int type;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -40,6 +40,14 @@ protected:
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
return pool->get(oid,true);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -66,7 +74,7 @@ public:
|
||||
class TemplateChmod : public RequestManagerChmod
|
||||
{
|
||||
public:
|
||||
TemplateChmod():
|
||||
TemplateChmod(int type):
|
||||
RequestManagerChmod("TemplateChmod",
|
||||
"Changes permission bits of a virtual machine template")
|
||||
{
|
||||
@ -76,6 +84,26 @@ public:
|
||||
};
|
||||
|
||||
~TemplateChmod(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int obj_type = type;
|
||||
|
||||
if ( obj_type == -1 )
|
||||
{
|
||||
obj_type = xmlrpc_c::value_int(paramList.getInt(11));
|
||||
}
|
||||
|
||||
VMTemplatePool* tpool = static_cast<VMTemplatePool*>(pool);
|
||||
return tpool->get(oid, obj_type, true);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
private:
|
||||
int type;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -52,6 +52,15 @@ protected:
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual PoolObjectSQL * get_obj(
|
||||
int oid,
|
||||
xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
return pool->get(oid,true);
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -78,16 +87,38 @@ public:
|
||||
class TemplateChown : public RequestManagerChown
|
||||
{
|
||||
public:
|
||||
TemplateChown():
|
||||
TemplateChown(int type):
|
||||
RequestManagerChown("TemplateChown",
|
||||
"Changes ownership of a virtual machine template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = PoolObjectSQL::TEMPLATE;
|
||||
|
||||
this->type = type;
|
||||
};
|
||||
|
||||
~TemplateChown(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int obj_type = type;
|
||||
|
||||
if ( obj_type == -1 )
|
||||
{
|
||||
obj_type = xmlrpc_c::value_int(paramList.getInt(4));
|
||||
}
|
||||
|
||||
VMTemplatePool* tpool = static_cast<VMTemplatePool*>(pool);
|
||||
return tpool->get(oid, obj_type, true);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
private:
|
||||
int type;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -53,6 +53,11 @@ protected:
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
return pool->get(oid,true);
|
||||
};
|
||||
|
||||
virtual int drop(int oid, PoolObjectSQL * object, string& error_msg);
|
||||
|
||||
virtual int get_cluster_id(PoolObjectSQL * object)
|
||||
@ -77,7 +82,7 @@ protected:
|
||||
class TemplateDelete : public RequestManagerDelete
|
||||
{
|
||||
public:
|
||||
TemplateDelete():
|
||||
TemplateDelete(int type):
|
||||
RequestManagerDelete("TemplateDelete",
|
||||
"Deletes a virtual machine template")
|
||||
{
|
||||
@ -87,6 +92,26 @@ public:
|
||||
};
|
||||
|
||||
~TemplateDelete(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int obj_type = type;
|
||||
|
||||
if ( obj_type == -1 )
|
||||
{
|
||||
obj_type = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
}
|
||||
|
||||
VMTemplatePool* tpool = static_cast<VMTemplatePool*>(pool);
|
||||
return tpool->get(oid, obj_type, true);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
private:
|
||||
int type;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -45,6 +45,13 @@ protected:
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
return pool->get(oid,true);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void to_xml(PoolObjectSQL * object, string& str)
|
||||
{
|
||||
object->to_xml(str);
|
||||
@ -83,16 +90,38 @@ public:
|
||||
class TemplateInfo : public RequestManagerInfo
|
||||
{
|
||||
public:
|
||||
TemplateInfo():
|
||||
TemplateInfo(int type):
|
||||
RequestManagerInfo("TemplateInfo",
|
||||
"Returns virtual machine template information")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = PoolObjectSQL::TEMPLATE;
|
||||
|
||||
this->type = type;
|
||||
};
|
||||
|
||||
~TemplateInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int obj_type = type;
|
||||
|
||||
if ( obj_type == -1 )
|
||||
{
|
||||
obj_type = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
}
|
||||
|
||||
VMTemplatePool* tpool = static_cast<VMTemplatePool*>(pool);
|
||||
return tpool->get(oid, obj_type, true);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
private:
|
||||
int type;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -160,17 +160,29 @@ public:
|
||||
class TemplatePoolInfo : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
TemplatePoolInfo():
|
||||
TemplatePoolInfo(int type):
|
||||
RequestManagerPoolInfoFilter("TemplatePoolInfo",
|
||||
"Returns the virtual machine template pool",
|
||||
"A:siii")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = PoolObjectSQL::TEMPLATE;
|
||||
|
||||
this->type = type;
|
||||
};
|
||||
|
||||
~TemplatePoolInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
private:
|
||||
int type;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -42,6 +42,13 @@ protected:
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
return pool->get(oid,true);
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -50,16 +57,38 @@ protected:
|
||||
class TemplateUpdateTemplate: public RequestManagerUpdateTemplate
|
||||
{
|
||||
public:
|
||||
TemplateUpdateTemplate():
|
||||
TemplateUpdateTemplate(int type):
|
||||
RequestManagerUpdateTemplate("TemplateUpdateTemplate",
|
||||
"Updates a virtual machine template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = PoolObjectSQL::TEMPLATE;
|
||||
|
||||
this->type = type;
|
||||
};
|
||||
|
||||
~TemplateUpdateTemplate(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
PoolObjectSQL * get_obj(int oid, xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int obj_type = type;
|
||||
|
||||
if ( obj_type == -1 )
|
||||
{
|
||||
obj_type = xmlrpc_c::value_int(paramList.getInt(3));
|
||||
}
|
||||
|
||||
VMTemplatePool* tpool = static_cast<VMTemplatePool*>(pool);
|
||||
return tpool->get(oid, obj_type, true);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
private:
|
||||
int type;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
class VMTemplateClone : public RequestManagerVMTemplate
|
||||
{
|
||||
public:
|
||||
VMTemplateClone():
|
||||
VMTemplateClone(int type):
|
||||
RequestManagerVMTemplate("VMTemplateClone",
|
||||
"Clone an existing virtual machine template",
|
||||
"A:sis")
|
||||
@ -86,6 +86,9 @@ public:
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
|
||||
private:
|
||||
int type;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -59,6 +59,16 @@ public:
|
||||
*(static_cast<VirtualMachineTemplate *>(obj_template)));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the template type, 0 for VM Templates
|
||||
*
|
||||
* @return the template type
|
||||
*/
|
||||
int get_template_type()
|
||||
{
|
||||
return type;
|
||||
};
|
||||
|
||||
private:
|
||||
// -------------------------------------------------------------------------
|
||||
// Friends
|
||||
@ -75,6 +85,12 @@ private:
|
||||
*/
|
||||
time_t regtime;
|
||||
|
||||
/**
|
||||
* Template type, to implement generic objects.
|
||||
* The default VM templates are type 0
|
||||
*/
|
||||
int type;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
@ -117,6 +133,7 @@ protected:
|
||||
int gid,
|
||||
const string& uname,
|
||||
const string& gname,
|
||||
int type,
|
||||
VirtualMachineTemplate * _template_contents);
|
||||
|
||||
~VMTemplate();
|
||||
|
@ -36,6 +36,9 @@ public:
|
||||
* allocated for the object.
|
||||
* @param uid user id (the owner of the Template)
|
||||
* @param gid the id of the group this object is assigned to
|
||||
* @param uname name of the owner user
|
||||
* @param gname name of the group
|
||||
* @param type for the new template
|
||||
* @param template_contents a VM Template object
|
||||
* @param oid the id assigned to the Template
|
||||
* @param error_str Returns the error reason, if any
|
||||
@ -46,6 +49,7 @@ public:
|
||||
int gid,
|
||||
const string& uname,
|
||||
const string& gname,
|
||||
int type,
|
||||
VirtualMachineTemplate * template_contents,
|
||||
int * oid,
|
||||
string& error_str);
|
||||
@ -58,9 +62,21 @@ public:
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
VMTemplate * get(int oid, bool lock)
|
||||
VMTemplate * get(int oid, int type, bool lock)
|
||||
{
|
||||
return static_cast<VMTemplate *>(PoolSQL::get(oid,lock));
|
||||
VMTemplate* tmpl = static_cast<VMTemplate *>(PoolSQL::get(oid,lock));
|
||||
|
||||
if ( tmpl != 0 && tmpl->get_template_type() != type )
|
||||
{
|
||||
if ( lock )
|
||||
{
|
||||
tmpl->unlock();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return tmpl;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -118,7 +134,7 @@ private:
|
||||
*/
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new VMTemplate(-1,-1,-1,"","",0);
|
||||
return new VMTemplate(-1,-1,-1,"","",0,0);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -236,7 +236,8 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
// VMTemplate Methods
|
||||
xmlrpc_c::methodPtr template_instantiate(new VMTemplateInstantiate());
|
||||
xmlrpc_c::methodPtr template_clone(new VMTemplateClone());
|
||||
xmlrpc_c::methodPtr template_clone(new VMTemplateClone(0));
|
||||
xmlrpc_c::methodPtr generic_clone(new VMTemplateClone(-1));
|
||||
|
||||
// VirtualMachine Methods
|
||||
xmlrpc_c::methodPtr vm_deploy(new VirtualMachineDeploy());
|
||||
@ -255,43 +256,47 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
// Update Template Methods
|
||||
xmlrpc_c::methodPtr image_update(new ImageUpdateTemplate());
|
||||
xmlrpc_c::methodPtr template_update(new TemplateUpdateTemplate());
|
||||
xmlrpc_c::methodPtr template_update(new TemplateUpdateTemplate(0));
|
||||
xmlrpc_c::methodPtr host_update(new HostUpdateTemplate());
|
||||
xmlrpc_c::methodPtr vn_update(new VirtualNetworkUpdateTemplate());
|
||||
xmlrpc_c::methodPtr user_update(new UserUpdateTemplate());
|
||||
xmlrpc_c::methodPtr datastore_update(new DatastoreUpdateTemplate());
|
||||
xmlrpc_c::methodPtr generic_update(new TemplateUpdateTemplate(-1));
|
||||
|
||||
// Allocate Methods
|
||||
xmlrpc_c::methodPtr vm_allocate(new VirtualMachineAllocate());
|
||||
xmlrpc_c::methodPtr image_allocate(new ImageAllocate());
|
||||
xmlrpc_c::methodPtr vn_allocate(new VirtualNetworkAllocate());
|
||||
xmlrpc_c::methodPtr group_allocate(new GroupAllocate());
|
||||
xmlrpc_c::methodPtr template_allocate(new TemplateAllocate());
|
||||
xmlrpc_c::methodPtr template_allocate(new TemplateAllocate(0));
|
||||
xmlrpc_c::methodPtr host_allocate(new HostAllocate());
|
||||
xmlrpc_c::methodPtr user_allocate(new UserAllocate());
|
||||
xmlrpc_c::methodPtr datastore_allocate(new DatastoreAllocate());
|
||||
xmlrpc_c::methodPtr cluster_allocate(new ClusterAllocate());
|
||||
xmlrpc_c::methodPtr generic_allocate(new TemplateAllocate(-1));
|
||||
|
||||
// Delete Methods
|
||||
xmlrpc_c::methodPtr host_delete(new HostDelete());
|
||||
xmlrpc_c::methodPtr template_delete(new TemplateDelete());
|
||||
xmlrpc_c::methodPtr template_delete(new TemplateDelete(0));
|
||||
xmlrpc_c::methodPtr group_delete(new GroupDelete());
|
||||
xmlrpc_c::methodPtr vn_delete(new VirtualNetworkDelete());
|
||||
xmlrpc_c::methodPtr user_delete(new UserDelete());
|
||||
xmlrpc_c::methodPtr image_delete(new ImageDelete());
|
||||
xmlrpc_c::methodPtr datastore_delete(new DatastoreDelete());
|
||||
xmlrpc_c::methodPtr cluster_delete(new ClusterDelete());
|
||||
xmlrpc_c::methodPtr generic_delete(new TemplateDelete(-1));
|
||||
|
||||
// Info Methods
|
||||
xmlrpc_c::methodPtr vm_info(new VirtualMachineInfo());
|
||||
xmlrpc_c::methodPtr host_info(new HostInfo());
|
||||
xmlrpc_c::methodPtr template_info(new TemplateInfo());
|
||||
xmlrpc_c::methodPtr template_info(new TemplateInfo(0));
|
||||
xmlrpc_c::methodPtr group_info(new GroupInfo());
|
||||
xmlrpc_c::methodPtr vn_info(new VirtualNetworkInfo());
|
||||
xmlrpc_c::methodPtr user_info(new UserInfo());
|
||||
xmlrpc_c::methodPtr image_info(new ImageInfo());
|
||||
xmlrpc_c::methodPtr datastore_info(new DatastoreInfo());
|
||||
xmlrpc_c::methodPtr cluster_info(new ClusterInfo());
|
||||
xmlrpc_c::methodPtr generic_info(new TemplateInfo(-1));
|
||||
|
||||
// PoolInfo Methods
|
||||
xmlrpc_c::methodPtr hostpool_info(new HostPoolInfo());
|
||||
@ -299,10 +304,11 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr userpool_info(new UserPoolInfo());
|
||||
xmlrpc_c::methodPtr datastorepool_info(new DatastorePoolInfo());
|
||||
xmlrpc_c::methodPtr vm_pool_info(new VirtualMachinePoolInfo());
|
||||
xmlrpc_c::methodPtr template_pool_info(new TemplatePoolInfo());
|
||||
xmlrpc_c::methodPtr template_pool_info(new TemplatePoolInfo(0));
|
||||
xmlrpc_c::methodPtr vnpool_info(new VirtualNetworkPoolInfo());
|
||||
xmlrpc_c::methodPtr imagepool_info(new ImagePoolInfo());
|
||||
xmlrpc_c::methodPtr clusterpool_info(new ClusterPoolInfo());
|
||||
xmlrpc_c::methodPtr generic_pool_info(new TemplatePoolInfo(-1));
|
||||
|
||||
// Host Methods
|
||||
xmlrpc_c::methodPtr host_enable(new HostEnable());
|
||||
@ -316,18 +322,20 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
// Chown Methods
|
||||
xmlrpc_c::methodPtr vm_chown(new VirtualMachineChown());
|
||||
xmlrpc_c::methodPtr template_chown(new TemplateChown());
|
||||
xmlrpc_c::methodPtr template_chown(new TemplateChown(0));
|
||||
xmlrpc_c::methodPtr vn_chown(new VirtualNetworkChown());
|
||||
xmlrpc_c::methodPtr image_chown(new ImageChown());
|
||||
xmlrpc_c::methodPtr user_chown(new UserChown());
|
||||
xmlrpc_c::methodPtr datastore_chown(new DatastoreChown());
|
||||
xmlrpc_c::methodPtr generic_chown(new TemplateChown(-1));
|
||||
|
||||
// Chmod Methods
|
||||
xmlrpc_c::methodPtr vm_chmod(new VirtualMachineChmod());
|
||||
xmlrpc_c::methodPtr template_chmod(new TemplateChmod());
|
||||
xmlrpc_c::methodPtr template_chmod(new TemplateChmod(0));
|
||||
xmlrpc_c::methodPtr vn_chmod(new VirtualNetworkChmod());
|
||||
xmlrpc_c::methodPtr image_chmod(new ImageChmod());
|
||||
xmlrpc_c::methodPtr datastore_chmod(new DatastoreChmod());
|
||||
xmlrpc_c::methodPtr generic_chmod(new TemplateChmod(-1));
|
||||
|
||||
// ACL Methods
|
||||
xmlrpc_c::methodPtr acl_addrule(new AclAddRule());
|
||||
@ -369,6 +377,17 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
RequestManagerRegistry.addMethod("one.templatepool.info",template_pool_info);
|
||||
|
||||
/* Generic objects related methods*/
|
||||
RequestManagerRegistry.addMethod("one.generic.allocate",generic_allocate);
|
||||
RequestManagerRegistry.addMethod("one.generic.delete", generic_delete);
|
||||
RequestManagerRegistry.addMethod("one.generic.info", generic_info);
|
||||
RequestManagerRegistry.addMethod("one.generic.update", generic_update);
|
||||
RequestManagerRegistry.addMethod("one.generic.chown", generic_chown);
|
||||
RequestManagerRegistry.addMethod("one.generic.chmod", generic_chmod);
|
||||
RequestManagerRegistry.addMethod("one.generic.clone", generic_clone);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.genericpool.info",generic_pool_info);
|
||||
|
||||
/* Host related methods*/
|
||||
RequestManagerRegistry.addMethod("one.host.enable", host_enable);
|
||||
RequestManagerRegistry.addMethod("one.host.update", host_update);
|
||||
|
@ -417,18 +417,28 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int TemplateAllocate::pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
int TemplateAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int obj_type = type;
|
||||
|
||||
if ( obj_type == -1 )
|
||||
{
|
||||
obj_type = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
|
||||
// TODO: check type is >= 100, to reserve the
|
||||
// other types for internal usage
|
||||
}
|
||||
|
||||
VMTemplatePool * tpool = static_cast<VMTemplatePool *>(pool);
|
||||
|
||||
VirtualMachineTemplate * ttmpl=static_cast<VirtualMachineTemplate *>(tmpl);
|
||||
|
||||
return tpool->allocate(att.uid, att.gid, att.uname, att.gname, ttmpl, &id,
|
||||
error_str);
|
||||
return tpool->allocate(att.uid, att.gid, att.uname, att.gname, obj_type,
|
||||
ttmpl, &id, error_str);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -49,7 +49,7 @@ void RequestManagerChmod::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
AuthRequest::Operation op = AuthRequest::MANAGE;
|
||||
PoolObjectAuth perms;
|
||||
|
||||
object = pool->get(oid,true);
|
||||
object = get_obj(oid, paramList);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
@ -128,7 +128,7 @@ void RequestManagerChmod::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
// ------------- Update the object ---------------------
|
||||
|
||||
object = pool->get(oid,true);
|
||||
object = get_obj(oid, paramList);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
|
@ -104,7 +104,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
// ------------- Update the object ---------------------
|
||||
|
||||
object = pool->get(oid,true);
|
||||
object = get_obj(oid, true);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
object = pool->get(oid,true);
|
||||
object = get_obj(oid, paramList);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
object = pool->get(oid,true);
|
||||
object = get_obj(oid, paramList);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
|
@ -167,6 +167,30 @@ void VirtualMachinePoolMonitoring::request_execute(
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void TemplatePoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int filter_flag = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
int start_id = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
int end_id = xmlrpc_c::value_int(paramList.getInt(3));
|
||||
|
||||
int obj_type = type;
|
||||
|
||||
if ( obj_type == -1 )
|
||||
{
|
||||
obj_type = xmlrpc_c::value_int(paramList.getInt(4));
|
||||
}
|
||||
|
||||
ostringstream oss;
|
||||
oss << "type = " << obj_type;
|
||||
|
||||
dump(att, filter_flag, start_id, end_id, oss.str(), "");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void HostPoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
|
@ -38,7 +38,7 @@ void RequestManagerUpdateTemplate::request_execute(
|
||||
return;
|
||||
}
|
||||
|
||||
object = pool->get(oid,true);
|
||||
object = get_obj(oid, true);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
|
||||
string error_str;
|
||||
string aname;
|
||||
|
||||
rtmpl = tpool->get(id,true);
|
||||
rtmpl = tpool->get(id, 0, true);
|
||||
|
||||
if ( rtmpl == 0 )
|
||||
{
|
||||
@ -135,7 +135,14 @@ void VMTemplateClone::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
string error_str;
|
||||
|
||||
source_tmpl = tpool->get(source_id,true);
|
||||
int obj_type = type;
|
||||
|
||||
if ( obj_type == -1 )
|
||||
{
|
||||
obj_type = xmlrpc_c::value_int(paramList.getInt(3));
|
||||
}
|
||||
|
||||
source_tmpl = tpool->get(source_id, obj_type, true);
|
||||
|
||||
if ( source_tmpl == 0 )
|
||||
{
|
||||
@ -178,7 +185,7 @@ void VMTemplateClone::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
}
|
||||
}
|
||||
|
||||
rc = tpool->allocate(att.uid, att.gid, att.uname, att.gname,
|
||||
rc = tpool->allocate(att.uid, att.gid, att.uname, att.gname, obj_type,
|
||||
tmpl, &new_id, error_str);
|
||||
|
||||
if ( rc < 0 )
|
||||
|
@ -28,9 +28,11 @@ VMTemplate::VMTemplate(int id,
|
||||
int _gid,
|
||||
const string& _uname,
|
||||
const string& _gname,
|
||||
int _type,
|
||||
VirtualMachineTemplate * _template_contents):
|
||||
PoolObjectSQL(id,TEMPLATE,"",_uid,_gid,_uname,_gname,table),
|
||||
regtime(time(0))
|
||||
regtime(time(0)),
|
||||
type(_type)
|
||||
{
|
||||
if (_template_contents != 0)
|
||||
{
|
||||
@ -60,12 +62,13 @@ VMTemplate::~VMTemplate()
|
||||
const char * VMTemplate::table = "template_pool";
|
||||
|
||||
const char * VMTemplate::db_names =
|
||||
"oid, name, body, uid, gid, owner_u, group_u, other_u";
|
||||
"oid, name, body, type, uid, gid, owner_u, group_u, other_u";
|
||||
|
||||
const char * VMTemplate::db_bootstrap =
|
||||
"CREATE TABLE IF NOT EXISTS template_pool (oid INTEGER PRIMARY KEY, "
|
||||
"name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, "
|
||||
"owner_u INTEGER, group_u INTEGER, other_u INTEGER)";
|
||||
"name VARCHAR(128), body TEXT, type INTEGER, uid INTEGER, gid INTEGER, "
|
||||
"owner_u INTEGER, group_u INTEGER, other_u INTEGER,"
|
||||
"UNIQUE(name,uid,type))";
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
@ -156,6 +159,7 @@ int VMTemplate::insert_replace(SqlDB *db, bool replace, string& error_str)
|
||||
<< oid << ","
|
||||
<< "'" << sql_name << "',"
|
||||
<< "'" << sql_xml << "',"
|
||||
<< type << ","
|
||||
<< uid << ","
|
||||
<< gid << ","
|
||||
<< owner_u << ","
|
||||
@ -207,6 +211,7 @@ string& VMTemplate::to_xml(string& xml) const
|
||||
<< "<UNAME>" << uname << "</UNAME>"
|
||||
<< "<GNAME>" << gname << "</GNAME>"
|
||||
<< "<NAME>" << name << "</NAME>"
|
||||
<< "<TYPE>" << type << "</TYPE>"
|
||||
<< perms_to_xml(perm_str)
|
||||
<< "<REGTIME>" << regtime << "</REGTIME>"
|
||||
<< obj_template->to_xml(template_xml)
|
||||
@ -235,6 +240,7 @@ int VMTemplate::from_xml(const string& xml)
|
||||
rc += xpath(uname, "/VMTEMPLATE/UNAME", "not_found");
|
||||
rc += xpath(gname, "/VMTEMPLATE/GNAME", "not_found");
|
||||
rc += xpath(name, "/VMTEMPLATE/NAME", "not_found");
|
||||
rc += xpath(type, "/VMTEMPLATE/TYPE", 0);
|
||||
rc += xpath(regtime, "/VMTEMPLATE/REGTIME", 0);
|
||||
|
||||
// Permissions
|
||||
|
@ -28,6 +28,7 @@ int VMTemplatePool::allocate (
|
||||
int gid,
|
||||
const string& uname,
|
||||
const string& gname,
|
||||
int type,
|
||||
VirtualMachineTemplate * template_contents,
|
||||
int * oid,
|
||||
string& error_str)
|
||||
@ -40,7 +41,8 @@ int VMTemplatePool::allocate (
|
||||
// ------------------------------------------------------------------------
|
||||
// Build a new VMTemplate object
|
||||
// ------------------------------------------------------------------------
|
||||
vm_template = new VMTemplate(-1, uid, gid, uname, gname,template_contents);
|
||||
vm_template = new VMTemplate(-1, uid, gid, uname, gname,
|
||||
type, template_contents);
|
||||
|
||||
// Check name
|
||||
vm_template->get_template_attribute("NAME", name);
|
||||
|
Loading…
Reference in New Issue
Block a user