[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Ovirt-devel] [PATCH matahari] Removes HAL code from the HostAgent codebase.



Now all aspects of the host environment are details by other means. The
fully qualified hostname and architecture are taken from uname(). Memory
is taken from sysinfo(). The machine UUID is taken from DBus rather than
udev since udev reports hardware UUID which is not guaranteed to be
unique, while DBus is designed to be just that.

Refactored, for now, the NICWrapper class to get its own HAL context
rather than it being supplied by the HostAgent class. This way the
HostAgent is completely HAL free.

Signed-off-by: Darryl L. Pierce <dpierce redhat com>
---
 src/host.cpp   |  131 +++++++++++++++++++++++++++----------------------------
 src/nic.cpp    |    4 +-
 src/nic.h      |    3 +-
 src/schema.xml |    2 +-
 4 files changed, 68 insertions(+), 72 deletions(-)

diff --git a/src/host.cpp b/src/host.cpp
index 885068b..11c5a8f 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -17,16 +17,12 @@
  * also available at http://www.gnu.org/copyleft/gpl.html.
  */
 
-#include <qpid/management/Manageable.h>
-
-#include <iostream>
 #include <fstream>
-#include <stdexcept>
-
-#include <cstdlib>
-#include <unistd.h>
 
 #include <libvirt/libvirt.h>
+#include <qpid/management/Manageable.h>
+#include <sys/sysinfo.h>
+#include <sys/utsname.h>
 
 #include "host.h"
 #include "qmf/com/redhat/matahari/Host.h"
@@ -46,67 +42,68 @@ HostAgent::setup(ManagementAgent* agent)
   // discover the aspects of the host
   processors.setup(agent, this);
 
-  LibHalContext *hal_ctx;
-  int ret;
-
-  // Get our HAL Context or die trying
-  hal_ctx = get_hal_ctx();
-  if (!hal_ctx)
-    throw runtime_error("Unable to get HAL Context Structure.");
-
-  try {
-    NICWrapper::fillNICInfo(this->nics, agent, hal_ctx);
-
-    // Host UUID
-    char *uuid_c = get_uuid(hal_ctx);
-    string uuid(uuid_c);
-    management_object->set_uuid(uuid);
-
-    // Hostname
-    char hostname_c[HOST_NAME_MAX];
-    ret = gethostname(hostname_c, sizeof(hostname_c));
-    if (ret != 0)
-      throw runtime_error("Unable to get hostname");
-    string hostname(hostname_c);
-    management_object->set_hostname(hostname);
-
-    // Hypervisor, arch, memory
-    management_object->set_memory(0);
-    management_object->set_hypervisor("unknown");
-    management_object->set_arch("unknown");
-
-    virConnectPtr connection;
-    virNodeInfo info;
-    connection = virConnectOpenReadOnly(NULL);
-    if (connection) {
-      const char *hv = virConnectGetType(connection);
-      if (hv != NULL)
-        management_object->set_hypervisor(hv);
-      ret = virNodeGetInfo(connection, &info);
-      if (ret == 0) {
-        management_object->set_arch(info.model);
-        management_object->set_memory(info.memory);
-      }
+  struct utsname details;
+  string uuid         = "Unknown";
+  string hostname     = "Unknown";
+  string hypervisor   = "Unknown";
+  string architecture = "None";
+  unsigned long memory = 0;
+  bool beeping        = false;
+
+  ifstream input("/var/lib/dbus/machine-id");
+
+  if(input.is_open())
+    {
+      getline(input, uuid);
+      input.close();
+    }
+
+  if(!uname(&details))
+    {
+      hostname = string(details.nodename);
+      architecture = string(details.machine);
+    }
+  else
+    {
+      throw runtime_error("Unable to retrieve system details");
+    }
+
+  virConnectPtr lvconn = virConnectOpenReadOnly(NULL);
+
+  if(lvconn)
+    {
+      hypervisor = string(virConnectGetType(lvconn));
+      virConnectClose(lvconn);
+    }
+
+  struct sysinfo sysinf;
+  if(!sysinfo(&sysinf))
+    {
+      memory = sysinf.totalram / 1024L;
+    }
+  else
+    {
+      throw runtime_error("Unable to retrieve system memory details.");
+    }
+
+  cout << "memory: " << memory << endl;
+
+  management_object->set_uuid(uuid);
+  management_object->set_hostname(hostname);
+  management_object->set_hypervisor(hypervisor);
+  management_object->set_arch(architecture);
+  management_object->set_memory(memory);
+  management_object->set_beeping(beeping);
+
+  NICWrapper::fillNICInfo(this->nics, agent);
+
+  // setup the nic objects
+  for(vector<NICWrapper*>::iterator iter = nics.begin();
+      iter != nics.end();
+      iter++)
+    {
+      (*iter)->setupQMFObject(agent, this);
     }
-    virConnectClose(connection);
-
-    management_object->set_beeping(false);
-
-    // setup the nic objects
-    for(vector<NICWrapper*>::iterator iter = nics.begin();
-        iter != nics.end();
-        iter++)
-      {
-        (*iter)->setupQMFObject(agent, this);
-      }
-  }
-  catch (...) {
-    put_hal_ctx(hal_ctx);
-    throw;
-  }
-
-  // Close the Hal Context
-  put_hal_ctx(hal_ctx);
 }
 
 void
diff --git a/src/nic.cpp b/src/nic.cpp
index 197f5c7..040ca67 100644
--- a/src/nic.cpp
+++ b/src/nic.cpp
@@ -227,9 +227,9 @@ NICWrapper *NICWrapper::getNIC(ManagementAgent *agent,
  * calls.
  */
 void NICWrapper::fillNICInfo(vector <NICWrapper*> &nics,
-                             ManagementAgent *agent,
-                             LibHalContext *hal_ctx)
+                             ManagementAgent *agent)
 {
+  LibHalContext* hal_ctx = get_hal_ctx();
     char **net_devices;
     int num_results, i;
     net_devices = libhal_find_device_by_capability(hal_ctx,
diff --git a/src/nic.h b/src/nic.h
index c79ecf9..e0e5874 100644
--- a/src/nic.h
+++ b/src/nic.h
@@ -79,8 +79,7 @@ public:
     void setupQMFObject(ManagementAgent *agent, Manageable *parent);
     // Factory like method
     static void fillNICInfo(vector<NICWrapper*> &nics,
-                            ManagementAgent *agent,
-                            LibHalContext *ctx);
+                            ManagementAgent *agent);
 
     // QMF Methods
     ManagementObject *GetManagementObject(void) const { return mgmt_object; }
diff --git a/src/schema.xml b/src/schema.xml
index e6b54db..890e4ed 100644
--- a/src/schema.xml
+++ b/src/schema.xml
@@ -4,7 +4,7 @@
 
     <property name="uuid"       type="sstr"  access="RO" desc="Host UUID" index="y"/>
     <property name="hostname"   type="sstr"  access="RO" desc="Hostname"/>
-    <property name="memory"     type="int32" access="RO" desc="Amount of primary memory for host (kb)" unit="kb"/>
+    <property name="memory"     type="int64" access="RO" desc="Amount of primary memory for host (kb)" unit="kb"/>
     <property name="hypervisor" type="sstr"  access="RO" desc="Hypervisor used by host"/>
     <property name="arch"       type="sstr"  access="RO" desc="Architecture of host"/>
     <property name="beeping"    type="bool"  access="RW" desc="speaker beep loop active? (used to identify host)"/>
-- 
1.6.6.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]