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

Feature #4215: update-context uses the user token password

This commit is contained in:
Carlos Martín 2016-01-25 17:38:46 +01:00
parent 3cee54afc9
commit d7eb8769e1
3 changed files with 64 additions and 4 deletions

View File

@ -1324,8 +1324,6 @@ public:
*/
const VectorAttribute* get_disk(int disk_id) const;
const VectorAttribute* get_context_disk() const;
const VectorAttribute* get_nic(int nic_id) const;
// ------------------------------------------------------------------------
@ -1366,6 +1364,14 @@ public:
int replace_context_attribute(const string& name, const string& value);
const VectorAttribute* get_context_disk() const;
/**
* Returns the CREATED_BY template attribute, or the uid if it does not exist
* @return uid
*/
int get_created_by_uid() const;
// -------------------------------------------------------------------------
// "Save as" Disk related functions (save_as hot)
// -------------------------------------------------------------------------

View File

@ -3481,6 +3481,22 @@ int VirtualMachine::replace_context_attribute(const string& name, const string&
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachine::get_created_by_uid() const
{
int created_by_uid;
if (obj_template->get("CREATED_BY", created_by_uid))
{
return created_by_uid;
}
return get_uid();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -1928,6 +1928,7 @@ void VirtualMachineManager::update_context_action(
string prolog_cmd;
string epilog_cmd;
string disk_path;
string token_password;
const VectorAttribute * disk;
int disk_id;
@ -1944,6 +1945,24 @@ void VirtualMachineManager::update_context_action(
return;
}
int uid = vm->get_created_by_uid();
vm->unlock();
User * user = Nebula::instance().get_upool()->get(uid, true);
if (user != 0)
{
user->get_template_attribute("TOKEN_PASSWORD", token_password);
user->unlock();
}
vm = vmpool->get(vid,true);
if (vm == 0)
{
return;
}
if (!vm->hasHistory())
{
goto error_history;
@ -1971,7 +1990,7 @@ void VirtualMachineManager::update_context_action(
rc = tm->prolog_context_command(
vm,
"", // TODO token_password
token_password,
vm_tm_mad,
opennebula_hostname,
os,
@ -2539,6 +2558,7 @@ void VirtualMachineManager::attach_nic_action(
string prolog_cmd;
string epilog_cmd;
string disk_path;
string token_password;
const VectorAttribute * disk;
int disk_id;
@ -2555,6 +2575,24 @@ void VirtualMachineManager::attach_nic_action(
return;
}
int uid = vm->get_created_by_uid();
vm->unlock();
User * user = Nebula::instance().get_upool()->get(uid, true);
if (user != 0)
{
user->get_template_attribute("TOKEN_PASSWORD", token_password);
user->unlock();
}
vm = vmpool->get(vid,true);
if (vm == 0)
{
return;
}
if (!vm->hasHistory())
{
goto error_history;
@ -2578,7 +2616,7 @@ void VirtualMachineManager::attach_nic_action(
rc = tm->prolog_context_command(
vm,
"", // TODO token_password
token_password,
vm_tm_mad,
opennebula_hostname,
os,