Exemplo n.º 1
0
    def get_plugins_attributes(cls,
                               cluster,
                               all_versions=False,
                               default=False):
        """Gets attributes of all plugins connected with given cluster.

        :param cluster: A cluster instance
        :type cluster: nailgun.db.sqlalchemy.models.cluster.Cluster
        :param all_versions: True to get attributes of all versions of plugins
        :type all_versions: bool
        :param default: True to return a default plugins attributes (for UI)
        :type default: bool
        :return: Plugins attributes
        :rtype: dict
        """
        plugins_attributes = {}
        for plugin in ClusterPlugins.get_connected_plugins_data(cluster.id):
            db_plugin = Plugin.get_by_uid(plugin.id)
            plugin_adapter = wrap_plugin(db_plugin)
            default_attrs = plugin_adapter.attributes_metadata

            if all_versions:
                container = plugins_attributes.setdefault(plugin.name, {})
                enabled = plugin.enabled and not (all_versions and default)
                cls.create_common_metadata(plugin, container, enabled)
                container['metadata']['default'] = default

                versions = container['metadata'].setdefault('versions', [])
                if default:
                    actual_attrs = copy.deepcopy(default_attrs)
                    actual_attrs.setdefault('metadata', {})
                else:
                    actual_attrs = copy.deepcopy(plugin.attributes)
                    actual_attrs['metadata'] = default_attrs.get(
                        'metadata', {})
                cls.fill_plugin_metadata(plugin, actual_attrs['metadata'])
                versions.append(actual_attrs)

                container['metadata'].setdefault('chosen_id', plugin.id)
                if enabled:
                    container['metadata']['chosen_id'] = plugin.id

            elif plugin.enabled:
                container = plugins_attributes.setdefault(plugin.name, {})
                cls.create_common_metadata(plugin, container)
                container['metadata'].update(default_attrs.get('metadata', {}))
                cls.fill_plugin_metadata(plugin, container['metadata'])
                container.update(plugin.attributes)

        return plugins_attributes
Exemplo n.º 2
0
    def get_plugins_attributes(
            cls, cluster, all_versions=False, default=False):
        """Gets attributes of all plugins connected with given cluster.

        :param cluster: A cluster instance
        :type cluster: nailgun.db.sqlalchemy.models.cluster.Cluster
        :param all_versions: True to get attributes of all versions of plugins
        :type all_versions: bool
        :param default: True to return a default plugins attributes (for UI)
        :type default: bool
        :return: Plugins attributes
        :rtype: dict
        """
        plugins_attributes = {}
        for plugin in ClusterPlugins.get_connected_plugins_data(cluster.id):
            db_plugin = Plugin.get_by_uid(plugin.id)
            plugin_adapter = wrap_plugin(db_plugin)
            default_attrs = plugin_adapter.attributes_metadata

            if all_versions:
                container = plugins_attributes.setdefault(plugin.name, {})
                enabled = plugin.enabled and not (all_versions and default)
                cls.create_common_metadata(plugin, container, enabled)
                container['metadata']['default'] = default

                versions = container['metadata'].setdefault('versions', [])
                if default:
                    actual_attrs = copy.deepcopy(default_attrs)
                    actual_attrs.setdefault('metadata', {})
                else:
                    actual_attrs = copy.deepcopy(plugin.attributes)
                    actual_attrs['metadata'] = default_attrs.get('metadata',
                                                                 {})
                cls.fill_plugin_metadata(plugin, actual_attrs['metadata'])
                versions.append(actual_attrs)

                container['metadata'].setdefault('chosen_id', plugin.id)
                if enabled:
                    container['metadata']['chosen_id'] = plugin.id

            elif plugin.enabled:
                container = plugins_attributes.setdefault(plugin.name, {})
                cls.create_common_metadata(plugin, container)
                container['metadata'].update(default_attrs.get('metadata', {}))
                cls.fill_plugin_metadata(plugin, container['metadata'])
                container.update(plugin.attributes)

        return plugins_attributes
Exemplo n.º 3
0
    def get_plugins_attributes(cls,
                               cluster,
                               all_versions=False,
                               default=False):
        """Gets attributes of all plugins connected with given cluster.

        :param cluster: A cluster instance
        :type cluster: nailgun.objects.cluster.Cluster
        :param all_versions: True to get attributes of all versions of plugins
        :type all_versions: bool
        :param default: True to return a default plugins attributes (for UI)
        :type default: bool
        :return: Plugins attributes
        :rtype: dict
        """
        versions = {
            'type': 'radio',
            'values': [],
            'weight': 10,
            'value': None,
            'label': 'Choose a plugin version'
        }

        plugins_attributes = {}
        for plugin in ClusterPlugins.get_connected_plugins_data(cluster.id):
            plugin_id = str(plugin.id)
            enabled = plugin.enabled and not (all_versions and default)
            plugin_attributes = plugins_attributes.setdefault(plugin.name, {})
            metadata = plugin_attributes.setdefault('metadata', {
                'toggleable': True,
                'weight': 70
            })
            metadata['enabled'] = enabled or metadata.get('enabled', False)
            metadata['label'] = plugin.title
            if plugin.is_hotpluggable:
                metadata["always_editable"] = True

            if all_versions:
                metadata['default'] = default

                plugin_attributes.update(
                    cls.convert_plugin_attributes(
                        plugin, plugin.attributes_metadata
                        if default else plugin.attributes))

                plugin_version = {
                    'data': plugin_id,
                    'description': '',
                    'label': plugin.version,
                }
                if not plugin.is_hotpluggable:
                    plugin_version['restrictions'] = [{
                        'action':
                        'disable',
                        'condition':
                        'cluster:is_locked'
                    }]

                plugin_versions = plugin_attributes.get('plugin_versions')
                if plugin_versions is not None:
                    if enabled:
                        plugin_versions['value'] = plugin_id
                else:
                    plugin_versions = copy.deepcopy(versions)
                    plugin_versions['value'] = plugin_id
                    plugin_attributes['plugin_versions'] = plugin_versions

                plugin_versions['values'].append(plugin_version)
            elif enabled:
                plugin_attributes.update(plugin.attributes)

        return plugins_attributes
Exemplo n.º 4
0
    def get_plugins_attributes(
            cls, cluster, all_versions=False, default=False):
        """Gets attributes of all plugins connected with given cluster.

        :param cluster: A cluster instance
        :type cluster: nailgun.objects.cluster.Cluster
        :param all_versions: True to get attributes of all versions of plugins
        :type all_versions: bool
        :param default: True to return a default plugins attributes (for UI)
        :type default: bool
        :return: Plugins attributes
        :rtype: dict
        """
        versions = {
            'type': 'radio',
            'values': [],
            'weight': 10,
            'value': None,
            'label': 'Choose a plugin version'
        }

        plugins_attributes = {}
        for plugin in ClusterPlugins.get_connected_plugins_data(cluster.id):
            plugin_id = str(plugin.id)
            enabled = plugin.enabled and not (all_versions and default)
            plugin_attributes = plugins_attributes.setdefault(plugin.name, {})
            metadata = plugin_attributes.setdefault('metadata', {
                'toggleable': True,
                'weight': 70
            })
            metadata['enabled'] = enabled or metadata.get('enabled', False)
            metadata['label'] = plugin.title
            if plugin.is_hotpluggable:
                metadata["always_editable"] = True

            if all_versions:
                metadata['default'] = default

                plugin_attributes.update(
                    cls.convert_plugin_attributes(
                        plugin,
                        plugin.attributes_metadata
                        if default else plugin.attributes
                    )
                )

                plugin_version = {
                    'data': plugin_id,
                    'description': '',
                    'label': plugin.version,
                }
                if not plugin.is_hotpluggable:
                    plugin_version['restrictions'] = [{
                        'action': 'disable',
                        'condition': 'cluster:is_locked'
                    }]

                plugin_versions = plugin_attributes.get('plugin_versions')
                if plugin_versions is not None:
                    if enabled:
                        plugin_versions['value'] = plugin_id
                else:
                    plugin_versions = copy.deepcopy(versions)
                    plugin_versions['value'] = plugin_id
                    plugin_attributes['plugin_versions'] = plugin_versions

                plugin_versions['values'].append(plugin_version)
            elif enabled:
                plugin_attributes.update(plugin.attributes)

        return plugins_attributes