[Ovirt-devel] [PATCH matahari] Created the NetworkDevice agent.

Darryl L. Pierce dpierce at redhat.com
Mon Apr 26 19:49:58 UTC 2010


Created a new class to represent network interface devices, named
NetworkDeviceAgent.

Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
 src/Makefile.am        |    9 +-
 src/host.cpp           |   26 +++--
 src/host.h             |    4 +-
 src/linux_platform.cpp |   70 +++++++++++
 src/linux_platform.h   |    4 +
 src/networkdevice.cpp  |   49 ++++++++
 src/networkdevice.h    |   52 +++++++++
 src/nic.cpp            |  297 ------------------------------------------------
 src/nic.h              |   95 ---------------
 src/platform.h         |    5 +
 src/processors.h       |    5 +
 src/schema.xml         |   22 +---
 12 files changed, 214 insertions(+), 424 deletions(-)
 create mode 100644 src/networkdevice.cpp
 create mode 100644 src/networkdevice.h
 delete mode 100644 src/nic.cpp
 delete mode 100644 src/nic.h

diff --git a/src/Makefile.am b/src/Makefile.am
index e4f394d..92ccec7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,10 +5,9 @@ sbin_PROGRAMS = matahari
 first = qmf/com/redhat/matahari/Host.cpp
 
 generated_file_list = \
-	qmf/com/redhat/matahari/ArgsNICIdentify_nic.h \
 	qmf/com/redhat/matahari/Host.h \
-	qmf/com/redhat/matahari/NIC.cpp \
-	qmf/com/redhat/matahari/NIC.h \
+	qmf/com/redhat/matahari/NetworkDevice.cpp \
+	qmf/com/redhat/matahari/NetworkDevice.h \
 	qmf/com/redhat/matahari/Package.cpp \
 	qmf/com/redhat/matahari/Package.h \
 	qmf/com/redhat/matahari/Processors.cpp \
@@ -24,8 +23,8 @@ matahari_SOURCES = \
 	linux_platform.cpp \
 	linux_platform.h \
 	main.cpp \
-	nic.cpp \
-	nic.h \
+	networkdevice.cpp \
+	networkdevice.h \
 	platform.cpp \
 	platform.h \
 	processors.cpp \
diff --git a/src/host.cpp b/src/host.cpp
index 11c5a8f..34d4550 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -25,6 +25,7 @@
 #include <sys/utsname.h>
 
 #include "host.h"
+#include "platform.h"
 #include "qmf/com/redhat/matahari/Host.h"
 
 using namespace qpid::management;
@@ -41,6 +42,14 @@ HostAgent::setup(ManagementAgent* agent)
 
   // discover the aspects of the host
   processors.setup(agent, this);
+  networkdevices = Platform::instance()->get_network_devices();
+
+  for(vector<NetworkDeviceAgent>::iterator iter = networkdevices.begin();
+      iter != networkdevices.end();
+      iter++)
+    {
+      iter->setup(agent, this);
+    }
 
   struct utsname details;
   string uuid         = "Unknown";
@@ -94,20 +103,17 @@ HostAgent::setup(ManagementAgent* agent)
   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);
-    }
 }
 
 void
 HostAgent::update(void)
 {
   processors.update();
+
+  for(vector<NetworkDeviceAgent>::iterator iter = networkdevices.begin();
+      iter != networkdevices.end();
+      iter++)
+    {
+      iter->update();
+    }
 }
diff --git a/src/host.h b/src/host.h
index ba5a1ed..d2da776 100644
--- a/src/host.h
+++ b/src/host.h
@@ -26,7 +26,7 @@
 
 #include "qmf/com/redhat/matahari/Host.h"
 
-#include "nic.h"
+#include "networkdevice.h"
 #include "processors.h"
 
 using namespace qpid::management;
@@ -39,7 +39,7 @@ class HostAgent : public Manageable
  private:
   qmf::com::redhat::matahari::Host* management_object;
   ProcessorsAgent processors;
-  vector<NICWrapper*> nics;
+  vector<NetworkDeviceAgent> networkdevices;
 
  public:
   HostAgent() {}
diff --git a/src/linux_platform.cpp b/src/linux_platform.cpp
index 26418f5..fbcfdb9 100644
--- a/src/linux_platform.cpp
+++ b/src/linux_platform.cpp
@@ -18,9 +18,14 @@
  */
 
 #include <fstream>
+#include <iomanip>
 #include <iostream>
