# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1211403918 25200
# Node ID 94274683dee5aed5621dc555c8604dc56b378c85
# Parent 93dbca94a762bb2ba443025db96d43977484c40d
[TEST] #2 Update create_netpool_conf() to support new pool creation.
This includes the following changes:
-Updated create_netpool_conf() so that caller can specify whether to use an existing pool
or create a new pool.
-Added destroy_netpool() / destroy_vnet()
-Updated CIM_NetResourceAllocationSettingData to set the PoolID
-Added xml_get_net_network().
Updates:
-Removed if statement for setting the value of self.ResourceType. This value should
always be for network devices.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 93dbca94a762 -r 94274683dee5 suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Jun 19 01:42:12 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Wed May 21 14:05:18 2008 -0700
@@ -22,6 +22,7 @@
#
import os
import pywbem
+import random
from distutils.file_util import move_file
from XenKvmLib.test_xml import *
from XenKvmLib.test_doms import *
@@ -331,19 +332,22 @@
return status, diskid
-def create_netpool_conf(server, virt):
+def create_netpool_conf(server, virt, use_existing=True):
status = PASS
test_network = None
try:
- vir_network = net_list(server, virt)
- if len(vir_network) > 0:
- test_network = vir_network[0]
- else:
- netxml = NetXML(server, virt=virt)
+ if use_existing == True:
+ vir_network = net_list(server, virt)
+ if len(vir_network) > 0:
+ test_network = vir_network[0]
+
+ if test_network == None:
+ net_name = "default-net" + str(random.randint(1, 100))
+ netxml = NetXML(server, virt=virt, networkname=net_name)
ret = netxml.create_vnet()
if not ret:
logger.error("Failed to create Virtual Network '%s'",
- test_network)
+ net_name)
status = FAIL
else:
test_network = netxml.xml_get_netpool_name()
@@ -351,3 +355,17 @@
logger.error("Exception: In fn create_netpool_conf(): %s", detail)
status=FAIL
return status, test_network
+
+def destroy_netpool(server, virt, net_name):
+ if net_name == None:
+ return FAIL
+
+ netxml = NetXML(server, virt=virt, networkname=net_name)
+ ret = netxml.destroy_vnet()
+ if not ret:
+ logger.error("Failed to destroy Virtual Network '%s'",
+ net_name)
+ return FAIL
+
+ return PASS
+
diff -r 93dbca94a762 -r 94274683dee5 suites/libvirt-cim/lib/XenKvmLib/vsms.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vsms.py Thu Jun 19 01:42:12 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/vsms.py Wed May 21 14:05:18 2008 -0700
@@ -151,13 +151,13 @@
pass
class CIM_NetResourceAllocationSettingData(CIMClassMOF):
- def __init__(self, type, mac, name):
+ def __init__(self, type, mac, name, virt_net=None):
self.Address = mac
self.NetworkType = type
- if type == 'ethernet' or type == 'bridge' :
- self.ResourceType = RASD_TYPE_NET_ETHER
- else:
- self.ResourceType = RASD_TYPE_NET_OTHER
+ self.ResourceType = RASD_TYPE_NET_ETHER
+
+ if virt_net != None :
+ self.PoolID = "NetworkPool/%s" % virt_net
if mac != None:
self.InstanceID = '%s/%s' % (name, mac)
diff -r 93dbca94a762 -r 94274683dee5 suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Thu Jun 19 01:42:12 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Wed May 21 14:05:18 2008 -0700
@@ -214,6 +214,9 @@
def create_vnet(self):
return self.run(self.server, 'net-create', self.xml_string)
+
+ def destroy_vnet(self):
+ return self.run(self.server, 'net-destroy', self.net_name)
def xml_get_netpool_name(self):
npoolname = self.get_value_xpath('/network/name')