Exemplo n.º 1
0
    def process_cluster_attributes(cls, cluster, attributes):
        """Generate Cluster-Plugins relation based on attributes.

        Iterates through plugins attributes, creates
        or deletes Cluster <-> Plugins relation if plugin
        is enabled or disabled.

        :param cluster: A cluster instance
        :type cluster: nailgun.db.sqlalchemy.models.cluster.Cluster
        :param attributes: Cluster attributes
        :type attributes: dict
        """
        plugins = {}

        # Detach plugins data
        for k in list(attributes):
            if cls.is_plugin_data(attributes[k]):
                plugins[k] = attributes.pop(k)['metadata']

        for container in six.itervalues(plugins):
            default = container.get('default', False)
            for attrs in container.get('versions', []):
                version_metadata = attrs.pop('metadata')
                plugin_id = version_metadata['plugin_id']
                plugin = Plugin.get_by_uid(plugin_id)
                if not plugin:
                    logger.warning(
                        'Plugin with id "%s" is not found, skip it', plugin_id)
                    continue
                enabled = container['enabled']\
                    and plugin_id == container['chosen_id']
                ClusterPlugin.set_attributes(
                    cluster.id, plugin.id, enabled=enabled,
                    attrs=attrs if enabled or default else None
                )
Exemplo n.º 2
0
    def process_cluster_attributes(cls, cluster, attributes):
        """Generate Cluster-Plugins relation based on attributes.

        Iterates through plugins attributes, creates
        or deletes Cluster <-> Plugins relation if plugin
        is enabled or disabled.

        :param cluster: A cluster instance
        :type cluster: nailgun.db.sqlalchemy.models.cluster.Cluster
        :param attributes: Cluster attributes
        :type attributes: dict
        """
        from nailgun.objects import Release

        plugins = {}

        # Detach plugins data
        for k in list(attributes):
            if cls.is_plugin_data(attributes[k]):
                plugins[k] = attributes.pop(k)['metadata']

        propagate_task_deploy = get_in(
            attributes, 'common', 'propagate_task_deploy', 'value')
        if propagate_task_deploy is not None:
            legacy_tasks_are_ignored = not propagate_task_deploy
        else:
            legacy_tasks_are_ignored = not get_in(
                cluster.attributes.editable,
                'common', 'propagate_task_deploy', 'value')

        for container in six.itervalues(plugins):
            default = container.get('default', False)
            for attrs in container.get('versions', []):
                version_metadata = attrs.pop('metadata')
                plugin_id = version_metadata['plugin_id']
                plugin = Plugin.get_by_uid(plugin_id)
                if not plugin:
                    logger.warning(
                        'Plugin with id "%s" is not found, skip it', plugin_id)
                    continue
                enabled = container['enabled'] \
                    and plugin_id == container['chosen_id']
                if (enabled and
                        Release.is_lcm_supported(cluster.release) and
                        legacy_tasks_are_ignored and
                        cls.contains_legacy_tasks(
                            wrap_plugin(Plugin.get_by_uid(plugin.id)))):
                    raise errors.InvalidData(
                        'Cannot enable plugin with legacy tasks unless '
                        'propagate_task_deploy attribute is set. '
                        'Ensure tasks.yaml is empty and all tasks '
                        'has version >= 2.0.0.')
                ClusterPlugin.set_attributes(
                    cluster.id, plugin.id, enabled=enabled,
                    attrs=attrs if enabled or default else None
                )
