mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 04:10:44 -03:30
add a -q flag to make scripting easier and general improvements for readability
This commit is contained in:
parent
c0b812c47a
commit
cece7ff741
@ -24,7 +24,7 @@ from awx.api.generics import APIView
|
||||
from awx.conf.registry import settings_registry
|
||||
from awx.main.analytics import all_collectors
|
||||
from awx.main.ha import is_ha_environment
|
||||
from awx.main.utils import get_awx_version, to_python_boolean, get_custom_venv_choices
|
||||
from awx.main.utils import get_awx_version, get_custom_venv_choices
|
||||
from awx.main.utils.licensing import validate_entitlement_manifest
|
||||
from awx.api.versioning import reverse, drf_reverse
|
||||
from awx.main.constants import PRIVILEGE_ESCALATION_METHODS
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from awx.main.utils.common import get_custom_venv_choices
|
||||
from awx.main.models import Organization, InventorySource, JobTemplate, Project
|
||||
import yaml
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
@ -17,6 +18,7 @@ class Command(BaseCommand):
|
||||
default='',
|
||||
help='run this with a path to a virtual environment as an argument to see the associated Job Templates, Organizations, Projects, and Inventory Sources.',
|
||||
)
|
||||
parser.add_argument('-q', action='store_true', help='run with -q to output only the results of the query.')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# look organiztions and unified job templates (which include JTs, workflows, and Inventory updates)
|
||||
@ -24,14 +26,26 @@ class Command(BaseCommand):
|
||||
results = {}
|
||||
path = options.get('path')
|
||||
if path:
|
||||
if path in get_custom_venv_choices(): # verify this is a valid path
|
||||
path = options.get('path')[0]
|
||||
if path[0] in get_custom_venv_choices(): # verify this is a valid path
|
||||
path = path[0]
|
||||
orgs = [{"name": org.name, "id": org.id} for org in Organization.objects.filter(custom_virtualenv=path)]
|
||||
jts = [{"name": jt.name, "id": jt.id} for jt in JobTemplate.objects.filter(custom_virtualenv=path)]
|
||||
proj = [{"name": proj.name, "id": proj.id} for proj in Project.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["Job Templates"] = jts
|
||||
results["Projects"] = proj
|
||||
results["Inventory Sources"] = invsrc
|
||||
print(results)
|
||||
results["organizations"] = orgs
|
||||
results["job_templates"] = jts
|
||||
results["projects"] = proj
|
||||
results["inventory_sources"] = invsrc
|
||||
print('\n', '# {}'.format("Virtual environments associations:"))
|
||||
print(yaml.dump(results))
|
||||
if not options.get('q'):
|
||||
msg = [
|
||||
'',
|
||||
'To list all (now deprecated) custom virtual environments run:',
|
||||
'awx-manage list_custom_venvs',
|
||||
'',
|
||||
'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))
|
||||
|
||||
@ -16,15 +16,22 @@ class Command(BaseCommand):
|
||||
default='',
|
||||
help='run this with a path to a virtual environment as an argument to see the pip freeze data',
|
||||
)
|
||||
parser.add_argument('-q', action='store_true', help='run with -q to output only the results of the query.')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
super(Command, self).__init__()
|
||||
if options.get('path'):
|
||||
pip_data = get_custom_venv_pip_freeze(options.get('path')[0])
|
||||
if pip_data:
|
||||
print('\n', '# {}'.format("Virtual environment contents:"))
|
||||
print(pip_data)
|
||||
msg = [
|
||||
'To list all (now deprecated) custom virtual environments run:',
|
||||
'awx-manage list_custom_venvs',
|
||||
]
|
||||
print('\n'.join(msg))
|
||||
if not options.get('q'):
|
||||
msg = [
|
||||
'To list all (now deprecated) custom virtual environments run:',
|
||||
'awx-manage list_custom_venvs',
|
||||
'',
|
||||
'To view the connections a (deprecated) virtual environment had in the database, run the following command while supplying the path as an argument:',
|
||||
'awx-manage custom_venv_associations /path/to/venv',
|
||||
'',
|
||||
]
|
||||
print('\n'.join(msg))
|
||||
|
||||
@ -10,20 +10,30 @@ from django.conf import settings
|
||||
class Command(BaseCommand):
|
||||
"""Returns a list of custom venv paths from the path passed in the argument"""
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('-q', action='store_true', help='run with -q to output only the results of the query.')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
super(Command, self).__init__()
|
||||
venvs = get_custom_venv_choices()
|
||||
if venvs:
|
||||
print('# {}'.format("Discovered virtual environments:"))
|
||||
print('\n', '# {}'.format("Discovered virtual environments:"))
|
||||
for venv in venvs:
|
||||
print(venv)
|
||||
if not options.get('q'):
|
||||
msg = [
|
||||
'',
|
||||
'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',
|
||||
'',
|
||||
'To view the connections a (deprecated) virtual environment had in the database, run the following command while supplying the path as an argument:',
|
||||
'awx-manage custom_venv_associations /path/to/venv',
|
||||
'',
|
||||
]
|
||||
print('\n'.join(msg))
|
||||
else:
|
||||
print('\n')
|
||||
|
||||
msg = [
|
||||
'',
|
||||
'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))
|
||||
else:
|
||||
msg = ["No custom virtual environments detected in:", settings.BASE_VENV_PATH]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user