F #1401: Configurable VM_*_OPERATIONS per group and user. Restructure of the API

authorization levels and initialization logic.

Co-authored-by: Pavel Czerny <pczerny@opennebula.systems>
This commit is contained in:
Ruben S. MonteroandPavel Czerny committed 2019-09-09 13:13:52 +02:00
1 parent 332560d38f
commit 500e45dbd6
58 files changed
+1442 -1130

No files matched your search

+10 -10
View File
@@ -1218,7 +1218,7 @@ int DispatchManager::delete_recreate(VirtualMachine * vm,
case VirtualMachine::HOLD:
if (vm->hasHistory())
{
vm->set_action(History::DELETE_RECREATE_ACTION, ra.uid, ra.gid,
vm->set_action(VMActions::DELETE_RECREATE_ACTION, ra.uid, ra.gid,
ra.req_id);
vmpool->update_history(vm);
}
@@ -1384,7 +1384,7 @@ int DispatchManager::attach(int vid, VirtualMachineTemplate * tmpl,
vm->set_etime(the_time);
vm->set_action(History::DISK_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id);
vm->set_action(VMActions::DISK_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id);
vmpool->update_history(vm);
@@ -1474,7 +1474,7 @@ int DispatchManager::detach(int vid, int disk_id, const RequestAttributes& ra,
vm->set_etime(the_time);
vm->set_action(History::DISK_DETACH_ACTION, ra.uid, ra.gid, ra.req_id);
vm->set_action(VMActions::DISK_DETACH_ACTION, ra.uid, ra.gid, ra.req_id);
vmpool->update_history(vm);
@@ -1764,11 +1764,11 @@ int DispatchManager::attach_nic(int vid, VirtualMachineTemplate* tmpl,
if ( tmpl->get("NIC") != 0 )
{
vm->set_action(History::NIC_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id);
vm->set_action(VMActions::NIC_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id);
}
else
{
vm->set_action(History::ALIAS_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id);
vm->set_action(VMActions::ALIAS_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id);
}
vmpool->update_history(vm);
@@ -1862,11 +1862,11 @@ int DispatchManager::detach_nic(int vid, int nic_id,const RequestAttributes& ra,
if ( !vm->get_nic(nic_id)->is_alias() )
{
vm->set_action(History::NIC_DETACH_ACTION, ra.uid, ra.gid, ra.req_id);
vm->set_action(VMActions::NIC_DETACH_ACTION, ra.uid, ra.gid, ra.req_id);
}
else
{
vm->set_action(History::ALIAS_DETACH_ACTION, ra.uid, ra.gid, ra.req_id);
vm->set_action(VMActions::ALIAS_DETACH_ACTION, ra.uid, ra.gid, ra.req_id);
}
vmpool->update_history(vm);
@@ -1996,7 +1996,7 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name,
vm->set_etime(the_time);
vm->set_action(History::DISK_SNAPSHOT_CREATE_ACTION, ra.uid, ra.gid,
vm->set_action(VMActions::DISK_SNAPSHOT_CREATE_ACTION, ra.uid, ra.gid,
ra.req_id);
vmpool->update_history(vm);
@@ -2192,7 +2192,7 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id,
vm->set_etime(the_time);
vm->set_action(History::DISK_SNAPSHOT_DELETE_ACTION, ra.uid, ra.gid,
vm->set_action(VMActions::DISK_SNAPSHOT_DELETE_ACTION, ra.uid, ra.gid,
ra.req_id);
vmpool->update_history(vm);
@@ -2307,7 +2307,7 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size,
vm->set_etime(the_time);
vm->set_action(History::DISK_RESIZE_ACTION, ra.uid, ra.gid,
vm->set_action(VMActions::DISK_RESIZE_ACTION, ra.uid, ra.gid,
ra.req_id);
vmpool->update_history(vm);
+4 -4
View File
@@ -101,9 +101,9 @@ void DispatchManager::stop_success_action(int vid)
vm->set_state(VirtualMachine::LCM_INIT);
//Set history action field to perform the right TM command on resume
if (vm->get_action() == History::NONE_ACTION)
if (vm->get_action() == VMActions::NONE_ACTION)
{
vm->set_internal_action(History::STOP_ACTION);
vm->set_internal_action(VMActions::STOP_ACTION);
vmpool->update_history(vm);
}
@@ -161,9 +161,9 @@ void DispatchManager::undeploy_success_action(int vid)
vm->set_state(VirtualMachine::LCM_INIT);
//Set history action field to perform the right TM command on resume
if (vm->get_action() == History::NONE_ACTION)
if (vm->get_action() == VMActions::NONE_ACTION)
{
vm->set_internal_action(History::UNDEPLOY_ACTION);
vm->set_internal_action(VMActions::UNDEPLOY_ACTION);
vmpool->update_history(vm);
}
+35 -31
View File
@@ -248,6 +248,9 @@ string& Group::to_xml_extended(string& xml, bool extended) const
int Group::from_xml(const string& xml)
{
int rc = 0;
string error;
vector<xmlNodePtr> content;
vector<xmlNodePtr>::iterator it;
@@ -283,6 +286,8 @@ int Group::from_xml(const string& xml)
ObjectXML::free_nodes(content);
content.clear();
rc += vm_actions.set_auth_ops(*obj_template, error);
if (rc != 0)
{
return -1;
@@ -540,42 +545,41 @@ void Group::sunstone_views(const string& user_default, const string& user_views,
const string& admin_default, const string& admin_views)
{
VectorAttribute * sunstone = obj_template->get("SUNSTONE");
VectorAttribute * sunstone = obj_template->get("SUNSTONE");
if ( sunstone == 0 )
{
map<string,string> vvalue;
if ( sunstone == 0 )
{
map<string,string> vvalue;
vvalue.insert(make_pair("DEFAULT_VIEW", user_default));
vvalue.insert(make_pair("VIEWS", user_views));
vvalue.insert(make_pair("GROUP_ADMIN_DEFAULT_VIEW", admin_default));
vvalue.insert(make_pair("GROUP_ADMIN_VIEWS", admin_views));
vvalue.insert(make_pair("DEFAULT_VIEW", user_default));
vvalue.insert(make_pair("VIEWS", user_views));
vvalue.insert(make_pair("GROUP_ADMIN_DEFAULT_VIEW", admin_default));
vvalue.insert(make_pair("GROUP_ADMIN_VIEWS", admin_views));
sunstone = new VectorAttribute("SUNSTONE", vvalue);
sunstone = new VectorAttribute("SUNSTONE", vvalue);
obj_template->set(sunstone);
}
else
{
if ( sunstone->vector_value("DEFAULT_VIEW").empty() )
{
sunstone->replace("DEFAULT_VIEW", user_default);
}
obj_template->set(sunstone);
}
else
{
if ( sunstone->vector_value("DEFAULT_VIEW").empty() )
{
sunstone->replace("DEFAULT_VIEW", user_default);
}
if ( sunstone->vector_value("VIEWS").empty() )
{
sunstone->replace("VIEWS", user_views);
}
if ( sunstone->vector_value("VIEWS").empty() )
{
sunstone->replace("VIEWS", user_views);
}
if ( sunstone->vector_value("GROUP_ADMIN_DEFAULT_VIEW").empty() )
{
sunstone->replace("GROUP_ADMIN_DEFAULT_VIEW", admin_default);
}
if ( sunstone->vector_value("GROUP_ADMIN_DEFAULT_VIEW").empty() )
{
sunstone->replace("GROUP_ADMIN_DEFAULT_VIEW", admin_default);
}
if ( sunstone->vector_value("GROUP_ADMIN_VIEWS").empty() )
{
sunstone->replace("GROUP_ADMIN_VIEWS", admin_views);
}
}
if ( sunstone->vector_value("GROUP_ADMIN_VIEWS").empty() )
{
sunstone->replace("GROUP_ADMIN_VIEWS", admin_views);
}
}
}
+8 -4
View File
@@ -38,7 +38,8 @@ const int GroupPool::USERS_ID = 1;
/* -------------------------------------------------------------------------- */
GroupPool::GroupPool(SqlDB * db, vector<const VectorAttribute *> hook_mads,
const string& remotes_location, bool is_federation_slave) :
const string& remotes_location, bool is_federation_slave,
vector<const SingleAttribute *>& restricted_attrs) :
PoolSQL(db, Group::table)
{
ostringstream oss;
@@ -61,7 +62,7 @@ GroupPool::GroupPool(SqlDB * db, vector<const VectorAttribute *> hook_mads,
rc = PoolSQL::allocate(group, error_str);
if( rc < 0 )
if (rc < 0)
{
goto error_groups;
}
@@ -72,7 +73,7 @@ GroupPool::GroupPool(SqlDB * db, vector<const VectorAttribute *> hook_mads,
rc = PoolSQL::allocate(group, error_str);
if(rc < 0)
if (rc < 0)
{
goto error_groups;
}
@@ -82,6 +83,9 @@ GroupPool::GroupPool(SqlDB * db, vector<const VectorAttribute *> hook_mads,
register_hooks(hook_mads, remotes_location);
// Set restricted attributes
GroupTemplate::parse_restricted(restricted_attrs);
return;
error_groups:
@@ -222,7 +226,7 @@ int GroupPool::drop(PoolObjectSQL * objsql, string& error_msg)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int GroupPool::dump(string& oss, const string& where,
int GroupPool::dump(string& oss, const string& where,
const string& limit, bool desc)
{
int rc;
+22
View File
@@ -0,0 +1,22 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
/* */
/* 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 "GroupTemplate.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
std::map<std::string, std::set<std::string>> GroupTemplate::restricted;
+2 -1
View File
@@ -23,7 +23,8 @@ lib_name='nebula_group'
# Sources to generate the library
source_files=[
'GroupPool.cc',
'Group.cc'
'Group.cc',
'GroupTemplate.cc'
]
# Build library
+29 -29
View File
@@ -55,13 +55,13 @@ void LifeCycleManager::deploy_action(const LCMAction& la)
if (vm->hasPreviousHistory())
{
if (vm->get_previous_action() == History::STOP_ACTION)
if (vm->get_previous_action() == VMActions::STOP_ACTION)
{
vm_state = VirtualMachine::PROLOG_RESUME;
tm_action = TMAction::PROLOG_RESUME;
}
else if (vm->get_previous_action() == History::UNDEPLOY_ACTION ||
vm->get_previous_action() == History::UNDEPLOY_HARD_ACTION)
else if (vm->get_previous_action() == VMActions::UNDEPLOY_ACTION ||
vm->get_previous_action() == VMActions::UNDEPLOY_HARD_ACTION)
{
vm_state = VirtualMachine::PROLOG_UNDEPLOY;
tm_action = TMAction::PROLOG_RESUME;
@@ -125,7 +125,7 @@ void LifeCycleManager::suspend_action(const LCMAction& la)
vm->set_resched(false);
vm->set_action(History::SUSPEND_ACTION, la.uid(), la.gid(), la.req_id());
vm->set_action(VMActions::SUSPEND_ACTION, la.uid(), la.gid(), la.req_id());
vmpool->update_history(vm);
@@ -170,7 +170,7 @@ void LifeCycleManager::stop_action(const LCMAction& la)
vm->set_resched(false);
vm->set_action(History::STOP_ACTION, la.uid(), la.gid(), la.req_id());
vm->set_action(VMActions::STOP_ACTION, la.uid(), la.gid(), la.req_id());
vmpool->update_history(vm);
@@ -188,7 +188,7 @@ void LifeCycleManager::stop_action(const LCMAction& la)
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::EPILOG_STOP);
vm->set_action(History::STOP_ACTION, la.uid(), la.gid(), la.req_id());
vm->set_action(VMActions::STOP_ACTION, la.uid(), la.gid(), la.req_id());
vm->set_epilog_stime(time(0));
@@ -235,18 +235,18 @@ void LifeCycleManager::migrate_action(const LCMAction& la)
// SAVE_MIGRATE STATE
//----------------------------------------------------
History::VMAction action;
VMActions::Action action;
switch (la.action())
{
case LCMAction::POFF_MIGRATE :
action = History::POFF_MIGRATE_ACTION;
action = VMActions::POFF_MIGRATE_ACTION;
break;
case LCMAction::POFF_HARD_MIGRATE :
action = History::POFF_HARD_MIGRATE_ACTION;
action = VMActions::POFF_HARD_MIGRATE_ACTION;
break;
default :
action = History::MIGRATE_ACTION;
action = VMActions::MIGRATE_ACTION;
break;
}
@@ -297,14 +297,14 @@ void LifeCycleManager::migrate_action(const LCMAction& la)
if (vm->get_state() == VirtualMachine::POWEROFF)
{
vm->set_state(VirtualMachine::PROLOG_MIGRATE_POWEROFF);
vm->set_action(History::MIGRATE_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::MIGRATE_ACTION, la.uid(), la.gid(),
la.req_id());
}
else if (vm->get_state() == VirtualMachine::SUSPENDED)
{
vm->set_state(VirtualMachine::PROLOG_MIGRATE_SUSPEND);
vm->set_action(History::MIGRATE_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::MIGRATE_ACTION, la.uid(), la.gid(),
la.req_id());
}
else //VirtualMachine::UNKNOWN
@@ -315,7 +315,7 @@ void LifeCycleManager::migrate_action(const LCMAction& la)
vm->set_previous_etime(the_time);
vm->set_previous_action(History::MIGRATE_ACTION, la.uid(), la.gid(),
vm->set_previous_action(VMActions::MIGRATE_ACTION, la.uid(), la.gid(),
la.req_id());
vm->set_previous_vm_info();
@@ -400,12 +400,12 @@ void LifeCycleManager::live_migrate_action(const LCMAction& la)
vm->set_stime(time(0));
vm->set_action(History::LIVE_MIGRATE_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::LIVE_MIGRATE_ACTION, la.uid(), la.gid(),
la.req_id());
vmpool->update_history(vm);
vm->set_previous_action(History::LIVE_MIGRATE_ACTION, la.uid(),la.gid(),
vm->set_previous_action(VMActions::LIVE_MIGRATE_ACTION, la.uid(),la.gid(),
la.req_id());
vmpool->update_previous_history(vm);
@@ -475,14 +475,14 @@ void LifeCycleManager::shutdown_action(const LCMAction& la, bool hard)
if (hard)
{
vm->set_action(History::TERMINATE_HARD_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::TERMINATE_HARD_ACTION, la.uid(), la.gid(),
la.req_id());
vmm->trigger(VMMAction::CANCEL,vid);
}
else
{
vm->set_action(History::TERMINATE_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::TERMINATE_ACTION, la.uid(), la.gid(),
la.req_id());
vmm->trigger(VMMAction::SHUTDOWN,vid);
@@ -502,7 +502,7 @@ void LifeCycleManager::shutdown_action(const LCMAction& la, bool hard)
Quotas::vm_check(uid, gid, &quota_tmpl, error);
vm->set_action(History::TERMINATE_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::TERMINATE_ACTION, la.uid(), la.gid(),
la.req_id());
vm->set_epilog_stime(time(0));
@@ -523,7 +523,7 @@ void LifeCycleManager::shutdown_action(const LCMAction& la, bool hard)
Quotas::vm_check(uid, gid, &quota_tmpl, error);
vm->set_action(History::TERMINATE_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::TERMINATE_ACTION, la.uid(), la.gid(),
la.req_id());
vm->set_epilog_stime(time(0));
@@ -574,14 +574,14 @@ void LifeCycleManager::undeploy_action(const LCMAction& la, bool hard)
if (hard)
{
vm->set_action(History::UNDEPLOY_HARD_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::UNDEPLOY_HARD_ACTION, la.uid(), la.gid(),
la.req_id());
vmm->trigger(VMMAction::CANCEL,vid);
}
else
{
vm->set_action(History::UNDEPLOY_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::UNDEPLOY_ACTION, la.uid(), la.gid(),
la.req_id());
vmm->trigger(VMMAction::SHUTDOWN,vid);
@@ -608,7 +608,7 @@ void LifeCycleManager::undeploy_action(const LCMAction& la, bool hard)
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::EPILOG_UNDEPLOY);
vm->set_action(History::UNDEPLOY_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::UNDEPLOY_ACTION, la.uid(), la.gid(),
la.req_id());
vm->set_epilog_stime(time(0));
@@ -678,14 +678,14 @@ void LifeCycleManager::poweroff_action(int vid, bool hard, const LCMAction& la)
if (hard)
{
vm->set_action(History::POWEROFF_HARD_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::POWEROFF_HARD_ACTION, la.uid(), la.gid(),
la.req_id());
vmm->trigger(VMMAction::CANCEL,vid);
}
else
{
vm->set_action(History::POWEROFF_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::POWEROFF_ACTION, la.uid(), la.gid(),
la.req_id());
vmm->trigger(VMMAction::SHUTDOWN,vid);
@@ -742,7 +742,7 @@ void LifeCycleManager::restore_action(const LCMAction& la)
vm->set_running_stime(the_time);
vm->set_action(History::RESUME_ACTION, la.uid(), la.gid(), la.req_id());
vm->set_action(VMActions::RESUME_ACTION, la.uid(), la.gid(), la.req_id());
vmpool->insert_history(vm);
@@ -801,7 +801,7 @@ void LifeCycleManager::restart_action(const LCMAction& la)
vm->set_running_stime(the_time);
vm->set_action(History::RESUME_ACTION, la.uid(), la.gid(), la.req_id());
vm->set_action(VMActions::RESUME_ACTION, la.uid(), la.gid(), la.req_id());
vmpool->insert_history(vm);
@@ -977,12 +977,12 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose,
if (dispose)
{
vm->set_state(VirtualMachine::CLEANUP_DELETE);
vm->set_action(History::DELETE_ACTION, la.uid(), la.gid(), la.req_id());
vm->set_action(VMActions::DELETE_ACTION, la.uid(), la.gid(), la.req_id());
}
else
{
vm->set_state(VirtualMachine::CLEANUP_RESUBMIT);
vm->set_action(History::DELETE_RECREATE_ACTION, la.uid(), la.gid(),
vm->set_action(VMActions::DELETE_RECREATE_ACTION, la.uid(), la.gid(),
la.req_id());
}
@@ -1617,7 +1617,7 @@ void LifeCycleManager::retry(VirtualMachine * vm)
case VirtualMachine::SHUTDOWN:
case VirtualMachine::SHUTDOWN_POWEROFF:
case VirtualMachine::SHUTDOWN_UNDEPLOY:
if (vm->get_action() == History::TERMINATE_ACTION)
if (vm->get_action() == VMActions::TERMINATE_ACTION)
{
vmm->trigger(VMMAction::SHUTDOWN,vid);
}
+4 -4
View File
@@ -673,8 +673,8 @@ void LifeCycleManager::prolog_success_action(int vid)
case VirtualMachine::PROLOG_MIGRATE:
case VirtualMachine::PROLOG_MIGRATE_FAILURE: //recover success
if (vm->get_action() == History::POFF_MIGRATE_ACTION ||
vm->get_action() == History::POFF_HARD_MIGRATE_ACTION)
if (vm->get_action() == VMActions::POFF_MIGRATE_ACTION ||
vm->get_action() == VMActions::POFF_HARD_MIGRATE_ACTION)
{
action = VMMAction::DEPLOY;
vm->set_state(VirtualMachine::BOOT);
@@ -1105,7 +1105,7 @@ void LifeCycleManager::monitor_suspend_action(int vid)
vm->set_vm_info();
vm->set_internal_action(History::MONITOR_ACTION);
vm->set_internal_action(VMActions::MONITOR_ACTION);
vmpool->update_history(vm);
@@ -1198,7 +1198,7 @@ void LifeCycleManager::monitor_poweroff_action(int vid)
vm->set_vm_info();
vm->set_internal_action(History::MONITOR_ACTION);
vm->set_internal_action(VMActions::MONITOR_ACTION);
vmpool->update_history(vm);
+6 -3
View File
@@ -639,20 +639,23 @@ void Nebula::start(bool bootstrap_only)
/* ----------------------- Group/User Pool -------------------------- */
vector<const VectorAttribute *> user_hooks;
vector<const VectorAttribute *> group_hooks;
vector<const SingleAttribute *> user_restricted_attrs;
vector<const SingleAttribute *> group_restricted_attrs;
time_t expiration_time;
nebula_configuration->get("GROUP_HOOK", group_hooks);
nebula_configuration->get("GROUP_RESTRICTED_ATTR", group_restricted_attrs);
gpool = new GroupPool(db_ptr, group_hooks, remotes_location,
is_federation_slave());
is_federation_slave(), group_restricted_attrs);
nebula_configuration->get("SESSION_EXPIRATION_TIME", expiration_time);
nebula_configuration->get("USER_HOOK", user_hooks);
nebula_configuration->get("USER_RESTRICTED_ATTR", user_restricted_attrs);
upool = new UserPool(db_ptr, expiration_time, user_hooks,
remotes_location, is_federation_slave());
remotes_location, is_federation_slave(), user_restricted_attrs);
/* -------------------- Image/Datastore Pool ------------------------ */
string image_type;
+1 -201
View File
@@ -94,7 +94,7 @@ int OpenNebulaTemplate::load_configuration()
return -1;
}
if ( set_vm_auth_ops(error) != 0 )
if ( vm_actions.set_auth_ops(*this, error) != 0 )
{
cout << "\nError while parsing configuration file:\n" << error << endl;
return -1;
@@ -711,203 +711,3 @@ int OpenNebulaTemplate::load_key()
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static int _set_vm_auth_ops(const std::string& ops_str,
ActionSet<History::VMAction>& ops_set, std::string& error_op)
{
std::set<std::string> ops;
std::set<std::string>::iterator it;
one_util::split_unique(ops_str, ',', ops);
for ( it = ops.begin() ; it != ops.end() ; ++it )
{
std::string the_op = one_util::trim(*it);
one_util::tolower(the_op);
if ( the_op == "migrate" )
{
ops_set.set(History::MIGRATE_ACTION);
ops_set.set(History::LIVE_MIGRATE_ACTION);
}
else if ( the_op == "delete" )
{
ops_set.set(History::DELETE_ACTION);
ops_set.set(History::DELETE_RECREATE_ACTION);
}
else if ( the_op == "recover" )
{
ops_set.set(History::RECOVER_ACTION);
}
else if ( the_op == "retry" )
{
ops_set.set(History::RETRY_ACTION);
}
else if ( the_op == "deploy" )
{
ops_set.set(History::DEPLOY_ACTION);
}
else if ( the_op == "resched" )
{
ops_set.set(History::RESCHED_ACTION);
ops_set.set(History::UNRESCHED_ACTION);
}
else if ( the_op == "undeploy" )
{
ops_set.set(History::UNDEPLOY_ACTION);
ops_set.set(History::UNDEPLOY_HARD_ACTION);
}
else if ( the_op == "hold" )
{
ops_set.set(History::HOLD_ACTION);
}
else if ( the_op == "release" )
{
ops_set.set(History::RELEASE_ACTION);
}
else if ( the_op == "stop" )
{
ops_set.set(History::STOP_ACTION);
}
else if ( the_op == "suspend" )
{
ops_set.set(History::SUSPEND_ACTION);
}
else if ( the_op == "resume" )
{
ops_set.set(History::RESUME_ACTION);
}
else if ( the_op == "reboot" )
{
ops_set.set(History::REBOOT_ACTION);
ops_set.set(History::REBOOT_HARD_ACTION);
}
else if ( the_op == "poweroff" )
{
ops_set.set(History::POWEROFF_ACTION);
ops_set.set(History::POWEROFF_HARD_ACTION);
}
else if ( the_op == "disk-attach" )
{
ops_set.set(History::DISK_ATTACH_ACTION);
ops_set.set(History::DISK_DETACH_ACTION);
}
else if ( the_op == "nic-attach" )
{
ops_set.set(History::NIC_ATTACH_ACTION);
ops_set.set(History::NIC_DETACH_ACTION);
}
else if ( the_op == "disk-snapshot" )
{
ops_set.set(History::DISK_SNAPSHOT_CREATE_ACTION);
ops_set.set(History::DISK_SNAPSHOT_DELETE_ACTION);
ops_set.set(History::DISK_SNAPSHOT_REVERT_ACTION);
ops_set.set(History::DISK_SNAPSHOT_RENAME_ACTION);
}
else if ( the_op == "terminate" )
{
ops_set.set(History::TERMINATE_ACTION);
ops_set.set(History::TERMINATE_HARD_ACTION);
}
else if ( the_op == "disk-resize" )
{
ops_set.set(History::DISK_RESIZE_ACTION);
}
else if ( the_op == "snapshot" )
{
ops_set.set(History::SNAPSHOT_CREATE_ACTION);
ops_set.set(History::SNAPSHOT_DELETE_ACTION);
ops_set.set(History::SNAPSHOT_REVERT_ACTION);
}
else if ( the_op == "updateconf" )
{
ops_set.set(History::UPDATECONF_ACTION);
}
else if ( the_op == "rename" )
{
ops_set.set(History::RENAME_ACTION);
}
else if ( the_op == "resize" )
{
ops_set.set(History::RESIZE_ACTION);
}
else if ( the_op == "update" )
{
ops_set.set(History::UPDATE_ACTION);
}
else if ( the_op == "disk-saveas" )
{
ops_set.set(History::DISK_SAVEAS_ACTION);
}
else
{
error_op = the_op;
return -1;
}
}
return 0;
}
/* -------------------------------------------------------------------------- */
int OpenNebulaTemplate::set_vm_auth_ops(std::string& error)
{
std::string error_op;
std::string admin, manage, use;
get("VM_ADMIN_OPERATIONS", admin);
if ( _set_vm_auth_ops(admin, vm_admin_actions, error_op) != 0 )
{
goto error_op;
}
get("VM_MANAGE_OPERATIONS", manage);
if ( _set_vm_auth_ops(manage, vm_manage_actions, error_op) != 0 )
{
goto error_op;
}
get("VM_USE_OPERATIONS", use);
if ( _set_vm_auth_ops(use, vm_use_actions, error_op) != 0 )
{
goto error_op;
}
return 0;
error_op:
error = "Unknown vm operation: " + error_op;
return -1;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
AuthRequest::Operation OpenNebulaTemplate::get_vm_auth_op(History::VMAction ac)
{
if ( vm_admin_actions.is_set(ac) )
{
return AuthRequest::ADMIN;
}
else if ( vm_manage_actions.is_set(ac) )
{
return AuthRequest::MANAGE;
}
else if ( vm_use_actions.is_set(ac) )
{
return AuthRequest::USE;
}
else
{
return AuthRequest::MANAGE;
}
}
+66 -12
View File
@@ -356,7 +356,7 @@ void Request::execute(
const xmlrpc_c::callInfo * _callInfoP,
xmlrpc_c::value * const _retval)
{
RequestAttributes att;
RequestAttributes att(auth_op);
att.retval = _retval;
att.session = xmlrpc_c::value_string(_paramList.getString(0));
@@ -371,6 +371,8 @@ void Request::execute(
bool authenticated = upool->authenticate(att.session, att.password,
att.uid, att.gid, att.uname, att.gname, att.group_ids, att.umask);
att.set_auth_op(vm_action);
if ( log_method_call )
{
log_method_invoked(att, _paramList, format_str, method_name,
@@ -440,11 +442,9 @@ void Request::execute(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool Request::basic_authorization(int oid,
AuthRequest::Operation op,
RequestAttributes& att)
bool Request::basic_authorization(int oid, RequestAttributes& att)
{
ErrorCode ec = basic_authorization(pool, oid, op, auth_object, att);
ErrorCode ec = basic_authorization(pool, oid, auth_object, att);
if (ec == SUCCESS)
{
@@ -463,7 +463,6 @@ bool Request::basic_authorization(int oid,
Request::ErrorCode Request::basic_authorization(
PoolSQL* pool,
int oid,
AuthRequest::Operation op,
PoolObjectSQL::ObjectType auth_object,
RequestAttributes& att)
{
@@ -493,7 +492,7 @@ Request::ErrorCode Request::basic_authorization(
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(op, perms);
ar.add_auth(att.auth_op, perms);
if (UserPool::authorize(ar) == -1)
{
@@ -942,25 +941,29 @@ int Request::get_info(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
Request::ErrorCode Request::as_uid_gid(Template * tmpl,
RequestAttributes& att)
Request::ErrorCode Request::as_uid_gid(Template * tmpl, RequestAttributes& att)
{
string gname;
string uname;
PoolObjectAuth uperms;
PoolObjectAuth gperms;
int uid = att.uid, as_uid = -1, as_gid = -1;
set<int> gids = att.group_ids;
int rc;
UserPool * upool = Nebula::instance().get_upool();
UserPool * upool = Nebula::instance().get_upool();
GroupPool * gpool = Nebula::instance().get_gpool();
if ( tmpl->get("AS_UID", as_uid) )
{
tmpl->erase("AS_UID");
rc = get_info(upool, as_uid, PoolObjectSQL::USER, att, uperms, uname,true);
rc = get_info(upool, as_uid, PoolObjectSQL::USER, att, uperms, uname,
true);
if ( rc == -1 )
{
@@ -975,7 +978,9 @@ Request::ErrorCode Request::as_uid_gid(Template * tmpl,
if ( tmpl->get("AS_GID", as_gid) )
{
tmpl->erase("AS_GID");
rc = get_info(gpool, as_gid, PoolObjectSQL::GROUP, att, gperms, gname,true);
rc = get_info(gpool, as_gid, PoolObjectSQL::GROUP, att, gperms, gname,
true);
if ( rc == -1 )
{
@@ -1031,3 +1036,52 @@ Request::ErrorCode Request::as_uid_gid(Template * tmpl,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RequestAttributes::set_auth_op(VMActions::Action action)
{
if (action == VMActions::NONE_ACTION)
{
return;
}
AuthRequest::Operation result = AuthRequest::NONE;
auto& nd = Nebula::instance();
auto user = nd.get_upool()->get_ro(uid);
if (user != nullptr)
{
result = user->get_vm_auth_op(action);
}
user->unlock();
if (result != AuthRequest::NONE)
{
auth_op = result;
return;
}
auto group = nd.get_gpool()->get_ro(gid);
if (group != nullptr)
{
result = group->get_vm_auth_op(action);
}
group->unlock();
if (result != AuthRequest::NONE)
{
auth_op = result;
return;
}
result = nd.get_vm_auth_op(action);
if (result != AuthRequest::NONE)
{
auth_op = result;
}
}
+3 -3
View File
@@ -332,7 +332,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
ar.add_auth(auth_op, operms); // MANAGE OBJECT
ar.add_auth(att.auth_op, operms); // MANAGE OBJECT
if ( noid > -1 )
{
@@ -411,7 +411,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
}
// --------------- Recursive change associated VM objects ------------------
// IMPORTANT!: pool/auth_object members are redirected to the VM pool to
// IMPORTANT!: pool/auth_object members are redirected to the VM pool to
// chown VMs
// -------------------------------------------------------------------------
bool error_vm_quotas = false;
@@ -546,7 +546,7 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(auth_op, uperms); // MANAGE USER
ar.add_auth(att.auth_op, uperms); // MANAGE USER
ar.add_auth(AuthRequest::USE, ngperms); // USE GROUP
if (UserPool::authorize(ar) == -1)
+1 -1
View File
@@ -89,7 +89,7 @@ Request::ErrorCode RequestManagerClone::clone(int source_id, const string &name,
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(auth_op, perms); //USE OBJECT
ar.add_auth(att.auth_op, perms); //USE OBJECT
tmpl->to_xml(tmpl_str);
+2 -2
View File
@@ -59,7 +59,7 @@ void RequestManagerCluster::action_generic(
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(auth_op, c_perms); // ADMIN CLUSTER
ar.add_auth(att.auth_op, c_perms); // ADMIN CLUSTER
ar.add_auth(AuthRequest::ADMIN, obj_perms); // ADMIN OBJECT
if (UserPool::authorize(ar) == -1)
@@ -218,7 +218,7 @@ void RequestManagerClusterHost::add_generic(
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(auth_op, c_perms); // ADMIN CLUSTER
ar.add_auth(att.auth_op, c_perms); // ADMIN CLUSTER
ar.add_auth(AuthRequest::ADMIN, obj_perms); // ADMIN HOST
if (UserPool::authorize(ar) == -1)
+10 -12
View File
@@ -20,8 +20,8 @@
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static Request::ErrorCode delete_authorization(PoolSQL* pool,
int oid, AuthRequest::Operation auth_op, RequestAttributes& att)
static Request::ErrorCode delete_authorization(PoolSQL* pool, int oid,
RequestAttributes& att)
{
PoolObjectAuth perms;
@@ -39,7 +39,7 @@ static Request::ErrorCode delete_authorization(PoolSQL* pool,
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(auth_op, perms); // <MANAGE|ADMIN> OBJECT
ar.add_auth(att.auth_op, perms); // <MANAGE|ADMIN> OBJECT
if (UserPool::authorize(ar) == -1)
{
@@ -64,7 +64,7 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList,
recursive = xmlrpc_c::value_boolean(paramList.getBoolean(2));
}
ErrorCode ec = delete_object(oid, recursive, att, auth_op);
ErrorCode ec = delete_object(oid, recursive, att);
if ( ec == SUCCESS )
{
@@ -79,10 +79,8 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList,
void ImageDelete::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
int oid = xmlrpc_c::value_int(paramList.getInt(1));
AuthRequest::Operation auth = auth_op;
int oid = xmlrpc_c::value_int(paramList.getInt(1));
//get the image
Image* img = static_cast<ImagePool *>(pool)->get_ro(oid);
if (img == 0)
@@ -94,12 +92,12 @@ void ImageDelete::request_execute(xmlrpc_c::paramList const& paramList,
if (img->is_locked())
{
auth = AuthRequest::ADMIN;
att.auth_op = AuthRequest::ADMIN;
}
img->unlock();
ErrorCode ec = delete_object(oid, false, att, auth);
ErrorCode ec = delete_object(oid, false, att);
if ( ec == SUCCESS )
{
@@ -115,13 +113,13 @@ void ImageDelete::request_execute(xmlrpc_c::paramList const& paramList,
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
Request::ErrorCode RequestManagerDelete::delete_object(int oid,
bool recursive, RequestAttributes& att, AuthRequest::Operation auth)
Request::ErrorCode RequestManagerDelete::delete_object(int oid, bool recursive,
RequestAttributes& att)
{
string err;
ErrorCode ec;
ec = delete_authorization(pool, oid, auth, att);
ec = delete_authorization(pool, oid, att);
if ( ec != SUCCESS )
{
+1 -2
View File
@@ -99,8 +99,7 @@ Request::ErrorCode ImagePersistent::request_execute(
ErrorCode ec;
ec = basic_authorization(ipool, id,
AuthRequest::MANAGE, PoolObjectSQL::IMAGE, att);
ec = basic_authorization(ipool, id, PoolObjectSQL::IMAGE, att);
if ( ec != SUCCESS)
{
+2 -2
View File
@@ -120,7 +120,7 @@ void TemplateInfo::request_execute(xmlrpc_c::paramList const& paramList,
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(auth_op, perms); //USE TEMPLATE
ar.add_auth(att.auth_op, perms); //USE TEMPLATE
if (extended)
{
@@ -209,7 +209,7 @@ void VirtualNetworkTemplateInfo::request_execute(xmlrpc_c::paramList const& para
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(auth_op, perms); //USE TEMPLATE
ar.add_auth(att.auth_op, perms); //USE TEMPLATE
if (UserPool::authorize(ar) == -1)
{
+1 -1
View File
@@ -63,7 +63,7 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList,
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(auth_op, operms); // MANAGE OBJECT
ar.add_auth(att.auth_op, operms); // MANAGE OBJECT
if (UserPool::authorize(ar) == -1)
{
-1
View File
@@ -127,4 +127,3 @@ void RequestManagerUpdateTemplate::request_execute(
return;
}
+1 -1
View File
@@ -430,7 +430,7 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList,
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(auth_op, perms);
ar.add_auth(att.auth_op, perms);
if (UserPool::authorize(ar) == -1)
{
+87 -96
View File
@@ -30,8 +30,7 @@ bool RequestManagerVirtualMachine::vm_authorization(
RequestAttributes& att,
PoolObjectAuth * host_perm,
PoolObjectAuth * ds_perm,
PoolObjectAuth * img_perm,
AuthRequest::Operation op)
PoolObjectAuth * img_perm)
{
PoolObjectSQL * object;
PoolObjectAuth vm_perms;
@@ -52,7 +51,7 @@ bool RequestManagerVirtualMachine::vm_authorization(
AuthRequest ar(att.uid, att.group_ids);
ar.add_auth(op, vm_perms);
ar.add_auth(att.auth_op, vm_perms);
if (host_perm != nullptr)
{
@@ -496,8 +495,7 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
ostringstream oss;
string error;
AuthRequest::Operation op;
History::VMAction action;
VMActions::Action action;
VirtualMachineTemplate quota_tmpl;
@@ -513,11 +511,12 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
action_st = "terminate";
}
History::action_from_str(action_st, action);
VMActions::action_from_str(action_st, action);
op = nd.get_vm_auth_op(action);
// Update the authorization level for the action
att.set_auth_op(action);
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -527,21 +526,7 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
vm->get_template_attribute("MEMORY", memory);
vm->get_template_attribute("CPU", cpu);
quota_tmpl.add("RUNNING_MEMORY", memory);
quota_tmpl.add("RUNNING_CPU", cpu);
quota_tmpl.add("RUNNING_VMS", 1);
quota_tmpl.add("VMS", 0);
quota_tmpl.add("MEMORY", 0);
quota_tmpl.add("CPU", 0);
RequestAttributes& att_aux(att);
att_aux.uid = vm->get_uid();
att_aux.gid = vm->get_gid();
// Check if the action is supported for imported VMs
if (vm->is_imported() && !vm->is_imported_action_supported(action))
{
att.resp_msg = "Action \"" + action_st + "\" is not supported for "
@@ -553,11 +538,30 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
// Generate quota information for resume action
RequestAttributes& att_aux(att);
if (action == VMActions::RESUME_ACTION)
{
vm->get_template_attribute("MEMORY", memory);
vm->get_template_attribute("CPU", cpu);
quota_tmpl.add("RUNNING_MEMORY", memory);
quota_tmpl.add("RUNNING_CPU", cpu);
quota_tmpl.add("RUNNING_VMS", 1);
quota_tmpl.add("VMS", 0);
quota_tmpl.add("MEMORY", 0);
quota_tmpl.add("CPU", 0);
att_aux.uid = vm->get_uid();
att_aux.gid = vm->get_gid();
}
vm->unlock();
if ( action == History::RESUME_ACTION &&
!quota_authorization(&quota_tmpl, Quotas::VIRTUALMACHINE, att_aux,
att.resp_msg) )
if (action == VMActions::RESUME_ACTION && !quota_authorization(&quota_tmpl,
Quotas::VIRTUALMACHINE, att_aux, att.resp_msg))
{
failure_response(ACTION, att);
return;
@@ -565,49 +569,49 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
switch (action)
{
case History::TERMINATE_ACTION:
case VMActions::TERMINATE_ACTION:
rc = dm->terminate(id, false, att, error);
break;
case History::TERMINATE_HARD_ACTION:
case VMActions::TERMINATE_HARD_ACTION:
rc = dm->terminate(id, true, att, error);
break;
case History::HOLD_ACTION:
case VMActions::HOLD_ACTION:
rc = dm->hold(id, att, error);
break;
case History::RELEASE_ACTION:
case VMActions::RELEASE_ACTION:
rc = dm->release(id, att, error);
break;
case History::STOP_ACTION:
case VMActions::STOP_ACTION:
rc = dm->stop(id, att, error);
break;
case History::SUSPEND_ACTION:
case VMActions::SUSPEND_ACTION:
rc = dm->suspend(id, att, error);
break;
case History::RESUME_ACTION:
case VMActions::RESUME_ACTION:
rc = dm->resume(id, att, error);
break;
case History::REBOOT_ACTION:
case VMActions::REBOOT_ACTION:
rc = dm->reboot(id, false, att, error);
break;
case History::REBOOT_HARD_ACTION:
case VMActions::REBOOT_HARD_ACTION:
rc = dm->reboot(id, true, att, error);
break;
case History::RESCHED_ACTION:
case VMActions::RESCHED_ACTION:
rc = dm->resched(id, true, att, error);
break;
case History::UNRESCHED_ACTION:
case VMActions::UNRESCHED_ACTION:
rc = dm->resched(id, false, att, error);
break;
case History::POWEROFF_ACTION:
case VMActions::POWEROFF_ACTION:
rc = dm->poweroff(id, false, att, error);
break;
case History::POWEROFF_HARD_ACTION:
case VMActions::POWEROFF_HARD_ACTION:
rc = dm->poweroff(id, true, att, error);
break;
case History::UNDEPLOY_ACTION:
case VMActions::UNDEPLOY_ACTION:
rc = dm->undeploy(id, false, att, error);
break;
case History::UNDEPLOY_HARD_ACTION:
case VMActions::UNDEPLOY_HARD_ACTION:
rc = dm->undeploy(id, true, att, error);
break;
default:
@@ -702,7 +706,7 @@ int set_vnc_port(VirtualMachine *vm, int cluster_id, RequestAttributes& att)
{
return 0;
}
else if (vm->hasHistory() && vm->get_action()==History::STOP_ACTION)
else if (vm->hasHistory() && vm->get_action()==VMActions::STOP_ACTION)
{
return 0;
}
@@ -761,6 +765,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
bool auth = false;
bool check_nic_auto = false;
// ------------------------------------------------------------------------
// Get request parameters and information about the target host
// ------------------------------------------------------------------------
@@ -815,9 +820,9 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
}
if (vm->hasHistory() &&
(vm->get_action() == History::STOP_ACTION ||
vm->get_action() == History::UNDEPLOY_ACTION ||
vm->get_action() == History::UNDEPLOY_HARD_ACTION))
(vm->get_action() == VMActions::STOP_ACTION ||
vm->get_action() == VMActions::UNDEPLOY_ACTION ||
vm->get_action() == VMActions::UNDEPLOY_HARD_ACTION))
{
ds_id = vm->get_ds_id();
@@ -924,13 +929,11 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
auth = vm_authorization(id, 0, &tmpl, att, &host_perms, auth_ds_perms,0,
auth_op);
auth = vm_authorization(id, 0, &tmpl, att, &host_perms, auth_ds_perms,0);
}
else
{
auth = vm_authorization(id, 0, 0, att, &host_perms, auth_ds_perms, 0,
auth_op);
auth = vm_authorization(id, 0, 0, att, &host_perms, auth_ds_perms, 0);
}
if (auth == false)
@@ -1068,7 +1071,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
string error;
History::VMAction action;
VMActions::Action action;
// ------------------------------------------------------------------------
// Get request parameters and information about the target host
@@ -1134,8 +1137,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
// ------------------------------------------------------------------------
// Authorize request
// ------------------------------------------------------------------------
auth = vm_authorization(id, 0, 0, att, &host_perms, auth_ds_perms, 0, auth_op);
auth = vm_authorization(id, 0, 0, att, &host_perms, auth_ds_perms, 0);
if (auth == false)
{
@@ -1174,7 +1176,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
if (live)
{
action = History::LIVE_MIGRATE_ACTION;
action = VMActions::LIVE_MIGRATE_ACTION;
if ( vm->is_pinned() )
{
@@ -1187,7 +1189,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
}
else
{
action = History::MIGRATE_ACTION;
action = VMActions::MIGRATE_ACTION;
}
if (vm->is_imported() && !vm->is_imported_action_supported(action))
@@ -1589,7 +1591,7 @@ void VirtualMachineDiskSaveas::request_execute(
// -------------------------------------------------------------------------
// Authorize the operation & check quotas
// -------------------------------------------------------------------------
rc_auth = vm_authorization(id, itemplate, 0, att, 0,&ds_perms,0,auth_op);
rc_auth = vm_authorization(id, itemplate, 0, att, 0, &ds_perms, 0);
if ( rc_auth == true )
{
@@ -1720,7 +1722,7 @@ void VirtualMachineMonitoring::request_execute(
string oss;
bool auth = vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op);
bool auth = vm_authorization(id, 0, 0, att, 0, 0, 0);
if ( auth == false )
{
@@ -1829,8 +1831,7 @@ Request::ErrorCode VirtualMachineAttach::request_execute(int id,
// -------------------------------------------------------------------------
// Authorize the operation & check quotas
// -------------------------------------------------------------------------
if ( vm_authorization(id, 0, &tmpl, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, &tmpl, att, 0, 0, 0) == false)
{
return AUTHORIZATION;
}
@@ -1914,8 +1915,7 @@ void VirtualMachineDetach::request_execute(xmlrpc_c::paramList const& paramList,
// -------------------------------------------------------------------------
// Authorize the operation
// -------------------------------------------------------------------------
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -2038,7 +2038,7 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList,
/* ---------------------------------------------------------------------- */
/* Authorize the operation & restricted attributes */
/* ---------------------------------------------------------------------- */
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -2217,8 +2217,7 @@ void VirtualMachineSnapshotCreate::request_execute(
// -------------------------------------------------------------------------
// Authorize the operation
// -------------------------------------------------------------------------
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -2255,8 +2254,7 @@ void VirtualMachineSnapshotRevert::request_execute(
// -------------------------------------------------------------------------
// Authorize the operation
// -------------------------------------------------------------------------
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -2293,8 +2291,7 @@ void VirtualMachineSnapshotDelete::request_execute(
// -------------------------------------------------------------------------
// Authorize the operation
// -------------------------------------------------------------------------
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -2560,23 +2557,21 @@ void VirtualMachineRecover::request_execute(
Nebula& nd = Nebula::instance();
DispatchManager * dm = nd.get_dm();
AuthRequest::Operation aop;
switch (op)
{
case 0: //recover-failure
case 1: //recover-success
aop = nd.get_vm_auth_op(History::RECOVER_ACTION);
att.set_auth_op(VMActions::RECOVER_ACTION);
break;
case 2: //retry
aop = nd.get_vm_auth_op(History::RETRY_ACTION);
att.set_auth_op(VMActions::RETRY_ACTION);
break;
case 3: //delete
case 4: //delete-recreate set same as delete in OpenNebulaTemplate
case 5: //delete-db
aop = nd.get_vm_auth_op(History::DELETE_ACTION);
att.set_auth_op(VMActions::DELETE_ACTION);
break;
default:
@@ -2585,7 +2580,7 @@ void VirtualMachineRecover::request_execute(
return;
}
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, aop) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -2751,14 +2746,10 @@ void VirtualMachineDiskSnapshotCreate::request_execute(
}
/* ---------- Attributes for quota update requests ---------------------- */
RequestAttributes img_att_quota;
RequestAttributes vm_att_quota;
PoolObjectAuth img_perms;
if (img_ds_quota)
{
PoolObjectAuth img_perms;
Image* img = ipool->get_ro(img_id);
if (img == nullptr)
@@ -2774,19 +2765,21 @@ void VirtualMachineDiskSnapshotCreate::request_execute(
img->unlock();
if (vm_authorization(id, 0, 0, att, 0, 0, &img_perms, auth_op) == false)
if (vm_authorization(id, 0, 0, att, 0, 0, &img_perms) == false)
{
return;
}
img_att_quota = RequestAttributes(img_perms.uid, img_perms.gid, att);
}
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
vm_att_quota = RequestAttributes(vm_perms.uid, vm_perms.gid, att);
RequestAttributes vm_att_quota = RequestAttributes(vm_perms.uid,
vm_perms.gid, att);
RequestAttributes img_att_quota = RequestAttributes(img_perms.uid,
img_perms.gid, att);
/* ---------------------------------------------------------------------- */
/* Check quotas for the new size in image/system datastoress */
@@ -2874,7 +2867,7 @@ void VirtualMachineDiskSnapshotRevert::request_execute(
int did = xmlrpc_c::value_int(paramList.getInt(2));
int snap_id = xmlrpc_c::value_int(paramList.getInt(3));
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -2955,12 +2948,12 @@ void VirtualMachineDiskSnapshotDelete::request_execute(
img->unlock();
if (vm_authorization(id, 0, 0, att, 0, 0, &img_perms, auth_op) == false)
if (vm_authorization(id, 0, 0, att, 0, 0, &img_perms) == false)
{
return;
}
}
else if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
else if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -2998,7 +2991,7 @@ void VirtualMachineDiskSnapshotRename::request_execute(xmlrpc_c::paramList const
int snap_id = xmlrpc_c::value_int(paramList.getInt(3));
string new_snap_name = xmlrpc_c::value_string(paramList.getString(4));
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -3072,7 +3065,7 @@ void VirtualMachineUpdateConf::request_execute(
/* ---------------------------------------------------------------------- */
/* Authorize the operation & restricted attributes */
/* ---------------------------------------------------------------------- */
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
@@ -3260,13 +3253,10 @@ void VirtualMachineDiskResize::request_execute(
/* ---------------------------------------------------------------------- */
/* Authorize the request for VM and IMAGE for persistent disks */
/* ---------------------------------------------------------------------- */
RequestAttributes img_att_quota;
RequestAttributes vm_att_quota;
PoolObjectAuth img_perms;
if ( img_ds_quota )
{
PoolObjectAuth img_perms;
if ( img_id != -1 )
{
Image* img = ipool->get_ro(img_id);
@@ -3285,23 +3275,24 @@ void VirtualMachineDiskResize::request_execute(
img->unlock();
}
if (vm_authorization(id, 0, 0, att, 0, 0, &img_perms, auth_op) == false)
if (vm_authorization(id, 0, 0, att, 0, 0, &img_perms) == false)
{
return;
}
img_att_quota = RequestAttributes(img_perms.uid, img_perms.gid, att);
}
if ( vm_ds_quota )
{
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false)
{
return;
}
}
vm_att_quota = RequestAttributes(vm_perms.uid, vm_perms.gid, att);
RequestAttributes img_att_quota = RequestAttributes(img_perms.uid,
img_perms.gid, att);
RequestAttributes vm_att_quota = RequestAttributes(vm_perms.uid,
vm_perms.gid, att);
/* ---------------------------------------------------------------------- */
/* Check quotas for the new size in image/system datastoress */
+2 -2
View File
@@ -57,8 +57,8 @@ void VirtualMachineXML::init_attributes()
resched = tmp == 1;
xpath(action, "/VM/HISTORY_RECORDS/HISTORY/ACTION", -1);
resume = (action == History::STOP_ACTION || action == History::UNDEPLOY_ACTION
|| action == History::UNDEPLOY_HARD_ACTION );
resume = (action == VMActions::STOP_ACTION || action == VMActions::UNDEPLOY_ACTION
|| action == VMActions::UNDEPLOY_HARD_ACTION );
xpath(hid, "/VM/HISTORY_RECORDS/HISTORY/HID", -1);
xpath(dsid, "/VM/HISTORY_RECORDS/HISTORY/DS_ID", -1);
+1
View File
@@ -24,6 +24,7 @@ lib_name='nebula_um'
source_files=[
'User.cc',
'UserPool.cc',
'UserTemplate.cc',
'Quota.cc',
'QuotaDatastore.cc',
'QuotaNetwork.cc',
+6 -2
View File
@@ -267,7 +267,11 @@ string& User::to_xml_extended(string& xml, bool extended) const
int User::from_xml(const string& xml)
{
int rc = 0;
int int_enabled;
string error;
vector<xmlNodePtr> content;
// Initialize the internal XML object
@@ -309,6 +313,8 @@ int User::from_xml(const string& xml)
ObjectXML::free_nodes(content);
content.clear();
rc += vm_actions.set_auth_ops(*obj_template, error);
rc += groups.from_xml(this, "/USER/");
if (rc != 0)
@@ -435,5 +441,3 @@ int User::get_default_umask()
return (umask & 0777);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
+10 -6
View File
@@ -51,11 +51,12 @@ string UserPool::oneadmin_name;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
UserPool::UserPool(SqlDB * db,
time_t __session_expiration_time,
vector<const VectorAttribute *> hook_mads,
const string& remotes_location,
bool is_federation_slave):
UserPool::UserPool(SqlDB * db,
time_t __session_expiration_time,
vector<const VectorAttribute *> hook_mads,
const string& remotes_location,
bool is_federation_slave,
vector<const SingleAttribute *>& restricted_attrs):
PoolSQL(db, User::table)
{
int one_uid = -1;
@@ -186,6 +187,9 @@ UserPool::UserPool(SqlDB * db,
register_hooks(hook_mads, remotes_location);
// Set restricted attributes
UserTemplate::parse_restricted(restricted_attrs);
return;
error_readoneauth:
@@ -305,7 +309,7 @@ static int master_chgrp(int user_id, int group_id, string& error_str)
/* -------------------------------------------------------------------------- */
int UserPool::allocate (
int UserPool::allocate(
int * oid,
const string& uname,
int gid,
+22
View File
@@ -0,0 +1,22 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
/* */
/* 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 "UserTemplate.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
std::map<std::string, std::set<std::string>> UserTemplate::restricted;
+3 -344
View File
@@ -57,7 +57,7 @@ History::History(
running_etime(0),
epilog_stime(0),
epilog_etime(0),
action(NONE_ACTION),
action(VMActions::NONE_ACTION),
vm_info("<VM/>"){};
/* -------------------------------------------------------------------------- */
@@ -91,7 +91,7 @@ History::History(
running_etime(0),
epilog_stime(0),
epilog_etime(0),
action(NONE_ACTION),
action(VMActions::NONE_ACTION),
vm_info(_vm_info)
{
non_persistent_data();
@@ -456,7 +456,7 @@ int History::rebuild_attributes()
rc += xpath(gid, "/HISTORY/GID", -1);
rc += xpath(req_id, "/HISTORY/REQUEST_ID", -1);
action = static_cast<VMAction>(int_action);
action = static_cast<VMActions::Action>(int_action);
// -------------------------------------------------------------------------
ObjectXML::get_nodes("/HISTORY/VM", content);
@@ -486,344 +486,3 @@ int History::rebuild_attributes()
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string History::action_to_str(VMAction action)
{
string st;
switch (action)
{
case MIGRATE_ACTION:
st = "migrate";
break;
case POFF_MIGRATE_ACTION:
st = "poweroff-migrate";
break;
case POFF_HARD_MIGRATE_ACTION:
st = "poweroff-hard-migrate";
break;
case LIVE_MIGRATE_ACTION:
st = "live-migrate";
break;
case TERMINATE_ACTION:
st = "terminate";
break;
case TERMINATE_HARD_ACTION:
st = "terminate-hard";
break;
case UNDEPLOY_ACTION:
st = "undeploy";
break;
case UNDEPLOY_HARD_ACTION:
st = "undeploy-hard";
break;
case HOLD_ACTION:
st = "hold";
break;
case RELEASE_ACTION:
st = "release";
break;
case STOP_ACTION:
st = "stop";
break;
case SUSPEND_ACTION:
st = "suspend";
break;
case RESUME_ACTION:
st = "resume";
break;
case DELETE_ACTION:
st = "delete";
break;
case DELETE_RECREATE_ACTION:
st = "delete-recreate";
break;
case REBOOT_ACTION:
st = "reboot";
break;
case REBOOT_HARD_ACTION:
st = "reboot-hard";
break;
case RESCHED_ACTION:
st = "resched";
break;
case UNRESCHED_ACTION:
st = "unresched";
break;
case POWEROFF_ACTION:
st = "poweroff";
break;
case POWEROFF_HARD_ACTION:
st = "poweroff-hard";
break;
case DISK_ATTACH_ACTION:
st = "disk-attach";
break;
case DISK_DETACH_ACTION:
st = "disk-detach";
break;
case NIC_ATTACH_ACTION:
st = "nic-attach";
break;
case NIC_DETACH_ACTION:
st = "nic-detach";
break;
case ALIAS_ATTACH_ACTION:
st = "alias-attach";
break;
case ALIAS_DETACH_ACTION:
st = "alias-detach";
break;
case DISK_SNAPSHOT_CREATE_ACTION:
st = "disk-snapshot-create";
break;
case DISK_SNAPSHOT_DELETE_ACTION:
st = "disk-snapshot-delete";
break;
case DISK_SNAPSHOT_RENAME_ACTION:
st = "disk-snapshot-rename";
break;
case DISK_RESIZE_ACTION:
st = "disk-resize";
break;
case DEPLOY_ACTION:
st = "deploy";
break;
case CHOWN_ACTION:
st = "chown";
break;
case CHMOD_ACTION:
st = "chmod";
break;
case UPDATECONF_ACTION:
st = "updateconf";
break;
case RENAME_ACTION:
st = "rename";
break;
case RESIZE_ACTION:
st = "resize";
break;
case UPDATE_ACTION:
st = "update";
break;
case SNAPSHOT_CREATE_ACTION:
st = "snapshot-create";
break;
case SNAPSHOT_DELETE_ACTION:
st = "snapshot-delete";
break;
case SNAPSHOT_REVERT_ACTION:
st = "snapshot-revert";
break;
case DISK_SAVEAS_ACTION:
st = "disk-saveas";
break;
case DISK_SNAPSHOT_REVERT_ACTION:
st = "disk-snapshot-revert";
break;
case RECOVER_ACTION:
st = "recover";
break;
case RETRY_ACTION:
st = "retry";
break;
case MONITOR_ACTION:
st = "monitor";
break;
case NONE_ACTION:
st = "none";
break;
}
return st;
};
int History::action_from_str(const string& st, VMAction& action)
{
if (st == "migrate")
{
action = MIGRATE_ACTION;
}
else if (st == "live-migrate")
{
action = LIVE_MIGRATE_ACTION;
}
else if (st == "terminate")
{
action = TERMINATE_ACTION;
}
else if (st == "terminate-hard")
{
action = TERMINATE_HARD_ACTION;
}
else if (st == "undeploy")
{
action = UNDEPLOY_ACTION;
}
else if (st == "undeploy-hard")
{
action = UNDEPLOY_HARD_ACTION;
}
else if (st == "hold")
{
action = HOLD_ACTION;
}
else if (st == "release")
{
action = RELEASE_ACTION;
}
else if (st == "stop")
{
action = STOP_ACTION;
}
else if (st == "suspend")
{
action = SUSPEND_ACTION;
}
else if (st == "resume")
{
action = RESUME_ACTION;
}
else if (st == "delete")
{
action = DELETE_ACTION;
}
else if (st == "delete-recreate")
{
action = DELETE_RECREATE_ACTION;
}
else if (st == "reboot")
{
action = REBOOT_ACTION;
}
else if (st == "reboot-hard")
{
action = REBOOT_HARD_ACTION;
}
else if (st == "resched")
{
action = RESCHED_ACTION;
}
else if (st == "unresched")
{
action = UNRESCHED_ACTION;
}
else if (st == "poweroff")
{
action = POWEROFF_ACTION;
}
else if (st == "poweroff-hard")
{
action = POWEROFF_HARD_ACTION;
}
else if (st == "disk-attach")
{
action = DISK_ATTACH_ACTION;
}
else if (st == "disk-detach")
{
action = DISK_DETACH_ACTION;
}
else if (st == "nic-attach")
{
action = NIC_ATTACH_ACTION;
}
else if (st == "nic-detach")
{
action = NIC_DETACH_ACTION;
}
else if (st == "alias-attach")
{
action = ALIAS_ATTACH_ACTION;
}
else if (st == "alias-detach")
{
action = ALIAS_DETACH_ACTION;
}
else if (st == "disk-snapshot-create")
{
action = DISK_SNAPSHOT_CREATE_ACTION;
}
else if (st == "disk-snapshot-snap-delete")
{
action = DISK_SNAPSHOT_DELETE_ACTION;
}
else if (st == "disk-snapshot-rename")
{
action = DISK_SNAPSHOT_RENAME_ACTION;
}
else if (st == "disk-resize")
{
action = DISK_RESIZE_ACTION;
}
else if ( st == "deploy")
{
action = DEPLOY_ACTION;
}
else if ( st == "chown")
{
action = CHOWN_ACTION;
}
else if ( st == "chmod")
{
action = CHMOD_ACTION;
}
else if ( st == "updateconf")
{
action = UPDATECONF_ACTION;
}
else if ( st == "rename")
{
action = RENAME_ACTION;
}
else if ( st == "resize")
{
action = RESIZE_ACTION;
}
else if ( st == "update")
{
action = UPDATE_ACTION;
}
else if ( st == "snapshot-create")
{
action = SNAPSHOT_CREATE_ACTION;
}
else if ( st == "snapshot-delete")
{
action = SNAPSHOT_DELETE_ACTION;
}
else if ( st == "snapshot-revert")
{
action = SNAPSHOT_REVERT_ACTION;
}
else if ( st == "disk-saveas")
{
action = DISK_SAVEAS_ACTION;
}
else if ( st == "disk-snapshot-revert")
{
action = DISK_SNAPSHOT_REVERT_ACTION;
}
else if ( st == "recover")
{
action = RECOVER_ACTION;
}
else if ( st == "retry")
{
action = RETRY_ACTION;
}
else if ( st == "monitor")
{
action = MONITOR_ACTION;
}
else
{
action = NONE_ACTION;
return -1;
}
return 0;
};
+1
View File
@@ -33,6 +33,7 @@ source_files=[
'VirtualMachineSystemSnapshot.cc',
'VirtualMachineParser.cc',
'VirtualMachineContext.cc',
'VMActions.cc',
'Snapshots.cc'
]
+550
View File
@@ -0,0 +1,550 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
/* */
/* 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 "VMActions.h"
#include "NebulaUtil.h"
#include "Template.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
AuthRequest::Operation VMActions::get_auth_op(Action action) const
{
if (admin_actions.is_set(action))
{
return AuthRequest::ADMIN;
}
else if (manage_actions.is_set(action))
{
return AuthRequest::MANAGE;
}
else if (use_actions.is_set(action))
{
return AuthRequest::USE;
}
return AuthRequest::NONE;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VMActions::set_auth_ops(const Template& tmpl, string& error)
{
std::string admin, manage, use;
tmpl.get("VM_ADMIN_OPERATIONS", admin);
if (set_auth_ops(admin, admin_actions, error) != 0)
{
return -1;
}
tmpl.get("VM_MANAGE_OPERATIONS", manage);
if (set_auth_ops(manage, manage_actions, error) != 0)
{
return -1;
}
tmpl.get("VM_USE_OPERATIONS", use);
if (set_auth_ops(use, use_actions, error) != 0)
{
return -1;
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VMActions::set_auth_ops(const string& ops_str,
ActionSet<Action>& ops_set, string& error)
{
std::set<std::string> ops;
one_util::split_unique(ops_str, ',', ops);
for (const string& op : ops)
{
std::string the_op = one_util::trim(op);
one_util::tolower(the_op);
if ( the_op == "migrate" )
{
ops_set.set(MIGRATE_ACTION);
ops_set.set(LIVE_MIGRATE_ACTION);
}
else if ( the_op == "delete" )
{
ops_set.set(DELETE_ACTION);
ops_set.set(DELETE_RECREATE_ACTION);
}
else if ( the_op == "recover" )
{
ops_set.set(RECOVER_ACTION);
}
else if ( the_op == "retry" )
{
ops_set.set(RETRY_ACTION);
}
else if ( the_op == "deploy" )
{
ops_set.set(DEPLOY_ACTION);
}
else if ( the_op == "resched" )
{
ops_set.set(RESCHED_ACTION);
ops_set.set(UNRESCHED_ACTION);
}
else if ( the_op == "undeploy" )
{
ops_set.set(UNDEPLOY_ACTION);
ops_set.set(UNDEPLOY_HARD_ACTION);
}
else if ( the_op == "hold" )
{
ops_set.set(HOLD_ACTION);
}
else if ( the_op == "release" )
{
ops_set.set(RELEASE_ACTION);
}
else if ( the_op == "stop" )
{
ops_set.set(STOP_ACTION);
}
else if ( the_op == "suspend" )
{
ops_set.set(SUSPEND_ACTION);
}
else if ( the_op == "resume" )
{
ops_set.set(RESUME_ACTION);
}
else if ( the_op == "reboot" )
{
ops_set.set(REBOOT_ACTION);
ops_set.set(REBOOT_HARD_ACTION);
}
else if ( the_op == "poweroff" )
{
ops_set.set(POWEROFF_ACTION);
ops_set.set(POWEROFF_HARD_ACTION);
}
else if ( the_op == "disk-attach" )
{
ops_set.set(DISK_ATTACH_ACTION);
ops_set.set(DISK_DETACH_ACTION);
}
else if ( the_op == "nic-attach" )
{
ops_set.set(NIC_ATTACH_ACTION);
ops_set.set(NIC_DETACH_ACTION);
}
else if ( the_op == "disk-snapshot" )
{
ops_set.set(DISK_SNAPSHOT_CREATE_ACTION);
ops_set.set(DISK_SNAPSHOT_DELETE_ACTION);
ops_set.set(DISK_SNAPSHOT_REVERT_ACTION);
ops_set.set(DISK_SNAPSHOT_RENAME_ACTION);
}
else if ( the_op == "terminate" )
{
ops_set.set(TERMINATE_ACTION);
ops_set.set(TERMINATE_HARD_ACTION);
}
else if ( the_op == "disk-resize" )
{
ops_set.set(DISK_RESIZE_ACTION);
}
else if ( the_op == "snapshot" )
{
ops_set.set(SNAPSHOT_CREATE_ACTION);
ops_set.set(SNAPSHOT_DELETE_ACTION);
ops_set.set(SNAPSHOT_REVERT_ACTION);
}
else if ( the_op == "updateconf" )
{
ops_set.set(UPDATECONF_ACTION);
}
else if ( the_op == "rename" )
{
ops_set.set(RENAME_ACTION);
}
else if ( the_op == "resize" )
{
ops_set.set(RESIZE_ACTION);
}
else if ( the_op == "update" )
{
ops_set.set(UPDATE_ACTION);
}
else if ( the_op == "disk-saveas" )
{
ops_set.set(DISK_SAVEAS_ACTION);
}
else
{
error = "Unknown vm operation: " + the_op;
return -1;
}
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string VMActions::action_to_str(Action action)
{
string st;
switch (action)
{
case MIGRATE_ACTION:
st = "migrate";
break;
case POFF_MIGRATE_ACTION:
st = "poweroff-migrate";
break;
case POFF_HARD_MIGRATE_ACTION:
st = "poweroff-hard-migrate";
break;
case LIVE_MIGRATE_ACTION:
st = "live-migrate";
break;
case TERMINATE_ACTION:
st = "terminate";
break;
case TERMINATE_HARD_ACTION:
st = "terminate-hard";
break;
case UNDEPLOY_ACTION:
st = "undeploy";
break;
case UNDEPLOY_HARD_ACTION:
st = "undeploy-hard";
break;
case HOLD_ACTION:
st = "hold";
break;
case RELEASE_ACTION:
st = "release";
break;
case STOP_ACTION:
st = "stop";
break;
case SUSPEND_ACTION:
st = "suspend";
break;
case RESUME_ACTION:
st = "resume";
break;
case DELETE_ACTION:
st = "delete";
break;
case DELETE_RECREATE_ACTION:
st = "delete-recreate";
break;
case REBOOT_ACTION:
st = "reboot";
break;
case REBOOT_HARD_ACTION:
st = "reboot-hard";
break;
case RESCHED_ACTION:
st = "resched";
break;
case UNRESCHED_ACTION:
st = "unresched";
break;
case POWEROFF_ACTION:
st = "poweroff";
break;
case POWEROFF_HARD_ACTION:
st = "poweroff-hard";
break;
case DISK_ATTACH_ACTION:
st = "disk-attach";
break;
case DISK_DETACH_ACTION:
st = "disk-detach";
break;
case NIC_ATTACH_ACTION:
st = "nic-attach";
break;
case NIC_DETACH_ACTION:
st = "nic-detach";
break;
case ALIAS_ATTACH_ACTION:
st = "alias-attach";
break;
case ALIAS_DETACH_ACTION:
st = "alias-detach";
break;
case DISK_SNAPSHOT_CREATE_ACTION:
st = "disk-snapshot-create";
break;
case DISK_SNAPSHOT_DELETE_ACTION:
st = "disk-snapshot-delete";
break;
case DISK_SNAPSHOT_RENAME_ACTION:
st = "disk-snapshot-rename";
break;
case DISK_RESIZE_ACTION:
st = "disk-resize";
break;
case DEPLOY_ACTION:
st = "deploy";
break;
case CHOWN_ACTION:
st = "chown";
break;
case CHMOD_ACTION:
st = "chmod";
break;
case UPDATECONF_ACTION:
st = "updateconf";
break;
case RENAME_ACTION:
st = "rename";
break;
case RESIZE_ACTION:
st = "resize";
break;
case UPDATE_ACTION:
st = "update";
break;
case SNAPSHOT_CREATE_ACTION:
st = "snapshot-create";
break;
case SNAPSHOT_DELETE_ACTION:
st = "snapshot-delete";
break;
case SNAPSHOT_REVERT_ACTION:
st = "snapshot-revert";
break;
case DISK_SAVEAS_ACTION:
st = "disk-saveas";
break;
case DISK_SNAPSHOT_REVERT_ACTION:
st = "disk-snapshot-revert";
break;
case RECOVER_ACTION:
st = "recover";
break;
case RETRY_ACTION:
st = "retry";
break;
case MONITOR_ACTION:
st = "monitor";
break;
case NONE_ACTION:
st = "none";
break;
}
return st;
};
int VMActions::action_from_str(const string& st, Action& action)
{
if (st == "migrate")
{
action = MIGRATE_ACTION;
}
else if (st == "live-migrate")
{
action = LIVE_MIGRATE_ACTION;
}
else if (st == "terminate")
{
action = TERMINATE_ACTION;
}
else if (st == "terminate-hard")
{
action = TERMINATE_HARD_ACTION;
}
else if (st == "undeploy")
{
action = UNDEPLOY_ACTION;
}
else if (st == "undeploy-hard")
{
action = UNDEPLOY_HARD_ACTION;
}
else if (st == "hold")
{
action = HOLD_ACTION;
}
else if (st == "release")
{
action = RELEASE_ACTION;
}
else if (st == "stop")
{
action = STOP_ACTION;
}
else if (st == "suspend")
{
action = SUSPEND_ACTION;
}
else if (st == "resume")
{
action = RESUME_ACTION;
}
else if (st == "delete")
{
action = DELETE_ACTION;
}
else if (st == "delete-recreate")
{
action = DELETE_RECREATE_ACTION;
}
else if (st == "reboot")
{
action = REBOOT_ACTION;
}
else if (st == "reboot-hard")
{
action = REBOOT_HARD_ACTION;
}
else if (st == "resched")
{
action = RESCHED_ACTION;
}
else if (st == "unresched")
{
action = UNRESCHED_ACTION;
}
else if (st == "poweroff")
{
action = POWEROFF_ACTION;
}
else if (st == "poweroff-hard")
{
action = POWEROFF_HARD_ACTION;
}
else if (st == "disk-attach")
{
action = DISK_ATTACH_ACTION;
}
else if (st == "disk-detach")
{
action = DISK_DETACH_ACTION;
}
else if (st == "nic-attach")
{
action = NIC_ATTACH_ACTION;
}
else if (st == "nic-detach")
{
action = NIC_DETACH_ACTION;
}
else if (st == "alias-attach")
{
action = ALIAS_ATTACH_ACTION;
}
else if (st == "alias-detach")
{
action = ALIAS_DETACH_ACTION;
}
else if (st == "disk-snapshot-create")
{
action = DISK_SNAPSHOT_CREATE_ACTION;
}
else if (st == "disk-snapshot-snap-delete")
{
action = DISK_SNAPSHOT_DELETE_ACTION;
}
else if (st == "disk-snapshot-rename")
{
action = DISK_SNAPSHOT_RENAME_ACTION;
}
else if (st == "disk-resize")
{
action = DISK_RESIZE_ACTION;
}
else if ( st == "deploy")
{
action = DEPLOY_ACTION;
}
else if ( st == "chown")
{
action = CHOWN_ACTION;
}
else if ( st == "chmod")
{
action = CHMOD_ACTION;
}
else if ( st == "updateconf")
{
action = UPDATECONF_ACTION;
}
else if ( st == "rename")
{
action = RENAME_ACTION;
}
else if ( st == "resize")
{
action = RESIZE_ACTION;
}
else if ( st == "update")
{
action = UPDATE_ACTION;
}
else if ( st == "snapshot-create")
{
action = SNAPSHOT_CREATE_ACTION;
}
else if ( st == "snapshot-delete")
{
action = SNAPSHOT_DELETE_ACTION;
}
else if ( st == "snapshot-revert")
{
action = SNAPSHOT_REVERT_ACTION;
}
else if ( st == "disk-saveas")
{
action = DISK_SAVEAS_ACTION;
}
else if ( st == "disk-snapshot-revert")
{
action = DISK_SNAPSHOT_REVERT_ACTION;
}
else if ( st == "recover")
{
action = RECOVER_ACTION;
}
else if ( st == "retry")
{
action = RETRY_ACTION;
}
else if ( st == "monitor")
{
action = MONITOR_ACTION;
}
else
{
action = NONE_ACTION;
return -1;
}
return 0;
};
+1 -1
View File
@@ -2107,7 +2107,7 @@ string VirtualMachine::get_import_state()
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool VirtualMachine::is_imported_action_supported(History::VMAction action) const
bool VirtualMachine::is_imported_action_supported(VMActions::Action action) const
{
if (!hasHistory())
{
+2 -2
View File
@@ -350,8 +350,8 @@ int VirtualMachine::generate_network_context(VectorAttribute* context,
}
bool alias_detach = hasPreviousHistory() &&
previous_history->action == History::ALIAS_DETACH_ACTION &&
vatts[i]->vector_value("ATTACH") == "YES";
previous_history->action == VMActions::ALIAS_DETACH_ACTION &&
vatts[i]->vector_value("ATTACH") == "YES";
parse_context_network(NETWORK_CONTEXT, &tmp_context, vatts[i], alias_detach);
parse_context_network(NETWORK6_CONTEXT, &tmp_context, vatts[i], alias_detach);
+15 -15
View File
@@ -115,29 +115,29 @@ VirtualMachineManagerDriver::VirtualMachineManagerDriver(
}
else
{
NebulaLog::log("VMM", Log::INFO, "Using default imported VMs actions");
NebulaLog::log("VMM", Log::INFO, "Using default imported VMs actions");
it = attrs.find("NAME");
it = attrs.find("NAME");
if (it != attrs.end())
{
if ( it->second == "kvm" || it->second == "xen" )
{
action_defaults = imported_actions_default;
}
else if ( it->second == "sl" || it->second == "ec2" ||
it->second == "az" || it->second == "vcenter" )
{
if (it != attrs.end())
{
if ( it->second == "kvm" || it->second == "xen" )
{
action_defaults = imported_actions_default;
}
else if ( it->second == "sl" || it->second == "ec2" ||
it->second == "az" || it->second == "vcenter" )
{
action_defaults = imported_actions_default_public;
}
}
}
}
}
vector<string> actions;
vector<string>::iterator vit;
string action;
History::VMAction id;
VMActions::Action id;
actions = one_util::split(action_defaults, ',');
@@ -145,7 +145,7 @@ VirtualMachineManagerDriver::VirtualMachineManagerDriver(
{
action = one_util::trim(*vit);
if ( History::action_from_str(action, id) != 0 )
if ( VMActions::action_from_str(action, id) != 0 )
{
NebulaLog::log("VMM", Log::ERROR, "Wrong action: " + action);
continue;