Exemplo n.º 3
0
    def process_cluster_attributes(cls, cluster, attributes):
        """Generate Cluster-Plugins relation based on attributes.

        Iterates through plugins attributes, creates
        or deletes Cluster <-> Plugins relation if plugin
        is enabled or disabled.

        :param cluster: A cluster instance
        :type cluster: nailgun.db.sqlalchemy.models.cluster.Cluster
        :param attributes: Cluster attributes
        :type attributes: dict
        """
        from nailgun.objects import Release

        plugins = {}

        # Detach plugins data
        for k in list(attributes):
            if cls.is_plugin_data(attributes[k]):
                plugins[k] = attributes.pop(k)['metadata']

        propagate_task_deploy = get_in(attributes, 'common',
                                       'propagate_task_deploy', 'value')
        if propagate_task_deploy is not None:
            legacy_tasks_are_ignored = not propagate_task_deploy
        else:
            legacy_tasks_are_ignored = not get_in(
                cluster.attributes.editable, 'common', 'propagate_task_deploy',
                'value')

        for container in six.itervalues(plugins):
            default = container.get('default', False)
            for attrs in container.get('versions', []):
                version_metadata = attrs.pop('metadata')
                plugin_id = version_metadata['plugin_id']
                plugin = Plugin.get_by_uid(plugin_id)
                if not plugin:
                    logger.warning('Plugin with id "%s" is not found, skip it',
                                   plugin_id)
                    continue
                enabled = container['enabled'] \
                    and plugin_id == container['chosen_id']
                if (enabled and Release.is_lcm_supported(cluster.release)
                        and legacy_tasks_are_ignored
                        and cls.contains_legacy_tasks(
                            wrap_plugin(Plugin.get_by_uid(plugin.id)))):
                    raise errors.InvalidData(
                        'Cannot enable plugin with legacy tasks unless '
                        'propagate_task_deploy attribute is set. '
                        'Ensure tasks.yaml is empty and all tasks '
                        'has version >= 2.0.0.')
                ClusterPlugin.set_attributes(
                    cluster.id,
                    plugin.id,
                    enabled=enabled,
                    attrs=attrs if enabled or default else None)
Exemplo n.º 4
0
    def get_plugins_node_roles(cls, cluster):
        result = {}
        core_roles = set(cluster.release.roles_metadata)

        for plugin_db in ClusterPlugin.get_enabled(cluster.id):
            plugin_roles = wrap_plugin(plugin_db).normalized_roles_metadata

            # we should check all possible cases of roles intersection
            # with core ones and those from other plugins
            # and afterwards show them in error message;
            # thus role names for which following checks
            # fails are accumulated in err_info variable
            err_roles = set(r for r in plugin_roles
                            if r in core_roles or r in result)
            if err_roles:
                raise errors.AlreadyExists(
                    "Plugin (ID={0}) is unable to register the following "
                    "node roles: {1}".format(plugin_db.id,
                                             ", ".join(sorted(err_roles))))

            # update info on processed roles in case of
            # success of all intersection checks
            result.update(plugin_roles)

        return result
Exemplo n.º 5
0
    def get_plugins_node_roles(cls, cluster):
        result = {}
        core_roles = set(cluster.release.roles_metadata)

        for plugin_db in ClusterPlugin.get_enabled(cluster.id):
            plugin_roles = wrap_plugin(plugin_db).normalized_roles_metadata

            # we should check all possible cases of roles intersection
            # with core ones and those from other plugins
            # and afterwards show them in error message;
            # thus role names for which following checks
            # fails are accumulated in err_info variable
            err_roles = set(
                r for r in plugin_roles if r in core_roles or r in result
            )
            if err_roles:
                raise errors.AlreadyExists(
                    "Plugin (ID={0}) is unable to register the following "
                    "node roles: {1}".format(plugin_db.id,
                                             ", ".join(sorted(err_roles)))
                )

            # update info on processed roles in case of
            # success of all intersection checks
            result.update(plugin_roles)

        return result
Exemplo n.º 6
0
    def get_plugins_deployment_graph(cls, cluster, graph_type=None):
        deployment_tasks = []
        processed_tasks = {}

        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        graph_metadata = {}
        for plugin_adapter in map(wrap_plugin, enabled_plugins):
            depl_graph = plugin_adapter.get_deployment_graph(graph_type)
            depl_tasks = depl_graph.pop('tasks')
            dict_update(graph_metadata, depl_graph)

            for t in depl_tasks:
                t_id = t['id']
                if t_id in processed_tasks:
                    raise errors.AlreadyExists(
                        'Plugin {0} is overlapping with plugin {1} '
                        'by introducing the same deployment task with '
                        'id {2}'.format(
                            plugin_adapter.full_name,
                            processed_tasks[t_id],
                            t_id
                        )
                    )
                processed_tasks[t_id] = plugin_adapter.full_name

            deployment_tasks.extend(depl_tasks)
        graph_metadata['tasks'] = deployment_tasks
        return graph_metadata
