mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02: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:
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(
|
parser.add_argument(
|
||||||
'path',
|
'path',
|
||||||
type=str,
|
type=str,
|
||||||
|
nargs=1,
|
||||||
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',
|
||||||
)
|
)
|
||||||
@@ -19,7 +20,7 @@ class Command(BaseCommand):
|
|||||||
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'))
|
pip_data = get_custom_venv_pip_freeze(options.get('path')[0])
|
||||||
if pip_data:
|
if pip_data:
|
||||||
print(pip_data)
|
print(pip_data)
|
||||||
msg = [
|
msg = [
|
||||||
@@ -27,5 +28,3 @@ class Command(BaseCommand):
|
|||||||
'awx-manage list_custom_venvs',
|
'awx-manage list_custom_venvs',
|
||||||
]
|
]
|
||||||
print('\n'.join(msg))
|
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.")
|
|
||||||
Reference in New Issue
Block a user