mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
feature #662: Adding/removing files
This commit is contained in:
parent
d42f3d33f1
commit
9af500b4cd
104
include/RequestManagerUpdateTemplate.h
Normal file
104
include/RequestManagerUpdateTemplate.h
Normal file
@ -0,0 +1,104 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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_UPDATE_TEMPLATE_H
|
||||
#define REQUEST_MANAGER_UPDATE_TEMPLATE_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerUpdateTemplate: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerUpdateTemplate(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:sis",help)
|
||||
{
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
~RequestManagerUpdateTemplate(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class TemplateUpdateTemplate: public RequestManagerUpdateTemplate
|
||||
{
|
||||
public:
|
||||
TemplateUpdateTemplate():
|
||||
RequestManagerUpdateTemplate("TemplateUpdateTemplate",
|
||||
"Updates a virtual machine template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = AuthRequest::TEMPLATE;
|
||||
};
|
||||
|
||||
~TemplateUpdateTemplate(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImageUpdateTemplate: public RequestManagerUpdateTemplate
|
||||
{
|
||||
public:
|
||||
ImageUpdateTemplate():
|
||||
RequestManagerUpdateTemplate("ImageUpdateTemplate",
|
||||
"Updates an image template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = AuthRequest::IMAGE;
|
||||
};
|
||||
|
||||
~ImageUpdateTemplate(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostUpdateTemplate : public RequestManagerUpdateTemplate
|
||||
{
|
||||
public:
|
||||
HostUpdateTemplate():
|
||||
RequestManagerUpdateTemplate("HostUpdateTemplate",
|
||||
"Updates a host template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
auth_object = AuthRequest::HOST;
|
||||
};
|
||||
|
||||
~HostUpdateTemplate(){};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
73
include/RequestManagerVMTemplate.h
Normal file
73
include/RequestManagerVMTemplate.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_VM_TEMPLATE_H
|
||||
#define REQUEST_MANAGER_VM_TEMPLATE_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerVMTemplate: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerVMTemplate(const string& method_name,
|
||||
const string& help,
|
||||
const string& params)
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
|
||||
auth_object = AuthRequest::TEMPLATE;
|
||||
};
|
||||
|
||||
~RequestManagerVMTemplate(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList) = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VMTemplateInstantiate : public RequestManagerVMTemplate
|
||||
{
|
||||
public:
|
||||
VMTemplateInstantiate():
|
||||
RequestManagerVMTemplate("TemplateInstantiate",
|
||||
"Instantiates a new virtual machine using a template",
|
||||
"A:sis")
|
||||
{
|
||||
auth_op = AuthRequest::INSTANTIATE;
|
||||
};
|
||||
|
||||
~VMTemplateInstantiate(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
@ -1,159 +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::ImageRemoveAttribute::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
string name;
|
||||
|
||||
int iid;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
int image_owner;
|
||||
bool is_public;
|
||||
|
||||
Image * image;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
const string method_name = "ImageRemoveAttribute";
|
||||
|
||||
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
|
||||
uid = ImageRemoveAttribute::upool->authenticate(session);
|
||||
|
||||
if ( uid == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Get image from the ImagePool
|
||||
image = ImageRemoveAttribute::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 image from the ImagePool
|
||||
image = ImageRemoveAttribute::ipool->get(iid,true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
goto error_image_get;
|
||||
}
|
||||
|
||||
rc = image->remove_template_attribute(name);
|
||||
|
||||
if(rc == 0)
|
||||
{
|
||||
rc = ImageRemoveAttribute::ipool->update(image);
|
||||
}
|
||||
|
||||
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.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_remove_attribute:
|
||||
oss.str(action_error(method_name, "PUBLISH/UNPUBLISH", "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,160 +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::ImageUpdate::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int iid;
|
||||
int uid;
|
||||
string name;
|
||||
string value;
|
||||
int rc;
|
||||
|
||||
int image_owner;
|
||||
bool is_public;
|
||||
|
||||
Image * image;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
const string method_name = "ImageUpdate";
|
||||
|
||||
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
|
||||
uid = ImageUpdate::upool->authenticate(session);
|
||||
|
||||
if ( uid == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Get image from the ImagePool
|
||||
image = ImageUpdate::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 image from the ImagePool
|
||||
image = ImageUpdate::ipool->get(iid,true);
|
||||
|
||||
if ( image == 0 )
|
||||
{
|
||||
goto error_image_get;
|
||||
}
|
||||
|
||||
rc = image->replace_template_attribute(name, value);
|
||||
|
||||
if(rc == 0)
|
||||
{
|
||||
rc = ImageUpdate::ipool->update(image);
|
||||
}
|
||||
|
||||
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.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_update:
|
||||
oss.str(action_error(method_name, "UPDATE ATTRIBUTE", "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,159 +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::TemplateRemoveAttribute::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
string name;
|
||||
|
||||
int oid;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
int owner;
|
||||
bool is_public;
|
||||
|
||||
VMTemplate * vm_template;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
const string method_name = "TemplateRemoveAttribute";
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"TemplateRemoveAttribute invoked");
|
||||
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
oid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
name = xmlrpc_c::value_string(paramList.getString(2));
|
||||
|
||||
// First, we need to authenticate the user
|
||||
uid = TemplateRemoveAttribute::upool->authenticate(session);
|
||||
|
||||
if ( uid == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Get object from the pool
|
||||
vm_template = TemplateRemoveAttribute::tpool->get(oid,true);
|
||||
|
||||
if ( vm_template == 0 )
|
||||
{
|
||||
goto error_get;
|
||||
}
|
||||
|
||||
owner = vm_template->get_uid();
|
||||
is_public = vm_template->isPublic();
|
||||
|
||||
vm_template->unlock();
|
||||
|
||||
//Authorize the operation
|
||||
if ( uid != 0 ) // uid == 0 means oneadmin
|
||||
{
|
||||
AuthRequest ar(uid);
|
||||
|
||||
ar.add_auth(AuthRequest::TEMPLATE,
|
||||
oid,
|
||||
AuthRequest::MANAGE,
|
||||
owner,
|
||||
is_public);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// Get object from the pool
|
||||
vm_template = TemplateRemoveAttribute::tpool->get(oid,true);
|
||||
|
||||
if ( vm_template == 0 )
|
||||
{
|
||||
goto error_get;
|
||||
}
|
||||
|
||||
rc = vm_template->remove_template_attribute(name);
|
||||
|
||||
if(rc == 0)
|
||||
{
|
||||
rc = TemplateRemoveAttribute::tpool->update(vm_template);
|
||||
}
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
goto error_remove_attribute;
|
||||
}
|
||||
|
||||
vm_template->unlock();
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true));
|
||||
arrayData.push_back(xmlrpc_c::value_int(oid));
|
||||
|
||||
// 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_get:
|
||||
oss.str(get_error(method_name, "TEMPLATE", oid));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "MANAGE", "TEMPLATE", uid, oid));
|
||||
goto error_common;
|
||||
|
||||
error_remove_attribute:
|
||||
oss.str(action_error(method_name, "PUBLISH/UNPUBLISH", "TEMPLATE", oid, rc));
|
||||
vm_template->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,160 +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::TemplateUpdate::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int oid;
|
||||
int uid;
|
||||
string name;
|
||||
string value;
|
||||
int rc;
|
||||
|
||||
int owner;
|
||||
bool is_public;
|
||||
|
||||
VMTemplate * vm_template;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
const string method_name = "TemplateUpdate";
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"TemplateUpdate invoked");
|
||||
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
oid = 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
|
||||
uid = TemplateUpdate::upool->authenticate(session);
|
||||
|
||||
if ( uid == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Get template from the pool
|
||||
vm_template = TemplateUpdate::tpool->get(oid,true);
|
||||
|
||||
if ( vm_template == 0 )
|
||||
{
|
||||
goto error_get;
|
||||
}
|
||||
|
||||
owner = vm_template->get_uid();
|
||||
is_public = vm_template->isPublic();
|
||||
|
||||
vm_template->unlock();
|
||||
|
||||
//Authorize the operation
|
||||
if ( uid != 0 ) // uid == 0 means oneadmin
|
||||
{
|
||||
AuthRequest ar(uid);
|
||||
|
||||
ar.add_auth(AuthRequest::TEMPLATE,
|
||||
oid,
|
||||
AuthRequest::MANAGE,
|
||||
owner,
|
||||
is_public);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// Get template from the pool
|
||||
vm_template = TemplateUpdate::tpool->get(oid,true);
|
||||
|
||||
if ( vm_template == 0 )
|
||||
{
|
||||
goto error_get;
|
||||
}
|
||||
|
||||
rc = vm_template->replace_template_attribute(name, value);
|
||||
|
||||
if(rc == 0)
|
||||
{
|
||||
rc = TemplateUpdate::tpool->update(vm_template);
|
||||
}
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
goto error_update;
|
||||
}
|
||||
|
||||
vm_template->unlock();
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true));
|
||||
arrayData.push_back(xmlrpc_c::value_int(oid));
|
||||
|
||||
// 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_get:
|
||||
oss.str(get_error(method_name, "TEMPLATE", oid));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "MANAGE", "TEMPLATE", uid, oid));
|
||||
goto error_common;
|
||||
|
||||
error_update:
|
||||
oss.str(action_error(method_name, "UPDATE ATTRIBUTE", "TEMPLATE", oid, rc));
|
||||
vm_template->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;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
65
src/rm/RequestManagerUpdateTemplate.cc
Normal file
65
src/rm/RequestManagerUpdateTemplate.cc
Normal file
@ -0,0 +1,65 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 "RequestManagerUpdateTemplate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManagerUpdateTemplate::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int rc;
|
||||
string error_str;
|
||||
|
||||
int oid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
string tmpl = xmlrpc_c::value_string(paramList.getString(2));
|
||||
|
||||
PoolObjectSQL * object;
|
||||
|
||||
if ( basic_authorization(oid) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
object = pool->get(oid,true);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error(object_name(auth_object),oid));
|
||||
return;
|
||||
}
|
||||
|
||||
rc = object->replace_template(tmpl, error_str);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL, error_str); //TODO
|
||||
object->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
|
||||
success_response(oid);
|
||||
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user