[Kimchi-devel] [PATCH 1/3] probe that libvirt support to change a live VM network source
shaohef at linux.vnet.ibm.com
shaohef at linux.vnet.ibm.com
Fri May 9 15:41:03 UTC 2014
From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
This is a good feature to user, but it is not supported by low version
libvirt.
So we need to probe it.
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
src/kimchi/featuretests.py | 43 ++++++++++++++++++++++++++++++++++++++++++-
src/kimchi/model/config.py | 3 +++
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py
index 5192361..6eb29f4 100644
--- a/src/kimchi/featuretests.py
+++ b/src/kimchi/featuretests.py
@@ -62,8 +62,25 @@ SIMPLE_VM_XML = """
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
+ <devices>
+ %s
+ </devices>
</domain>"""
+SIMPLE_NETWORK_XML = """
+<network>
+ <name>%s</name>
+</network>
+"""
+
+VM_IFACE_XML = """
+<interface type='network'>
+ <mac address='52:54:00:12:34:56'/>
+ <source network='%s'/>
+ <model type='rtl8139'/>
+</interface>
+"""
+
SCSI_FC_XML = """
<pool type='scsi'>
<name>TEST_SCSI_FC_POOL</name>
@@ -196,7 +213,7 @@ class FeatureTests(object):
rollback.prependDefer(FeatureTests.enable_screen_error_logging)
conn = libvirt.open('qemu:///system')
rollback.prependDefer(conn.close)
- dom = conn.defineXML(SIMPLE_VM_XML)
+ dom = conn.defineXML(SIMPLE_VM_XML % "")
rollback.prependDefer(dom.undefine)
try:
dom.setMetadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT,
@@ -206,3 +223,27 @@ class FeatureTests(object):
return True
except libvirt.libvirtError:
return False
+
+ @staticmethod
+ def change_live_vm_network():
+ with RollbackContext() as rollback:
+ FeatureTests.disable_screen_error_logging()
+ rollback.prependDefer(FeatureTests.enable_screen_error_logging)
+ conn = libvirt.open('qemu:///system')
+ rollback.prependDefer(conn.close)
+ net1_name = "isolated_test_net1"
+ net2_name = "isolated_test_net2"
+ net1 = conn.networkCreateXML(SIMPLE_NETWORK_XML % net1_name)
+ rollback.prependDefer(net1.destroy)
+ net2 = conn.networkCreateXML(SIMPLE_NETWORK_XML % net2_name)
+ rollback.prependDefer(net2.destroy)
+ iface1_xml = VM_IFACE_XML % net1_name
+ iface2_xml = VM_IFACE_XML % net2_name
+ dom = conn.createXML(SIMPLE_VM_XML % iface1_xml, flags=0)
+ rollback.prependDefer(dom.destroy)
+ try:
+ dom.updateDeviceFlags(iface2_xml,
+ libvirt.VIR_DOMAIN_AFFECT_LIVE)
+ return True
+ except libvirt.libvirtError:
+ return False
diff --git a/src/kimchi/model/config.py b/src/kimchi/model/config.py
index 0ef0855..88ab681 100644
--- a/src/kimchi/model/config.py
+++ b/src/kimchi/model/config.py
@@ -54,6 +54,7 @@ class CapabilitiesModel(object):
self.libvirt_stream_protocols = []
self.fc_host_support = False
self.metadata_support = False
+ self.change_live_vm_network = False
# Subscribe function to set host capabilities to be run when cherrypy
# server is up
@@ -67,6 +68,8 @@ class CapabilitiesModel(object):
self.nfs_target_probe = FeatureTests.libvirt_support_nfs_probe()
self.fc_host_support = FeatureTests.libvirt_support_fc_host()
self.metadata_support = FeatureTests.has_metadata_support()
+ self.change_live_vm_network = FeatureTests.change_live_vm_network()
+
self.libvirt_stream_protocols = []
for p in ['http', 'https', 'ftp', 'ftps', 'tftp']:
--
1.9.0
More information about the Kimchi-devel
mailing list