mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
parent
d68be6fef1
commit
2c9bbb9642
@ -390,6 +390,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get address range vector attribute representation
|
||||
*/
|
||||
VectorAttribute * get_attr()
|
||||
{
|
||||
return attr;
|
||||
@ -401,6 +404,18 @@ public:
|
||||
*/
|
||||
friend int AddressRangePool::add_ar(AddressRange * ar);
|
||||
|
||||
/*
|
||||
* rm_ar from AddressRangePool needs to access the internal representation
|
||||
* of the AR to remove it from the ARPool template.
|
||||
*/
|
||||
friend int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg);
|
||||
|
||||
/*
|
||||
* rm_ars from AddressRangePool needs to access the internal representation
|
||||
* of the AR to remove it from the ARPool template.
|
||||
*/
|
||||
friend int AddressRangePool::rm_ars(string& error_msg);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Base constructor it cannot be called directly but from the
|
||||
|
@ -72,6 +72,13 @@ public:
|
||||
*/
|
||||
int rm_ar(unsigned int ar_id, string& error_msg);
|
||||
|
||||
/**
|
||||
* Removes all address ranges from the pool if it does not contain any used
|
||||
* leases
|
||||
* @return 0 on success, -1 if not exists or has used addresses
|
||||
*/
|
||||
int rm_ars(string& error_msg);
|
||||
|
||||
/**
|
||||
* Updates the given address ranges
|
||||
* @param ars vector of address ranges as VectorAttributes obtained from
|
||||
|
@ -239,6 +239,13 @@ public:
|
||||
*/
|
||||
int rm_ar(unsigned int ar_id, string& error_msg);
|
||||
|
||||
/**
|
||||
* Removes all address ranges from the VNET
|
||||
* @param error_msg If the action fails, this message contains the reason.
|
||||
* @return 0 on success
|
||||
*/
|
||||
int rm_ars(string& error_msg);
|
||||
|
||||
/**
|
||||
* Allocates a new (and empty) address range. It is not added to the
|
||||
* ar_pool
|
||||
|
@ -559,11 +559,26 @@ int VirtualNetworkDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes
|
||||
return -1;
|
||||
}
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
VirtualNetworkPool * vnpool = nd.get_vnpool();
|
||||
|
||||
int pvid = vnet->get_parent();
|
||||
int uid = vnet->get_uid();
|
||||
int gid = vnet->get_gid();
|
||||
|
||||
int rc = RequestManagerDelete::drop(object, false, att);
|
||||
// Delete all address ranges to call IPAM if needed
|
||||
string error_msg;
|
||||
|
||||
int rc = vnet->rm_ars(error_msg);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
vnpool->update(vnet);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = RequestManagerDelete::drop(object, false, att);
|
||||
|
||||
if (pvid != -1)
|
||||
{
|
||||
@ -574,6 +589,16 @@ int VirtualNetworkDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Delete all address ranges to call IPAM if needed
|
||||
rc = vnet->rm_ars(error_msg);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
vnpool->update(vnet);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int freed = vnet->free_addr_by_owner(PoolObjectSQL::NET, oid);
|
||||
|
||||
pool->update(vnet);
|
||||
@ -602,7 +627,6 @@ int VirtualNetworkDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes
|
||||
}
|
||||
|
||||
// Remove virtual network from VDC
|
||||
Nebula& nd = Nebula::instance();
|
||||
int zone_id = nd.get_zone_id();
|
||||
|
||||
VdcPool * vdcpool = nd.get_vdcpool();
|
||||
|
@ -209,6 +209,7 @@ int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg)
|
||||
}
|
||||
|
||||
AddressRange * ar_ptr = it->second;
|
||||
VectorAttribute * the_ar = ar_ptr->attr;
|
||||
|
||||
if(ar_ptr->is_ipam())
|
||||
{
|
||||
@ -231,24 +232,6 @@ int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg)
|
||||
|
||||
delete ar_ptr;
|
||||
|
||||
vector<VectorAttribute *> ars;
|
||||
vector<VectorAttribute *>::iterator it_ar;
|
||||
|
||||
VectorAttribute * the_ar = 0;
|
||||
|
||||
unsigned int ar_id_tpl;
|
||||
|
||||
ar_template.get("AR", ars);
|
||||
|
||||
for (it_ar=ars.begin(); it_ar!=ars.end(); it_ar++)
|
||||
{
|
||||
if (((*it_ar)->vector_value("AR_ID",ar_id_tpl)==0) && (ar_id_tpl==ar_id))
|
||||
{
|
||||
the_ar = *it_ar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (the_ar != 0)
|
||||
{
|
||||
delete ar_template.remove(the_ar);
|
||||
@ -260,6 +243,43 @@ int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::rm_ars(string& error_msg)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
|
||||
for ( it = ar_pool.begin(); it != ar_pool.end(); )
|
||||
{
|
||||
if(it->second->is_ipam())
|
||||
{
|
||||
IPAMManager * ipamm = Nebula::instance().get_ipamm();
|
||||
|
||||
IPAMRequest ir(it->second->attr);
|
||||
|
||||
ipamm->trigger(IPMAction::UNREGISTER_ADDRESS_RANGE, &ir);
|
||||
|
||||
ir.wait();
|
||||
|
||||
if (ir.result != true)
|
||||
{
|
||||
error_msg = ir.message;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (it->second->attr != 0)
|
||||
{
|
||||
delete ar_template.remove(it->second->attr);
|
||||
}
|
||||
|
||||
it = ar_pool.erase(it);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string& AddressRangePool::to_xml(string& sstream, bool extended,
|
||||
const vector<int>& vms, const vector<int>& vnets,
|
||||
const vector<int>& vrs) const
|
||||
|
@ -1073,6 +1073,14 @@ int VirtualNetwork::rm_ar(unsigned int ar_id, string& error_msg)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetwork::rm_ars(string& error_msg)
|
||||
{
|
||||
return ar_pool.rm_ars(error_msg);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetwork::hold_leases(VirtualNetworkTemplate * leases_template,
|
||||
string& error_msg)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user