mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-08 20:58:17 +03:00
Feature #662: Refactored RM methods for Hosts and Images
This commit is contained in:
parent
8b41fbf512
commit
0fecbced92
73
include/RequestManagerHost.h
Normal file
73
include/RequestManagerHost.h
Normal file
@ -0,0 +1,73 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_HOST_H
|
||||
#define REQUEST_MANAGER_HOST_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerHost: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerHost( const string& method_name,
|
||||
const string& help,
|
||||
const string& params)
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
|
||||
auth_object = AuthRequest::HOST;
|
||||
};
|
||||
|
||||
~RequestManagerHost(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList) = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostEnable : public RequestManagerHost
|
||||
{
|
||||
public:
|
||||
HostEnable():
|
||||
RequestManagerHost("HostEnable",
|
||||
"Enables or disables a host",
|
||||
"A:sib")
|
||||
{
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
~HostEnable(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
83
include/RequestManagerImage.h
Normal file
83
include/RequestManagerImage.h
Normal file
@ -0,0 +1,83 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_IMAGE_H
|
||||
#define REQUEST_MANAGER_IMAGE_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerImage: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerImage(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:sib",help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
|
||||
auth_object = AuthRequest::IMAGE;
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
~RequestManagerImage(){};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList) = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImageEnable : public RequestManagerImage
|
||||
{
|
||||
public:
|
||||
ImageEnable():
|
||||
RequestManagerImage("ImageEnable", "Enables or disables an image"){};
|
||||
|
||||
~ImageEnable(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImagePersistent : public RequestManagerImage
|
||||
{
|
||||
public:
|
||||
ImagePersistent():
|
||||
RequestManagerImage("ImagePersistent",
|
||||
"Makes an image persistent or non-persistent"){};
|
||||
|
||||
~ImagePersistent(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
@ -30,6 +30,8 @@
|
||||
#include "RequestManagerVirtualNetwork.h"
|
||||
#include "RequestManagerVirtualMachine.h"
|
||||
#include "RequestManagerVMTemplate.h"
|
||||
#include "RequestManagerHost.h"
|
||||
#include "RequestManagerImage.h"
|
||||
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
@ -231,7 +233,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr user_add_group(new UserAddGroup());
|
||||
xmlrpc_c::methodPtr user_del_group(new UserDelGroup());
|
||||
|
||||
// VirtualMachine Template Methods
|
||||
// VMTemplate Methods
|
||||
xmlrpc_c::methodPtr template_instantiate(new VMTemplateInstantiate());
|
||||
|
||||
// VirtualMachine Methods
|
||||
@ -293,31 +295,25 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr vnpool_info(new VirtualNetworkPoolInfo());
|
||||
xmlrpc_c::methodPtr imagepool_info(new ImagePoolInfo());
|
||||
|
||||
// Host Methods
|
||||
xmlrpc_c::methodPtr host_enable(new HostEnable());
|
||||
|
||||
// Image Methods
|
||||
xmlrpc_c::methodPtr image_persistent(new ImagePersistent());
|
||||
xmlrpc_c::methodPtr image_enable(new ImageEnable());
|
||||
|
||||
/*
|
||||
xmlrpc_c::methodPtr vm_chown(new
|
||||
RequestManager::GenericChown(this,AuthRequest::VM));
|
||||
|
||||
|
||||
xmlrpc_c::methodPtr template_chown(new
|
||||
RequestManager::GenericChown(this,AuthRequest::TEMPLATE));
|
||||
|
||||
|
||||
xmlrpc_c::methodPtr host_enable(new
|
||||
RequestManager::HostEnable(hpool,upool));
|
||||
|
||||
xmlrpc_c::methodPtr vn_chown(new
|
||||
RequestManager::GenericChown(this,AuthRequest::NET));
|
||||
|
||||
|
||||
|
||||
xmlrpc_c::methodPtr user_chown(new
|
||||
RequestManager::GenericChown(this,USER));
|
||||
|
||||
xmlrpc_c::methodPtr image_persistent(new
|
||||
RequestManager::ImagePersistent(ipool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr image_enable(new
|
||||
RequestManager::ImageEnable(ipool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr image_chown(new
|
||||
RequestManager::GenericChown(this,IMAGE));
|
||||
@ -351,9 +347,8 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.templatepool.info",template_pool_info);
|
||||
|
||||
/* Host related methods*/
|
||||
/*
|
||||
|
||||
RequestManagerRegistry.addMethod("one.host.enable", host_enable);
|
||||
*/
|
||||
RequestManagerRegistry.addMethod("one.host.update", host_update);
|
||||
RequestManagerRegistry.addMethod("one.host.allocate", host_allocate);
|
||||
RequestManagerRegistry.addMethod("one.host.delete", host_delete);
|
||||
@ -397,11 +392,11 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.userpool.info", userpool_info);
|
||||
|
||||
/* Image related methods*/
|
||||
/*
|
||||
RequestManagerRegistry.addMethod("one.image.persistent", image_persistent);
|
||||
RequestManagerRegistry.addMethod("one.image.enable", image_enable);
|
||||
RequestManagerRegistry.addMethod("one.image.chown", image_chown);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.image.persistent", image_persistent);
|
||||
RequestManagerRegistry.addMethod("one.image.enable", image_enable);
|
||||
/*
|
||||
RequestManagerRegistry.addMethod("one.image.chown", image_chown);
|
||||
*/
|
||||
RequestManagerRegistry.addMethod("one.image.update", image_update);
|
||||
RequestManagerRegistry.addMethod("one.image.allocate", image_allocate);
|
||||
|
74
src/rm/RequestManagerHost.cc
Normal file
74
src/rm/RequestManagerHost.cc
Normal file
@ -0,0 +1,74 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, 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 "RequestManagerHost.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void HostEnable::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
bool enable = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
|
||||
Host * host;
|
||||
|
||||
HostPool * hpool = static_cast<HostPool *>(pool);
|
||||
|
||||
string error_str;
|
||||
|
||||
host = hpool->get(id,true);
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error(object_name(auth_object),id));
|
||||
return;
|
||||
}
|
||||
|
||||
if ( uid != 0 )
|
||||
{
|
||||
AuthRequest ar(uid);
|
||||
|
||||
ar.add_auth(auth_object, id, auth_op, 0, false);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
failure_response(AUTHORIZATION, //TODO
|
||||
authorization_error("MANAGE",object_name(auth_object),id,-1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( enable == true)
|
||||
{
|
||||
host->enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
host->disable();
|
||||
}
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
host->unlock();
|
||||
|
||||
success_response(id);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -1,127 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, 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 "AuthManager.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::HostEnable::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int hid;
|
||||
int rc;
|
||||
bool enable;
|
||||
Host * host;
|
||||
ostringstream oss;
|
||||
|
||||
const string method_name = "HostEnable";
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"HostEnable method invoked");
|
||||
|
||||
// Get the parameters & host
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
hid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
enable = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
|
||||
//Authenticate the user
|
||||
rc = HostEnable::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
//Authorize the operation
|
||||
if ( rc != 0 ) // rc == 0 means oneadmin
|
||||
{
|
||||
AuthRequest ar(rc);
|
||||
|
||||
ar.add_auth(AuthRequest::HOST,hid,AuthRequest::MANAGE,0,false);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
host = HostEnable::hpool->get(hid,true);
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
goto error_host_get;
|
||||
}
|
||||
|
||||
if ( enable == true)
|
||||
{
|
||||
host->enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
host->disable();
|
||||
}
|
||||
|
||||
HostEnable::hpool->update(host);
|
||||
|
||||
host->unlock();
|
||||
|
||||
//Result
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true));
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
|
||||
*retval = *arrayresult;
|
||||
|
||||
delete arrayresult;
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "MANAGE", "HOST", rc, hid));
|
||||
goto error_common;
|
||||
|
||||
error_host_get:
|
||||
oss.str(get_error(method_name, "HOST", hid));
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false));
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
103
src/rm/RequestManagerImage.cc
Normal file
103
src/rm/RequestManagerImage.cc
Normal file
@ -0,0 +1,103 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, 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 "RequestManagerImage.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void ImageEnable::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
bool enable_flag = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
int rc;
|
||||
|
||||
string err_msg;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
ImageManager * imagem = nd.get_imagem();
|
||||
|
||||
if ( basic_authorization(id) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rc = imagem->enable_image(id,enable_flag);
|
||||
|
||||
if( rc < 0 )
|
||||
{
|
||||
if (enable_flag == true)
|
||||
{
|
||||
err_msg = "Could not enable image";
|
||||
}
|
||||
else
|
||||
{
|
||||
err_msg = "Could not disable image";
|
||||
}
|
||||
|
||||
failure_response(INTERNAL, err_msg);//TODO
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(id);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
bool persistent_flag = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
bool result;
|
||||
|
||||
Image * image;
|
||||
string err_msg;
|
||||
|
||||
if ( basic_authorization(id) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
image = static_cast<Image *>(pool->get(id,true));
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error(object_name(auth_object),id));
|
||||
return;
|
||||
}
|
||||
|
||||
result = image->persistent(persistent_flag);
|
||||
image->unlock();
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
if (persistent_flag == true)
|
||||
{
|
||||
err_msg = "Could not make image persistent";
|
||||
}
|
||||
else
|
||||
{
|
||||
err_msg = "Could not make image non-persistent";
|
||||
}
|
||||
failure_response(INTERNAL, err_msg); //TODO
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(id);
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, 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"
|
||||
|
||||
#include "AuthManager.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::ImageEnable::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
string err_msg;
|
||||
|
||||
int iid;
|
||||
bool enable_flag;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
int image_owner;
|
||||
bool is_public;
|
||||
|
||||
Image * image;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
const string method_name = "ImageEnable";
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
ImageManager * imagem = nd.get_imagem();
|
||||
|
||||
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(2));
|
||||
|
||||
// First, we need to authenticate the user
|
||||
uid = ImageEnable::upool->authenticate(session);
|
||||
|
||||
if ( uid == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Get image from the ImagePool
|
||||
image = ImageEnable::ipool->get(iid,true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
goto error_image_get;
|
||||
}
|
||||
|
||||
image_owner = image->get_uid();
|
||||
is_public = image->isPublic();
|
||||
|
||||
image->unlock();
|
||||
|
||||
//Authorize the operation
|
||||
if ( uid != 0 ) // uid == 0 means oneadmin
|
||||
{
|
||||
AuthRequest ar(uid);
|
||||
|
||||
ar.add_auth(AuthRequest::IMAGE,
|
||||
iid,
|
||||
AuthRequest::MANAGE,
|
||||
image_owner,
|
||||
is_public);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable the Image
|
||||
rc = imagem->enable_image(iid,enable_flag);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
goto error_enable;
|
||||
}
|
||||
|
||||
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.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_image_get:
|
||||
oss.str(get_error(method_name, "IMAGE", iid));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "MANAGE", "IMAGE", uid, iid));
|
||||
goto error_common;
|
||||
|
||||
error_enable:
|
||||
if (enable_flag == TRUE)
|
||||
{
|
||||
err_msg = "ENABLE";
|
||||
} else {
|
||||
err_msg = "DISABLE";
|
||||
}
|
||||
oss.str(action_error(method_name, err_msg, "IMAGE", iid, rc));
|
||||
image->unlock();
|
||||
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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
@ -1,157 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, 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"
|
||||
|
||||
#include "AuthManager.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::ImagePersistent::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int iid;
|
||||
bool persistent_flag;
|
||||
int uid;
|
||||
|
||||
int image_owner;
|
||||
bool is_public;
|
||||
|
||||
Image * image;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
bool response;
|
||||
|
||||
const string method_name = "ImagePersistent";
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ImagePersistent invoked");
|
||||
|
||||
session = xmlrpc_c::value_string (paramList.getString(0));
|
||||
iid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
persistent_flag = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
|
||||
// First, we need to authenticate the user
|
||||
uid = ImagePersistent::upool->authenticate(session);
|
||||
|
||||
if ( uid == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Get image from the ImagePool
|
||||
image = ImagePersistent::ipool->get(iid,true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
goto error_image_get;
|
||||
}
|
||||
|
||||
image_owner = image->get_uid();
|
||||
is_public = image->isPublic();
|
||||
|
||||
image->unlock();
|
||||
|
||||
//Authorize the operation
|
||||
if ( uid != 0 ) // uid == 0 means oneadmin
|
||||
{
|
||||
AuthRequest ar(uid);
|
||||
|
||||
ar.add_auth(AuthRequest::IMAGE,
|
||||
iid,
|
||||
AuthRequest::MANAGE,
|
||||
image_owner,
|
||||
is_public);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the image locked again
|
||||
image = ImagePersistent::ipool->get(iid,true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
goto error_image_get;
|
||||
}
|
||||
|
||||
response = image->persistent(persistent_flag);
|
||||
|
||||
if (!response)
|
||||
{
|
||||
goto error_persistent;
|
||||
}
|
||||
|
||||
ImagePersistent::ipool->update(image);
|
||||
|
||||
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.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_image_get:
|
||||
oss.str(get_error(method_name, "IMAGE", iid));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "MANAGE", "IMAGE", uid, iid));
|
||||
goto error_common;
|
||||
|
||||
error_persistent:
|
||||
image->unlock();
|
||||
oss.str(action_error(method_name, "MANAGE", "IMAGE", iid, 0));
|
||||
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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
@ -35,6 +35,8 @@ source_files=[
|
||||
'RequestManagerVMTemplate.cc',
|
||||
'RequestManagerUpdateTemplate.cc',
|
||||
'RequestManagerUser.cc',
|
||||
'RequestManagerHost.cc',
|
||||
'RequestManagerImage.cc',
|
||||
|
||||
# 'RequestManagerAction.cc',
|
||||
# 'RequestManagerAllocate.cc',
|
||||
|
Loading…
x
Reference in New Issue
Block a user