Exemplo n.º 7
0
    def get_network_roles(cls, cluster, merge_policy):
        """Returns the network roles from plugins.

        The roles cluster and plugins will be mixed
        according to merge policy.
        """

        instance_roles = cluster.release.network_roles_metadata
        all_roles = dict((role['id'], role) for role in instance_roles)
        conflict_roles = dict()

        for plugin in ClusterPlugin.get_enabled(cluster.id):
            for role in plugin.network_roles_metadata:
                role_id = role['id']
                if role_id in all_roles:
                    try:
                        merge_policy.apply_patch(
                            all_roles[role_id],
                            role
                        )
                    except errors.UnresolvableConflict as e:
                        logger.error("cannot merge plugin {0}: {1}"
                                     .format(plugin.name, e))
                        conflict_roles[role_id] = plugin.name
                else:
                    all_roles[role_id] = role

        if conflict_roles:
            raise errors.NetworkRoleConflict(
                "Cannot override existing network roles: '{0}' in "
                "plugins: '{1}'".format(
                    ', '.join(conflict_roles),
                    ', '.join(set(conflict_roles.values()))))

        return list(all_roles.values())
Exemplo n.º 8
0
    def get_network_roles(cls, cluster, merge_policy):
        """Returns the network roles from plugins.

        The roles cluster and plugins will be mixed
        according to merge policy.
        """

        instance_roles = cluster.release.network_roles_metadata
        all_roles = dict((role['id'], role) for role in instance_roles)
        conflict_roles = dict()

        for plugin in ClusterPlugin.get_enabled(cluster.id):
            for role in plugin.network_roles_metadata:
                role_id = role['id']
                if role_id in all_roles:
                    try:
                        merge_policy.apply_patch(all_roles[role_id], role)
                    except errors.UnresolvableConflict as e:
                        logger.error("cannot merge plugin {0}: {1}".format(
                            plugin.name, e))
                        conflict_roles[role_id] = plugin.name
                else:
                    all_roles[role_id] = role

        if conflict_roles:
            raise errors.NetworkRoleConflict(
                "Cannot override existing network roles: '{0}' in "
                "plugins: '{1}'".format(
                    ', '.join(conflict_roles),
                    ', '.join(set(conflict_roles.values()))))

        return list(all_roles.values())
Exemplo n.º 9
0
    def get_cluster_plugins_info(self, cluster):
        plugins_info = []
        for plugin_inst in ClusterPlugin.get_enabled(cluster.id):
            plugin_info = self.get_attributes(plugin_inst.__dict__,
                                              self.plugin_info_white_list)
            plugins_info.append(plugin_info)

        return plugins_info
Exemplo n.º 10
0
    def _is_plugin_deletable(cls, plugin):
        """Check if plugin deletion is enable

        :param plugin: the plugin instance
        :type plugin: plugin model
        :returns: boolean
        """
        return not ClusterPlugin.is_plugin_used(plugin.id)
Exemplo n.º 11
0
    def _is_plugin_deletable(cls, plugin):
        """Check if plugin deletion is enable

        :param plugin: the plugin instance
        :type plugin: plugin model
        :returns: boolean
        """
        return ClusterPlugin.is_plugin_used(plugin.id)
Exemplo n.º 12
0
    def get_volumes_metadata(cls, cluster):
        """Get volumes metadata for all plugins enabled for the cluster

        :param cluster: A cluster instance
        :type cluster: Cluster model
        :return: dict -- Object with merged volumes data from plugins
        """
        def _get_volumes_ids(instance):
            return [v['id']
                    for v in instance.volumes_metadata.get('volumes', [])]

        volumes_metadata = {
            'volumes': [],
            'volumes_roles_mapping': {},
            'rule_to_pick_boot_disk': [],
        }

        cluster_volumes_ids = _get_volumes_ids(cluster)
        release_volumes_ids = _get_volumes_ids(cluster.release)
        processed_volumes = {}

        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin_adapter in map(wrap_plugin, enabled_plugins):
            metadata = plugin_adapter.volumes_metadata

            for volume in metadata.get('volumes', []):
                volume_id = volume['id']
                for owner, volumes_ids in (('cluster', cluster_volumes_ids),
                                           ('release', release_volumes_ids)):
                    if volume_id in volumes_ids:
                        raise errors.AlreadyExists(
                            'Plugin {0} is overlapping with {1} '
                            'by introducing the same volume with '
                            'id "{2}"'.format(plugin_adapter.full_name,
                                              owner,
                                              volume_id)
                        )
                    elif volume_id in processed_volumes:
                        raise errors.AlreadyExists(
                            'Plugin {0} is overlapping with plugin {1} '
                            'by introducing the same volume with '
                            'id "{2}"'.format(
                                plugin_adapter.full_name,
                                processed_volumes[volume_id],
                                volume_id
                            )
                        )

                processed_volumes[volume_id] = plugin_adapter.full_name

            volumes_metadata.get('volumes_roles_mapping', {}).update(
                metadata.get('volumes_roles_mapping', {}))
            volumes_metadata.get('volumes', []).extend(
                metadata.get('volumes', []))
            volumes_metadata.get('rule_to_pick_boot_disk', []).extend(
                metadata.get('rule_to_pick_boot_disk', []))

        return volumes_metadata
