1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-28 14:50:08 +03:00

Feature #407: Use new xpath methods in Host unmarshall

This commit is contained in:
Carlos Martín 2011-02-25 15:23:46 +01:00
parent 63ca42e432
commit f1157f524b
4 changed files with 44 additions and 25 deletions

View File

@ -78,6 +78,15 @@ public:
*/
void xpath(int& value, const char * xpath_expr, const int& def);
/**
* Gets and sets a xpath attribute, if the attribute is not found a default
* is used
* @param value to set
* @param xpath_expr of the xml element
* @param def default value if the element is not found
*/
void xpath(time_t& value, const char * xpath_expr, const time_t& def);
/**
* Gets the value of an element from an xml string
* @param value the value of the element

View File

@ -224,25 +224,23 @@ string& Host::to_xml(string& xml) const
int Host::from_xml(const string& xml)
{
vector<xmlNodePtr> content;
int int_state;
// Initialize the internal XML object
update_from_str(xml);
oid = atoi(((*this)["/HOST/ID"] )[0].c_str() );
hostname = ((*this)["/HOST/NAME"])[0];
state = static_cast<HostState>( atoi(((*this)["/HOST/STATE"])[0].c_str()) );
xpath(oid, "/HOST/ID", -1);
xpath(hostname, "/HOST/NAME", "not_found");
xpath(int_state, "/HOST/STATE", 0);
state = static_cast<HostState>( int_state );
// TODO: create an ObjectXML method to allow this syntax:
// im_mad_name = xpath("/HOST/IM_MAD", "im_default");
xpath(im_mad_name, "/HOST/IM_MAD", "not_found");
xpath(vmm_mad_name, "/HOST/VM_MAD", "not_found");
xpath(tm_mad_name, "/HOST/TM_MAD", "not_found");
im_mad_name = ((*this)["/HOST/IM_MAD"])[0];
vmm_mad_name = ((*this)["/HOST/VM_MAD"])[0];
tm_mad_name = ((*this)["/HOST/TM_MAD"])[0];
xpath(last_monitored, "/HOST/LAST_MON_TIME", 0);
last_monitored = static_cast<time_t>( atoi(((*this)["/HOST/LAST_MON_TIME"] )[0].c_str() ) );
cluster = ((*this)["/HOST/CLUSTER"])[0];
xpath(cluster, "/HOST/CLUSTER", "not_found");
ObjectXML::get_nodes("/HOST/HOST_SHARE", content);
host_share.from_xml_node( content[0] );

View File

@ -92,23 +92,23 @@ int HostShare::from_xml_node(const xmlNodePtr node)
// Initialize the internal XML object
ObjectXML::update_from_node(node);
disk_usage = atoi(((*this)["/HOST_SHARE/DISK_USAGE"] )[0].c_str() );
mem_usage = atoi(((*this)["/HOST_SHARE/MEM_USAGE"] )[0].c_str() );
cpu_usage = atoi(((*this)["/HOST_SHARE/CPU_USAGE"] )[0].c_str() );
xpath(disk_usage, "/HOST_SHARE/DISK_USAGE", -1);
xpath(mem_usage, "/HOST_SHARE/MEM_USAGE", -1);
xpath(cpu_usage, "/HOST_SHARE/CPU_USAGE", -1);
max_disk = atoi(((*this)["/HOST_SHARE/MAX_DISK"] )[0].c_str() );
max_mem = atoi(((*this)["/HOST_SHARE/MAX_MEM"] )[0].c_str() );
max_cpu = atoi(((*this)["/HOST_SHARE/MAX_CPU"] )[0].c_str() );
xpath(max_disk, "/HOST_SHARE/MAX_DISK", -1);
xpath(max_mem , "/HOST_SHARE/MAX_MEM", -1);
xpath(max_cpu , "/HOST_SHARE/MAX_CPU", -1);
free_disk = atoi(((*this)["/HOST_SHARE/FREE_DISK"] )[0].c_str() );
free_mem = atoi(((*this)["/HOST_SHARE/FREE_MEM"] )[0].c_str() );
free_cpu = atoi(((*this)["/HOST_SHARE/FREE_CPU"] )[0].c_str() );
xpath(free_disk, "/HOST_SHARE/FREE_DISK", -1);
xpath(free_mem , "/HOST_SHARE/FREE_MEM", -1);
xpath(free_cpu , "/HOST_SHARE/FREE_CPU", -1);
used_disk = atoi(((*this)["/HOST_SHARE/USED_DISK"] )[0].c_str() );
used_mem = atoi(((*this)["/HOST_SHARE/USED_MEM"] )[0].c_str() );
used_cpu = atoi(((*this)["/HOST_SHARE/USED_CPU"] )[0].c_str() );
xpath(used_disk, "/HOST_SHARE/USED_DISK", -1);
xpath(used_mem , "/HOST_SHARE/USED_MEM", -1);
xpath(used_cpu , "/HOST_SHARE/USED_CPU", -1);
running_vms = atoi(((*this)["/HOST_SHARE/RUNNING_VMS"] )[0].c_str() );
xpath(running_vms,"/HOST_SHARE/RUNNING_VMS",-1);
return 0;
}

View File

@ -179,6 +179,18 @@ void ObjectXML::xpath(int& value, const char * xpath_expr, const int& def)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ObjectXML::xpath(time_t& value, const char * xpath_expr, const time_t& def)
{
int int_val;
int int_def = static_cast<time_t>(def);
xpath(int_val, xpath_expr, int_def);
value = static_cast<time_t>(int_val);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ObjectXML::xpath_value(string& value,const char *doc,const char *the_xpath)
{
int rc = 0;