def enable_plugins_by_components(cls, cluster): """Enable plugin by components. :param cluster: A cluster instance :type cluster: Cluster model """ cluster_components = set(cluster.components) plugin_ids = [p.id for p in PluginCollection.all_newest()] for plugin in ClusterPlugins.get_connected_plugins( cluster, plugin_ids): plugin_adapter = wrap_plugin(plugin) plugin_components = set( component['name'] for component in plugin_adapter.components_metadata) if cluster_components & plugin_components: ClusterPlugins.set_attributes( cluster.id, plugin.id, enabled=True)
def enable_plugins_by_components(cls, cluster): """Enable plugin by components. :param cluster: A cluster instance :type cluster: Cluster model """ cluster_components = set(cluster.components) plugin_ids = [p.id for p in PluginCollection.all_newest()] for plugin in ClusterPlugins.get_connected_plugins( cluster, plugin_ids): plugin_adapter = wrap_plugin(plugin) plugin_components = set( component['name'] for component in plugin_adapter.components_metadata) if cluster_components & plugin_components: ClusterPlugins.set_attributes(cluster.id, plugin.id, enabled=True)
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 = { u'type': u'radio', u'values': [], u'weight': 10, u'value': None, u'label': 'Choose a plugin version' } def _convert_attr(pid, name, title, attr): restrictions = attr.setdefault('restrictions', []) restrictions.append({ 'action': 'hide', 'condition': "settings:{0}.plugin_versions.value != '{1}'" .format(name, pid) }) return "#{0}_{1}".format(pid, title), attr plugins_attributes = {} for pid, name, title, version, enabled, default_attrs, cluster_attrs\ in ClusterPlugins.get_connected_plugins(cluster.id): if all_versions: enabled = enabled and not default data = plugins_attributes.get(name, {}) metadata = data.setdefault('metadata', { u'toggleable': True, u'weight': 70 }) metadata['enabled'] = enabled or metadata.get('enabled', False) metadata['label'] = title if all_versions: metadata['default'] = default attrs = default_attrs if default else cluster_attrs data.update(_convert_attr(pid, name, key, attrs[key]) for key in attrs) if 'plugin_versions' in data: plugin_versions = data['plugin_versions'] else: plugin_versions = copy.deepcopy(versions) plugin_versions['values'].append({ u'data': str(pid), u'description': '', u'label': version }) if not plugin_versions['value'] or enabled: plugin_versions['value'] = str(pid) data['plugin_versions'] = plugin_versions else: data.update(cluster_attrs if enabled else {}) plugins_attributes[name] = data return plugins_attributes
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 = { u'type': u'radio', u'values': [], u'weight': 10, u'value': None, u'label': 'Choose a plugin version' } def _convert_attr(pid, name, title, attr): restrictions = attr.setdefault('restrictions', []) restrictions.append({ 'action': 'hide', 'condition': "settings:{0}.plugin_versions.value != '{1}'".format( name, pid) }) return "#{0}_{1}".format(pid, title), attr plugins_attributes = {} for pid, name, title, version, enabled, default_attrs, cluster_attrs\ in ClusterPlugins.get_connected_plugins(cluster.id): if all_versions: enabled = enabled and not default data = plugins_attributes.get(name, {}) metadata = data.setdefault('metadata', { u'toggleable': True, u'weight': 70 }) metadata['enabled'] = enabled or metadata.get('enabled', False) metadata['label'] = title if all_versions: metadata['default'] = default attrs = default_attrs if default else cluster_attrs data.update( _convert_attr(pid, name, key, attrs[key]) for key in attrs) if 'plugin_versions' in data: plugin_versions = data['plugin_versions'] else: plugin_versions = copy.deepcopy(versions) plugin_versions['values'].append({ u'data': str(pid), u'description': '', u'label': version }) if not plugin_versions['value'] or enabled: plugin_versions['value'] = str(pid) data['plugin_versions'] = plugin_versions else: data.update(cluster_attrs if enabled else {}) plugins_attributes[name] = data return plugins_attributes