mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-13 13:17:39 +03:00
feature #200: Adding enable, publish & remove attribute for images to RM
This commit is contained in:
parent
1c9e70dd80
commit
f718cd310a
@ -763,6 +763,81 @@ private:
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ImageRemoveAttribute: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ImageRemoveAttribute(ImagePool * _ipool,
|
||||
UserPool * _upool):
|
||||
ipool(_ipool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:sis";
|
||||
_help="Removes image attribute";
|
||||
};
|
||||
|
||||
~ImageRemoveAttribute(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
ImagePool * ipool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ImagePublish: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ImagePublish(ImagePool * _ipool,
|
||||
UserPool * _upool):
|
||||
ipool(_ipool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:sib";
|
||||
_help="Removes image attribute";
|
||||
};
|
||||
|
||||
~ImagePublish(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
ImagePool * ipool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ImageEnable: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ImageEnable(ImagePool * _ipool,
|
||||
UserPool * _upool):
|
||||
ipool(_ipool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:sib";
|
||||
_help="Removes image attribute";
|
||||
};
|
||||
|
||||
~ImageEnable(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
ImagePool * ipool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ImagePoolInfo: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
|
@ -281,6 +281,15 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
xmlrpc_c::methodPtr image_update(new
|
||||
RequestManager::ImageUpdate(ipool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr image_rm_attribute(new
|
||||
RequestManager::ImageRemoveAttribute(ipool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr image_publish(new
|
||||
RequestManager::ImagePublish(ipool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr image_enable(new
|
||||
RequestManager::ImageEnable(ipool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr imagepool_info(new
|
||||
RequestManager::ImagePoolInfo(ipool, upool));
|
||||
@ -323,10 +332,13 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
/* Image related 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.update", image_update);
|
||||
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.update", image_update);
|
||||
RequestManagerRegistry.addMethod("one.image.rmattr", image_rm_attribute);
|
||||
RequestManagerRegistry.addMethod("one.image.publish", image_publish);
|
||||
RequestManagerRegistry.addMethod("one.image.enable", image_enable);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
|
||||
|
||||
|
125
src/rm/RequestManagerImageEnable.cc
Normal file
125
src/rm/RequestManagerImageEnable.cc
Normal file
@ -0,0 +1,125 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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::ImageEnable::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int iid;
|
||||
bool enable_flag;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
Image * image;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ImageEnable invoked");
|
||||
|
||||
session = xmlrpc_c::value_string (paramList.getString(0));
|
||||
iid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
enable_flag = xmlrpc_c::value_boolean(paramList.getBoolean(1));
|
||||
|
||||
// First, we need to authenticate the user
|
||||
rc = ImageEnable::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
uid = rc;
|
||||
|
||||
// Get image from the ImagePool
|
||||
image = ImageEnable::ipool->get(iid,true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
goto error_image_get;
|
||||
}
|
||||
|
||||
if ( uid != 0 && uid != image->get_uid() )
|
||||
{
|
||||
goto error_authorization;
|
||||
}
|
||||
|
||||
rc = image->enable(enable_flag);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
goto error_remove_attribute;
|
||||
|
||||
}
|
||||
|
||||
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 << "[ImageEnable] User not authenticated, aborting call.";
|
||||
goto error_common;
|
||||
|
||||
error_image_get:
|
||||
oss << "[ImageEnable] Error getting image with ID = " << iid;
|
||||
goto error_common;
|
||||
|
||||
error_authorization:
|
||||
oss << "[ImageEnable] User not authorized to enable/disable image" <<
|
||||
" attributes, aborting call.";
|
||||
goto error_common;
|
||||
|
||||
error_remove_attribute:
|
||||
oss << "[ImageEnable] Cannot enable/disable image [" << iid << "]";
|
||||
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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
119
src/rm/RequestManagerImagePublish.cc
Normal file
119
src/rm/RequestManagerImagePublish.cc
Normal file
@ -0,0 +1,119 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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::ImagePublish::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int iid;
|
||||
bool publish_flag;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
Image * image;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ImagePublish invoked");
|
||||
|
||||
session = xmlrpc_c::value_string (paramList.getString(0));
|
||||
iid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
publish_flag = xmlrpc_c::value_boolean(paramList.getBoolean(1));
|
||||
|
||||
// First, we need to authenticate the user
|
||||
rc = ImagePublish::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
uid = rc;
|
||||
|
||||
// Get image from the ImagePool
|
||||
image = ImagePublish::ipool->get(iid,true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
goto error_image_get;
|
||||
}
|
||||
|
||||
if ( uid != 0 && uid != image->get_uid() )
|
||||
{
|
||||
goto error_authorization;
|
||||
}
|
||||
|
||||
image->publish(publish_flag);
|
||||
|
||||
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 << "[ImagePublish] User not authenticated, aborting call.";
|
||||
goto error_common;
|
||||
|
||||
error_image_get:
|
||||
oss << "[ImagePublish] Error getting image with ID = " << iid;
|
||||
goto error_common;
|
||||
|
||||
error_authorization:
|
||||
oss << "[ImagePublish] User not authorized to publish/unpublish image" <<
|
||||
", aborting call.";
|
||||
goto error_common;
|
||||
|
||||
error_remove_attribute:
|
||||
oss << "[ImagePublish] Cannot publish/unpublish image [" << iid << "]";
|
||||
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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
127
src/rm/RequestManagerImageRemoveAttribute.cc
Normal file
127
src/rm/RequestManagerImageRemoveAttribute.cc
Normal file
@ -0,0 +1,127 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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::ImageRemoveAttribute::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
string name;
|
||||
|
||||
int iid;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
Image * image;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ImageRemoveAttribute 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));
|
||||
|
||||
// First, we need to authenticate the user
|
||||
rc = ImageRemoveAttribute::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
uid = rc;
|
||||
|
||||
// Get image from the ImagePool
|
||||
image = ImageRemoveAttribute::ipool->get(iid,true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
goto error_image_get;
|
||||
}
|
||||
|
||||
|
||||
if ( uid != 0 && uid != image->get_uid() )
|
||||
{
|
||||
goto error_authorization;
|
||||
}
|
||||
|
||||
rc = ImageRemoveAttribute::ipool->remove_attribute(image, name);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
goto error_remove_attribute;
|
||||
|
||||
}
|
||||
|
||||
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 << "[ImageRemoveAttribute] User not authenticated, aborting call.";
|
||||
goto error_common;
|
||||
|
||||
error_image_get:
|
||||
oss << "[ImageRemoveAttribute] Error getting image with ID = " << iid;
|
||||
goto error_common;
|
||||
|
||||
error_authorization:
|
||||
oss << "[ImageRemoveAttribute] User not authorized to remove image" <<
|
||||
" attributes aborting call.";
|
||||
goto error_common;
|
||||
|
||||
error_remove_attribute:
|
||||
oss << "[ImageRemoveAttribute] Cannot remove attribute with name = "
|
||||
<< name << " for image [" << iid << "]";
|
||||
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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
@ -75,7 +75,9 @@ void RequestManager::ImageUpdate::execute(
|
||||
goto error_authorization;
|
||||
}
|
||||
|
||||
rc = ImageUpdate::ipool->modify_image_attribute(image, name, value);
|
||||
// This will perform the update on the DB as well,
|
||||
// so no need to do it manually
|
||||
rc = ImageUpdate::ipool->replace_attribute(image, name, value);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
|
@ -37,8 +37,11 @@ source_files=[
|
||||
'RequestManagerImageAllocate.cc',
|
||||
'RequestManagerImageDelete.cc',
|
||||
'RequestManagerImageInfo.cc',
|
||||
'RequestManagerImagePoolInfo.cc',
|
||||
'RequestManagerImageUpdate.cc',
|
||||
'RequestManagerImageRemoveAttribute.cc',
|
||||
'RequestManagerImagePublish.cc',
|
||||
'RequestManagerImageEnable.cc',
|
||||
'RequestManagerImagePoolInfo.cc',
|
||||
'RequestManagerVirtualNetworkAllocate.cc',
|
||||
'RequestManagerVirtualNetworkInfo.cc',
|
||||
'RequestManagerVirtualNetworkPoolInfo.cc',
|
||||
|
Loading…
Reference in New Issue
Block a user