1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

feature #3028: Print HostShare and HostXML into streams. Scheduler now parses PCI device lists

This commit is contained in:
Ruben S. Montero 2015-08-21 13:46:10 +02:00
parent c4c6416458
commit 6d8ea1a337
6 changed files with 100 additions and 18 deletions

View File

@ -99,6 +99,12 @@ public:
*/
void set_monitorization(vector<Attribute*> &pci_att);
/**
* Prints the PCI device list to an output stream. This function is used
* for logging purposes and *not* for generating DB content.
*/
friend ostream& operator<<(ostream& o, const HostSharePCI& p);
private:
/**
* Sets the internal class structures from the template

View File

@ -233,6 +233,9 @@ unsigned int HostSharePCI::get_pci_value(const char * name,
return pci_value;
}
/* ------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------*/
HostSharePCI::PCIDevice::PCIDevice(VectorAttribute * _attrs)
: vmid(-1), attrs(_attrs)
{
@ -248,6 +251,27 @@ HostSharePCI::PCIDevice::PCIDevice(VectorAttribute * _attrs)
attrs->vector_value("ADDRESS", address);
};
/* ------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------*/
ostream& operator<<(ostream& os, const HostSharePCI& pci)
{
map<string, HostSharePCI::PCIDevice *>::const_iterator it;
for (it=pci.pci_devices.begin(); it!=pci.pci_devices.end(); it++)
{
HostSharePCI::PCIDevice * dev = it->second;
os << endl << "CLASS : " << dev->class_id;
os << endl << "VENDOR : " << dev->vendor_id;
os << endl << "DEVICE : " << dev->device_id;
os << endl << "ADDRESS : " << dev->address;
os << endl << "VMID : " << dev->vmid;
os << endl;
}
return os;
}
/* ************************************************************************ */
/* HostShare :: Constructor/Destructor */
/* ************************************************************************ */
@ -266,9 +290,7 @@ HostShare::HostShare(long long _max_disk,long long _max_mem,long long _max_cpu):
used_disk(0),
used_mem(0),
used_cpu(0),
running_vms(0),
ds(),
pci(){};
running_vms(0){};
ostream& operator<<(ostream& os, HostShare& hs)
{

View File

@ -20,6 +20,7 @@
#include <map>
#include "ObjectXML.h"
#include "HostShare.h"
using namespace std;
@ -131,6 +132,12 @@ public:
return public_cloud;
}
/**
* Prints the Host information to an output stream. This function is used
* for logging purposes.
*/
friend ostream& operator<<(ostream& o, const HostXML& p);
private:
int oid;
int cluster_id;
@ -150,6 +157,8 @@ private:
bool public_cloud;
HostSharePCI pci;
// Configuration attributes
static const char *host_paths[]; /**< paths for search function */

View File

@ -29,11 +29,13 @@ int HostPoolXML::set_up()
{
oss << "Discovered Hosts (enabled):" << endl;
map<int,ObjectXML*>::iterator it;
map<int, ObjectXML*>::iterator it;
for (it=objects.begin();it!=objects.end();it++)
{
oss << " " << it->first;
HostXML * h = dynamic_cast<HostXML *>(it->second);
oss << *h << endl;
}
}
else

View File

@ -36,36 +36,50 @@ const char *HostXML::host_paths[] = {
void HostXML::init_attributes()
{
xpath(oid, "/HOST/ID", -1);
xpath(cluster_id, "/HOST/CLUSTER_ID", -1);
xpath(mem_usage, "/HOST/HOST_SHARE/MEM_USAGE", 0);
xpath(cpu_usage, "/HOST/HOST_SHARE/CPU_USAGE", 0);
xpath(max_mem, "/HOST/HOST_SHARE/MAX_MEM", 0);
xpath(max_cpu, "/HOST/HOST_SHARE/MAX_CPU", 0);
xpath(free_disk, "/HOST/HOST_SHARE/FREE_DISK", 0);
xpath(running_vms, "/HOST/HOST_SHARE/RUNNING_VMS", 0);
xpath(oid, "/HOST/ID", -1);
xpath(cluster_id, "/HOST/CLUSTER_ID", -1);
xpath(mem_usage, "/HOST/HOST_SHARE/MEM_USAGE", 0);
xpath(cpu_usage, "/HOST/HOST_SHARE/CPU_USAGE", 0);
xpath(max_mem, "/HOST/HOST_SHARE/MAX_MEM", 0);
xpath(max_cpu, "/HOST/HOST_SHARE/MAX_CPU", 0);
xpath(free_disk, "/HOST/HOST_SHARE/FREE_DISK", 0);
xpath(running_vms, "/HOST/HOST_SHARE/RUNNING_VMS", 0);
string public_cloud_st;
xpath(public_cloud_st, "/HOST/TEMPLATE/PUBLIC_CLOUD", "");
public_cloud = (one_util::toupper(public_cloud_st) == "YES");
vector<string> ds_ids = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/ID"];
vector<string> ds_free_mb = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/FREE_MB"];
//-------------------- HostShare Datastores ------------------------------
vector<string> ds_ids = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/ID"];
vector<string> ds_free = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/FREE_MB"];
int id;
long long disk;
for (size_t i = 0; i < ds_ids.size() && i < ds_free_mb.size(); i++)
for (size_t i = 0; i < ds_ids.size() && i < ds_free.size(); i++)
{
id = atoi(ds_ids[i].c_str());
disk = atoll(ds_free_mb[i].c_str());
disk = atoll(ds_free[i].c_str());
ds_free_disk[id] = disk;
}
//Init search xpath routes
//-------------------- HostShare PCI Devices ------------------------------
vector<xmlNodePtr> content;
get_nodes("/HOST/HOST_SHARE/PCI_DEVICES", content);
if( !content.empty())
{
pci.from_xml_node(content[0]);
free_nodes(content);
content.clear();
}
//-------------------- Init search xpath routes ---------------------------
ObjectXML::paths = host_paths;
ObjectXML::num_paths = host_num_paths;
}
@ -169,3 +183,31 @@ void HostXML::add_ds_capacity(int dsid, long long vm_disk_mb)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
ostream& operator<<(ostream& o, const HostXML& p)
{
map<int, long long>::const_iterator it;
o << "ID : " << p.oid << endl;
o << "CLUSTER_ID : " << p.cluster_id << endl;
o << "MEM_USAGE : " << p.mem_usage << endl;
o << "CPU_USAGE : " << p.cpu_usage << endl;
o << "MAX_MEM : " << p.max_mem << endl;
o << "MAX_CPU : " << p.max_cpu << endl;
o << "FREE_DISK : " << p.free_disk << endl;
o << "RUNNING_VMS : " << p.running_vms << endl;
o << "PUBLIC : " << p.public_cloud << endl;
o << "DATASTORES" << endl;
o << "----------" << endl;
for (it = p.ds_free_disk.begin() ; it != p.ds_free_disk.end() ; it++)
{
o <<"\tDSID: "<< it->first << "\t\tFREE_MB: " << it->second << endl;
}
o << "PCI DEVICES"<< endl;
o << "-----------"<< endl;
o << p.pci;
return o;
}

View File

@ -39,6 +39,7 @@ sched_env.Prepend(LIBS=[
'nebula_core',
'nebula_template',
'nebula_vm',
'nebula_host',
'crypto',
'xml2'
])