1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Feature #4217: Get the attributes from the App properly

This commit is contained in:
Jaime Melis 2016-01-26 23:19:31 +01:00
parent 8a4135faaf
commit e5c1c549bb
3 changed files with 41 additions and 75 deletions

View File

@ -121,10 +121,8 @@ public:
* Copies the special attributes of the App to the template
* @param tmp The template object
* @param error_str Returns the error reason, if any
*
* @return 0 on success, -1 otherwise
*/
int to_template(Template * tmpl, std::string& error_str);
void to_template(Template * tmpl);
/**
* Enable or disable the app. A disabled app cannot be exported
@ -182,6 +180,22 @@ public:
return source;
}
const string& get_md5()
{
return md5;
}
long long get_size()
{
return size_mb;
}
const string& get_format()
{
return format;
}
MarketPlaceAppState get_state()
{
return state;

View File

@ -411,34 +411,12 @@ int MarketPlaceApp::enable(bool enable, string& error_str)
/* --------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------- */
int MarketPlaceApp::to_template(Template * tmpl, std::string& error_str)
void MarketPlaceApp::to_template(Template * tmpl)
{
bool rc;
string app_path;
string app_format;
string app_md5;
string app_name;
int market_id;
get_template_attribute("SOURCE", app_path);
get_template_attribute("FORMAT", app_format);
get_template_attribute("MD5", app_md5);
get_template_attribute("NAME", app_name);
if ( app_path.empty() )
{
error_str = "The appliance has no SOURCE";
return -1;
}
tmpl->replace("PATH", app_path);
tmpl->replace("FORMAT", app_format);
tmpl->replace("MD5", app_format);
tmpl->replace("FROM_APP_NAME", app_name);
return 0;
tmpl->replace("FROM_APP_NAME", get_name());
tmpl->replace("PATH", get_source());
tmpl->replace("FORMAT", get_format());
tmpl->replace("MD5", get_md5());
}
/* --------------------------------------------------------------------------- */

View File

@ -398,53 +398,25 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
{
// This image comes from a MarketPlaceApp. Get the Market info and
// the size.
bool market_check;
app = apppool->get(app_id, true);
if ( app_id == 0 )
if ( app == 0 )
{
failure_response(INTERNAL,
"Cannot find appliance referenced by FROM_APP",
"Cannot find appliance referenced by FROM_APP.",
att);
delete tmpl;
return;
}
rc = app->to_template(tmpl, error_str);
app->to_template(tmpl);
app->get_template_attribute("SIZE", size_str);
market_check = app->get_template_attribute("MARKETPLACE_ID", market_id);
size_mb = app->get_size();
market_id = app->get_market_id();
app->unlock();
if ( rc == -1 )
{
failure_response(INTERNAL, allocate_error(error_str), att);
delete tmpl;
return;
}
if ( !market_check )
{
error_str = "The appliance has no MARKETPLACE_ID";
failure_response(INTERNAL, allocate_error(error_str), att);
delete tmpl;
return;
}
if ( size_str.empty() )
{
error_str = "The appliance has no SIZE";
failure_response(INTERNAL, allocate_error(error_str), att);
delete tmpl;
return;
}
market = marketpool->get(market_id, true);
if ( market == 0 )
@ -466,24 +438,26 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
if ( rc == -1 )
{
failure_response(INTERNAL,
request_error("Cannot determine Image SIZE", size_str),
request_error("Cannot determine Image SIZE",
size_str),
att);
delete tmpl;
return;
}
iss.str(size_str);
iss >> size_mb;
if ( iss.fail() )
{
failure_response(INTERNAL,
request_error("Cannot parse SIZE", size_str),
att);
delete tmpl;
return;
}
}
iss.str(size_str);
iss >> size_mb;
if ( iss.fail() )
{
failure_response(INTERNAL,
request_error("Cannot parse SIZE", size_str),
att);
delete tmpl;
return;
}
if (ds_check && (size_mb > avail))
{