diff --git a/include/RequestManagerChmod.h b/include/RequestManagerChmod.h index a830716e15..3424e9f90b 100644 --- a/include/RequestManagerChmod.h +++ b/include/RequestManagerChmod.h @@ -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; }; /* ------------------------------------------------------------------------- */ diff --git a/include/VirtualRouter.h b/include/VirtualRouter.h index 5b2b7083ce..f56d41b7a2 100644 --- a/include/VirtualRouter.h +++ b/include/VirtualRouter.h @@ -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 SUPPORTED_ACTIONS; - // ************************************************************************* // Attributes // ************************************************************************* diff --git a/src/rm/RequestManagerChmod.cc b/src/rm/RequestManagerChmod.cc index c290333f6d..76a5798157 100644 --- a/src/rm/RequestManagerChmod.cc +++ b/src/rm/RequestManagerChmod.cc @@ -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::const_iterator it; + set 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); + } +} + diff --git a/src/rm/RequestManagerChown.cc b/src/rm/RequestManagerChown.cc index fce28f0844..e4c4c9e7d0 100644 --- a/src/rm/RequestManagerChown.cc +++ b/src/rm/RequestManagerChown.cc @@ -295,6 +295,8 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList, PoolObjectSQL * object; + set 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(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::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; } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index cd11538f82..afa1095304 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -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); diff --git a/src/vrouter/VirtualRouter.cc b/src/vrouter/VirtualRouter.cc index 87b070cffe..591838ec59 100644 --- a/src/vrouter/VirtualRouter.cc +++ b/src/vrouter/VirtualRouter.cc @@ -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 VirtualRouter::SUPPORTED_ACTIONS(action, 15); - /* -------------------------------------------------------------------------- */ static void vrouter_prefix(VectorAttribute* nic, const string& attr) @@ -221,9 +200,6 @@ int VirtualRouter::shutdown_vms(const set& _vms, const RequestAttributes& r return result; } -/* ------------------------------------------------------------------------ */ -/* ------------------------------------------------------------------------ */ - int VirtualRouter::get_network_leases(string& estr) { vector nics;