+#include <dirent.h>
+#include <net/if.h>
 #include <pcre.h>
 #include <stdexcept>
+#include <string.h>
+#include <sys/ioctl.h>
 
 // TODO remove this wrapper once rhbz#583747 is fixed
 extern "C" {
@@ -115,3 +120,68 @@ LinuxPlatform::get_load_average() const
 
   return load_average;
 }
+
+vector<NetworkDeviceAgent>
+LinuxPlatform::get_network_devices() const
+{
+  vector<NetworkDeviceAgent> result;
+
+  DIR* entries = opendir("/sys/class/net");
+
+  if(entries)
+    {
+      struct udev* udev = udev_new();
+      struct dirent* entry;
+
+      while(entry = (readdir(entries)))
+        {
+          string ifname = string(entry->d_name);
+          if(ifname != "." && ifname != "..")
+            {
+              string fullpath = "/sys/class/net/" + ifname;
+              struct udev_device* device = udev_device_new_from_syspath(udev,
+                                                                        fullpath.c_str());
+
+              if(udev_device_get_property_value(device, "ID_BUS"))
+                {
+                  int sock = socket(AF_INET, SOCK_DGRAM, 0);
+                  struct ifreq ifr;
+                  string vendor = string(udev_device_get_property_value(device, "ID_VENDOR_FROM_DATABASE"));
+                  string model  = string(udev_device_get_property_value(device, "ID_MODEL_FROM_DATABASE"));
+
+                  if(sock >= 0)
+                    {
+                      ifr.ifr_addr.sa_family = AF_INET;
+                      strncpy(ifr.ifr_name, ifname.c_str(), IFNAMSIZ - 1);
+
+                      if(!ioctl(sock, SIOCGIFHWADDR, &ifr))
+                        {
+                          char macaddr[256];
+
+                          sprintf(macaddr,
+                                  "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
+                                  (unsigned char )ifr.ifr_hwaddr.sa_data[0],
+                                  (unsigned char )ifr.ifr_hwaddr.sa_data[1],
+                                  (unsigned char )ifr.ifr_hwaddr.sa_data[2],
+                                  (unsigned char )ifr.ifr_hwaddr.sa_data[3],
+                                  (unsigned char )ifr.ifr_hwaddr.sa_data[4],
+                                  (unsigned char )ifr.ifr_hwaddr.sa_data[5]);
+
+                          result.push_back(NetworkDeviceAgent(ifname,
+                                                              vendor,
+                                                              model,
+                                                              string(macaddr)));
+                        }
+                    }
+
+                  udev_device_unref(device);
+                }
+            }
+        }
+
+      udev_unref(udev);
+      closedir(entries);
+   }
+
+  return result;
+}
diff --git a/src/linux_platform.h b/src/linux_platform.h
index 13116df..095bc08 100644
--- a/src/linux_platform.h
+++ b/src/linux_platform.h
@@ -21,7 +21,10 @@
  */
 
 #include <string>
+#include <vector>
+
 #include "platform.h"
+#include "networkdevice.h"
 
 class LinuxPlatform : public Platform
 {
@@ -30,6 +33,7 @@ class LinuxPlatform : public Platform
   virtual ~LinuxPlatform() {}
 
   virtual double get_load_average() const;
+  virtual vector<NetworkDeviceAgent> get_network_devices() const;
 };
 
 #endif
