1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-01 05:47:01 +03:00

commit 78c4be0ea0f684596d01557e6699377a7f137758

Author: juanmont <juanmont@ucm.es>
Date:   Tue Sep 4 17:35:17 2018 +0200

    F #2260: Allow all VM actions for the VRouter VMs except
    nic-attach/dettach. Recursive chmown/chmod for VR

(cherry picked from commit c5284b312c6ec7eb2524d4a4768718b933f32693)
This commit is contained in:
Ruben S. Montero 2018-09-10 18:06:51 +02:00
parent 21fb06809b
commit 59ee3f714a
6 changed files with 146 additions and 65 deletions

View File

@ -204,11 +204,19 @@ public:
"Changes permission bits of a virtual router")
{
Nebula& nd = Nebula::instance();
pool = nd.get_vrouterpool();
vrpool = nd.get_vrouterpool();
pool = nd.get_vmpool();
auth_object = PoolObjectSQL::VROUTER;
};
~VirtualRouterChmod(){};
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
private:
VirtualRouterPool * vrpool;
};
/* ------------------------------------------------------------------------- */

View File

@ -160,16 +160,6 @@ public:
static void set_auth_request(int uid, AuthRequest& ar, Template *tmpl,
bool check_lock);
/**
* Checks if the given action is supported for Virtual Router VMs
* @param action VM action to check
* @return true if the action is supported for Virtual Router VMs
*/
static bool is_action_supported(History::VMAction action)
{
return SUPPORTED_ACTIONS.is_set(action);
}
// -------------------------------------------------------------------------
// VM Management
@ -190,8 +180,6 @@ private:
// -------------------------------------------------------------------------
friend class VirtualRouterPool;
static const ActionSet<History::VMAction> SUPPORTED_ACTIONS;
// *************************************************************************
// Attributes
// *************************************************************************

View File

@ -264,3 +264,85 @@ Request::ErrorCode TemplateChmod::chmod(
return SUCCESS;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualRouterChmod::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
int oid = xmlrpc_c::value_int(paramList.getInt(1));
int owner_u = xmlrpc_c::value_int(paramList.getInt(2));
int owner_m = xmlrpc_c::value_int(paramList.getInt(3));
int owner_a = xmlrpc_c::value_int(paramList.getInt(4));
int group_u = xmlrpc_c::value_int(paramList.getInt(5));
int group_m = xmlrpc_c::value_int(paramList.getInt(6));
int group_a = xmlrpc_c::value_int(paramList.getInt(7));
int other_u = xmlrpc_c::value_int(paramList.getInt(8));
int other_m = xmlrpc_c::value_int(paramList.getInt(9));
int other_a = xmlrpc_c::value_int(paramList.getInt(10));
bool recursive = false;
VirtualRouter * vrouter;
set<int>::const_iterator it;
set<int> vms;
if (paramList.size() > 11)
{
recursive = xmlrpc_c::value_boolean(paramList.getBoolean(11));
}
vrouter = vrpool->get(oid);
if ( vrouter == 0 )
{
att.resp_id = oid;
failure_response(NO_EXISTS, att);
}
vms = vrouter->get_vms();
vrouter->unlock();
ErrorCode ec = chmod(vrpool, oid,
owner_u, owner_m, owner_a,
group_u, group_m, group_a,
other_u, other_m, other_a,
recursive, att);
if ( ec != SUCCESS )
{
failure_response(ec, att);
return;
}
for (it = vms.begin(); it != vms.end(); it++)
{
int vm_id = *it;
ErrorCode ec_aux = chmod(pool, vm_id,
owner_u, owner_m, owner_a,
group_u, group_m, group_a,
other_u, other_m, other_a,
recursive, att);
if ( ec_aux != SUCCESS )
{
ec = ec_aux;
}
}
if ( ec == SUCCESS )
{
success_response(oid, att);
}
else
{
failure_response(ec, att);
}
}

View File