Exemplo n.º 13
0
    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 ClusterPlugin.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:
                ClusterPlugin.set_attributes(
                    cluster.id, plugin.id, enabled=True)
Exemplo n.º 14
0
    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 ClusterPlugin.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:
                ClusterPlugin.set_attributes(cluster.id,
                                             plugin.id,
                                             enabled=True)
Exemplo n.º 15
0
 def get_cluster_tags_query(cls, cluster):
     plugins_ids = (ClusterPlugin.get_enabled(cluster.id)
                    .with_entities(models.Plugin.id).subquery())
     return db().query(models.Tag).filter(
         ((models.Tag.owner_id == cluster.release.id) &
          (models.Tag.owner_type == 'release')) |
         ((models.Tag.owner_id == cluster.id) &
          (models.Tag.owner_type == 'cluster')) |
         ((models.Tag.owner_id.in_(plugins_ids)) &
          (models.Tag.owner_type == 'plugin'))
     )
Exemplo n.º 16
0
    def get_volumes_metadata(cls, cluster):
        """Get volumes metadata for all plugins enabled for the cluster

        :param cluster: A cluster instance
        :type cluster: Cluster model
        :return: dict -- Object with merged volumes data from plugins
        """
        def _get_volumes_ids(instance):
            return [
                v['id'] for v in instance.volumes_metadata.get('volumes', [])
            ]

        volumes_metadata = {
            'volumes': [],
            'volumes_roles_mapping': {},
            'rule_to_pick_boot_disk': [],
        }

        cluster_volumes_ids = _get_volumes_ids(cluster)
        release_volumes_ids = _get_volumes_ids(cluster.release)
        processed_volumes = {}

        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin_adapter in map(wrap_plugin, enabled_plugins):
            metadata = plugin_adapter.volumes_metadata

            for volume in metadata.get('volumes', []):
                volume_id = volume['id']
                for owner, volumes_ids in (('cluster', cluster_volumes_ids),
                                           ('release', release_volumes_ids)):
                    if volume_id in volumes_ids:
                        raise errors.AlreadyExists(
                            'Plugin {0} is overlapping with {1} '
                            'by introducing the same volume with '
                            'id "{2}"'.format(plugin_adapter.full_name, owner,
                                              volume_id))
                    elif volume_id in processed_volumes:
                        raise errors.AlreadyExists(
                            'Plugin {0} is overlapping with plugin {1} '
                            'by introducing the same volume with '
                            'id "{2}"'.format(plugin_adapter.full_name,
                                              processed_volumes[volume_id],
                                              volume_id))

                processed_volumes[volume_id] = plugin_adapter.full_name

            volumes_metadata.get('volumes_roles_mapping', {}).update(
                metadata.get('volumes_roles_mapping', {}))
            volumes_metadata.get('volumes',
                                 []).extend(metadata.get('volumes', []))
            volumes_metadata.get('rule_to_pick_boot_disk', []).extend(
                metadata.get('rule_to_pick_boot_disk', []))

        return volumes_metadata
Exemplo n.º 17
0
    def get_tags_metadata(cls, cluster):
        """Get tags metadata for all plugins enabled for the cluster

        :param cluster: A cluster instance
        :type cluster: Cluster model
        :return: dict -- Object with merged tags data from plugins
        """
        tags_metadata = {}
        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin in enabled_plugins:
            tags_metadata.update(plugin.tags_metadata)
        return tags_metadata
Exemplo n.º 18
0
    def get_tags_metadata(cls, cluster):
        """Get tags metadata for all plugins enabled for the cluster

        :param cluster: A cluster instance
        :type cluster: Cluster model
        :return: dict -- Object with merged tags data from plugins
        """
        tags_metadata = {}
        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin in enabled_plugins:
            tags_metadata.update(plugin.tags_metadata)
        return tags_metadata
Exemplo n.º 19
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 ClusterPlugin.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', {})
                actual_attrs['metadata']['contains_legacy_tasks'] = \
                    cls.contains_legacy_tasks(plugin_adapter)
                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.º 20
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 ClusterPlugin.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',
                                                                 {})
                actual_attrs['metadata']['contains_legacy_tasks'] = \
                    cls.contains_legacy_tasks(plugin_adapter)
                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.º 21
