adding in a 3rd command that shows the associated templates, orgs, and invs the venv is tied to

This commit is contained in:
Rebeccah 2021-05-21 11:36:34 -04:00
parent 2ed3038a5c
commit b256e5b79d
No known key found for this signature in database
GPG Key ID: 40B19D22F2604B29
3 changed files with 38 additions and 4 deletions

View File

@ -12,7 +12,6 @@ class Command(BaseCommand):
parser.add_argument(
'path',
type=str,
nargs='?',
default='',
help='run this with a path to a virtual environment as an argument to see the pip freeze data',
)
@ -24,7 +23,7 @@ class Command(BaseCommand):
if pip_data:
print(pip_data)
msg = [
'To list all available custom virtual environments run:',
'To list all (now deprecated) custom virtual environments run:',
'awx-manage list_custom_venvs',
]
print('\n'.join(msg))

View File

@ -0,0 +1,35 @@
# Copyright (c) 2021 Ansible, Inc.
# All Rights Reserved
from django.core.management.base import BaseCommand
from awx.main.models import Organization, InventorySource, UnifiedJobTemplate
class Command(BaseCommand):
"""Returns the pip freeze from the path passed in the argument"""
def add_arguments(self, parser):
parser.add_argument(
'path',
type=str,
nargs='?',
default='',
help='run this with a path to a virtual environment as an argument to see the pip freeze data',
)
def handle(self, *args, **options):
# look organiztions and unified job templates (which include JTs, workflows, and Inventory updates)
super(Command, self).__init__()
results = {}
if options.get('path'):
# sanity check here - is path in list
path = options.get('path')
orgs = [{"name": org.name, "id": org.id} for org in Organization.objects.filter(custom_virtualenv=path)]
ujts = [{"name": org.name, "id": org.id} for org in UnifiedJobTemplate.objects.filter(custom_virtualenv=path)]
invsrc = [{"name": inv.name, "id": inv.id} for inv in InventorySource.objects.filter(custom_virtualenv=path)]
results["Organizations"] = orgs
results["Unified Job Templates"] = ujts
results["Inventory Sources"] = invsrc
print(results)
else:
print("missing argument: please include a path argument following the command.")

View File

@ -8,7 +8,7 @@ from django.conf import settings
class Command(BaseCommand):
"""Returns either a list of custom venv paths from the path passed in the argument"""
"""Returns a list of custom venv paths from the path passed in the argument"""
def handle(self, *args, **options):
super(Command, self).__init__()
@ -20,7 +20,7 @@ class Command(BaseCommand):
msg = [
'',
'To export the contents of a virtual environment, ' 'run the following command while supplying the path as an argument:',
'To export the contents of a (deprecated) virtual environment, ' 'run the following command while supplying the path as an argument:',
'awx-manage export_custom_venv /path/to/venv',
]
print('\n'.join(msg))