Re: [sandbox][PATCH v2] Fix delete of running container

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 07, 2013 at 09:24:14PM +0800, Wayne Sun wrote:
> Delete running container is not supprted and will report an error.
> 
> Related to bug:
> https://bugzilla.redhat.com/show_bug.cgi?id=994495
> 
> Signed-off-by: Wayne Sun <gsun@xxxxxxxxxx>
> ---
>  bin/virt-sandbox-service |   15 ++++++++++-----
>  1 files changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service
> index 550d46c..c07c33b 100755
> --- a/bin/virt-sandbox-service
> +++ b/bin/virt-sandbox-service
> @@ -254,11 +254,16 @@ class Container:
>  
>      def delete(self):
>          self.connect()
> -        # Stop service if it is running
> -        try:
> -            self.stop()
> -        except:
> -            pass
> +        # Check container is running or not
> +        cmd = "/usr/bin/virsh -c %s list | sed '1d;2d;$d' | awk -F' '\
> +               '{ print $2}'" % self.uri
> +        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
> +        out, err = p.communicate()
> +        if p.returncode and p.returncode != 0:
> +            raise OSError(_("Failed to list running domain"))
> +
> +        if self.name in out.splitlines():
> +            raise ValueError([_("Delete running container is not supported")])

virt-sandbox-service already has a connection to libvirt - no need to
spawn virsh here. Just do something like this (untested):

    self.conn.fetch_domains()
    dom  = self.conn.find_domain_by_name(self.name)
    info = dom.get_info()
    if info.state == LibvirtGObject.DomainState.RUNNING:
         .....error...


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]