mirror of
https://github.com/ansible/awx.git
synced 2026-05-15 13:27:40 -02:30
Merge pull request #10090 from rebeccahhh/custom_venv_command
add a new awx-manage command `custom_venvs` add an awx-manage command that gets pip freeze data from custom_venv and outputs to command line stdout SUMMARY part of #7062 - this command is a glorified pip freeze + some extra stuff, people could navigate to each of their custom virtual environments themselves and run a pip freeze, but this allows them to not, and everyone likes their life to be easier. The extra stuff allows users to see the connections that their existing virtual envs have in awx to things like organizations, jobs, inventory updates, and projects. ISSUE TYPE Feature Pull Request COMPONENT NAME API AWX VERSION awx: 19.1.0 ADDITIONAL INFORMATION This is built off of existing code and there is a line that gets custom venv paths from the settings module, that line does not seem to be working. I have written around that but want to make a note of it. Reviewed-by: Alan Rominger <arominge@redhat.com> Reviewed-by: Rebeccah Hunter <rhunter@redhat.com> Reviewed-by: Jeff Bradberry <None> Reviewed-by: Shane McDonald <me@shanemcd.com> Reviewed-by: Elijah DeLee <kdelee@redhat.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import json
|
||||
import yaml
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import re
|
||||
import stat
|
||||
import subprocess
|
||||
@@ -916,30 +917,35 @@ def get_current_apps():
|
||||
return current_apps
|
||||
|
||||
|
||||
def get_custom_venv_choices(custom_paths=None):
|
||||
def get_custom_venv_choices():
|
||||
from django.conf import settings
|
||||
|
||||
custom_paths = custom_paths or settings.CUSTOM_VENV_PATHS
|
||||
all_venv_paths = [settings.BASE_VENV_PATH] + custom_paths
|
||||
all_venv_paths = settings.CUSTOM_VENV_PATHS + [settings.BASE_VENV_PATH]
|
||||
custom_venv_choices = []
|
||||
|
||||
for custom_venv_path in all_venv_paths:
|
||||
try:
|
||||
if os.path.exists(custom_venv_path):
|
||||
custom_venv_choices.extend(
|
||||
[
|
||||
os.path.join(custom_venv_path, x, '')
|
||||
for x in os.listdir(custom_venv_path)
|
||||
if x != 'awx'
|
||||
and os.path.isdir(os.path.join(custom_venv_path, x))
|
||||
and os.path.exists(os.path.join(custom_venv_path, x, 'bin', 'activate'))
|
||||
]
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Encountered an error while discovering custom virtual environments.")
|
||||
for venv_path in all_venv_paths:
|
||||
if os.path.exists(venv_path):
|
||||
for d in os.listdir(venv_path):
|
||||
if venv_path == settings.BASE_VENV_PATH and d == 'awx':
|
||||
continue
|
||||
|
||||
if os.path.exists(os.path.join(venv_path, d, 'bin', 'pip')):
|
||||
custom_venv_choices.append(os.path.join(venv_path, d))
|
||||
|
||||
return custom_venv_choices
|
||||
|
||||
|
||||
def get_custom_venv_pip_freeze(venv_path):
|
||||
pip_path = os.path.join(venv_path, 'bin', 'pip')
|
||||
|
||||
try:
|
||||
freeze_data = subprocess.run([pip_path, "freeze"], capture_output=True)
|
||||
pip_data = (freeze_data.stdout).decode('UTF-8')
|
||||
return pip_data
|
||||
except Exception:
|
||||
logger.exception("Encountered an error while trying to run 'pip freeze' for custom virtual environments:")
|
||||
|
||||
|
||||
def is_ansible_variable(key):
|
||||
return key.startswith('ansible_')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user