# HG changeset patch
# User Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
# Date 1212493242 25200
# Node ID 05e8d5b17fd7e4d7eb3a6f1903fd834fcebcd311
# Parent 351d11163eaa0b0af28a9064177ad637aeeb2a8c
[TEST] Adding set_interface_details() fn to the vxml.py.
This function give choice to add different network types to
Xen/XenFV/KVM guest.
Signed-off-by: Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
diff -r 351d11163eaa -r 05e8d5b17fd7 suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Fri May 30 10:47:26 2008 +0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Tue Jun 03 04:40:42 2008 -0700
@@ -300,6 +300,10 @@ class VirtXML(Virsh, XMLClass):
self.set_attributes('/domain/devices/interface/source',
bridge=bridgename)
+ def set_nettype(self, nettype):
+ self.set_attributes('/domain/devices/interface/type',
+ type=nettype)
+
def set_diskimg(self, diskimg):
self.set_attributes('/domain/devices/disk/source', file=diskimg)
@@ -437,6 +441,39 @@ class VirtXML(Virsh, XMLClass):
return vbr
+ def set_interface_details(self, devices, net_mac, net_type, req_net_type,
virt_type):
+ if net_type != req_net_type:
+ interface = self.add_sub_node(devices, 'interface',
type=req_net_type)
+ else:
+ interface = self.add_sub_node(devices, 'interface', type=net_type)
+ self.add_sub_node(interface, 'mac', address=net_mac)
+ if req_net_type == 'bridge':
+ self._set_vbridge(CIM_IP, virt_type)
+ elif req_net_type == 'network':
+ self.set_vnetwork(interface, virt_type)
+ elif req_net_type == 'ethernet':
+ pass
+ else:
+ logger.error("%s is not a valid network type", net_type)
+ sys.exit(1)
+
+ def set_vnetwork(self, interface, virt_type):
+ network_list = live.net_list(CIM_IP, virt_type)
+ if len(network_list) > 0:
+ nname = network_list[0]
+ else:
+ logger.info('No virutal network found')
+ logger.info('Trying to create one ......')
+ netxml = NetXML(CIM_IP, virt_type)
+ ret = netxml.create_vnet()
+ if not ret:
+ logger.error('Failed to create the virtual network
"%s"',
+ netxml.net_name)
+ sys.exit(SKIP)
+ nname = netxml.xml_get_netpool_name()
+ self.add_sub_node(interface, 'source', network=nname)
+
+
class VirtCIM:
def __init__(self, virt, dom_name, disk_dev, disk_source,
@@ -497,7 +534,8 @@ class XenXML(VirtXML, VirtCIM):
vcpus=const.default_vcpus,
mac=const.Xen_default_mac,
disk_file_path=const.Xen_disk_path,
- disk=const.Xen_default_disk_dev):
+ disk=const.Xen_default_disk_dev,
+ req_nettype=const.Xen_default_net_type):
if not (os.path.exists(const.Xen_kernel_path) \
and os.path.exists(const.Xen_init_path)):
logger.error('ERROR: Either the kernel image '
@@ -505,7 +543,8 @@ class XenXML(VirtXML, VirtCIM):
sys.exit(1)
VirtXML.__init__(self, 'xen', test_dom, set_uuid(), mem, vcpus)
self._os(const.Xen_kernel_path, const.Xen_init_path)
- self._devices(disk_file_path, disk, const.Xen_default_net_type, mac)
+ self._devices(disk_file_path, disk, const.Xen_default_net_type, mac,
+ req_nettype)
VirtCIM.__init__(self, 'Xen', test_dom, disk, disk_file_path,
const.Xen_default_net_type, mac, vcpus, mem)
@@ -517,16 +556,15 @@ class XenXML(VirtXML, VirtCIM):
self.add_sub_node(os, 'initrd', os_initrd)
self.add_sub_node(os, 'cmdline', 'TERM=xterm')
- def _devices(self, disk_img, disk_dev, net_type, net_mac):
+ def _devices(self, disk_img, disk_dev, net_type, net_mac, req_nettype):
devices = self.get_node('/domain/devices')
disk = self.add_sub_node(devices, 'disk', type='file',
device='disk')
self.add_sub_node(disk, 'driver', name='file')
self.add_sub_node(disk, 'source', file=disk_img)
self.add_sub_node(disk, 'target', dev=disk_dev)
-
- interface = self.add_sub_node(devices, 'interface', type=net_type)
- self.add_sub_node(interface, 'mac', address=net_mac)
+ self.set_interface_details(devices, net_mac, net_type, req_nettype,
+ virt_type='Xen')
def set_bootloader(self, ip, gtype=0):
bldr = live.bootloader(ip, gtype)
@@ -552,19 +590,20 @@ class KVMXML(VirtXML):
vcpus=const.default_vcpus,
mac=const.KVM_default_mac,
disk_file_path=const.KVM_disk_path,
- disk=const.KVM_default_disk_dev):
+ disk=const.KVM_default_disk_dev,
+ req_nettype=const.KVM_default_net_type):
if not os.path.exists(disk_file_path):
logger.error('Error: Disk image does not exist')
sys.exit(1)
VirtXML.__init__(self, 'kvm', test_dom, set_uuid(), mem, vcpus)
self._os()
self._devices(const.KVM_default_emulator, const.KVM_default_net_type,
- disk_file_path, disk, mac)
+ disk_file_path, disk, mac, req_nettype)
def _os(self):
self.add_sub_node('/domain/os', 'type', 'hvm')
- def _devices(self, emu, net_type, disk_img, disk_dev, net_mac):
+ def _devices(self, emu, net_type, disk_img, disk_dev, net_mac, req_nettype):
devices = self.get_node('/domain/devices')
self.add_sub_node(devices, 'emulator', emu)
@@ -572,33 +611,9 @@ class KVMXML(VirtXML):
self.add_sub_node(disk, 'source', file=disk_img)
self.add_sub_node(disk, 'target', dev=disk_dev)
- interface = self.add_sub_node(devices, 'interface', type=net_type)
- self.add_sub_node(interface, 'mac', address=net_mac)
+ self.set_interface_details(devices, net_mac, net_type, req_nettype,
+ virt_type='KVM')
- if net_type == 'bridge':
- self.set_vbridge(CIM_IP)
- elif net_type == 'network':
- self.set_vnetwork(interface)
- else:
- logger.error("%s is not a valid network type", net_type)
- sys.exit(1)
-
- def set_vnetwork(self, interface):
- network_list = live.net_list(CIM_IP, virt='KVM')
- if len(network_list) > 0:
- nname = network_list[0]
- else:
- logger.info('No virutal network found')
- logger.info('Trying to create one ......')
- netxml = NetXML(CIM_IP, virt='KVM')
- ret = netxml.create_vnet()
- if not ret:
- logger.error('Failed to create the virtual network
"%s"',
- netxml.net_name)
- sys.exit(SKIP)
- nname = netxml.xml_get_netpool_name()
- self.add_sub_node(interface, 'source', network=nname)
-
def set_emulator(self, emu):
return self._set_emulator(emu)
@@ -618,14 +633,16 @@ class XenFVXML(VirtXML):
vcpus=const.default_vcpus,
mac=const.XenFV_default_mac,
disk_file_path=const.XenFV_disk_path,
- disk=const.XenFV_default_disk_dev):
+ disk=const.XenFV_default_disk_dev,
+ req_nettype=const.XenFV_default_net_type):
if not os.path.exists(disk_file_path):
logger.error('Error: Disk image does not exist')
sys.exit(1)
VirtXML.__init__(self, 'xen', test_dom, set_uuid(), mem, vcpus)
self._os(const.XenFV_default_loader)
self._devices(const.XenFV_default_emulator,
- const.XenFV_default_net_type, mac, disk_file_path, disk)
+ const.XenFV_default_net_type, mac, disk_file_path,
+ disk, req_nettype)
def _os(self, os_loader):
os = self.get_node('/domain/os')
@@ -633,18 +650,16 @@ class XenFVXML(VirtXML):
self.add_sub_node(os, 'loader', os_loader)
self.add_sub_node(os, 'boot', dev='hd')
- def _devices(self, emu, net_type, net_mac, disk_img, disk_dev):
+ def _devices(self, emu, net_type, net_mac, disk_img, disk_dev,
+ req_nettype):
devices = self.get_node('/domain/devices')
self.add_sub_node(devices, 'emulator', emu)
-
- interface = self.add_sub_node(devices, 'interface', type=net_type)
- self.add_sub_node(interface, 'mac', address=net_mac)
- self.set_bridge(CIM_IP)
-
disk = self.add_sub_node(devices, 'disk', type='file')
self.add_sub_node(disk, 'source', file=disk_img)
self.add_sub_node(disk, 'target', dev=disk_dev)
+ self.set_interface_details(devices, net_mac, net_type, req_nettype,
+ virt_type='XenFV')
def set_emulator(self, emu):
return self._set_emulator(emu)