示例#1
0
    def _get_ports_query(self,
                         context,
                         filters=None,
                         sorts=None,
                         limit=None,
                         marker_obj=None,
                         page_reverse=False):
        Port = models_v2.Port
        IPAllocation = models_v2.IPAllocation

        if not filters:
            filters = {}

        query = self._model_query(context, Port)

        fixed_ips = filters.pop('fixed_ips', {})
        ip_addresses = fixed_ips.get('ip_address')
        subnet_ids = fixed_ips.get('subnet_id')
        if ip_addresses or subnet_ids:
            query = query.join(Port.fixed_ips)
            if ip_addresses:
                query = query.filter(IPAllocation.ip_address.in_(ip_addresses))
            if subnet_ids:
                query = query.filter(IPAllocation.subnet_id.in_(subnet_ids))

        query = self._apply_filters_to_query(query, Port, filters, context)
        if limit and page_reverse and sorts:
            sorts = [(s[0], not s[1]) for s in sorts]
        query = sqlalchemyutils.paginate_query(query, Port, limit, sorts,
                                               marker_obj)
        return query
示例#2
0
def _network_find(context,
                  limit,
                  sorts,
                  marker,
                  page_reverse,
                  fields,
                  defaults=None,
                  **filters):
    query = context.session.query(models.Network)
    model_filters = _model_query(context, models.Network, filters, query)

    if defaults:
        invert_defaults = False
        if INVERT_DEFAULTS in defaults:
            invert_defaults = True
            defaults.pop(0)
        if filters and invert_defaults:
            query = query.filter(
                and_(not_(models.Network.id.in_(defaults)),
                     and_(*model_filters)))
        elif filters and not invert_defaults:
            query = query.filter(
                or_(models.Network.id.in_(defaults), and_(*model_filters)))

        elif not invert_defaults:
            query = query.filter(models.Network.id.in_(defaults))
    else:
        query = query.filter(*model_filters)

    if "join_subnets" in filters:
        query = query.options(orm.joinedload(models.Network.subnets))

    return paginate_query(query, models.Network, limit, sorts, marker)
示例#3
0
    def _get_ports_query(self, context, filters=None, sorts=None, limit=None,
                         marker_obj=None, page_reverse=False):
        Port = models_v2.Port
        IPAllocation = models_v2.IPAllocation

        if not filters:
            filters = {}

        query = self._model_query(context, Port)

        fixed_ips = filters.pop('fixed_ips', {})
        ip_addresses = fixed_ips.get('ip_address')
        subnet_ids = fixed_ips.get('subnet_id')
        if ip_addresses or subnet_ids:
            query = query.join(Port.fixed_ips)
            if ip_addresses:
                query = query.filter(IPAllocation.ip_address.in_(ip_addresses))
            if subnet_ids:
                query = query.filter(IPAllocation.subnet_id.in_(subnet_ids))

        query = self._apply_filters_to_query(query, Port, filters)
        if limit and page_reverse and sorts:
            sorts = [(s[0], not s[1]) for s in sorts]
        query = sqlalchemyutils.paginate_query(query, Port, limit,
                                               sorts, marker_obj)
        return query
示例#4
0
def _subnet_find(context, limit, sorts, marker, page_reverse, fields,
                 defaults=None, provider_query=False, **filters):
    query = context.session.query(models.Subnet)
    model_filters = _model_query(context, models.Subnet, filters, query)

    if defaults:
        invert_defaults = False
        if INVERT_DEFAULTS in defaults:
            invert_defaults = True
            defaults.pop(0)
        if filters and invert_defaults:
            query = query.filter(and_(not_(models.Subnet.id.in_(defaults)),
                                      and_(*model_filters)))
        elif not provider_query and filters and not invert_defaults:
            query = query.filter(or_(models.Subnet.id.in_(defaults),
                                     and_(*model_filters)))

        elif not invert_defaults:
            query = query.filter(models.Subnet.id.in_(defaults))
    else:
        query = query.filter(*model_filters)

    if "join_dns" in filters:
        query = query.options(orm.joinedload(models.Subnet.dns_nameservers))

    if "join_routes" in filters:
        query = query.options(orm.joinedload(models.Subnet.routes))

    if "join_pool" in filters:
        query = query.options(orm.undefer('_allocation_pool_cache'))

    return paginate_query(query, models.Subnet, limit, sorts, marker)
