mirror of
https://github.com/ansible/awx.git
synced 2026-04-04 17:55:06 -02:30
Add descriptions for plugin names (#15643)
* Add descriptions for plugin names * Update serializers to display plugin and plugin description * Add function to extract plugin name descriptions * Add description for scm * Conditionalize scm and file descriptions
This commit is contained in:
@@ -2325,8 +2325,11 @@ class InventorySourceOptionsSerializer(BaseSerializer):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
if 'source' in self.fields:
|
if 'source' in self.fields:
|
||||||
self.fields['source'].choices = load_combined_inventory_source_options()
|
source_options = load_combined_inventory_source_options()
|
||||||
|
|
||||||
|
self.fields['source'].choices = [(plugin, description) for plugin, description in source_options.items()]
|
||||||
|
|
||||||
def get_related(self, obj):
|
def get_related(self, obj):
|
||||||
res = super(InventorySourceOptionsSerializer, self).get_related(obj)
|
res = super(InventorySourceOptionsSerializer, self).get_related(obj)
|
||||||
|
|||||||
@@ -43,6 +43,24 @@ def compute_cloud_inventory_sources() -> dict[str, str]:
|
|||||||
return dict(zip(plugins, plugins), scm='scm', constructed='constructed')
|
return dict(zip(plugins, plugins), scm='scm', constructed='constructed')
|
||||||
|
|
||||||
|
|
||||||
|
@cache
|
||||||
|
def discover_available_cloud_provider_descriptions() -> dict[str, str]:
|
||||||
|
"""
|
||||||
|
Return a dictionary of cloud provider plugin descriptions
|
||||||
|
available.
|
||||||
|
|
||||||
|
:returns: Dictionary of plugin cloud descriptions.
|
||||||
|
:rtype: dict[str, str]
|
||||||
|
"""
|
||||||
|
from awx.main.models.inventory import InventorySourceOptions
|
||||||
|
|
||||||
|
plugin_description_list = [(plugin_name, plugin.plugin_description) for plugin_name, plugin in InventorySourceOptions.injectors.items()]
|
||||||
|
|
||||||
|
plugin_description = dict(plugin_description_list)
|
||||||
|
|
||||||
|
return plugin_description
|
||||||
|
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def load_combined_inventory_source_options() -> dict[str, str]:
|
def load_combined_inventory_source_options() -> dict[str, str]:
|
||||||
"""
|
"""
|
||||||
@@ -56,4 +74,14 @@ def load_combined_inventory_source_options() -> dict[str, str]:
|
|||||||
|
|
||||||
plugins = compute_cloud_inventory_sources()
|
plugins = compute_cloud_inventory_sources()
|
||||||
|
|
||||||
return dict(zip(plugins, plugins), file='file')
|
plugin_description = discover_available_cloud_provider_descriptions()
|
||||||
|
|
||||||
|
if 'scm' in plugins:
|
||||||
|
plugin_description['scm'] = 'Sourced from a Project'
|
||||||
|
|
||||||
|
if 'file' in plugins:
|
||||||
|
plugin_description['file'] = 'File-based inventory source'
|
||||||
|
|
||||||
|
result = {plugin: plugin_description.get(plugin, plugin) for plugin in plugins}
|
||||||
|
|
||||||
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user