mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
feature #3183:Extend VNET to_xml method to list only VM and VNET information granted by the ACL system
This commit is contained in:
parent
7afeaaaa5d
commit
dcd2e80281
@ -116,8 +116,14 @@ public:
|
||||
/**
|
||||
* Builds an extended XML representation of the AR to send it back to
|
||||
* clients
|
||||
* @param oss stream to write the XML
|
||||
* @param vm_ids list of VM the user can access VNET usage info from.
|
||||
* 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.
|
||||
*/
|
||||
void to_xml(ostringstream &oss) const;
|
||||
void to_xml(ostringstream &oss, const vector<int>& vms,
|
||||
const vector<int>& vnets) const;
|
||||
|
||||
// *************************************************************************
|
||||
// Address allocation functions
|
||||
|
@ -318,9 +318,14 @@ public:
|
||||
* Generate a XML representation of the Address Range Pool
|
||||
* @param sstream where the ARPool is written
|
||||
* @param extended true to include lease information
|
||||
* @param vm_ids list of VM the user can access VNET usage info from.
|
||||
* 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.
|
||||
* @return the string with the XML
|
||||
*/
|
||||
string& to_xml(string& sstream, bool extended) const;
|
||||
string& to_xml(string& sstream, bool extended, const vector<int>& vms,
|
||||
const vector<int>& vnets) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -45,7 +45,8 @@ protected:
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void to_xml(PoolObjectSQL * object, string& str)
|
||||
virtual void to_xml(RequestAttributes& att, PoolObjectSQL * object,
|
||||
string& str)
|
||||
{
|
||||
object->to_xml(str);
|
||||
};
|
||||
@ -60,7 +61,7 @@ public:
|
||||
VirtualMachineInfo():
|
||||
RequestManagerInfo("VirtualMachineInfo",
|
||||
"Returns virtual machine instance information")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
auth_object = PoolObjectSQL::VM;
|
||||
@ -70,10 +71,9 @@ public:
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void to_xml(PoolObjectSQL * object, string& str)
|
||||
void to_xml(RequestAttributes& att, PoolObjectSQL * object, string& str)
|
||||
{
|
||||
VirtualMachine * vm = static_cast<VirtualMachine *>(object);
|
||||
vm->to_xml_extended(str);
|
||||
static_cast<VirtualMachine *>(object)->to_xml_extended(str);
|
||||
};
|
||||
};
|
||||
|
||||
@ -86,7 +86,7 @@ public:
|
||||
TemplateInfo():
|
||||
RequestManagerInfo("TemplateInfo",
|
||||
"Returns virtual machine template information")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = PoolObjectSQL::TEMPLATE;
|
||||
@ -105,7 +105,7 @@ public:
|
||||
VirtualNetworkInfo():
|
||||
RequestManagerInfo("VirtualNetworkInfo",
|
||||
"Returns virtual network information")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
auth_object = PoolObjectSQL::NET;
|
||||
@ -115,11 +115,7 @@ public:
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void to_xml(PoolObjectSQL * object, string& str)
|
||||
{
|
||||
VirtualNetwork * vn = static_cast<VirtualNetwork*>(object);
|
||||
vn->to_xml_extended(str);
|
||||
};
|
||||
void to_xml(RequestAttributes& att, PoolObjectSQL * object, string& str);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -131,7 +127,7 @@ public:
|
||||
ImageInfo():
|
||||
RequestManagerInfo("ImageInfo",
|
||||
"Returns image information")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = PoolObjectSQL::IMAGE;
|
||||
@ -150,7 +146,7 @@ public:
|
||||
HostInfo():
|
||||
RequestManagerInfo("HostInfo",
|
||||
"Returns host information")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
auth_object = PoolObjectSQL::HOST;
|
||||
@ -178,10 +174,9 @@ public:
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void to_xml(PoolObjectSQL * object, string& str)
|
||||
void to_xml(RequestAttributes& att, PoolObjectSQL * object, string& str)
|
||||
{
|
||||
Group * group = static_cast<Group*>(object);
|
||||
group->to_xml_extended(str);
|
||||
static_cast<Group*>(object)->to_xml_extended(str);
|
||||
};
|
||||
};
|
||||
|
||||
@ -204,10 +199,9 @@ public:
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void to_xml(PoolObjectSQL * object, string& str)
|
||||
void to_xml(RequestAttributes& att, PoolObjectSQL * object, string& str)
|
||||
{
|
||||
User * user = static_cast<User*>(object);
|
||||
user->to_xml_extended(str);
|
||||
static_cast<User*>(object)->to_xml_extended(str);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -39,6 +39,17 @@ public:
|
||||
/** Specify user's + group objects (-1) */
|
||||
static const int MINE_GROUP;
|
||||
|
||||
/**
|
||||
* Set a where filter to get the oids of objects that a user can "USE"
|
||||
* @param att the XML-RPC Attributes with user information
|
||||
* @param auth_object the object type
|
||||
* @param where_string will store the resulting SQL filter
|
||||
* @return true if the use_filter is empty and access to all objects
|
||||
* should be granted.
|
||||
*/
|
||||
static bool use_filter(RequestAttributes& att, PoolObjectSQL::ObjectType aobj,
|
||||
string& where_str);
|
||||
|
||||
protected:
|
||||
RequestManagerPoolInfoFilter(const string& method_name,
|
||||
const string& help,
|
||||
@ -56,12 +67,12 @@ protected:
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void where_filter(RequestAttributes& att,
|
||||
int filter_flag,
|
||||
int start_id,
|
||||
int end_id,
|
||||
const string& and_clause,
|
||||
const string& or_clause,
|
||||
string& where_string);
|
||||
int filter_flag,
|
||||
int start_id,
|
||||
int end_id,
|
||||
const string& and_clause,
|
||||
const string& or_clause,
|
||||
string& where_string);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
@ -90,7 +101,7 @@ public:
|
||||
RequestManagerPoolInfoFilter("VirtualMachinePoolInfo",
|
||||
"Returns the virtual machine instances pool",
|
||||
"A:siiii")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
auth_object = PoolObjectSQL::VM;
|
||||
@ -164,7 +175,7 @@ public:
|
||||
RequestManagerPoolInfoFilter("TemplatePoolInfo",
|
||||
"Returns the virtual machine template pool",
|
||||
"A:siii")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = PoolObjectSQL::TEMPLATE;
|
||||
@ -183,7 +194,7 @@ public:
|
||||
RequestManagerPoolInfoFilter("VirtualNetworkPoolInfo",
|
||||
"Returns the virtual network pool",
|
||||
"A:siii")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
auth_object = PoolObjectSQL::NET;
|
||||
@ -202,7 +213,7 @@ public:
|
||||
RequestManagerPoolInfoFilter("ImagePoolInfo",
|
||||
"Returns the image pool",
|
||||
"A:siii")
|
||||
{
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = PoolObjectSQL::IMAGE;
|
||||
|
@ -343,22 +343,18 @@ public:
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
/**
|
||||
* Function to print the object into a string in XML format
|
||||
* base64 encoded
|
||||
* @param xml64 the resulting XML string
|
||||
* @param extended return the extended template or the simple one
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml64(string &xml64, bool extended);
|
||||
|
||||
/**
|
||||
* Function to print the VirtualNetwork object into a string in
|
||||
* XML format. The extended XML includes the LEASES
|
||||
* @param xml the resulting XML string
|
||||
* @param vm_ids list of VM the user can access VNET usage info from.
|
||||
* 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.
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml_extended(string& xml) const;
|
||||
string& to_xml_extended(string& xml, const vector<int>& vms,
|
||||
const vector<int>& vnets) const;
|
||||
|
||||
/**
|
||||
* Replace the template of the virtual network it also updates the BRIDGE,
|
||||
@ -473,7 +469,8 @@ private:
|
||||
* @param extended If true, leases are included
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml_extended(string& xml, bool extended) const;
|
||||
string& to_xml_extended(string& xml, bool extended,
|
||||
const vector<int>& vm_ids, const vector<int>& vnet_oids) const;
|
||||
|
||||
/**
|
||||
* Rebuilds the object from an xml formatted string
|
||||
|
@ -15,6 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManagerInfo.h"
|
||||
#include "RequestManagerPoolInfoFilter.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -47,15 +48,15 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
object = pool->get(oid,true);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
if ( object == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(auth_object),oid),
|
||||
att);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
to_xml(object, str);
|
||||
to_xml(att, object, str);
|
||||
|
||||
object->unlock();
|
||||
|
||||
@ -64,3 +65,41 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualNetworkInfo::to_xml(RequestAttributes& att, PoolObjectSQL * object,
|
||||
string& str)
|
||||
{
|
||||
vector<int> vms;
|
||||
vector<int> vnets;
|
||||
|
||||
string where_str;
|
||||
|
||||
bool all = RequestManagerPoolInfoFilter::use_filter(att, PoolObjectSQL::NET,
|
||||
where_str);
|
||||
|
||||
if (all)
|
||||
{
|
||||
vnets.push_back(-1);
|
||||
vms.push_back(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( Nebula::instance().get_vnpool()->search(vnets, where_str) != 0 )
|
||||
{
|
||||
//Log warning
|
||||
}
|
||||
|
||||
where_str = "";
|
||||
|
||||
RequestManagerPoolInfoFilter::use_filter(att, PoolObjectSQL::VM, where_str);
|
||||
|
||||
if ( Nebula::instance().get_vmpool()->search(vms, where_str) != 0 )
|
||||
{
|
||||
//Log warning
|
||||
}
|
||||
}
|
||||
|
||||
static_cast<VirtualNetwork*>(object)->to_xml_extended(str, vms, vnets);
|
||||
};
|
||||
|
@ -23,7 +23,7 @@ using namespace std;
|
||||
|
||||
const int RequestManagerPoolInfoFilter::ALL = -2;
|
||||
|
||||
const int RequestManagerPoolInfoFilter::MINE = -3;
|
||||
const int RequestManagerPoolInfoFilter::MINE = -3;
|
||||
|
||||
const int RequestManagerPoolInfoFilter::MINE_GROUP = -1;
|
||||
|
||||
@ -31,7 +31,7 @@ const int RequestManagerPoolInfoFilter::MINE_GROUP = -1;
|
||||
|
||||
const int VirtualMachinePoolInfo::ALL_VM = -2;
|
||||
|
||||
const int VirtualMachinePoolInfo::NOT_DONE = -1;
|
||||
const int VirtualMachinePoolInfo::NOT_DONE = -1;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -50,6 +50,24 @@ void RequestManagerPoolInfoFilter::request_execute(
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
bool RequestManagerPoolInfoFilter::use_filter(RequestAttributes& att,
|
||||
PoolObjectSQL::ObjectType aobj,
|
||||
string& where_str)
|
||||
{
|
||||
bool all;
|
||||
|
||||
string acl_str;
|
||||
|
||||
PoolSQL::acl_filter(att.uid, att.group_ids, aobj, all, acl_str);
|
||||
|
||||
PoolSQL::usr_filter(att.uid, att.group_ids, ALL, all, acl_str, where_str);
|
||||
|
||||
return all;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachinePoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
@ -114,8 +132,8 @@ void VirtualMachinePoolAccounting::request_execute(
|
||||
where_filter(att, filter_flag, -1, -1, "", "", where);
|
||||
|
||||
rc = (static_cast<VirtualMachinePool *>(pool))->dump_acct(oss,
|
||||
where,
|
||||
time_start,
|
||||
where,
|
||||
time_start,
|
||||
time_end);
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -295,8 +313,8 @@ void RequestManagerPoolInfoFilter::where_filter(
|
||||
|
||||
PoolSQL::oid_filter(start_id, end_id, oid_str);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Compound WHERE clause
|
||||
// -------------------------------------------------------------------------
|
||||
// Compound WHERE clause
|
||||
// WHERE ( id_str ) AND ( uid_str ) AND ( and_clause ) OR ( or_clause )
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
@ -284,7 +284,7 @@ void get_network_attribute(VirtualMachine * vm,
|
||||
|
||||
if (attr_name == "TEMPLATE")
|
||||
{
|
||||
attr_value = vn->to_xml64(attr_value, true);
|
||||
attr_value = vn->to_xml64(attr_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -229,7 +229,7 @@ void get_network_attribute(VirtualMachine * vm,
|
||||
|
||||
if (attr_name == "TEMPLATE")
|
||||
{
|
||||
attr_value = vn->to_xml64(attr_value, true);
|
||||
attr_value = vn->to_xml64(attr_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "NebulaUtil.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -352,11 +353,15 @@ int AddressRange::from_vattr_db(VectorAttribute *vattr)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRange::to_xml(ostringstream &oss) const
|
||||
void AddressRange::to_xml(ostringstream &oss, const vector<int>& vms,
|
||||
const vector<int>& vns) const
|
||||
{
|
||||
const map<string,string>& ar_attrs = attr->value();
|
||||
map<string,string>::const_iterator it;
|
||||
|
||||
bool all_vms = (vms.size() == 1 && vms[0] == -1);
|
||||
bool all_vns = (vns.size() == 1 && vns[0] == -1);
|
||||
|
||||
oss << "<AR>";
|
||||
|
||||
for (it=ar_attrs.begin(); it != ar_attrs.end(); it++)
|
||||
@ -379,7 +384,9 @@ void AddressRange::to_xml(ostringstream &oss) const
|
||||
else
|
||||
{
|
||||
map<unsigned int, long long>::const_iterator it;
|
||||
|
||||
VectorAttribute lease("LEASE");
|
||||
bool is_in;
|
||||
|
||||
oss << "<LEASES>";
|
||||
|
||||
@ -387,6 +394,34 @@ void AddressRange::to_xml(ostringstream &oss) const
|
||||
{
|
||||
lease.clear();
|
||||
|
||||
is_in = false;
|
||||
|
||||
if (it->second & PoolObjectSQL::VM)
|
||||
{
|
||||
int vmid = it->second & 0x00000000FFFFFFFFLL;
|
||||
|
||||
if (all_vms || (find(vms.begin(),vms.end(),vmid) != vms.end()))
|
||||
{
|
||||
lease.replace("VM", vmid);
|
||||
is_in = true;
|
||||
}
|
||||
}
|
||||
else if (it->second & PoolObjectSQL::NET)
|
||||
{
|
||||
int vnid = it->second & 0x00000000FFFFFFFFLL;
|
||||
|
||||
if (all_vns || (find(vns.begin(),vns.end(),vnid) != vns.end()))
|
||||
{
|
||||
lease.replace("VNET", vnid);
|
||||
is_in = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_in)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
set_mac(it->first, &lease);
|
||||
|
||||
if (type & 0x00000002 )
|
||||
@ -399,19 +434,6 @@ void AddressRange::to_xml(ostringstream &oss) const
|
||||
set_ip6(it->first, &lease);
|
||||
}
|
||||
|
||||
if (it->second & PoolObjectSQL::VM)
|
||||
{
|
||||
int vmid = it->second & 0x00000000FFFFFFFFLL;
|
||||
|
||||
lease.replace("VM", vmid);
|
||||
}
|
||||
else if (it->second & PoolObjectSQL::NET)
|
||||
{
|
||||
int vnid = it->second & 0x00000000FFFFFFFFLL;
|
||||
|
||||
lease.replace("VNET", vnid);
|
||||
}
|
||||
|
||||
lease.to_xml(oss);
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,8 @@ int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string& AddressRangePool::to_xml(string& sstream, bool extended) const
|
||||
string& AddressRangePool::to_xml(string& sstream, bool extended,
|
||||
const vector<int>& vms, const vector<int>& vnets) const
|
||||
{
|
||||
if (extended)
|
||||
{
|
||||
@ -239,7 +240,7 @@ string& AddressRangePool::to_xml(string& sstream, bool extended) const
|
||||
|
||||
for (it=ar_pool.begin(); it!=ar_pool.end(); it++)
|
||||
{
|
||||
it->second->to_xml(oss);
|
||||
it->second->to_xml(oss, vms, vnets);
|
||||
}
|
||||
|
||||
oss << "</AR_POOL>";
|
||||
|
@ -375,39 +375,25 @@ error_common:
|
||||
|
||||
string& VirtualNetwork::to_xml(string& xml) const
|
||||
{
|
||||
return to_xml_extended(xml,false);
|
||||
const vector<int> empty;
|
||||
|
||||
return to_xml_extended(xml,false, empty, empty);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string& VirtualNetwork::to_xml64(string &xml64, bool extended)
|
||||
string& VirtualNetwork::to_xml_extended(string& xml, const vector<int>& vms,
|
||||
const vector<int>& vnets) const
|
||||
{
|
||||
string *str64;
|
||||
|
||||
to_xml_extended(xml64, extended);
|
||||
|
||||
str64 = one_util::base64_encode(xml64);
|
||||
|
||||
xml64 = *str64;
|
||||
|
||||
delete str64;
|
||||
|
||||
return xml64;
|
||||
return to_xml_extended(xml,true, vms, vnets);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string& VirtualNetwork::to_xml_extended(string& xml) const
|
||||
{
|
||||
return to_xml_extended(xml,true);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const
|
||||
string& VirtualNetwork::to_xml_extended(string& xml, bool extended,
|
||||
const vector<int>& vms, const vector<int>& vnets) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
@ -459,7 +445,7 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const
|
||||
|
||||
os << obj_template->to_xml(template_xml);
|
||||
|
||||
os << ar_pool.to_xml(leases_xml, extended);
|
||||
os << ar_pool.to_xml(leases_xml, extended, vms, vnets);
|
||||
|
||||
os << "</VNET>";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user