mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-25 23:21:29 +03:00
feature #200: Addde Image Update method
This commit is contained in:
parent
9ca75314b4
commit
b8de290197
@ -117,6 +117,31 @@ public:
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
/** Modify an image attribute in the template OR the public attribute
|
||||
* @param image pointer to Image
|
||||
* @param name of the attribute to be changed
|
||||
* @param new value for the attribute
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
int modify_image_attribute(
|
||||
Image * image,
|
||||
string& name,
|
||||
string& value)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if ( name == "PUBLIC" && ( value == "YES" || value == "NO" ))
|
||||
{
|
||||
image->public_img == value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return image->update_template_attribute(db, name, value);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Image pool
|
||||
@ -126,12 +151,6 @@ 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
|
||||
* query
|
||||
|
@ -738,6 +738,31 @@ private:
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ImageUpdate: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ImageUpdate(ImagePool * _ipool,
|
||||
UserPool * _upool):
|
||||
ipool(_ipool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:siss";
|
||||
_help="Modifies image attribute";
|
||||
};
|
||||
|
||||
~ImageUpdate(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
ImagePool * ipool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ImagePoolInfo: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
|
@ -307,9 +307,3 @@ string ImagePool::sha1_digest(const string& pass)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string ImagePool::get_template_table_name()
|
||||
{
|
||||
string table(ImageTemplate::table);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
@ -279,6 +279,9 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr image_info(new
|
||||
RequestManager::ImageInfo(ipool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr image_update(new
|
||||
RequestManager::ImageUpdate(ipool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr imagepool_info(new
|
||||
RequestManager::ImagePoolInfo(ipool, upool));
|
||||
|
||||
@ -322,7 +325,8 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
RequestManagerRegistry.addMethod("one.image.allocate", image_allocate);
|
||||
RequestManagerRegistry.addMethod("one.image.delete", image_delete);
|
||||
RequestManagerRegistry.addMethod("one.image.info", image_info);
|
||||
RequestManagerRegistry.addMethod("one.image.info", image_info);
|
||||
RequestManagerRegistry.addMethod("one.image.update", image_update);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
|
||||
|
||||
|
130
src/rm/RequestManagerImageUpdate.cc
Normal file
130
src/rm/RequestManagerImageUpdate.cc
Normal file
@ -0,0 +1,130 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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::ImageUpdate::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int iid;
|
||||
int uid;
|
||||
string name;
|
||||
string value;
|
||||
int rc;
|
||||
|
||||
Image * image;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ImageUpdate invoked");
|
||||
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
iid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
name = xmlrpc_c::value_string(paramList.getString(2));
|
||||
value = xmlrpc_c::value_string(paramList.getString(3));
|
||||
|
||||
|
||||
|
||||
// First, we need to authenticate the user
|
||||
rc = ImageUpdate::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
uid = rc;
|
||||
|
||||
// Get image from the ImagePool
|
||||
image = ImageUpdate::ipool->get(iid,true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
goto error_image_get;
|
||||
}
|
||||
|
||||
|
||||
if ( uid != 0 && uid != image->get_uid() )
|
||||
{
|
||||
goto error_authorization;
|
||||
}
|
||||
|
||||
rc = ImageUpdate::ipool->modify_image_attribute(image, name, value);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
goto error_update;
|
||||
|
||||
}
|
||||
|
||||
image->unlock();
|
||||
|
||||
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 ImageUpdate call.";
|
||||
goto error_common;
|
||||
|
||||
error_image_get:
|
||||
oss << "Error getting image with ID = " << iid;
|
||||
goto error_common;
|
||||
|
||||
error_authorization:
|
||||
oss << "User not authorized to modify image attributes " <<
|
||||
", aborting ImageUpdate call.";
|
||||
goto error_common;
|
||||
|
||||
error_update:
|
||||
oss << "Cannot modify image [" << iid << "] attribute with name = " << name;
|
||||
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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
@ -38,6 +38,7 @@ source_files=[
|
||||
'RequestManagerImageDelete.cc',
|
||||
'RequestManagerImageInfo.cc',
|
||||
'RequestManagerImagePoolInfo.cc',
|
||||
'RequestManagerImageUpdate.cc',
|
||||
'RequestManagerVirtualNetworkAllocate.cc',
|
||||
'RequestManagerVirtualNetworkInfo.cc',
|
||||
'RequestManagerVirtualNetworkPoolInfo.cc',
|
||||
|
Loading…
Reference in New Issue
Block a user