1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-08-24 17:49:28 +03:00

Feature #1727: New option --extend for onetemplate show

This commit is contained in:
Carlos Martín
2015-07-21 16:24:43 +02:00
parent 6e3e25ff59
commit 0a42146de1
7 changed files with 165 additions and 5 deletions

View File

@ -40,7 +40,7 @@ protected:
/* -------------------------------------------------------------------- */
void request_execute(xmlrpc_c::paramList const& _paramList,
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
/* -------------------------------------------------------------------- */
@ -93,6 +93,11 @@ public:
};
~TemplateInfo(){};
/* -------------------------------------------------------------------- */
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
};
/* ------------------------------------------------------------------------- */

View File

@ -37,6 +37,17 @@ public:
*/
string& to_xml(string& xml) const;
/**
* Function to print the VMTemplate object into a string in XML format
* @param xml the resulting XML string
* @param tmpl a template to replace the internal obj_template. It is only
* used to create the resulting xml string, the internal obj_template is
* not altered
* @return a reference to the generated string
*/
string& to_xml(string& xml, const Template* tmpl) const;
// ------------------------------------------------------------------------
// Template Contents
// ------------------------------------------------------------------------

View File

@ -43,6 +43,13 @@ EOT
:description => "Integrate userdata into the EC2 section"
}
EXTENDED={
:name => "extended",
:large => "--extended",
:description => "Process the template and included extended "+
"information, such as the SIZE for each DISK"
}
def self.rname
"VMTEMPLATE"
end
@ -51,6 +58,26 @@ EOT
"onetemplate.yaml"
end
def show_resource(id, options)
resource = retrieve_resource(id)
if !options[:extended].nil?
rc = resource.info(options[:extended])
else
rc = resource.info
end
return -1, rc.message if OpenNebula.is_error?(rc)
if options[:xml]
return 0, resource.to_xml(true)
else
format_resource(resource, options)
return 0
end
end
def format_pool(options)
config_file = self.class.table_conf

View File

@ -319,7 +319,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
Shows information for the given Template
EOT
command :show, show_desc, :templateid, :options=>OpenNebulaHelper::XML do
command :show, show_desc, :templateid,
:options=>[OpenNebulaHelper::XML,OneTemplateHelper::EXTENDED] do
helper.show_resource(args[0],options)
end

View File

@ -65,8 +65,22 @@ module OpenNebula
#######################################################################
# Retrieves the information of the given Template.
def info()
super(TEMPLATE_METHODS[:info], 'VMTEMPLATE')
# @param extended [true,false] optional flag to process the template and
# include extended information, such as the SIZE for each DISK
def info(extended=false)
return Error.new('ID not defined') if !@pe_id
rc = @client.call(TEMPLATE_METHODS[:info], @pe_id, extended)
if !OpenNebula.is_error?(rc)
initialize_xml(rc, 'VMTEMPLATE')
rc = nil
@pe_id = self['ID'].to_i if self['ID']
@name = self['NAME'] if self['NAME']
end
return rc
end
alias_method :info!, :info

View File

@ -68,6 +68,99 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList,
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void TemplateInfo::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
VMTemplatePool * tpool = static_cast<VMTemplatePool *>(pool);
VirtualMachineTemplate * extended_tmpl = 0;
VMTemplate * vm_tmpl;
PoolObjectAuth perms;
int oid = xmlrpc_c::value_int(paramList.getInt(1));
bool extended = false;
string str;
if ( paramList.size() > 2 )
{
extended = xmlrpc_c::value_boolean(paramList.getBoolean(2));
}
vm_tmpl = tpool->get(oid,true);
if ( vm_tmpl == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(auth_object),oid),
att);
return;
}
if (extended)
{
extended_tmpl = vm_tmpl->clone_template();
}
vm_tmpl->get_permissions(perms);
vm_tmpl->unlock();
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(auth_op, perms); //USE TEMPLATE
if (extended)
{
VirtualMachine::set_auth_request(att.uid, ar, extended_tmpl);
}
if ( att.uid != UserPool::ONEADMIN_ID && att.gid != GroupPool::ONEADMIN_ID )
{
if (UserPool::authorize(ar) == -1)
{
failure_response(AUTHORIZATION,
authorization_error(ar.message, att),
att);
delete extended_tmpl;
return;
}
}
vm_tmpl = tpool->get(oid,true);
if ( vm_tmpl == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(auth_object),oid),
att);
delete extended_tmpl;
return;
}
if (extended)
{
vm_tmpl->to_xml(str, extended_tmpl);
delete extended_tmpl;
}
else
{
vm_tmpl->to_xml(str);
}
vm_tmpl->unlock();
success_response(str, att);
return;
}
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void VirtualNetworkInfo::to_xml(RequestAttributes& att, PoolObjectSQL * object,
string& str)
{

View File

@ -172,6 +172,14 @@ error_common:
/* ************************************************************************ */
string& VMTemplate::to_xml(string& xml) const
{
return to_xml(xml, obj_template);
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
string& VMTemplate::to_xml(string& xml, const Template* tmpl) const
{
ostringstream oss;
string template_xml;
@ -186,7 +194,7 @@ string& VMTemplate::to_xml(string& xml) const
<< "<NAME>" << name << "</NAME>"
<< perms_to_xml(perm_str)
<< "<REGTIME>" << regtime << "</REGTIME>"
<< obj_template->to_xml(template_xml)
<< tmpl->to_xml(template_xml)
<< "</VMTEMPLATE>";
xml = oss.str();