示例#1
0
def _get_nodes_to_run(cluster, node_filter, ids=None):
    # Trying to run tasks on offline nodes will lead to error, since most
    # probably MCollective is unreachable. In order to avoid that, we need
    # to select only online nodes.
    nodes = objects.NodeCollection.filter_by(None,
                                             cluster_id=cluster.id,
                                             online=True)

    if node_filter is None:
        node_filter = _DEFAULT_NODE_FILTER

    if ids is None and node_filter:
        logger.debug("applying nodes filter: %s", node_filter)
        # TODO(bgaifullin) Need to implement adapter for YAQL
        # to direct query data from DB instead of query all data from DB
        yaql_exp = yaql_ext.get_default_engine()(
            '$.where({0}).select($.id)'.format(node_filter))
        ids = yaql_exp.evaluate(
            data=objects.NodeCollection.to_list(
                nodes,
                # TODO(bgaifullin) remove hard-coded list of fields
                # the field network_data causes fail of following
                # cluster serialization because it modifies attributes of
                # node and this update will be stored in DB.
                serializer=node_serializers.NodeSerializerForDeployment),
            context=yaql_ext.create_context(add_extensions=True,
                                            yaqlized=False))

    if ids is not None:
        logger.debug("filter by node_ids: %s", ids)
        nodes = objects.NodeCollection.filter_by_list(nodes, 'id', ids)

    return objects.NodeCollection.lock_for_update(
        objects.NodeCollection.order_by(nodes, 'id')).all()
示例#2
0
def _get_nodes_to_run(cluster, node_filter, ids=None):
    # Trying to run tasks on offline nodes will lead to error, since most
    # probably MCollective is unreachable. In order to avoid that, we need
    # to select only online nodes.
    nodes = objects.NodeCollection.filter_by(
        None, cluster_id=cluster.id, online=True)

    if ids is None and node_filter:
        # TODO(bgaifullin) Need to implement adapter for YAQL
        # to direct query data from DB instead of query all data from DB
        yaql_exp = yaql_ext.get_default_engine()(
            '$.where({0}).select($.id)'.format(node_filter)
        )
        ids = yaql_exp.evaluate(
            data=objects.NodeCollection.to_list(
                nodes,
                # TODO(bgaifullin) remove hard-coded list of fields
                # the field network_data causes fail of following
                # cluster serialization because it modifies attributes of
                # node and this update will be stored in DB.
                fields=(
                    'id',
                    'name',
                    'status',
                    'pending_deletion',
                    'pending_addition',
                    'error_type',
                    'roles',
                    'pending_roles',
                    'attributes',
                    'meta',
                    'hostname',
                    'labels'
                )
            ),
            context=yaql_ext.create_context(
                add_extensions=True, yaqlized=False
            )
        )

    if ids:
        nodes = objects.NodeCollection.filter_by_list(nodes, 'id', ids)

    return objects.NodeCollection.lock_for_update(
        objects.NodeCollection.order_by(nodes, 'id')
    ).all()
示例#3
0
def _get_nodes_to_run(cluster, node_filter, ids=None):
    # Trying to run tasks on offline nodes will lead to error, since most
    # probably MCollective is unreachable. In order to avoid that, we need
    # to select only online nodes.
    nodes = objects.NodeCollection.filter_by(None, cluster_id=cluster.id, online=True)

    if ids is None and node_filter:
        # TODO(bgaifullin) Need to implement adapter for YAQL
        # to direct query data from DB instead of query all data from DB
        yaql_exp = yaql_ext.get_default_engine()("$.where({0}).select($.id)".format(node_filter))
        ids = yaql_exp.evaluate(
            data=objects.NodeCollection.to_list(
                nodes,
                # TODO(bgaifullin) remove hard-coded list of fields
                # the field network_data causes fail of following
                # cluster serialization because it modifies attributes of
                # node and this update will be stored in DB.
                fields=(
                    "id",
                    "name",
                    "status",
                    "pending_deletion",
                    "pending_addition",
                    "error_type",
                    "roles",
                    "pending_roles",
                    "attributes",
                    "meta",
                    "hostname",
                    "labels",
                ),
            ),
            context=yaql_ext.create_context(add_extensions=True, yaqlized=False),
        )

    if ids:
        nodes = objects.NodeCollection.filter_by_list(nodes, "id", ids)

    return objects.NodeCollection.lock_for_update(objects.NodeCollection.order_by(nodes, "id")).all()
示例#4
0
def _get_nodes_to_run(cluster, node_filter, ids=None):
    # Trying to run tasks on offline nodes will lead to error, since most
    # probably MCollective is unreachable. In order to avoid that, we need
    # to select only online nodes.
    nodes = objects.NodeCollection.filter_by(
        None, cluster_id=cluster.id, online=True)

    if node_filter is None:
        node_filter = _DEFAULT_NODE_FILTER

    if ids is None and node_filter:
        logger.debug("applying nodes filter: %s", node_filter)
        # TODO(bgaifullin) Need to implement adapter for YAQL
        # to direct query data from DB instead of query all data from DB
        yaql_exp = yaql_ext.get_default_engine()(
            '$.where({0}).select($.id)'.format(node_filter)
        )
        ids = yaql_exp.evaluate(
            data=objects.NodeCollection.to_list(
                nodes,
                # TODO(bgaifullin) remove hard-coded list of fields
                # the field network_data causes fail of following
                # cluster serialization because it modifies attributes of
                # node and this update will be stored in DB.
                serializer=node_serializers.NodeSerializerForDeployment
            ),
            context=yaql_ext.create_context(
                add_extensions=True, yaqlized=False
            )
        )

    if ids is not None:
        logger.debug("filter by node_ids: %s", ids)
        nodes = objects.NodeCollection.filter_by_list(nodes, 'id', ids)

    return objects.NodeCollection.lock_for_update(
        objects.NodeCollection.order_by(nodes, 'id')
    ).all()
示例#5
0
 def test_get_default_engine(self):
     engine1 = yaql_ext.get_default_engine()
     engine2 = yaql_ext.get_default_engine()
     self.assertIs(engine1, engine2)