mirror of
https://github.com/ansible/awx.git
synced 2026-02-27 15:58:45 -03:30
delete_prefix local
This commit is contained in:
@@ -23,7 +23,7 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def init_logging(self):
|
def init_logging(self):
|
||||||
log_levels = dict(enumerate([logging.ERROR, logging.INFO, logging.DEBUG, 0]))
|
log_levels = dict(enumerate([logging.ERROR, logging.INFO, logging.DEBUG, 0]))
|
||||||
self.logger = logging.getLogger('awx.main.commands.cleanup_sessions')
|
self.logger = logging.getLogger('awx.main.commands.cleanup_images')
|
||||||
self.logger.setLevel(log_levels.get(self.verbosity, 0))
|
self.logger.setLevel(log_levels.get(self.verbosity, 0))
|
||||||
handler = logging.StreamHandler()
|
handler = logging.StreamHandler()
|
||||||
handler.setFormatter(logging.Formatter('%(message)s'))
|
handler.setFormatter(logging.Formatter('%(message)s'))
|
||||||
@@ -34,6 +34,10 @@ class Command(BaseCommand):
|
|||||||
parser.add_argument('--dry-run', dest='dry_run', action='store_true', default=False, help='Dry run mode (show items that would ' 'be removed)')
|
parser.add_argument('--dry-run', dest='dry_run', action='store_true', default=False, help='Dry run mode (show items that would ' 'be removed)')
|
||||||
|
|
||||||
def delete_images(self, images_json):
|
def delete_images(self, images_json):
|
||||||
|
if self.dry_run:
|
||||||
|
delete_prefix = "Would delete"
|
||||||
|
else:
|
||||||
|
delete_prefix = "Deleting"
|
||||||
for e in images_json:
|
for e in images_json:
|
||||||
if 'Names' in e:
|
if 'Names' in e:
|
||||||
image_names = e['Names']
|
image_names = e['Names']
|
||||||
@@ -43,7 +47,7 @@ class Command(BaseCommand):
|
|||||||
for i in image_names:
|
for i in image_names:
|
||||||
if i not in self.images_in_use and i not in self.deleted:
|
if i not in self.images_in_use and i not in self.deleted:
|
||||||
self.deleted.append(i)
|
self.deleted.append(i)
|
||||||
self.logger.info(f"{self.delete_prefix} {i}: {image_size:.0f} MB")
|
self.logger.info(f"{delete_prefix} {i}: {image_size:.0f} MB")
|
||||||
if not self.dry_run:
|
if not self.dry_run:
|
||||||
subprocess.run(['podman', 'rmi', i, '-f'], stdout=subprocess.DEVNULL)
|
subprocess.run(['podman', 'rmi', i, '-f'], stdout=subprocess.DEVNULL)
|
||||||
|
|
||||||
@@ -73,10 +77,7 @@ class Command(BaseCommand):
|
|||||||
self.init_logging()
|
self.init_logging()
|
||||||
self.dry_run = bool(options.get('dry_run', False))
|
self.dry_run = bool(options.get('dry_run', False))
|
||||||
if self.dry_run:
|
if self.dry_run:
|
||||||
self.delete_prefix = "Would delete"
|
|
||||||
self.logger.info("Dry run enabled, images will not be deleted")
|
self.logger.info("Dry run enabled, images will not be deleted")
|
||||||
else:
|
|
||||||
self.delete_prefix = "Deleting"
|
|
||||||
if settings.IS_K8S:
|
if settings.IS_K8S:
|
||||||
raise CommandError("Cannot run cleanup tool on k8s installations")
|
raise CommandError("Cannot run cleanup tool on k8s installations")
|
||||||
self.cleanup_images()
|
self.cleanup_images()
|
||||||
|
|||||||
Reference in New Issue
Block a user