1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

B #5405: unified functionality for free vm resources in a single function (#498)

This commit is contained in:
juanmont 2017-09-26 18:30:13 +02:00 committed by Ruben S. Montero
parent d8cc0fea13
commit beae0776c3
4 changed files with 37 additions and 70 deletions

View File

@ -21,6 +21,7 @@
#include "HostPool.h" #include "HostPool.h"
#include "VirtualMachinePool.h" #include "VirtualMachinePool.h"
#include "VirtualRouterPool.h" #include "VirtualRouterPool.h"
#include "ClusterPool.h"
using namespace std; using namespace std;
@ -82,7 +83,7 @@ class DispatchManager : public ActionListener
public: public:
DispatchManager(): DispatchManager():
hpool(0), vmpool(0), vrouterpool(0), tm(0), vmm(0), lcm(0), imagem(0) hpool(0), vmpool(0), clpool(0), vrouterpool(0), tm(0), vmm(0), lcm(0), imagem(0)
{ {
am.addListener(this); am.addListener(this);
}; };
@ -497,7 +498,12 @@ private:
VirtualMachinePool * vmpool; VirtualMachinePool * vmpool;
/** /**
* Pointer to the Virtual Machine Pool, to access hosts * Pointer to the Cluster Pool
*/
ClusterPool * clpool;
/**
* Pointer to the Virtual Router Pool
*/ */
VirtualRouterPool * vrouterpool; VirtualRouterPool * vrouterpool;

View File

@ -109,6 +109,7 @@ void DispatchManager::init_managers()
hpool = nd.get_hpool(); hpool = nd.get_hpool();
vmpool = nd.get_vmpool(); vmpool = nd.get_vmpool();
clpool = nd.get_clpool();
vrouterpool = nd.get_vrouterpool(); vrouterpool = nd.get_vrouterpool();
} }

View File

@ -214,19 +214,33 @@ void DispatchManager::free_vm_resources(VirtualMachine * vm)
Template* tmpl; Template* tmpl;
vector<Template *> ds_quotas; vector<Template *> ds_quotas;
int vmid;
int uid; int uid;
int gid; int gid;
string deploy_id;
int vrid = -1; int vrid = -1;
int vmid; unsigned int port;
vm->release_network_leases(); vm->release_network_leases();
vm->release_vmgroup(); vm->release_vmgroup();
vm->release_disk_images(ds_quotas); vm->release_disk_images(ds_quotas);
vm->set_state(VirtualMachine::DONE);
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_exit_time(time(0)); vm->set_exit_time(time(0));
vm->set_state(VirtualMachine::LCM_INIT); VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS");
vm->set_state(VirtualMachine::DONE);
if ( graphics != 0 && (graphics->vector_value("PORT", port) == 0))
{
graphics->remove("PORT");
clpool->release_vnc_port(vm->get_cid(), port);
}
vmpool->update(vm); vmpool->update(vm);
vmid = vm->get_oid(); vmid = vm->get_oid();
@ -234,6 +248,11 @@ void DispatchManager::free_vm_resources(VirtualMachine * vm)
gid = vm->get_gid(); gid = vm->get_gid();
tmpl = vm->clone_template(); tmpl = vm->clone_template();
if (vm->is_imported())
{
deploy_id = vm->get_deploy_id();
}
if (vm->is_vrouter()) if (vm->is_vrouter())
{ {
vrid = vm->get_vrouter_id(); vrid = vm->get_vrouter_id();
@ -250,6 +269,11 @@ void DispatchManager::free_vm_resources(VirtualMachine * vm)
Quotas::ds_del(uid, gid, ds_quotas); Quotas::ds_del(uid, gid, ds_quotas);
} }
if (!deploy_id.empty())
{
vmpool->drop_index(deploy_id);
}
if (vrid != -1) if (vrid != -1)
{ {
VirtualRouter* vr = vrouterpool->get(vrid, true); VirtualRouter* vr = vrouterpool->get(vrid, true);

View File

@ -202,14 +202,6 @@ void DispatchManager::poweroff_success_action(int vid)
void DispatchManager::done_action(int vid) void DispatchManager::done_action(int vid)
{ {
VirtualMachine * vm; VirtualMachine * vm;
Template * tmpl;
vector<Template *> ds_quotas;
int uid;
int gid;
string deploy_id;
int vrid = -1;
VirtualMachine::LcmState lcm_state; VirtualMachine::LcmState lcm_state;
VirtualMachine::VmState dm_state; VirtualMachine::VmState dm_state;
@ -228,63 +220,7 @@ void DispatchManager::done_action(int vid)
(lcm_state == VirtualMachine::EPILOG || (lcm_state == VirtualMachine::EPILOG ||
lcm_state == VirtualMachine::CLEANUP_DELETE)) lcm_state == VirtualMachine::CLEANUP_DELETE))
{ {
vm->release_network_leases(); free_vm_resources(vm);
vm->release_vmgroup();
vm->release_disk_images(ds_quotas);
vm->set_state(VirtualMachine::DONE);
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_exit_time(time(0));
vmpool->update(vm);
uid = vm->get_uid();
gid = vm->get_gid();
tmpl = vm->clone_template();
if (vm->is_imported())
{
deploy_id = vm->get_deploy_id();
}
if (vm->is_vrouter())
{
vrid = vm->get_vrouter_id();
}
vm->unlock();
Quotas::vm_del(uid, gid, tmpl);
delete tmpl;
if ( !ds_quotas.empty() )
{
Quotas::ds_del(uid, gid, ds_quotas);
}
if (!deploy_id.empty())
{
vmpool->drop_index(deploy_id);
}
if (vrid != -1)
{
VirtualRouter* vr = vrouterpool->get(vrid, true);
if (vr != 0)
{
vr->del_vmid(vid);
vrouterpool->update(vr);
vr->unlock();
}
}
} }
else else
{ {