diff --git a/include/UserPool.h b/include/UserPool.h index a1640d3e6b..8d557646d9 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -109,6 +109,15 @@ public: return name; }; + /** + * Function to get the token password of an user from the pool + * @param uid creator of the object + * @param uid owner of the object, only used if the creator not exists + * + * @return the user's token password + */ + string get_token_password(int oid, int bck_oid); + /** * Update a particular User. This method does not update the user's quotas * @param user pointer to User diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index ad4daece0e..cd35e5f276 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -582,15 +582,10 @@ void TransferManager::prolog_action(int vid) } int uid = vm->get_created_by_uid(); + int owner_id = vm->get_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(); - } + token_password = Nebula::instance().get_upool()->get_token_password(uid, owner_id); vm = vmpool->get(vid,true); @@ -881,16 +876,10 @@ void TransferManager::prolog_resume_action(int vid) } int uid = vm->get_created_by_uid(); - + int owner_id = vm->get_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(); - } + token_password = Nebula::instance().get_upool()->get_token_password(uid, owner_id); vm = vmpool->get(vid,true); diff --git a/src/um/UserPool.cc b/src/um/UserPool.cc index 7294fa7231..c9912b42cb 100644 --- a/src/um/UserPool.cc +++ b/src/um/UserPool.cc @@ -1320,3 +1320,27 @@ int UserPool::dump_cb(void * _oss, int num, char **values, char **names) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ + +string UserPool::get_token_password(int oid, int bck_oid){ + + string token_password = ""; + User * user = get(oid, true); + + if (user != 0) + { + user->get_template_attribute("TOKEN_PASSWORD", token_password); + user->unlock(); + } + else{ + user = get(bck_oid, true); + if (user != 0) + { + user->get_template_attribute("TOKEN_PASSWORD", token_password); + user->unlock(); + } + } + return token_password; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 4569abed77..f0326a55ea 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -354,16 +354,10 @@ void VirtualMachineManager::deploy_action(int vid) } int uid = vm->get_created_by_uid(); - + int owner_id = vm->get_uid(); vm->unlock(); - User * user = Nebula::instance().get_upool()->get(uid, true); - - if (user != 0) - { - user->get_template_attribute("TOKEN_PASSWORD", password); - user->unlock(); - } + password = Nebula::instance().get_upool()->get_token_password(uid, owner_id); vm = vmpool->get(vid,true); @@ -1215,16 +1209,10 @@ void VirtualMachineManager::restore_action( } int uid = vm->get_created_by_uid(); - + int owner_id = vm->get_uid(); vm->unlock(); - User * user = Nebula::instance().get_upool()->get(uid, true); - - if (user != 0) - { - user->get_template_attribute("TOKEN_PASSWORD", password); - user->unlock(); - } + password = Nebula::instance().get_upool()->get_token_password(uid, owner_id); vm = vmpool->get(vid,true); @@ -2277,15 +2265,10 @@ void VirtualMachineManager::attach_nic_action( } int uid = vm->get_created_by_uid(); + int owner_id = vm->get_uid(); vm->unlock(); - User * user = Nebula::instance().get_upool()->get(uid, true); - - if (user != 0) - { - user->get_template_attribute("TOKEN_PASSWORD", password); - user->unlock(); - } + password = Nebula::instance().get_upool()->get_token_password(uid, owner_id); vm = vmpool->get(vid,true);