This patch adds 3 API for libvirt_vm.
1) vm.define()
2) vm.attach_interface()
3) vm.detach_interface()
Signed-off-by: Tang Chen <[email protected]>
---
client/virt/libvirt_vm.py | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py
index 46db911..8dd8d30 100644
--- a/client/virt/libvirt_vm.py
+++ b/client/virt/libvirt_vm.py
@@ -431,6 +431,23 @@ def virsh_migrate(options, name, dest_uri, extra, uri =
""):
return False
return True
+def virsh_attach_detach_interface(name, command, type, extra = "", uri = ""):
+ """
+ Attach a nic to VM.
+ """
+ cmd = "%s --domain %s " % (command, name)
+ if type not in ('bridge', 'network', 'user', 'ethernet', 'direct', \
+ 'hostdev', 'mcast', 'server', 'client', ''):
+ logging.error("Unknown interface type.")
+ return False
+ cmd += "--type %s %s" % (type, extra)
+ try:
+ virsh_cmd(cmd, uri)
+ return True
+ except error.CmdError:
+ logging.error("Attaching interface to VM %s failed." % name)
+ return False
+
def virsh_attach_device(name, xml_file, extra = "", uri = ""):
"""
Attach a device to VM.
@@ -578,6 +595,15 @@ class VM(virt_vm.BaseVM):
else:
return False
+ def define(self, path):
+ """
+ Define the VM.
+ @param path: VM xmlfile path.
+ """
+ if not os.path.exists(path):
+ logging.error("File %s not found." % path)
+ return False
+ return virsh_define(path, self.connect_uri)
def undefine(self):
"""
@@ -1235,6 +1261,20 @@ class VM(virt_vm.BaseVM):
self.connect_uri = dest_uri
return result
+ def attach_interface(self, type, extra = ""):
+ """
+ Attach a nic to VM.
+ """
+ return virsh_attach_detach_interface(self.name, "attach-interface", \
+ type, extra, self.connect_uri)
+
+ def detach_interface(self, type, extra = ""):
+ """
+ Detach a nic from VM.
+ """
+ return virsh_attach_detach_interface(self.name, "detach-interface", \
+ type, extra, self.connect_uri)
+
def attach_device(self, xml_file, extra = ""):
"""
Attach a device to VM.
--
1.7.3.1
--
Best Regards,
Tang chen
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest