Add 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 | 54 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py
index d6ae7fb..ac689d3 100644
--- a/client/virt/libvirt_vm.py
+++ b/client/virt/libvirt_vm.py
@@ -477,6 +477,34 @@ def virsh_detach_device(name, xml_file, extra="", uri=""):
return False
+def virsh_attach_interface(name, option="", uri="", ignore_status=False,
print_info=False):
+ """
+ Attach a NIC to VM.
+ """
+ cmd = "attach-interface "
+
+ if name:
+ cmd += "--domain %s" % name
+ if option:
+ cmd += " %s" % option
+
+ return virsh_cmd(cmd, uri, ignore_status, print_info)
+
+
+def virsh_detach_interface(name, option="", uri="", ignore_status=False,
print_info=False):
+ """
+ Detach a NIC to VM.
+ """
+ cmd = "detach-interface "
+
+ if name:
+ cmd += "--domain %s" % name
+ if option:
+ cmd += " %s" % option
+
+ return virsh_cmd(cmd, uri, ignore_status, print_info)
+
+
class VM(virt_vm.BaseVM):
"""
This class handles all basic VM operations for libvirt.
@@ -571,6 +599,16 @@ class VM(virt_vm.BaseVM):
return virsh_undefine(self.name, self.connect_uri)
+ def define(self, xml_file):
+ """
+ Define the VM.
+ """
+ if not os.path.exists(xml_file):
+ logging.error("File %s not found." % xml_file)
+ return False
+ return virsh_define(xml_file, self.connect_uri)
+
+
def state(self):
"""
Return domain state.
@@ -1295,6 +1333,22 @@ class VM(virt_vm.BaseVM):
return virsh_detach_device(self.name, xml_file, extra,
self.connect_uri)
+ def attach_interface(self, option="", ignore_status=False,
print_info=False):
+ """
+ Attach a NIC to VM.
+ """
+ return virsh_attach_interface(self.name, option, self.connect_uri,
+ ignore_status=False, print_info=False)
+
+
+ def detach_interface(self, option="", ignore_status=False,
print_info=False):
+ """
+ Detach a NIC to VM.
+ """
+ return virsh_detach_interface(self.name, option, self.connect_uri,
+ ignore_status=False, print_info=False)
+
+
def destroy(self, gracefully=True, free_mac_addresses=True):
"""
Destroy the VM.
--
1.7.3.1
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest