Repository: ansible/awx
File: awx/main/utils/plugins.py (Python)

Code before:
    available plus source control management and constructed.

    :returns: Dictionary of plugin cloud names plus source control.
    :rtype: dict[str, str]
    """

    plugins = discover_available_cloud_provider_plugin_names()

    return dict(zip(plugins, plugins), scm='scm', constructed='constructed')


@cache
def load_combined_inventory_source_options() -> dict[str, str]:
    """
    Return a dictionary of cloud provider plugin names and 'file'.

    The 'file' entry is included separately since it needs to be consumed directly by the serializer.

    :returns: A dictionary of cloud provider plugin names (as both keys and values) plus the 'file' entry.
    :rtype: dict[str, str]
    """

    plugins = compute_cloud_inventory_sources()

    plugin_descriptions = {
        'azure_rm': 'Microsoft Azure Resource Manager',
        'ec2': 'Amazon EC2',
        'gce': 'Google Compute Engine',
        'vmware': 'VMware vCenter',
        'satellite6': 'Red Hat Satellite 6',
        'satellite6_supported': 'Supported Red Hat Satellite 6',
        'openstack': 'OpenStack',
        'rhv': 'Red Hat Virtualization',
        'rhv_supported': 'Supported Red Hat Virtualization',
        'foreman': 'Red Hat Satellite 6',
        'terraform': 'Terraform',
        'controller': 'Red Hat Ansible Automation Platform',
        'controller_supported': 'Supported Red Hat Ansible Automation Platform',
        'openshift_virtualization': 'OpenShift Virtualization',
        'openshift_virtualization_supported': 'Supported OpenShift Virtualization',
        'scm': 'Sourced from a Project',
        'insights': 'Red Hat Insights',
        'insights_supported': 'Red Hat Insights',
        'kubevirt': 'OpenShift Virtualization',
        'constructed': 'Template additional groups and hostvars at runtime',
    }

    result = {plugin: plugin_descriptions.get(plugin, plugin) for plugin in plugins}

    result['file'] = 'File-based inventory source'


Review comment (suggestion):
The description lives in `awx-plugins`. For example here is the azure description https://github.com/ansible/awx-plugins/blob/devel/src/awx_plugins/inventory/plugins.py#L154

We don't want the descriptions to be hard-coded here in awx because we don't know the entire set of plugins.

Say we introduce a new plugin. Call it `foo`. We wouldn't want to update this dictionary and add the description for `foo`. Instead, we want the description for `foo` to live _with_ the plugin, over in `awx-plugins`.


Code after:
    available plus source control management and constructed.

    :returns: Dictionary of plugin cloud names plus source control.
    :rtype: dict[str, str]
    """

    plugins = discover_available_cloud_provider_plugin_names()

    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
def load_combined_inventory_source_options() -> dict[str, str]:
    """
    Return a dictionary of cloud provider plugin names and 'file'.

    The 'file' entry is included separately since it needs to be consumed directly by the serializer.

    :returns: A dictionary of cloud provider plugin names (as both keys and values) plus the 'file' entry.
    :rtype: dict[str, str]
    """

    plugins = compute_cloud_inventory_sources()

    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}