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