diff --git a/src/networkdevice.cpp b/src/networkdevice.cpp
new file mode 100644
index 0000000..5e30e33
--- /dev/null
+++ b/src/networkdevice.cpp
@@ -0,0 +1,49 @@
+/* networkingdevice.cpp - Copyright (C) 2010 Red Hat, Inc.
+ * Written by Darryl L. Pierce <dpierce at redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.  A copy of the GNU General Public License is
+ * also available at http://www.gnu.org/copyleft/gpl.html.
+ */
+
+#include <qpid/agent/ManagementAgent.h>
+#include <qpid/management/Manageable.h>
+
+#include "networkdevice.h"
+
+namespace _qmf = qmf::com::redhat::matahari;
+
+NetworkDeviceAgent::NetworkDeviceAgent(string ifname, string vendor, string model, string macaddr)
+  :ifname(ifname)
+  ,vendor(vendor)
+  ,model(model)
+  ,macaddr(macaddr)
+{}
+
+void
+NetworkDeviceAgent::setup(ManagementAgent* agent, Manageable* parent)
+{
+  management_object = new _qmf::NetworkDevice(agent, this, parent);
+  agent->addObject(management_object);
+
+  management_object->set_interface(ifname);
+  management_object->set_vendor(vendor);
+  management_object->set_model(model);
+  management_object->set_mac_address(macaddr);
+}
+
+void
+NetworkDeviceAgent::update() const
+{
+}
diff --git a/src/networkdevice.h b/src/networkdevice.h
new file mode 100644
index 0000000..3884b22
--- /dev/null
+++ b/src/networkdevice.h
@@ -0,0 +1,52 @@
+#ifndef __NETWORKDEVICE_H
+#define __NETWORKDEVICE_H
+
+/* networkdevice.h - Copyright (C) 2010 Red Hat, Inc.
+ * Written by Darryl L. Pierce <dpierce at redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.  A copy of the GNU General Public License is
+ * also available at http://www.gnu.org/copyleft/gpl.html.
+ */
+
+#include <qpid/management/Manageable.h>
+
+#include "qmf/com/redhat/matahari/NetworkDevice.h"
+
+using namespace qpid::management;
+using namespace std;
+
+class NetworkDeviceAgent : public Manageable
+{
+ private:
+  qmf::com::redhat::matahari::NetworkDevice* management_object;
+
+  string ifname;
+  string vendor;
+  string model;
+  string macaddr;
+
+ public:
+  NetworkDeviceAgent(string ifname, string vendor, string model, string macaddr);
+  virtual ~NetworkDeviceAgent() {}
+
+  string get_mac_address() const { return macaddr; }
+
+  ManagementObject* GetManagementObject(void) const { return management_object; }
+
+  void setup(ManagementAgent* agent, Manageable* parent);
+  void update() const;
+};
+
+#endif
diff --git a/src/nic.cpp b/src/nic.cpp
deleted file mode 100644
index 040ca67..0000000
--- a/src/nic.cpp
+++ /dev/null
@@ -1,297 +0,0 @@
-/* nic.cpp - Copyright (C) 2009 Red Hat, Inc.
- * Written by Arjun Roy <arroy at redhat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.  A copy of the GNU General Public License is
- * also available at http://www.gnu.org/copyleft/gpl.html.
- */
-
-#include <iostream>
-#include <string>
-#include <sstream>
-#include <vector>
-#include <stdexcept>
-
-#include <hal/libhal.h>
-#include <cstdio>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <linux/types.h>
-#include <linux/ethtool.h>
-#include <linux/sockios.h>
-#include <linux/if.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <errno.h>
-
-#include "nic.h"
-#include "qmf/com/redhat/matahari/NIC.h"
-#include "qmf/com/redhat/matahari/ArgsNICIdentify_nic.h"
-
-using namespace qpid::management;
-using namespace std;
-
-using qpid::management::Manageable;
-
-namespace _qmf = qmf::com::redhat::matahari;
-
-extern DBusConnection *dbus_connection;
-extern DBusError dbus_error;
-
-ostream &operator<<(ostream& output, const NICWrapper& nic) {
-    output << "NIC" << endl;
-    output << "Interface Name: " << nic.interfaceName << endl;
-    output << "MAC Address: " << nic.macaddr << endl;
-    output << "IP Address: " << nic.ipaddr << endl;
-    output << "Netmask: " << nic.netmask << endl;
-    output << "Broadcast: " << nic.broadcast << endl;
-    output << "Bandwidth: " << nic.bandwidth << endl;
-    return output;
-}
-
-void NICWrapper::setupQMFObject(ManagementAgent *agent, Manageable *parent)
-{
-    mgmt_object = new _qmf::NIC(agent, this, parent);
-    agent->addObject(mgmt_object);
-    syncQMFObject();
-}
-
-void NICWrapper::cleanupQMFObject(void)
-{
-    mgmt_object->resourceDestroy();
-}
-
-void NICWrapper::syncQMFObject(void)
-{
-    mgmt_object->set_interface(interfaceName);
-    mgmt_object->set_macaddr(macaddr);
-    mgmt_object->set_ipaddr(ipaddr);
-    mgmt_object->set_netmask(netmask);
-    mgmt_object->set_broadcast(broadcast);
-    mgmt_object->set_bandwidth(bandwidth);
-}
-
-NICWrapper *NICWrapper::getNIC(ManagementAgent *agent,
-                   LibHalContext *hal_ctx,
-                   char *nic_handle)
-{
-    // Used to get the data
-    char *macaddr_c;
-    char *interface_c;
-    int sock, ret;
-    struct ifreq ifr;
-    struct ethtool_cmd ecmd;
-
-    // The data that we care about
-    NICWrapper *nic = NULL;
-    string macaddr;
-    string interface;
-    string ipaddr;
-    string netmask;
-    string broadcast;
-    int bandwidth;
-
-    // Grab the MAC Address from libhal
-    macaddr_c = libhal_device_get_property_string(hal_ctx,
-                                                nic_handle,
-                                                "net.address",
-                                                &dbus_error);
-    // Or throw an exception if we could not find it. No cleanup yet.
-    if (!macaddr_c)
-        throw runtime_error("Could not get mac address for NIC");
-
-    // Grab the interface name from libhal or return cleanup and fail
-    interface_c = libhal_device_get_property_string(hal_ctx,
-                          nic_handle,
-                          "net.interface",
-                          &dbus_error);
-    // Or cleanup the macaddr and return NULL.
-    if (!interface_c) {
-        libhal_free_string(macaddr_c);
-        throw runtime_error("Could not get interface name for nic");
-    }
-
-    // Open socket for running ioctls for getting rest of data
-    sock = socket(AF_INET, SOCK_DGRAM, 0);
-    if (sock >= 0) {
-        // Get the IP Address
-        ifr.ifr_addr.sa_family = AF_INET;
-        strncpy(ifr.ifr_name, interface_c, IFNAMSIZ - 1);
-        cout << interface_c << endl;
-
-        ret = ioctl(sock, SIOCGIFADDR, &ifr);
-        if(ret == 0) {
-            struct sockaddr_in *addr = (struct sockaddr_in *) &ifr.ifr_addr;
-            cout << "ip_address = " << inet_ntoa(addr->sin_addr) << endl;
-            ipaddr = inet_ntoa(addr->sin_addr);
-        }
-        else {
-            perror("SIOCGIFADDR");
-            ipaddr = "unable to determine";
-        }
-        // Get the netmask
-        ret = ioctl(sock, SIOCGIFNETMASK, &ifr);
-        if(ret == 0 && strcmp("255.255.255.255",
-            inet_ntoa(((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr))) {
-
-            struct sockaddr_in *addr = (struct sockaddr_in *) &ifr.ifr_addr;
-            cout << "netmask = " << inet_ntoa(addr->sin_addr) << endl;
-            netmask = inet_ntoa(addr->sin_addr);
-        }
-        else {
-            perror("SIOCGIFNETMASK");
-            netmask = "unable to determine";
-        }
-        // Get the broadcast address
-        ret = ioctl(sock, SIOCGIFBRDADDR, &ifr);
-        if(ret == 0) {
-            struct sockaddr_in *addr = (struct sockaddr_in *) &ifr.ifr_addr;
-            cout << "broadcast = " << inet_ntoa(addr->sin_addr);
-            broadcast = inet_ntoa(addr->sin_addr);
-        }
-        else {
-            perror("SIOCGIFBRDADDR");
-            broadcast = "unable to determine";
-        }
-        // Get the bandwidth for this NIC
-        ecmd.cmd = ETHTOOL_GSET;
-        ifr.ifr_data = (caddr_t)&ecmd;
-        bandwidth = 10;
-
-        // TODO: Error checking on this ioctl. For now, assume success
-        ret = ioctl(sock, SIOCETHTOOL, &ifr);
-        if (1) {
-
-            if (ecmd.supported & SUPPORTED_10000baseT_Full) {
-                bandwidth = 10000;
-            } else if (ecmd.supported & SUPPORTED_2500baseX_Full) {
-                bandwidth = 2500;
-            } else if (ecmd.supported & (SUPPORTED_1000baseT_Half |
-                                       SUPPORTED_1000baseT_Full)) {
-                bandwidth = 1000;
-            } else if (ecmd.supported & (SUPPORTED_100baseT_Half |
-                                       SUPPORTED_100baseT_Full)) {
-                bandwidth = 100;
-            } else if (ecmd.supported & (SUPPORTED_10baseT_Half |
-                                       SUPPORTED_10baseT_Full)) {
-                bandwidth = 10;
-            }
-        }
-        else {
-            cout << "Unable to determine link speed, defaulting to 10" << endl;
-        }
-        // And we're done here
-        close(sock);
-    }
-    else {
-        /* Couldn't open socket, so cleanup and fail */
-        libhal_free_string(interface_c);
-        libhal_free_string(macaddr_c);
-        throw runtime_error("Unable to open socket.");
-    }
-    // We have all the data. Create the NICWrapper instance
-    macaddr = macaddr_c;
-    interface = interface_c;
-    nic = new NICWrapper(interface,
-                         macaddr,
-                         ipaddr,
-                         netmask,
-                         broadcast,
-                         bandwidth);
-
-    // Free resources and return
-    libhal_free_string(interface_c);
-    libhal_free_string(macaddr_c);
-    return nic;
-}
-
-/**
- * void fillNICInfo(vector <NICWrapper*> &nics,
- *                  ManagementAgent *agent,
- *                  LibHalContext *hal_ctx)
- *
- * Takes in a vector of NICWrapper object pointers and populates it with
- * NICs found in the system found by querying dbus and making other system
- * calls.
- */
-void NICWrapper::fillNICInfo(vector <NICWrapper*> &nics,
-                             ManagementAgent *agent)
-{
-  LibHalContext* hal_ctx = get_hal_ctx();
-    char **net_devices;
-    int num_results, i;
-    net_devices = libhal_find_device_by_capability(hal_ctx,
-                           "net.80203",
-                           &num_results,
-                           &dbus_error);
-    if (!net_devices)
-        throw runtime_error("Error: Couldn't get NIC devices through libhal.");
-
-    cout << "Found " << num_results << " NICs" << endl;
-    for (i = 0; i < num_results; i++) {
-        NICWrapper *nic;
-        char *nic_handle = net_devices[i];
-        // If we couldn't read the info for a nic, free the list of devices
-        // and throw an error. Any devices added already will be cleaned up
-        // by the caller.
-        try {
-            nic = getNIC(agent, hal_ctx, nic_handle);
-        }
-        catch (...) {
-            libhal_free_string_array(net_devices);
-            throw;
-        }
-        // Add the NIC to our list
-        nics.push_back(nic);
-    }
-    // And we're all done.
-    libhal_free_string_array(net_devices);
-}
-
-int NICWrapper::identifyNIC(int seconds)
-{
-    struct ethtool_value edata;
-    struct ifreq ifr;
-    int sock, ret;
-
-    edata.cmd = ETHTOOL_PHYS_ID;
-    edata.data = seconds; // seconds of blink time
-
-    strncpy(ifr.ifr_name, interfaceName.c_str(), IFNAMSIZ - 1);
-    ifr.ifr_data = (caddr_t)&edata;
-
-    sock = socket(AF_INET, SOCK_DGRAM, 0);
-    ret = ioctl(sock, SIOCETHTOOL, &ifr);
-    close(sock);
-
-    if (ret != 0)
-        ret = errno;
-
-    return ret;
-}
-
-Manageable::status_t
-NICWrapper::ManagementMethod(uint32_t methodId, Args& args, string& text)
-{
-    switch (methodId) {
-        case _qmf::NIC::METHOD_IDENTIFY_NIC:
-            _qmf::ArgsNICIdentify_nic& ioArgs = (_qmf::ArgsNICIdentify_nic&) args;
-            int seconds = ioArgs.i_seconds;
-            ioArgs.o_ret = identifyNIC(seconds);
-            return STATUS_OK;
-    }
-
-    return STATUS_NOT_IMPLEMENTED;
-}
diff --git a/src/nic.h b/src/nic.h
deleted file mode 100644
index e0e5874..0000000
--- a/src/nic.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/* nic.h - Copyright (C) 2009 Red Hat, Inc.
- * Written by Arjun Roy <arroy at redhat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.  A copy of the GNU General Public License is
- * also available at http://www.gnu.org/copyleft/gpl.html.
- */
-
-#include <qpid/management/Manageable.h>
-#include <qpid/management/ManagementObject.h>
-#include <qpid/agent/ManagementAgent.h>
-
-#include "qmf/com/redhat/matahari/NIC.h"
-#include "hal.h"
-
-using namespace qpid::management;
-using namespace std;
-
-using qpid::management::Manageable;
-
-class NICWrapper : public Manageable
-{
-    friend ostream& operator <<(ostream &output, const NICWrapper& nic);
-    friend class HostWrapper;
-
-    // NIC Parameters
-    string interfaceName;
-    string macaddr;
-    string ipaddr;
-    string netmask;
-    string broadcast;
-    int bandwidth;
-
-    // QMF related fields
-    ManagementAgent *agent;
-    qmf::com::redhat::matahari::NIC *mgmt_object;
-
-    // Methods to put up / take down QMF Objects
-    void cleanupQMFObject(void);
-    void syncQMFObject(void);
-
-    // Constructors and Destructor are private
-    NICWrapper() {}
-    NICWrapper(const NICWrapper&) {}
-    ~NICWrapper() {}
-
-    NICWrapper(const string &interfaceName__,
-               const string &macaddr__,
-               const string &ipaddr__,
-               const string &netmask__,
-               const string &broadcast__,
-               int bandwidth__) {
-        interfaceName = interfaceName__;
-        macaddr = macaddr__;
-        ipaddr = ipaddr__;
-        netmask = netmask__;
-        broadcast = broadcast__;
-        bandwidth = bandwidth__;
-    }
-
-    static NICWrapper *getNIC(ManagementAgent *agent,
-                       LibHalContext *hal_ctx,
-                       char *nic_handle);
-
-    int identifyNIC(int seconds);
-public:
-
-    void setupQMFObject(ManagementAgent *agent, Manageable *parent);
-    // Factory like method
-    static void fillNICInfo(vector<NICWrapper*> &nics,
-                            ManagementAgent *agent);
-
-    // QMF Methods
-    ManagementObject *GetManagementObject(void) const { return mgmt_object; }
-    status_t ManagementMethod(uint32_t methodId, Args& args, string& text);
-
-    // Field Accessors
-    const string &getInterfaceName(void) { return interfaceName; }
-    const string &getMacaddr(void) { return macaddr; }
-    const string &getIpaddr(void) { return ipaddr; }
-    const string &getNetmask(void) { return netmask; }
-    const string &getBroadcast(void) { return broadcast; }
-    int getBandwidth(void) { return bandwidth; }
-};
diff --git a/src/platform.h b/src/platform.h
index 514ad20..54fbe37 100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -21,6 +21,8 @@
  */
 
 #include <string>
+#include <vector>
+#include "networkdevice.h"
 
 using namespace std;
 
@@ -57,6 +59,9 @@ class Platform
 
   // returns the load average for the platform
   virtual double get_load_average() const = 0;
+
+  // returns the list of network devices for this platform
+  virtual vector<NetworkDeviceAgent> get_network_devices() const = 0;
 };
 
 #endif
diff --git a/src/processors.h b/src/processors.h
index 17a6a6a..e681453 100644
--- a/src/processors.h
+++ b/src/processors.h
@@ -1,3 +1,6 @@
+#ifndef __PROCESSORS_H
+#define __PROCESSORS_H
+
 /* processor.h - Copyright (C) 2010 Red Hat, Inc.
  * Written by Darryl L. Pierce <dpierce at redhat.com>
  *
@@ -48,3 +51,5 @@ class ProcessorsAgent : public Manageable
   // agent methods
   void update_load_averages(void) const;
 };
+
+#endif
diff --git a/src/schema.xml b/src/schema.xml
index 890e4ed..206e39b 100644
--- a/src/schema.xml
+++ b/src/schema.xml
@@ -23,21 +23,13 @@
     <statistic name="load_average" type="float" desc="The processing load average." />
   </class>
 
-  <class name="NIC">
-
-    <property name="host"      type="objId" access="RO" desc="Host that this NIC belongs to" index="y" references="Host" parentRef="y"/>
-    <property name="macaddr"   type="sstr"  access="RO" desc="MAC Address"                   index="y"/>
-    <property name="interface" type="sstr"  access="RO" desc="Interface name"/>
-    <property name="ipaddr"    type="sstr"  access="RO" desc="IP Address"/>
-    <property name="netmask"   type="sstr"  access="RO" desc="Netmask"/>
-    <property name="broadcast" type="sstr"  access="RO" desc="Broadcast"/>
-    <property name="bandwidth" type="int32" access="RO" desc="Bandwidth"/>
-
-    <method name="identify_nic" desc="Physically Identify NIC">
-      <arg name="seconds" dir="I" type="int32" />
-      <arg name="ret" dir="O" type="int32" />
-    </method>
-
+  <!-- represents a physical network device -->
+  <class name="NetworkDevice">
+    <property name="host"        type="objId" access="RC" desc="The host machine." index="y" references="Host" parentRef="y" />
+    <property name="mac_address" type="sstr"  access="RO" desc="The device's MAC address" index="y" />
+    <property name="vendor"      type="sstr"  access="RO" desc="The device vendor." />
+    <property name="model"       type="sstr"  access="RO" desc="The device model." />
+    <property name="interface"   type="sstr"  access="RO" desc="The interface name for the device." />
   </class>
 
 </schema>
-- 
1.6.6.1




More information about the ovirt-devel mailing list