[Libvirt-cim] [PATCH] Code was added to parse input and generate

Sharad Mishra snmishra at us.ibm.com
Fri Jun 19 20:26:48 UTC 2009


# HG changeset patch
# User snmishra at us.ibm.com
# Date 1245184531 25200
# Node ID 5553213124aa2aaba274de49b78ed5c396d4e98f
# Parent  a1420debfc6fd48cb8b2ab23e4225e25e9881035
#2 Add support for bridge type NICs.
Code was added to parse input and generate
libvirt XML to support bridge devices.
Net_RASD mof was updated to add bridge device name.

Signed-off-by: Sharad Mishra <snmishra at us.ibm.com>

diff -r a1420debfc6f -r 5553213124aa libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h	Wed Jun 17 11:36:40 2009 -0700
+++ b/libxkutil/device_parsing.h	Tue Jun 16 13:35:31 2009 -0700
@@ -47,6 +47,7 @@
         char *mac;
         char *source;
         char *model;
+        char *name;
 };
 
 struct mem_device {
diff -r a1420debfc6f -r 5553213124aa libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c	Wed Jun 17 11:36:40 2009 -0700
+++ b/libxkutil/xmlgen.c	Tue Jun 16 13:35:31 2009 -0700
@@ -164,10 +164,12 @@
 {
         xmlNodePtr tmp;
 
-        if (dev->source != NULL) {
-                tmp = xmlNewChild(nic, NULL, BAD_CAST "source", NULL);
-                if (tmp == NULL) 
-                        return XML_ERROR;
+        tmp = xmlNewChild(nic, NULL, BAD_CAST "source", NULL);
+        if (tmp == NULL) 
+                return XML_ERROR;
+        if ((STREQC(src_type, "bridge")) && (dev->name != NULL)) {
+                xmlNewProp(tmp, BAD_CAST src_type, BAD_CAST dev->name);
+        } else if ((STREQC(src_type, "network")) && (dev->source != NULL)) {
                 xmlNewProp(tmp, BAD_CAST src_type, BAD_CAST dev->source);
         }
 
@@ -225,7 +227,7 @@
                 if (STREQ(dev->dev.net.type, "network"))
                         msg = set_net_source(nic, net, "network");
                 else if (STREQ(dev->dev.net.type, "bridge"))
-                        msg = bridge_net_to_xml(root, net);
+                        msg = bridge_net_to_xml(nic, net);
                 else if (STREQ(dev->dev.net.type, "user"))
                         continue;
                 else
diff -r a1420debfc6f -r 5553213124aa schema/ResourceAllocationSettingData.mof
--- a/schema/ResourceAllocationSettingData.mof	Wed Jun 17 11:36:40 2009 -0700
+++ b/schema/ResourceAllocationSettingData.mof	Tue Jun 16 13:35:31 2009 -0700
@@ -57,6 +57,10 @@
       [Description ("Interface type")]
       string NetworkType;
 
+      [Description ("Bridge name")]
+      string NetworkName;
+
+
 };
 
 [Description ("KVM virtual network configuration"),
@@ -68,6 +72,9 @@
       [Description ("Interface type")]
       string NetworkType;
 
+      [Description ("Bridge name")]
+      string NetworkName;
+
 };
 
 [Description ("LXC virtual network configuration"),
diff -r a1420debfc6f -r 5553213124aa src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Wed Jun 17 11:36:40 2009 -0700
+++ b/src/Virt_VirtualSystemManagementService.c	Tue Jun 16 13:35:31 2009 -0700
@@ -59,6 +59,8 @@
 
 #define DEFAULT_MAC_PREFIX "00:16:3e"
 #define DEFAULT_XEN_WEIGHT 1024
+#define BRIDGE_TYPE "bridge"
+#define NETWORK_TYPE "network"
 
 const static CMPIBroker *_BROKER;
 
@@ -553,22 +555,37 @@
         dev->id = strdup(dev->dev.net.mac);
 
         free(dev->dev.net.type);
-        dev->dev.net.type = strdup("network");
+        free(dev->dev.net.name);
+        if (cu_get_str_prop(inst, "NetworkType", &val) != CMPI_RC_OK) 
+                return "No Network Type specified";
+        if (STREQC(val, BRIDGE_TYPE)) {
+                dev->dev.net.type = strdup(BRIDGE_TYPE);
+                if (cu_get_str_prop(inst, "NetworkName", &val) == CMPI_RC_OK) 
+                        if (strlen(val) > 0)
+                                dev->dev.net.name = strdup(val);
+                        else
+                                return "bridge name is empty";
+                else 
+                        return "No Network bridge name specified";
+         } else if (STREQC(val, NETWORK_TYPE)) {
+                dev->dev.net.type = strdup(NETWORK_TYPE);
+                if (cu_get_str_prop(inst, "PoolID", &val) != CMPI_RC_OK)
+                        val = _default_network(inst, ns);
 
-        if (cu_get_str_prop(inst, "PoolID", &val) != CMPI_RC_OK)
-                val = _default_network(inst, ns);
+                if (val == NULL)
+                        return "No NetworkPool specified no default available";
 
-        if (val == NULL)
-                return "No NetworkPool specified and no default available";
+                free(dev->dev.net.source);
+                dev->dev.net.source = name_from_pool_id(val);
 
-        free(dev->dev.net.source);
-        dev->dev.net.source = name_from_pool_id(val);
-
-        free(dev->dev.net.model);
-        if (cu_get_str_prop(inst, "ResourceSubType", &val) != CMPI_RC_OK)
-                dev->dev.net.model = NULL; 
-        else 
-                dev->dev.net.model = strdup(val);
+                free(dev->dev.net.model);
+                if (cu_get_str_prop(inst, "ResourceSubType", &val) 
+                        != CMPI_RC_OK)
+                        dev->dev.net.model = NULL; 
+                else 
+                        dev->dev.net.model = strdup(val);
+        } else
+                return "Invalid Network Type specified";
 
  out:
         return msg;




More information about the Libvirt-cim mailing list