mirror of
https://github.com/ansible/awx.git
synced 2026-01-19 05:31:22 -03:30
split unified job templates out into jts and projects because workflows
don't have custom virtualenvs & rename file so the command is shorter update copypasta and add sanity check
This commit is contained in:
parent
b256e5b79d
commit
c0b812c47a
37
awx/main/management/commands/custom_venv_associations.py
Normal file
37
awx/main/management/commands/custom_venv_associations.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright (c) 2021 Ansible, Inc.
|
||||
# All Rights Reserved
|
||||
|
||||
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
|
||||
|
||||
|
||||
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=1,
|
||||
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.',
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# look organiztions and unified job templates (which include JTs, workflows, and Inventory updates)
|
||||
super(Command, self).__init__()
|
||||
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]
|
||||
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)
|
||||
@ -12,6 +12,7 @@ class Command(BaseCommand):
|
||||
parser.add_argument(
|
||||
'path',
|
||||
type=str,
|
||||
nargs=1,
|
||||
default='',
|
||||
help='run this with a path to a virtual environment as an argument to see the pip freeze data',
|
||||
)
|
||||
@ -19,7 +20,7 @@ class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
super(Command, self).__init__()
|
||||
if options.get('path'):
|
||||
pip_data = get_custom_venv_pip_freeze(options.get('path'))
|
||||
pip_data = get_custom_venv_pip_freeze(options.get('path')[0])
|
||||
if pip_data:
|
||||
print(pip_data)
|
||||
msg = [
|
||||
@ -27,5 +28,3 @@ class Command(BaseCommand):
|
||||
'awx-manage list_custom_venvs',
|
||||
]
|
||||
print('\n'.join(msg))
|
||||
else:
|
||||
print("missing argument: please include a path argument following the command.")
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
# 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.")
|
||||
Loading…
x
Reference in New Issue
Block a user