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

feature #200: Added ImageAllocate method to RM

This commit is contained in:
Constantino Vázquez Blanco 2010-06-02 19:41:05 +02:00
parent d1e3eb66a4
commit 328f3efca2
7 changed files with 147 additions and 8 deletions

View File

@ -124,6 +124,12 @@ public:
{
Image::bootstrap(_db);
};
/**
* Get the template table name
* @return string with the name of the template table
*/
string get_template_table_name();
/**
* Dumps the Image pool in XML format. A filter can be also added to the

View File

@ -35,6 +35,7 @@ public:
private:
friend class Image;
friend class ImagePool;
static const char * table;

View File

@ -646,7 +646,7 @@ private:
UserPoolInfo(UserPool * _upool):upool(_upool)
{
_signature="A:s";
_help="Creates a new user";
_help="Returns content of the user pool";
};
~UserPoolInfo(){};
@ -667,10 +667,13 @@ private:
class ImageAllocate: public xmlrpc_c::method
{
public:
ImageAllocate(UserPool * _upool):upool(_upool)
ImageAllocate(ImagePool * _ipool,
UserPool * _upool):
ipool(_ipool),
upool(_upool)
{
_signature="A:sss";
_help="Creates a new user";
_signature="A:ss";
_help="Creates a new image";
};
~ImageAllocate(){};
@ -680,7 +683,8 @@ private:
xmlrpc_c::value * const retvalP);
private:
UserPool * upool;
ImagePool * ipool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
@ -718,8 +722,8 @@ private:
ipool(_ipool),
upool(_upool)
{
_signature="A:ss";
_help="Allocates an image in the pool";
_signature="A:si";
_help="Returns content of image pool attending to the filter flag";
};
~ImagePoolInfo(){};

View File

@ -288,3 +288,13 @@ string ImagePool::sha1_digest(const string& pass)
return oss.str();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string ImagePool::get_template_table_name()
{
string table(ImageTemplate::table);
return table;
}

View File

@ -270,8 +270,14 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr userpool_info(new
RequestManager::UserPoolInfo(upool));
xmlrpc_c::methodPtr image_allocate(new
RequestManager::ImageAllocate(ipool, upool));
xmlrpc_c::methodPtr image_info(new
RequestManager::ImageInfo(ipool, upool));
xmlrpc_c::methodPtr imagepool_info(new
RequestManager::ImagePoolInfo(ipool, upool));
/* VM related methods */
@ -310,8 +316,11 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.userpool.info", userpool_info);
/* Image related methods*/
RequestManagerRegistry.addMethod("one.image.allocate", image_allocate);
RequestManagerRegistry.addMethod("one.image.info", image_info);
RequestManagerRegistry.addMethod("one.image.info", image_info);
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
};

View File

@ -0,0 +1,107 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include "RequestManager.h"
#include "NebulaLog.h"
#include "Nebula.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RequestManager::ImageAllocate::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
string session;
string image_template;
int iid;
int uid;
int rc;
ostringstream oss;
vector<xmlrpc_c::value> arrayData;
xmlrpc_c::value_array * arrayresult;
NebulaLog::log("ReM",Log::DEBUG,"ImageAllocate invoked");
session = xmlrpc_c::value_string(paramList.getString(0));
image_template = xmlrpc_c::value_string(paramList.getString(1));
image_template += "\n";
// First, we need to authenticate the user
rc = ImageAllocate::upool->authenticate(session);
if ( rc == -1 )
{
goto error_authenticate;
}
uid = rc;
rc = ImageAllocate::ipool->allocate(uid,image_template,&iid);
if ( rc < 0 )
{
goto error_allocate;
}
arrayData.push_back(xmlrpc_c::value_boolean(true));
arrayData.push_back(xmlrpc_c::value_int(iid));
// Copy arrayresult into retval mem space
arrayresult = new xmlrpc_c::value_array(arrayData);
*retval = *arrayresult;
delete arrayresult; // and get rid of the original
return;
error_authenticate:
oss << "User not authenticated, aborting ImageAllocate call.";
goto error_common;
error_allocate:
if (rc == -1)
{
oss << "Error allocating image, check oned.log";
}
else
{
oss << "Error parsing image template";
}
goto error_common;
error_common:
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
NebulaLog::log("ReM",Log::ERROR,oss);
xmlrpc_c::value_array arrayresult_error(arrayData);
*retval = arrayresult_error;
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -34,7 +34,9 @@ source_files=[
'RequestManagerHostInfo.cc',
'RequestManagerHostPoolInfo.cc',
'RequestManagerHostEnable.cc',
'RequestManagerImageAllocate.cc',
'RequestManagerImageInfo.cc',
'RequestManagerImagePoolInfo.cc',
'RequestManagerVirtualNetworkAllocate.cc',
'RequestManagerVirtualNetworkInfo.cc',
'RequestManagerVirtualNetworkPoolInfo.cc',