Exemple #1
0
def create_route(context, route):
    LOG.info("create_route for tenant %s" % context.tenant_id)
    route = route["route"]
    for key in ["gateway", "cidr", "subnet_id"]:
        if key not in route:
            raise exceptions.BadRequest(resource="routes", msg="%s is required" % key)

    subnet_id = route["subnet_id"]
    with context.session.begin():
        subnet = db_api.subnet_find(context, id=subnet_id, scope=db_api.ONE)
        if not subnet:
            raise exceptions.SubnetNotFound(subnet_id=subnet_id)
        policies = db_models.IPPolicy.get_ip_policy_cidrs(subnet)
        alloc_pools = allocation_pool.AllocationPools(subnet["cidr"], policies=policies)
        alloc_pools.validate_gateway_excluded(route["gateway"])

        # TODO(anyone): May want to denormalize the cidr values into columns
        #               to achieve single db lookup on conflict check
        route_cidr = netaddr.IPNetwork(route["cidr"])
        subnet_routes = db_api.route_find(context, subnet_id=subnet_id, scope=db_api.ALL)

        quota.QUOTAS.limit_check(context, context.tenant_id, routes_per_subnet=len(subnet_routes) + 1)

        for sub_route in subnet_routes:
            sub_route_cidr = netaddr.IPNetwork(sub_route["cidr"])
            if sub_route_cidr.value == DEFAULT_ROUTE.value:
                continue
            if route_cidr in sub_route_cidr or sub_route_cidr in route_cidr:
                raise quark_exceptions.RouteConflict(route_id=sub_route["id"], cidr=str(route_cidr))
        new_route = db_api.route_create(context, **route)
    return v._make_route_dict(new_route)
Exemple #2
0
def create_route(context, route):
    LOG.info("create_route for tenant %s" % context.tenant_id)
    if not route:
        raise n_exc.BadRequest(resource="routes", msg="Malformed body")
    route = route.get("route")
    if not route:
        raise n_exc.BadRequest(resource="routes", msg="Malformed body")
    for key in ["gateway", "cidr", "subnet_id"]:
        if key not in route:
            raise n_exc.BadRequest(resource="routes",
                                   msg="%s is required" % key)

    subnet_id = route["subnet_id"]
    with context.session.begin():
        subnet = db_api.subnet_find(context, id=subnet_id, scope=db_api.ONE)
        if not subnet:
            raise n_exc.SubnetNotFound(subnet_id=subnet_id)

        if subnet["ip_policy"]:
            policies = subnet["ip_policy"].get_cidrs_ip_set()
        else:
            policies = netaddr.IPSet([])

        alloc_pools = allocation_pool.AllocationPools(subnet["cidr"],
                                                      policies=policies)
        try:
            alloc_pools.validate_gateway_excluded(route["gateway"])
        except neutron_exc.GatewayConflictWithAllocationPools as e:
            LOG.exception(str(e))
            raise n_exc.BadRequest(resource="routes", msg=str(e))

        # TODO(anyone): May want to denormalize the cidr values into columns
        #               to achieve single db lookup on conflict check
        route_cidr = netaddr.IPNetwork(route["cidr"])
        subnet_routes = db_api.route_find(context, subnet_id=subnet_id,
                                          scope=db_api.ALL)

        quota.QUOTAS.limit_check(context, context.tenant_id,
                                 routes_per_subnet=len(subnet_routes) + 1)

        for sub_route in subnet_routes:
            sub_route_cidr = netaddr.IPNetwork(sub_route["cidr"])
            if sub_route_cidr.value == DEFAULT_ROUTE.value:
                continue
            if route_cidr in sub_route_cidr or sub_route_cidr in route_cidr:
                raise q_exc.RouteConflict(route_id=sub_route["id"],
                                          cidr=str(route_cidr))
        new_route = db_api.route_create(context, **route)
    return v._make_route_dict(new_route)
Exemple #3
0
def create_route(context, route):
    LOG.info("create_route for tenant %s" % context.tenant_id)
    route = route["route"]
    subnet_id = route["subnet_id"]
    subnet = db_api.subnet_find(context, id=subnet_id, scope=db_api.ONE)
    if not subnet:
        raise exceptions.SubnetNotFound(subnet_id=subnet_id)

    # TODO(anyone): May want to denormalize the cidr values into columns
    #               to achieve single db lookup on conflict check
    route_cidr = netaddr.IPNetwork(route["cidr"])
    subnet_routes = db_api.route_find(context, subnet_id=subnet_id,
                                      scope=db_api.ALL)
    for sub_route in subnet_routes:
        sub_route_cidr = netaddr.IPNetwork(sub_route["cidr"])
        if sub_route_cidr.value == DEFAULT_ROUTE.value:
            continue
        if route_cidr in sub_route_cidr or sub_route_cidr in route_cidr:
            raise quark_exceptions.RouteConflict(
                route_id=sub_route["id"], cidr=str(route_cidr))
    new_route = db_api.route_create(context, **route)
    return v._make_route_dict(new_route)
Exemple #4
0
def create_route(context, route):
    LOG.info("create_route for tenant %s" % context.tenant_id)
    route = route["route"]
    subnet_id = route["subnet_id"]
    subnet = db_api.subnet_find(context, id=subnet_id, scope=db_api.ONE)
    if not subnet:
        raise exceptions.SubnetNotFound(subnet_id=subnet_id)

    # TODO(anyone): May want to denormalize the cidr values into columns
    #               to achieve single db lookup on conflict check
    route_cidr = netaddr.IPNetwork(route["cidr"])
    subnet_routes = db_api.route_find(context,
                                      subnet_id=subnet_id,
                                      scope=db_api.ALL)
    for sub_route in subnet_routes:
        sub_route_cidr = netaddr.IPNetwork(sub_route["cidr"])
        if sub_route_cidr.value == DEFAULT_ROUTE.value:
            continue
        if route_cidr in sub_route_cidr or sub_route_cidr in route_cidr:
            raise quark_exceptions.RouteConflict(route_id=sub_route["id"],
                                                 cidr=str(route_cidr))
    new_route = db_api.route_create(context, **route)
    return v._make_route_dict(new_route)
Exemple #5
0
def get_routes(context):
    LOG.info("get_routes for tenant %s" % context.tenant_id)
    routes = db_api.route_find(context)
    return [v._make_route_dict(r) for r in routes]
Exemple #6
0
def get_route(context, id):
    LOG.info("get_route %s for tenant %s" % (id, context.tenant_id))
    route = db_api.route_find(context, id=id, scope=db_api.ONE)
    if not route:
        raise q_exc.RouteNotFound(route_id=id)
    return v._make_route_dict(route)
Exemple #7
0
def get_routes(context):
    LOG.info("get_routes for tenant %s" % context.tenant_id)
    routes = db_api.route_find(context)
    return [v._make_route_dict(r) for r in routes]
Exemple #8
0
def get_route(context, id):
    LOG.info("get_route %s for tenant %s" % (id, context.tenant_id))
    route = db_api.route_find(context, id=id, scope=db_api.ONE)
    if not route:
        raise quark_exceptions.RouteNotFound(route_id=id)
    return v._make_route_dict(route)