1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-30 22:50:10 +03:00

Feature #4215: Filter VR leases in onevnet show

This commit is contained in:
Carlos Martín 2016-01-07 16:58:54 +01:00
parent 831372003d
commit 034943e6b1
8 changed files with 55 additions and 16 deletions

View File

@ -121,9 +121,11 @@ public:
* A vector containing just -1 means all VMs.
* @param vnet_ids list of VNET the user can access reservation info from.
* A vector containing just -1 means all VNETs.
* @param vrs list of VRouter the user can access VNET usage info from.
* A vector containing just -1 means all VRouters.
*/
void to_xml(ostringstream &oss, const vector<int>& vms,
const vector<int>& vnets) const;
const vector<int>& vnets, const vector<int>& vrs) const;
// *************************************************************************
// Address allocation functions

View File

@ -341,10 +341,12 @@ public:
* A vector containing just -1 means all VMs.
* @param vnet_ids list of VNET the user can access reservation info from.
* A vector containing just -1 means all VNETs.
* @param vrs list of VRouter the user can access VNET usage info from.
* A vector containing just -1 means all VRouters.
* @return the string with the XML
*/
string& to_xml(string& sstream, bool extended, const vector<int>& vms,
const vector<int>& vnets) const;
const vector<int>& vnets, const vector<int>& vrs) const;
private:
/**

View File

@ -409,10 +409,12 @@ public:
* A vector containing just -1 means all VMs.
* @param vnet_ids list of VNET the user can access reservation info from.
* A vector containing just -1 means all VNETs.
* @param vrs list of VRouter the user can access reservation info from.
* A vector containing just -1 means all VRouters.
* @return a reference to the generated string
*/
string& to_xml_extended(string& xml, const vector<int>& vms,
const vector<int>& vnets) const;
const vector<int>& vnets, const vector<int>& vrs) const;
/**
* Gets a string based attribute (single) from an address range. If the
@ -527,7 +529,8 @@ private:
* @return a reference to the generated string
*/
string& to_xml_extended(string& xml, bool extended,
const vector<int>& vm_ids, const vector<int>& vnet_oids) const;
const vector<int>& vm_ids, const vector<int>& vnet_oids,
const vector<int>& vr_ids) const;
/**
* Rebuilds the object from an xml formatted string

View File

@ -124,6 +124,17 @@ public:
return VirtualRouter::bootstrap(_db);
};
/**
* Gets the IDs of objects matching the given SQL where string.
* @param oids a vector that contains the IDs
* @param where SQL clause
* @return 0 on success
*/
int search(vector<int>& oids, const string& where)
{
return PoolSQL::search(oids, VirtualRouter::table, where);
};
private:
/**
* Factory method to produce objects

View File

@ -166,12 +166,15 @@ void VirtualNetworkInfo::to_xml(RequestAttributes& att, PoolObjectSQL * object,
{
vector<int> vms;
vector<int> vnets;
vector<int> vrs;
string where_vnets;
string where_vms;
string where_vrs;
bool all_reservations;
bool all_vms;
bool all_vrs;
PoolObjectAuth perms;
@ -185,6 +188,7 @@ void VirtualNetworkInfo::to_xml(RequestAttributes& att, PoolObjectSQL * object,
{
all_reservations = true;
all_vms = true;
all_vrs = true;
}
else
{
@ -193,6 +197,9 @@ void VirtualNetworkInfo::to_xml(RequestAttributes& att, PoolObjectSQL * object,
all_vms = RequestManagerPoolInfoFilter::use_filter(att,
PoolObjectSQL::VM, false, false, false, "", where_vms);
all_vrs = RequestManagerPoolInfoFilter::use_filter(att,
PoolObjectSQL::VROUTER, false, false, false, "", where_vrs);
}
if ( all_reservations == true )
@ -213,5 +220,14 @@ void VirtualNetworkInfo::to_xml(RequestAttributes& att, PoolObjectSQL * object,
Nebula::instance().get_vmpool()->search(vms, where_vms);
}
static_cast<VirtualNetwork*>(object)->to_xml_extended(str, vms, vnets);
if ( all_vrs == true )
{
vrs.push_back(-1);
}
else
{
Nebula::instance().get_vrouterpool()->search(vrs, where_vrs);
}
static_cast<VirtualNetwork*>(object)->to_xml_extended(str, vms, vnets, vrs);
};

View File

@ -400,7 +400,7 @@ int AddressRange::from_vattr_db(VectorAttribute *vattr)
/* -------------------------------------------------------------------------- */
void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
const vector<int>& vns) const
const vector<int>& vns, const vector<int>& vrs) const
{
const map<string,string>& ar_attrs = attr->value();
map<string,string>::const_iterator it;
@ -411,6 +411,7 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
bool all_vms = (vms.size() == 1 && vms[0] == -1);
bool all_vns = (vns.size() == 1 && vns[0] == -1);
bool all_vrs = (vrs.size() == 1 && vrs[0] == -1);
oss << "<AR>";
@ -512,9 +513,11 @@ void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
{
int oid = it->second & 0x00000000FFFFFFFFLL;
// TODO: all_vrouters?
lease.replace("VROUTER", oid);
is_in = true;
if (all_vrs || (find(vrs.begin(),vrs.end(),oid) != vrs.end()))
{
lease.replace("VROUTER", oid);
is_in = true;
}
}
if (!is_in)

View File

@ -229,7 +229,8 @@ int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg)
/* -------------------------------------------------------------------------- */
string& AddressRangePool::to_xml(string& sstream, bool extended,
const vector<int>& vms, const vector<int>& vnets) const
const vector<int>& vms, const vector<int>& vnets,
const vector<int>& vrs) const
{
if (extended)
{
@ -240,7 +241,7 @@ string& AddressRangePool::to_xml(string& sstream, bool extended,
for (it=ar_pool.begin(); it!=ar_pool.end(); it++)
{
it->second->to_xml(oss, vms, vnets);
it->second->to_xml(oss, vms, vnets, vrs);
}
oss << "</AR_POOL>";

View File

@ -399,23 +399,24 @@ string& VirtualNetwork::to_xml(string& xml) const
{
const vector<int> empty;
return to_xml_extended(xml,false, empty, empty);
return to_xml_extended(xml,false, empty, empty, empty);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string& VirtualNetwork::to_xml_extended(string& xml, const vector<int>& vms,
const vector<int>& vnets) const
const vector<int>& vnets, const vector<int>& vrs) const
{
return to_xml_extended(xml,true, vms, vnets);
return to_xml_extended(xml,true, vms, vnets, vrs);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string& VirtualNetwork::to_xml_extended(string& xml, bool extended,
const vector<int>& vms, const vector<int>& vnets) const
const vector<int>& vms, const vector<int>& vnets,
const vector<int>& vrs) const
{
ostringstream os;
@ -470,7 +471,7 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended,
os << obj_template->to_xml(template_xml);
os << ar_pool.to_xml(leases_xml, extended, vms, vnets);
os << ar_pool.to_xml(leases_xml, extended, vms, vnets, vrs);
os << "</VNET>";