0
    def process_cluster_attributes(cls, cluster, attributes):
        """Generate Cluster-Plugins relation based on attributes.

        Iterates through plugins attributes, creates
        or deletes Cluster <-> Plugins relation if plugin
        is enabled or disabled.

        :param cluster: A cluster instance
        :type cluster: nailgun.db.sqlalchemy.models.cluster.Cluster
        :param attributes: Cluster attributes
        :type attributes: dict
        """
        plugins = {}

        # Detach plugins data
        for k in list(attributes):
            if cls.is_plugin_data(attributes[k]):
                plugins[k] = attributes.pop(k)['metadata']

        for container in six.itervalues(plugins):
            default = container.get('default', False)
            for attrs in container.get('versions', []):
                version_metadata = attrs.pop('metadata')
                plugin_id = version_metadata['plugin_id']
                plugin = Plugin.get_by_uid(plugin_id)
                if not plugin:
                    logger.warning('Plugin with id "%s" is not found, skip it',
                                   plugin_id)
                    continue
                enabled = container['enabled']\
                    and plugin_id == container['chosen_id']
                ClusterPlugin.set_attributes(
                    cluster.id,
                    plugin.id,
                    enabled=enabled,
                    attrs=attrs if enabled or default else None)
Exemplo n.º 22
0
    def get_plugins_node_default_attributes(cls, cluster):
        """Get node attributes metadata for enabled plugins of the cluster.

        :param cluster: A cluster instance
        :type cluster: models.Cluster
        :returns: dict -- Object with node attributes
        """
        plugins_node_metadata = {}
        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin_adapter in map(wrap_plugin, enabled_plugins):
            metadata = plugin_adapter.node_attributes_metadata
            # TODO(ekosareva): resolve conflicts of same attribute names
            #                  for different plugins
            plugins_node_metadata.update(metadata)

        return plugins_node_metadata
Exemplo n.º 23
0
    def get_plugins_node_default_attributes(cls, cluster):
        """Get node attributes metadata for enabled plugins of the cluster.

        :param cluster: A cluster instance
        :type cluster: models.Cluster
        :returns: dict -- Object with node attributes
        """
        plugins_node_metadata = {}
        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin_adapter in map(wrap_plugin, enabled_plugins):
            metadata = plugin_adapter.node_attributes_metadata
            # TODO(ekosareva): resolve conflicts of same attribute names
            #                  for different plugins
            plugins_node_metadata.update(metadata)

        return plugins_node_metadata
Exemplo n.º 24
0
    def get_volumes_metadata(cls, cluster):
        """Get volumes metadata for cluster from all plugins which enabled it.

        :param cluster: A cluster instance
        :type cluster: Cluster model
        :return: dict -- Object with merged volumes data from plugins
        """
        volumes_metadata = {
            'volumes': [],
            'volumes_roles_mapping': {},
            'rule_to_pick_boot_disk': [],
        }
        release_volumes = cluster.release.volumes_metadata.get('volumes', [])
        release_volumes_ids = [v['id'] for v in release_volumes]
        processed_volumes = {}

        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin_adapter in map(wrap_plugin, enabled_plugins):
            metadata = plugin_adapter.volumes_metadata

            for volume in metadata.get('volumes', []):
                volume_id = volume['id']
                if volume_id in release_volumes_ids:
                    raise errors.AlreadyExists(
                        'Plugin {0} is overlapping with release '
                        'by introducing the same volume with id "{1}"'
                        .format(plugin_adapter.full_name, volume_id))
                elif volume_id in processed_volumes:
                    raise errors.AlreadyExists(
                        'Plugin {0} is overlapping with plugin {1} '
                        'by introducing the same volume with id "{2}"'
                        .format(plugin_adapter.full_name,
                                processed_volumes[volume_id],
                                volume_id))

                processed_volumes[volume_id] = plugin_adapter.full_name

            volumes_metadata.get('volumes_roles_mapping', {}).update(
                metadata.get('volumes_roles_mapping', {}))
            volumes_metadata.get('volumes', []).extend(
                metadata.get('volumes', []))
            volumes_metadata.get('rule_to_pick_boot_disk', []).extend(
                metadata.get('rule_to_pick_boot_disk', []))

        return volumes_metadata
