Пример #1
0
 def __init__(self, transaction):
     self._transaction = transaction
     self._yaql_context = yaql_ext.create_context(add_serializers=True,
                                                  add_datadiff=True,
                                                  add_extensions=True)
     self._yaql_engine = yaql_ext.create_engine()
     self._yaql_expressions_cache = {}
Пример #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 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()
Пример #3
0
 def __init__(self, transaction):
     self._transaction = transaction
     self._yaql_context = yaql_ext.create_context(
         add_serializers=True, add_datadiff=True
     )
     self._yaql_engine = yaql_ext.create_engine()
     self._yaql_expressions_cache = {}
Пример #4
0
 def __init__(self):
     self._cluster = None
     self._node_id = None
     self._tasks = [None, None]
     self._infos = [None, None]
     self._yaql_context = yaql_ext.create_context(add_serializers=True,
                                                  add_datadiff=True)
     self._yaql_engine = yaql_ext.create_engine()
Пример #5
0
    def evaluate(self, expression, variables=None, engine=None):
        context = yaql_ext.create_context(add_datadiff=True,
                                          add_serializers=True)
        for k, v in six.iteritems(variables or self.variables):
            context[k] = v

        engine = engine or yaql_ext.create_engine()
        parsed_exp = engine(expression)
        return parsed_exp.evaluate(context=context)
Пример #6
0
 def __init__(self):
     self._cluster = None
     self._node_id = None
     self._tasks = [None, None]
     self._infos = [None, None]
     self._yaql_context = yaql_ext.create_context(
         add_serializers=True, add_datadiff=True, add_extensions=True
     )
     self._yaql_engine = yaql_ext.create_engine()
Пример #7
0
    def evaluate(self, expression, variables=None, engine=None):
        context = yaql_ext.create_context(
            add_datadiff=True, add_serializers=True
        )
        for k, v in six.iteritems(variables or self.variables):
            context[k] = v

        engine = engine or yaql_ext.create_engine()
        parsed_exp = engine(expression)
        return parsed_exp.evaluate(context=context)
Пример #8
0
    def get_interpreter(self):
        with mock.patch('nailgun.extensions.manager.get_all_extensions',
                        return_value=[self.YaqlUtils()]):
            context = yaql_ext.create_context(add_extensions=True)
            engine = yaql_ext.create_engine()

        def evaluate(expression):
            parsed_exp = engine(expression)
            return parsed_exp.evaluate(context=context)
        return evaluate
Пример #9
0
    def get_interpreter(self):
        with mock.patch('nailgun.extensions.manager.get_all_extensions',
                        return_value=[self.YaqlUtils()]):
            context = yaql_ext.create_context(add_extensions=True)
            engine = yaql_ext.create_engine()

        def evaluate(expression):
            parsed_exp = engine(expression)
            return parsed_exp.evaluate(context=context)
        return evaluate
Пример #10
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()
Пример #11
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()
Пример #12
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()
Пример #13
0
 def get_contexts(self):
     """Create main YAQL context"""
     main_yaql_context = yaql_ext.create_context(
         add_serializers=True, add_datadiff=True
     )
     self.context = main_yaql_context.create_child_context()
Пример #14
0
 def get_contexts(self):
     """Create main YAQL context"""
     main_yaql_context = yaql_ext.create_context(add_serializers=True,
                                                 add_datadiff=True)
     self.context = main_yaql_context.create_child_context()