On 06/29/2012 03:58 AM, tangchen wrote:
> 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.

This looks okay to me.  There may be complication if networking 
information is changing, but vm.virtnet is not updated and would get out 
of sync.  However, based on connect_uti, info. may be changing on a 
remote (i.e. not autotest client) machine.  This is reminder to me: Take 
a closer look at this interface later.

-- 
Chris Evich, RHCA, RHCE, RHCDS, RHCSS
Quality Assurance Engineer
e-mail: cevich + `@' + redhat.com o: 1-888-RED-HAT1 x44214
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to