Exemplo n.º 25
0
    def get_volumes_metadata(cls, cluster):
        """Get volumes metadata for cluster from all plugins which enabled it.

        :param cluster: A cluster instance
        :type cluster: Cluster model
        :return: dict -- Object with merged volumes data from plugins
        """
        volumes_metadata = {
            'volumes': [],
            'volumes_roles_mapping': {},
            'rule_to_pick_boot_disk': [],
        }
        release_volumes = cluster.release.volumes_metadata.get('volumes', [])
        release_volumes_ids = [v['id'] for v in release_volumes]
        processed_volumes = {}

        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin_adapter in map(wrap_plugin, enabled_plugins):
            metadata = plugin_adapter.volumes_metadata

            for volume in metadata.get('volumes', []):
                volume_id = volume['id']
                if volume_id in release_volumes_ids:
                    raise errors.AlreadyExists(
                        'Plugin {0} is overlapping with release '
                        'by introducing the same volume with id "{1}"'.format(
                            plugin_adapter.full_name, volume_id))
                elif volume_id in processed_volumes:
                    raise errors.AlreadyExists(
                        'Plugin {0} is overlapping with plugin {1} '
                        'by introducing the same volume with id "{2}"'.format(
                            plugin_adapter.full_name,
                            processed_volumes[volume_id], volume_id))

                processed_volumes[volume_id] = plugin_adapter.full_name

            volumes_metadata.get('volumes_roles_mapping', {}).update(
                metadata.get('volumes_roles_mapping', {}))
            volumes_metadata.get('volumes',
                                 []).extend(metadata.get('volumes', []))
            volumes_metadata.get('rule_to_pick_boot_disk', []).extend(
                metadata.get('rule_to_pick_boot_disk', []))

        return volumes_metadata
Exemplo n.º 26
0
    def get_nic_default_attributes(cls, cluster):
        """Get default plugin nic attributes for cluster.

        :param cluster: A cluster instance
        :type cluster: Cluster model
        :returns: dict -- Object with nic attributes
        """
        plugins_nic_metadata = {}
        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin_adapter in six.moves.map(wrap_plugin, enabled_plugins):
            metadata = plugin_adapter.nic_attributes_metadata
            if metadata:
                metadata = dict_merge({
                    'metadata': {
                        'label': plugin_adapter.title, 'class': 'plugin'}},
                    metadata)
                plugins_nic_metadata[plugin_adapter.name] = metadata

        return plugins_nic_metadata
Exemplo n.º 27
0
    def get_plugins_deployment_tasks(cls, cluster, graph_type=None):
        deployment_tasks = []
        processed_tasks = {}

        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin_adapter in map(wrap_plugin, enabled_plugins):
            depl_tasks = plugin_adapter.get_deployment_tasks(graph_type)

            for t in depl_tasks:
                t_id = t['id']
                if t_id in processed_tasks:
                    raise errors.AlreadyExists(
                        'Plugin {0} is overlapping with plugin {1} '
                        'by introducing the same deployment task with '
                        'id {2}'.format(plugin_adapter.full_name,
                                        processed_tasks[t_id], t_id))
                processed_tasks[t_id] = plugin_adapter.full_name

            deployment_tasks.extend(depl_tasks)

        return deployment_tasks
Exemplo n.º 28
0
    def get_nic_default_attributes(cls, cluster):
        """Get default plugin nic attributes for cluster.

        :param cluster: A cluster instance
        :type cluster: Cluster model
        :returns: dict -- Object with nic attributes
        """
        plugins_nic_metadata = {}
        enabled_plugins = ClusterPlugin.get_enabled(cluster.id)
        for plugin_adapter in six.moves.map(wrap_plugin, enabled_plugins):
            metadata = plugin_adapter.nic_attributes_metadata
            if metadata:
                metadata = dict_merge(
                    {
                        'metadata': {
                            'label': plugin_adapter.title,
                            'class': 'plugin'
                        }
                    }, metadata)
                plugins_nic_metadata[plugin_adapter.name] = metadata

        return plugins_nic_metadata
Exemplo n.º 29
0
 def get_enabled_plugins(cls, cluster):
     return [
         wrap_plugin(plugin)
         for plugin in ClusterPlugin.get_enabled(cluster.id)
     ]
Exemplo n.º 30
0
 def get_enabled_plugins(cls, cluster):
     return [wrap_plugin(plugin)
             for plugin in ClusterPlugin.get_enabled(cluster.id)]