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

(cherry picked from commit beae0776c3)
This commit is contained in:
juanmont authored and Ruben S. Montero committed 2017-09-26 18:30:51 +02:00
1 parent f7b4b98a82
commit fe65615f01
4 files changed
+37 -70

No files matched your search

+8 -2
View File
@@ -21,6 +21,7 @@
#include "HostPool.h"
#include "VirtualMachinePool.h"
#include "VirtualRouterPool.h"
#include "ClusterPool.h"
using namespace std;
@@ -82,7 +83,7 @@ class DispatchManager : public ActionListener
public:
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);
};
@@ -497,7 +498,12 @@ private:
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;
+1
View File
@@ -109,6 +109,7 @@ void DispatchManager::init_managers()
hpool = nd.get_hpool();
vmpool = nd.get_vmpool();
clpool = nd.get_clpool();
vrouterpool = nd.get_vrouterpool();
}
+27 -3
View File
@@ -214,19 +214,33 @@ void DispatchManager::free_vm_resources(VirtualMachine * vm)
Template* tmpl;
vector<Template *> ds_quotas;
int vmid;
int uid;
int gid;
string deploy_id;
int vrid = -1;
int vmid;
unsigned int port;
vm->release_network_leases();
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));
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_state(VirtualMachine::DONE);
VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS");
if ( graphics != 0 && (graphics->vector_value("PORT", port) == 0))
{
graphics->remove("PORT");
clpool->release_vnc_port(vm->get_cid(), port);
}
vmpool->update(vm);
vmid = vm->get_oid();
@@ -234,6 +248,11 @@ void DispatchManager::free_vm_resources(VirtualMachine * vm)
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();
@@ -250,6 +269,11 @@ void DispatchManager::free_vm_resources(VirtualMachine * vm)
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);
+1 -65
View File
@@ -202,14 +202,6 @@ void DispatchManager::poweroff_success_action(int vid)
void DispatchManager::done_action(int vid)
{
VirtualMachine * vm;
Template * tmpl;
vector<Template *> ds_quotas;
int uid;
int gid;
string deploy_id;
int vrid = -1;
VirtualMachine::LcmState lcm_state;
VirtualMachine::VmState dm_state;
@@ -228,63 +220,7 @@ void DispatchManager::done_action(int vid)
(lcm_state == VirtualMachine::EPILOG ||
lcm_state == VirtualMachine::CLEANUP_DELETE))
{
vm->release_network_leases();
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();
}
}
free_vm_resources(vm);
}
else
{