示例#5
0
def port_find(context,
              limit=None,
              sorts=None,
              marker_obj=None,
              fields=None,
              **filters):
    query = context.session.query(models.Port).options(
        orm.joinedload(models.Port.ip_addresses))
    model_filters = _model_query(context, models.Port, filters)
    if filters.get("ip_address_id"):
        model_filters.append(
            models.Port.ip_addresses.any(
                models.IPAddress.id.in_(filters["ip_address_id"])))

    if filters.get("device_id"):
        model_filters.append(models.Port.device_id.in_(filters["device_id"]))

    if "join_security_groups" in filters:
        query = query.options(orm.joinedload(models.Port.security_groups))

    if fields and "port_subnets" in fields:
        query = query.options(orm.joinedload("ip_addresses.subnet"))
        query = query.options(
            orm.joinedload("ip_addresses.subnet.dns_nameservers"))
        query = query.options(orm.joinedload("ip_addresses.subnet.routes"))
    return paginate_query(query.filter(*model_filters), models.Port, limit,
                          sorts, marker_obj)
示例#6
0
文件: api.py 项目: quadewarren/quark
def _subnet_find(context, limit, sorts, marker, page_reverse, fields,
                 defaults=None, provider_query=False, **filters):
    query = context.session.query(models.Subnet)
    model_filters = _model_query(context, models.Subnet, filters, query)

    if defaults:
        invert_defaults = False
        if INVERT_DEFAULTS in defaults:
            invert_defaults = True
            defaults.pop(0)
        if filters and invert_defaults:
            query = query.filter(and_(not_(models.Subnet.id.in_(defaults)),
                                      and_(*model_filters)))
        elif not provider_query and filters and not invert_defaults:
            query = query.filter(or_(models.Subnet.id.in_(defaults),
                                     and_(*model_filters)))

        elif not invert_defaults:
            query = query.filter(models.Subnet.id.in_(defaults))
    else:
        query = query.filter(*model_filters)

    if "join_dns" in filters:
        query = query.options(orm.joinedload(models.Subnet.dns_nameservers))

    if "join_routes" in filters:
        query = query.options(orm.joinedload(models.Subnet.routes))

    if "join_pool" in filters:
        query = query.options(orm.undefer('_allocation_pool_cache'))

    return paginate_query(query, models.Subnet, limit, sorts, marker)
示例#7
0
文件: api.py 项目: quadewarren/quark
def port_find(context, limit=None, sorts=None, marker_obj=None, fields=None,
              **filters):
    query = context.session.query(models.Port).options(
        orm.joinedload(models.Port.ip_addresses))
    model_filters = _model_query(context, models.Port, filters)
    if filters.get("ip_address_id"):
        model_filters.append(models.Port.ip_addresses.any(
            models.IPAddress.id.in_(filters["ip_address_id"])))

    if filters.get("device_id"):
        model_filters.append(models.Port.device_id.in_(filters["device_id"]))

    if filters.get("service"):
        model_filters.append(models.Port.associations.any(
            models.PortIpAssociation.service == filters["service"]))

    if "join_security_groups" in filters:
        query = query.options(orm.joinedload(models.Port.security_groups))

    if fields and "port_subnets" in fields:
        query = query.options(orm.joinedload("ip_addresses.subnet"))
        query = query.options(
            orm.joinedload("ip_addresses.subnet.dns_nameservers"))
        query = query.options(
            orm.joinedload("ip_addresses.subnet.routes"))
    return paginate_query(query.filter(*model_filters), models.Port, limit,
                          sorts, marker_obj)
示例#8
0
文件: api.py 项目: quadewarren/quark
def _network_find(context, limit, sorts, marker, page_reverse, fields,
                  defaults=None, provider_query=False, **filters):
    query = context.session.query(models.Network)
    model_filters = _model_query(context, models.Network, filters, query)

    if defaults:
        invert_defaults = False
        if INVERT_DEFAULTS in defaults:
            invert_defaults = True
            defaults.pop(0)
        if filters and invert_defaults:
            query = query.filter(and_(not_(models.Network.id.in_(defaults)),
                                      and_(*model_filters)))
        elif not provider_query and filters and not invert_defaults:
            query = query.filter(or_(models.Network.id.in_(defaults),
                                     and_(*model_filters)))

        elif not invert_defaults:
            query = query.filter(models.Network.id.in_(defaults))
    else:
        query = query.filter(*model_filters)

    if "join_subnets" in filters:
        query = query.options(orm.joinedload(models.Network.subnets))

    return paginate_query(query, models.Network, limit, sorts, marker)