@ -295,6 +295,8 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
PoolObjectSQL * object;
set<int> vms;
// ------------- Check new user and group id's ---------------------
if ( noid > -1 )
@ -375,6 +377,10 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
att.resp_id = oid;
failure_response(NO_EXISTS, att);
}
else if ( auth_object == PoolObjectSQL::VROUTER )
{
vms = static_cast<VirtualRouter *>(object)->get_vms();
}
}
if ( object == 0 )
@ -396,7 +402,47 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
object->unlock();
success_response(oid, att);
// --------------- Recursive change associated VM objects ------------------
// IMPORTANT!: pool/auth_object members are redirected to the VM pool to
// chown VMs
// -------------------------------------------------------------------------
bool error_vm_quotas = false;
pool = Nebula::instance().get_vmpool();
auth_object = PoolObjectSQL::VM;
for (set<int>::const_iterator it = vms.begin(); it != vms.end(); it++)
{
int vm_id = *it;
PoolObjectSQL * vm = get_and_quota(vm_id, noid, ngid, att);
if ( vm == 0 )
{
error_vm_quotas = true;
continue;
}
if ( noid != -1 )
{
vm->set_user(noid, nuname);
}
if ( ngid != -1 )
{
vm->set_group(ngid, ngname);
}
pool->update(vm);
vm->unlock();
}
if (!error_vm_quotas)
{
success_response(oid, att);
}
return;
}
@ -582,3 +628,7 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -543,17 +543,6 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
if (vm->is_vrouter() && !VirtualRouter::is_action_supported(action))
{
att.resp_msg = "Action \"" + action_st + "\" is not supported for "
"virtual router VMs";
failure_response(ACTION, att);
vm->unlock();
return;
}
vm->unlock();
if ( action == History::RESUME_ACTION &&
@ -1113,15 +1102,6 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
return;
}
if (vm->is_vrouter() && !VirtualRouter::is_action_supported(action))
{
att.resp_msg = "Migration is not supported for virtual router VMs";
failure_response(ACTION, att);
vm->unlock();
return;
}
// Get System DS information from current History record
c_ds_id = vm->get_ds_id();
c_tm_mad = vm->get_tm_mad();
@ -1665,8 +1645,7 @@ void VirtualMachineAttach::request_execute(
return;
}
if (vm->is_vrouter() &&
!VirtualRouter::is_action_supported(History::NIC_ATTACH_ACTION))
if (vm->is_vrouter())
{
att.resp_msg = "Action is not supported for virtual router VMs";
failure_response(Request::ACTION, att);
@ -1818,7 +1797,7 @@ void VirtualMachineDetach::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
if (vm->is_vrouter() && !VirtualRouter::is_action_supported(History::NIC_DETACH_ACTION))
if (vm->is_vrouter())
{
att.resp_msg = "Action is not supported for virtual router VMs";
failure_response(ACTION, att);
@ -2278,8 +2257,7 @@ void VirtualMachineAttachNic::request_execute(
return;
}
if (vm->is_vrouter() &&
!VirtualRouter::is_action_supported(History::NIC_ATTACH_ACTION))
if (vm->is_vrouter())
{
att.resp_msg = "Action is not supported for virtual router VMs";
failure_response(Request::ACTION, att);
@ -2414,8 +2392,7 @@ void VirtualMachineDetachNic::request_execute(
return;
}
if (vm->is_vrouter() &&
!VirtualRouter::is_action_supported(History::NIC_DETACH_ACTION))
if (vm->is_vrouter())
{
att.resp_msg = "Action is not supported for virtual router VMs";
failure_response(Request::ACTION, att);

View File

@ -19,27 +19,6 @@
#include "Nebula.h"
#include "VirtualMachine.h"
#include "Request.h"
static const History::VMAction action[15] = {
History::MIGRATE_ACTION,
History::LIVE_MIGRATE_ACTION,
History::HOLD_ACTION,
History::RELEASE_ACTION,
History::RESUME_ACTION,
History::REBOOT_ACTION,
History::REBOOT_HARD_ACTION,
History::RESCHED_ACTION,
History::UNRESCHED_ACTION,
History::DISK_SNAPSHOT_CREATE_ACTION,
History::DISK_SNAPSHOT_DELETE_ACTION,
History::TERMINATE_ACTION,
History::TERMINATE_HARD_ACTION,
History::DELETE_ACTION,
History::DELETE_RECREATE_ACTION
};
const ActionSet<History::VMAction> VirtualRouter::SUPPORTED_ACTIONS(action, 15);
/* -------------------------------------------------------------------------- */
static void vrouter_prefix(VectorAttribute* nic, const string& attr)
@ -221,9 +200,6 @@ int VirtualRouter::shutdown_vms(const set<int>& _vms, const RequestAttributes& r
return result;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int VirtualRouter::get_network_leases(string& estr)
{
vector<VectorAttribute *> nics;