mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
feature #2858: Adds lease usage information to XML descriptions
This commit is contained in:
parent
72b61e9ec5
commit
f0e64384cf
@ -34,7 +34,7 @@ class AddressRange
|
||||
{
|
||||
public:
|
||||
|
||||
AddressRange(unsigned int _id):id(_id),next(0){};
|
||||
AddressRange(unsigned int _id):id(_id),next(0),used_addr(0){};
|
||||
|
||||
virtual ~AddressRange(){};
|
||||
|
||||
@ -145,17 +145,26 @@ public:
|
||||
* @param ot the object type of the owner of the address
|
||||
* @param obid the id of the owner of the address
|
||||
* @param mac the MAC address in string form
|
||||
* @return 0 if the address was freed
|
||||
*/
|
||||
void free_addr(PoolObjectSQL::ObjectType ot, int obid, const string& mac);
|
||||
int free_addr(PoolObjectSQL::ObjectType ot, int obid, const string& mac);
|
||||
|
||||
/**
|
||||
* Return the id for this address range
|
||||
*/
|
||||
unsigned int ar_id()
|
||||
unsigned int ar_id() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of used addresses
|
||||
*/
|
||||
unsigned int get_used_addr() const
|
||||
{
|
||||
return used_addr;
|
||||
}
|
||||
|
||||
private:
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* String to binary conversion functions for different address types */
|
||||
@ -242,7 +251,7 @@ private:
|
||||
/**
|
||||
* Frees an address from the map. Updates the ALLOCATED attribute
|
||||
*/
|
||||
void free_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
int free_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
unsigned int addr_index);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -306,7 +315,9 @@ private:
|
||||
*/
|
||||
map<unsigned int, long long> allocated;
|
||||
|
||||
unsigned int next;
|
||||
unsigned int next;
|
||||
|
||||
unsigned int used_addr;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Restricted Attributes */
|
||||
|
@ -107,6 +107,14 @@ public:
|
||||
void free_addr(unsigned int arid, PoolObjectSQL::ObjectType ot, int obid,
|
||||
const string& mac);
|
||||
|
||||
/**
|
||||
* Return the number of used addresses
|
||||
*/
|
||||
unsigned int get_used_addr() const
|
||||
{
|
||||
return used_addr;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Stores the Address Ranges in a template form. This template is used
|
||||
@ -123,6 +131,11 @@ private:
|
||||
* Map to access each range
|
||||
*/
|
||||
map<unsigned int, AddressRange *> ar_pool;
|
||||
|
||||
/**
|
||||
* Used addresses
|
||||
*/
|
||||
unsigned int used_addr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -150,26 +150,13 @@ public:
|
||||
ar_pool.free_addr(arid, PoolObjectSQL::VM, vid, mac);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets size of the network (used + free)
|
||||
* @return number of hosts that can be fitted in this network
|
||||
*/
|
||||
unsigned int get_size()
|
||||
{
|
||||
//TODO
|
||||
return 0;
|
||||
//return leases->size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets used leases
|
||||
* @return number of network leases in used
|
||||
*/
|
||||
unsigned int get_used()
|
||||
{
|
||||
//TODO
|
||||
return 0;
|
||||
//return leases->n_used;
|
||||
return ar_pool.get_used_addr();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -276,6 +276,8 @@ void AddressRange::to_xml(ostringstream &oss) const
|
||||
oss << "</LEASES>";
|
||||
}
|
||||
|
||||
oss << "<TOTAL_LEASES>" << used_addr << "</TOTAL_LEASES>";
|
||||
|
||||
oss << "</AR>";
|
||||
}
|
||||
|
||||
@ -592,6 +594,8 @@ int AddressRange::attr_to_allocated(const string& allocated_s)
|
||||
}
|
||||
|
||||
allocated.insert(make_pair(addr_index,object_pack));
|
||||
|
||||
used_addr++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -605,12 +609,14 @@ void AddressRange::allocate_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
|
||||
allocated.insert(make_pair(addr_index,ot|obid));
|
||||
|
||||
used_addr++;
|
||||
|
||||
allocated_to_attr();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRange::free_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
int AddressRange::free_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
unsigned int addr_index)
|
||||
{
|
||||
map<unsigned int, long long>::iterator it;
|
||||
@ -621,7 +627,13 @@ void AddressRange::free_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
{
|
||||
allocated.erase(it);
|
||||
allocated_to_attr();
|
||||
|
||||
used_addr--;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
@ -764,7 +776,7 @@ int AddressRange::allocate_by_ip(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRange::free_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
int AddressRange::free_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
const string& mac_s)
|
||||
{
|
||||
unsigned int mac_i[2];
|
||||
@ -775,8 +787,10 @@ void AddressRange::free_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
|
||||
if ((mac_i[0] >= mac[0]) && (index < size))
|
||||
{
|
||||
free_addr(ot, obid, index);
|
||||
return free_addr(ot, obid, index);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
AddressRangePool::AddressRangePool():ar_template(false,'=',"AR_POOL"),next_ar(0)
|
||||
{};
|
||||
AddressRangePool::AddressRangePool():ar_template(false,'=',"AR_POOL"),
|
||||
next_ar(0), used_addr(0){};
|
||||
|
||||
AddressRangePool::~AddressRangePool()
|
||||
{
|
||||
@ -104,6 +104,8 @@ int AddressRangePool::from_xml_node(const xmlNodePtr node)
|
||||
{
|
||||
next_ar = ar->ar_id() + 1;
|
||||
}
|
||||
|
||||
used_addr += ar->get_used_addr();
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -148,6 +150,7 @@ int AddressRangePool::allocate_addr(PoolObjectSQL::ObjectType ot, int obid,
|
||||
{
|
||||
if (it->second->allocate_addr(ot, obid, nic, inherit) == 0)
|
||||
{
|
||||
used_addr++;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -168,6 +171,7 @@ int AddressRangePool::allocate_by_mac(const string &mac,
|
||||
{
|
||||
if (it->second->allocate_by_mac(mac, ot, obid, nic, inherit) == 0)
|
||||
{
|
||||
used_addr++;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -188,6 +192,7 @@ int AddressRangePool::allocate_by_ip(const string &ip,
|
||||
{
|
||||
if (it->second->allocate_by_ip(ip, ot, obid, nic, inherit) == 0)
|
||||
{
|
||||
used_addr++;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -207,6 +212,9 @@ void AddressRangePool::free_addr(unsigned int arid, PoolObjectSQL::ObjectType ot
|
||||
|
||||
if (it!=ar_pool.end())
|
||||
{
|
||||
it->second->free_addr(ot, obid, mac);
|
||||
if ( it->second->free_addr(ot, obid, mac) == 0 )
|
||||
{
|
||||
used_addr--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -431,6 +431,7 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const
|
||||
{
|
||||
os << "<VLAN_ID/>";
|
||||
}
|
||||
os << "<TOTAL_LEASES>"<< ar_pool.get_used_addr() << "</TOTAL_LEASES>";
|
||||
|
||||
os << obj_template->to_xml(template_xml);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user