mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-30 22:50:10 +03:00
Feature #2270: VNets can be only deleted if there are not used leases
This commit is contained in:
parent
5604a14f38
commit
caf4484680
@ -117,6 +117,8 @@ public:
|
||||
{
|
||||
return cluster->del_vnet(id, error_msg);
|
||||
};
|
||||
|
||||
int drop(int oid, PoolObjectSQL * object, string& error_msg);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -169,6 +169,15 @@ public:
|
||||
return leases->size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets used leases
|
||||
* @return number of network leases in used
|
||||
*/
|
||||
unsigned int get_used()
|
||||
{
|
||||
return leases->n_used;
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to print the VirtualNetwork object into a string in
|
||||
* XML format
|
||||
|
@ -317,3 +317,22 @@ int ZoneDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetworkDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
{
|
||||
VirtualNetwork * vnet = static_cast<VirtualNetwork *>(object);
|
||||
|
||||
if ( vnet->get_used() > 0 )
|
||||
{
|
||||
error_msg = "Can not remove a virtual network with leases in use";
|
||||
|
||||
vnet->unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return RequestManagerDelete::drop(oid, object, error_msg);
|
||||
}
|
||||
|
@ -615,14 +615,6 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const
|
||||
string leases_xml;
|
||||
string perm_str;
|
||||
|
||||
// Total leases is the number of used leases.
|
||||
int total_leases = 0;
|
||||
|
||||
if (leases != 0)
|
||||
{
|
||||
total_leases = leases->n_used;
|
||||
}
|
||||
|
||||
os <<
|
||||
"<VNET>" <<
|
||||
"<ID>" << oid << "</ID>" <<
|
||||
@ -689,21 +681,12 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const
|
||||
"</RANGE>";
|
||||
}
|
||||
|
||||
os << "<TOTAL_LEASES>"<< total_leases << "</TOTAL_LEASES>"<<
|
||||
os << "<TOTAL_LEASES>"<< leases->n_used << "</TOTAL_LEASES>"<<
|
||||
obj_template->to_xml(template_xml);
|
||||
|
||||
if (extended)
|
||||
{
|
||||
if (leases != 0)
|
||||
{
|
||||
os << "<LEASES>" <<
|
||||
leases->to_xml(leases_xml) <<
|
||||
"</LEASES>";
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "<LEASES/>";
|
||||
}
|
||||
os << "<LEASES>" << leases->to_xml(leases_xml) << "</LEASES>";
|
||||
}
|
||||
|
||||
os << "</VNET>";
|
||||
|
Loading…
x
Reference in New Issue
Block a user