From 22024478c3ff07b20cd3f1dbddea3c4efc6f2dab Mon Sep 17 00:00:00 2001 From: FroggyFlox Date: Fri, 6 Sep 2019 15:12:31 -0400 Subject: [PATCH] Take image tag into account when updating DImage model during parsing of rock-on JSON definition file. Add image tag to docker rmi command to ensure the correct image is deleted if two different image versions are present on the system. --- src/rockstor/scripts/rockon_delete.py | 10 ++++++---- src/rockstor/storageadmin/views/rockon.py | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/rockstor/scripts/rockon_delete.py b/src/rockstor/scripts/rockon_delete.py index 1e142214b..70f2afc26 100644 --- a/src/rockstor/scripts/rockon_delete.py +++ b/src/rockstor/scripts/rockon_delete.py @@ -19,10 +19,10 @@ """ import sys + from storageadmin.models import (RockOn, DContainer) from system.osi import run_command - DOCKER = '/usr/bin/docker' @@ -44,9 +44,11 @@ def delete_rockon(): # We don't throw any exceptions because we want to ensure metadata is # deleted for sure. It would be nice to fully delete containers and # images, but that's not a hard requirement. - run_command([DOCKER, 'stop', c.name], throw=False) - run_command([DOCKER, 'rm', c.name], throw=False) - run_command([DOCKER, 'rmi', c.dimage.name], throw=False) + run_command([DOCKER, 'stop', c.name], throw=False, log=True) + run_command([DOCKER, 'rm', c.name], throw=False, log=True) + # Get image name with tag information + img_plus_tag = '{}:{}'.format(c.dimage.name, c.dimage.tag) + run_command([DOCKER, 'rmi', img_plus_tag], throw=False, log=True) ro.delete() print('Rock-On(%s) metadata in the db is deleted' % name) diff --git a/src/rockstor/storageadmin/views/rockon.py b/src/rockstor/storageadmin/views/rockon.py index 887f98e43..be8d999dc 100644 --- a/src/rockstor/storageadmin/views/rockon.py +++ b/src/rockstor/storageadmin/views/rockon.py @@ -195,9 +195,9 @@ def _create_update_meta(self, name, r_d): co.dimage.delete() if (co is None): co = DContainer(name=c, rockon=ro) - defaults = {'tag': c_d.get('tag', 'latest'), - 'repo': 'na', } + defaults = {'repo': 'na', } io, created = DImage.objects.get_or_create(name=c_d['image'], + tag=c_d.get('tag', 'latest'), defaults=defaults) co.dimage = io co.launch_order = c_d['launch_order']