[libvirt] [sandbox][PATCH v3] Fix delete of running container

Delete running container is not supprted and will report an error. Related to bug: https://bugzilla.redhat.com/show_bug.cgi?id=994495 v1: Fix stop function and delete running container. v2: Delete running container is not allowed, spawn virsh to get domain status. v3: Using exist libvirt connection to get dom status. Signed-off-by: Wayne Sun <gsun@redhat.com> --- bin/virt-sandbox-service | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service index 550d46c..03873c9 100755 --- a/bin/virt-sandbox-service +++ b/bin/virt-sandbox-service @@ -254,11 +254,11 @@ class Container: def delete(self): self.connect() - # Stop service if it is running - try: - self.stop() - except: - pass + self.conn.fetch_domains(None) + dom = self.conn.find_domain_by_name(self.name) + info = dom.get_info() + if info.state == LibvirtGObject.DomainState.RUNNING: + raise ValueError([_("Cannot delete running container")]) # Not sure we should remove content if os.path.exists(self.dest): -- 1.7.1

On 08/08/2013 03:42 PM, 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
v1: Fix stop function and delete running container. v2: Delete running container is not allowed, spawn virsh to get domain status. v3: Using exist libvirt connection to get dom status.
Signed-off-by: Wayne Sun<gsun@redhat.com> --- bin/virt-sandbox-service | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service index 550d46c..03873c9 100755 --- a/bin/virt-sandbox-service +++ b/bin/virt-sandbox-service @@ -254,11 +254,11 @@ class Container:
def delete(self): self.connect() - # Stop service if it is running - try: - self.stop() - except: - pass + self.conn.fetch_domains(None) + dom = self.conn.find_domain_by_name(self.name) + info = dom.get_info() + if info.state == LibvirtGObject.DomainState.RUNNING: + raise ValueError([_("Cannot delete running container")])
# Not sure we should remove content if os.path.exists(self.dest):
Works for me. # virsh -c lxc:// list Id Name State ---------------------------------------------------- 7090 testbox running # virt-sandbox-service delete testbox /usr/bin/virt-sandbox-service: Cannot delete running container # echo $? 1 # virsh -c lxc:// list Id Name State ---------------------------------------------------- 7090 testbox running # virsh -c lxc:// destroy testbox Domain testbox destroyed # virsh -c lxc:// list --all Id Name State ---------------------------------------------------- - testbox shut off # virt-sandbox-service delete testbox # echo $? 0 # virsh -c lxc:// list --all Nothing.

On Thu, Aug 08, 2013 at 03:42:28PM +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
v1: Fix stop function and delete running container. v2: Delete running container is not allowed, spawn virsh to get domain status. v3: Using exist libvirt connection to get dom status.
Signed-off-by: Wayne Sun <gsun@redhat.com> --- bin/virt-sandbox-service | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service index 550d46c..03873c9 100755 --- a/bin/virt-sandbox-service +++ b/bin/virt-sandbox-service @@ -254,11 +254,11 @@ class Container:
def delete(self): self.connect() - # Stop service if it is running - try: - self.stop() - except: - pass + self.conn.fetch_domains(None) + dom = self.conn.find_domain_by_name(self.name) + info = dom.get_info() + if info.state == LibvirtGObject.DomainState.RUNNING: + raise ValueError([_("Cannot delete running container")])
# Not sure we should remove content if os.path.exists(self.dest):
ACK, looks good now. 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 :|

On 08/08/2013 06:42 PM, Daniel P. Berrange wrote:
On Thu, Aug 08, 2013 at 03:42:28PM +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
v1: Fix stop function and delete running container. v2: Delete running container is not allowed, spawn virsh to get domain status. v3: Using exist libvirt connection to get dom status.
Signed-off-by: Wayne Sun<gsun@redhat.com> --- bin/virt-sandbox-service | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service index 550d46c..03873c9 100755 --- a/bin/virt-sandbox-service +++ b/bin/virt-sandbox-service @@ -254,11 +254,11 @@ class Container:
def delete(self): self.connect() - # Stop service if it is running - try: - self.stop() - except: - pass + self.conn.fetch_domains(None) + dom = self.conn.find_domain_by_name(self.name) + info = dom.get_info() + if info.state == LibvirtGObject.DomainState.RUNNING: + raise ValueError([_("Cannot delete running container")])
# Not sure we should remove content if os.path.exists(self.dest): ACK, looks good now.
Daniel
Daniel, I push this one now.
participants (3)
-
Alex Jia
-
Daniel P. Berrange
-
Wayne Sun