示例#9
0
文件: api.py 项目: alanquillin/quark
def floating_ip_find(context,
                     lock_mode=False,
                     limit=None,
                     sorts=None,
                     marker=None,
                     page_reverse=False,
                     fields=None,
                     **filters):
    query = context.session.query(models.IPAddress)

    if lock_mode:
        query = query.with_lockmode("update")

    model_filters = _model_query(context, models.IPAddress, filters)

    if filters.get("port_id"):
        model_filters.append(
            models.IPAddress.ports.any(models.Port.id == filters['port_id']))

    if filters.get("transaction_id"):
        model_filters.append(
            models.IPAddress.transaction_id == filters['transaction_id'])

    return paginate_query(query.filter(*model_filters), models.IPAddress,
                          limit, sorts, marker)
示例#10
0
    def _get_routers_query(self,
                           context,
                           filters=None,
                           sorts=None,
                           limit=None,
                           marker_obj=None,
                           page_reverse=False):
        Router = l3_db.Router
        RouterExtraAttributes = l3_attrs_db.RouterExtraAttributes
        if not filters:
            filters = {}
        query = self._model_query(context, Router)
        query = query.outerjoin(RouterExtraAttributes,
                                Router.id == RouterExtraAttributes.router_id)

        distributed = filters.pop('distributed', None)
        if distributed is not None:
            query = query.filter(
                RouterExtraAttributes.distributed == distributed[0])
        query = self._apply_filters_to_query(query, Router, filters)

        ha = filters.pop('ha', None)
        if ha is not None:
            query = query.filter(RouterExtraAttributes.ha == ha[0])
        query = self._apply_filters_to_query(query, Router, filters)

        if limit and page_reverse and sorts:
            sorts = [(s[0], not s[1]) for s in sorts]
        query = sqlalchemyutils.paginate_query(query,
                                               Router,
                                               limit,
                                               sorts,
                                               marker_obj=marker_obj)
        return query
示例#11
0
 def _get_collection_query(
     self, context, model, filters=None, sorts=None, limit=None, marker_obj=None, page_reverse=False
 ):
     collection = self._model_query(context, model)
     collection = self._apply_filters_to_query(collection, model, filters, context)
     if limit and page_reverse and sorts:
         sorts = [(s[0], not s[1]) for s in sorts]
     collection = sqlalchemyutils.paginate_query(collection, model, limit, sorts, marker_obj=marker_obj)
     return collection
 def _get_collection_query(self, session, model, filters=None,
                           sorts=None, limit=None, marker_obj=None,
                           page_reverse=False):
     collection = self._model_query(session, model)
     collection = self._apply_filters_to_query(collection, model, filters)
     if limit and page_reverse and sorts:
         sorts = [(s[0], not s[1]) for s in sorts]
     collection = sqlalchemyutils.paginate_query(collection, model, limit,
             sorts, marker_obj=marker_obj)
     return collection
示例#13
0
 def get_node_instance_network_function_maps(self, session, sc_instance_id):
     try:
         with session.begin(subtransactions=True):
             query = session.query(
                 nfp_db_model.ServiceNodeInstanceNetworkFunctionMapping)
             query = query.filter_by(sc_instance_id=sc_instance_id)
             from neutron.db import sqlalchemyutils
             collection = sqlalchemyutils.paginate_query(
                 query,
                 nfp_db_model.ServiceNodeInstanceNetworkFunctionMapping,
                 None, None)
             return [item for item in collection]
     except exc.NoResultFound:
         return []
示例#14
0
def subnet_find(context, limit=None, page_reverse=False, sorts=None,
                marker_obj=None, **filters):
    if "shared" in filters and True in filters["shared"]:
        return []
    query = context.session.query(models.Subnet)
    model_filters = _model_query(context, models.Subnet, filters)

    if "join_dns" in filters:
        query = query.options(orm.joinedload(models.Subnet.dns_nameservers))

    if "join_routes" in filters:
        query = query.options(orm.joinedload(models.Subnet.routes))
    return paginate_query(query.filter(*model_filters), models.Subnet, limit,
                          sorts, marker_obj)
示例#15
0
def subnet_find(context, limit=None, page_reverse=False, sorts=None,
                marker_obj=None, **filters):
    if "shared" in filters and True in filters["shared"]:
        return []
    query = context.session.query(models.Subnet)
    model_filters = _model_query(context, models.Subnet, filters)

    if "join_dns" in filters:
        query = query.options(orm.joinedload(models.Subnet.dns_nameservers))

    if "join_routes" in filters:
        query = query.options(orm.joinedload(models.Subnet.routes))
    return paginate_query(query.filter(*model_filters), models.Subnet, limit,
                          sorts, marker_obj)
示例#16
0
 def get_node_instance_network_function_maps(self, session, sc_instance_id):
     try:
         with session.begin(subtransactions=True):
             query = session.query(
                 nfp_db_model.ServiceNodeInstanceNetworkFunctionMapping)
             query = query.filter_by(sc_instance_id=sc_instance_id)
             from neutron.db import sqlalchemyutils
             collection = sqlalchemyutils.paginate_query(
                     query,
                     nfp_db_model.ServiceNodeInstanceNetworkFunctionMapping,
                     None, None)
             return [item for item in collection]
     except exc.NoResultFound:
         return []
示例#17
0
文件: api.py 项目: quadewarren/quark
def floating_ip_find(context, lock_mode=False, limit=None, sorts=None,
                     marker=None, page_reverse=False, fields=None, **filters):
    query = context.session.query(models.IPAddress)

    if lock_mode:
        query = query.with_lockmode("update")

    model_filters = _model_query(context, models.IPAddress, filters)

    if filters.get("port_id"):
        model_filters.append(models.IPAddress.ports.any(
            models.Port.id == filters['port_id']))

    if filters.get("transaction_id"):
        model_filters.append(
            models.IPAddress.transaction_id == filters['transaction_id'])

    return paginate_query(query.filter(*model_filters), models.IPAddress,
                          limit, sorts, marker)
示例#18
0
文件: api.py 项目: roaet/quark
def _subnet_find(context, limit, sorts, marker, page_reverse, fields,
                 defaults=None, provider_query=False, **filters):
    query = context.session.query(models.Subnet)
    model_filters = _model_query(context, models.Subnet, filters, query)

    if defaults:
        invert_defaults = False
        if INVERT_DEFAULTS in defaults:
            invert_defaults = True
            defaults.pop(0)

        # when 'invert_defaults' were the only entry in defaults,
        # defaults will be empty now. The next 4 lines optimize
        # performance by avoiding running the in_ filter on an empty set:
        # like so: models.Subnet.id.in_([])
        if defaults:
            subnet_filter = models.Subnet.id.in_(defaults)
        else:
            # if defaults is an empty list, just create a False
            # BinaryExpression
            subnet_filter = models.Subnet.id != models.Subnet.id

        if filters and invert_defaults:
            query = query.filter(and_(not_(subnet_filter),
                                      and_(*model_filters)))
        elif not provider_query and filters and not invert_defaults:
            query = query.filter(or_(subnet_filter, and_(*model_filters)))

        elif not invert_defaults:
            query = query.filter(subnet_filter)
    else:
        query = query.filter(*model_filters)

    if "join_dns" in filters:
        query = query.options(orm.joinedload(models.Subnet.dns_nameservers))

    if "join_routes" in filters:
        query = query.options(orm.joinedload(models.Subnet.routes))

    if "join_pool" in filters:
        query = query.options(orm.undefer('_allocation_pool_cache'))

    return paginate_query(query, models.Subnet, limit, sorts, marker)
示例#19
0
    def _get_routers_query(self, context, filters=None, sorts=None, limit=None,
                         marker_obj=None, page_reverse=False):
        Router = l3_db.Router
        RouterExtraAttributes = l3_attrs_db.RouterExtraAttributes
        if not filters:
            filters = {}
        query = self._model_query(context, Router)
        query = query.outerjoin(RouterExtraAttributes, Router.id == RouterExtraAttributes.router_id)

        distributed = filters.pop('distributed', None)
        if distributed is not None:
            query = query.filter(RouterExtraAttributes.distributed == distributed[0])
        query = self._apply_filters_to_query(query, Router, filters)

        ha = filters.pop('ha', None)
        if ha is not None:
            query = query.filter(RouterExtraAttributes.ha == ha[0])
        query = self._apply_filters_to_query(query, Router, filters)

        if limit and page_reverse and sorts:
            sorts = [(s[0], not s[1]) for s in sorts]
        query = sqlalchemyutils.paginate_query(query, Router, limit,
                                               sorts, marker_obj=marker_obj)
        return query