def create_mac_address_range(context, mac_range): LOG.info("create_mac_address_range for tenant %s" % context.tenant_id) if not context.is_admin: raise n_exc.NotAuthorized() if not mac_range or "mac_address_range" not in mac_range: raise n_exc.BadRequest(resource="mac_address_range", msg="Malformed body") rng = mac_range.get("mac_address_range") cidr = rng.get("cidr") if not cidr: raise n_exc.BadRequest(resource="mac_address_range", msg="Missing cidr") do_not_use = rng.get("do_not_use", "0") cidr, first_address, last_address = _to_mac_range(cidr) with context.session.begin(): new_range = db_api.mac_address_range_create( context, cidr=cidr, first_address=first_address, last_address=last_address, next_auto_assign_mac=first_address, do_not_use=do_not_use, ) return v._make_mac_range_dict(new_range)
def get_mac_address_ranges(context): LOG.info("get_mac_address_ranges for tenant %s" % context.tenant_id) if not context.is_admin: raise n_exc.NotAuthorized() ranges = db_api.mac_address_range_find(context) return [v._make_mac_range_dict(m) for m in ranges]
def create_mac_address_range(context, mac_range): LOG.info("create_mac_address_range for tenant %s" % context.tenant_id) cidr = mac_range["mac_address_range"]["cidr"] cidr, first_address, last_address = _to_mac_range(cidr) new_range = db_api.mac_address_range_create( context, cidr=cidr, first_address=first_address, last_address=last_address, next_auto_assign_mac=first_address) return v._make_mac_range_dict(new_range)
def create_mac_address_range(context, mac_range): LOG.info("create_mac_address_range for tenant %s" % context.tenant_id) if not context.is_admin: raise exceptions.NotAuthorized() cidr = mac_range["mac_address_range"]["cidr"] cidr, first_address, last_address = _to_mac_range(cidr) with context.session.begin(): new_range = db_api.mac_address_range_create( context, cidr=cidr, first_address=first_address, last_address=last_address, next_auto_assign_mac=first_address) return v._make_mac_range_dict(new_range)
def get_mac_address_range(context, id, fields=None): """Retrieve a mac_address_range. : param context: neutron api request context : param id: UUID representing the network to fetch. : param fields: a list of strings that are valid keys in a network dictionary as listed in the RESOURCE_ATTRIBUTE_MAP object in neutron/api/v2/attributes.py. Only these fields will be returned. """ LOG.info("get_mac_address_range %s for tenant %s fields %s" % (id, context.tenant_id, fields)) mac_address_range = db_api.mac_address_range_find( context, id=id, scope=db_api.ONE) if not mac_address_range: raise quark_exceptions.MacAddressRangeNotFound( mac_address_range_id=id) return v._make_mac_range_dict(mac_address_range)
def create_mac_address_range(context, mac_range): LOG.info("create_mac_address_range for tenant %s" % context.tenant_id) if not context.is_admin: raise n_exc.NotAuthorized() if not mac_range or "mac_address_range" not in mac_range: raise n_exc.BadRequest(resource="mac_address_range", msg="Malformed body") rng = mac_range.get("mac_address_range") cidr = rng.get("cidr") if not cidr: raise n_exc.BadRequest(resource="mac_address_range", msg="Missing cidr") do_not_use = rng.get("do_not_use", "0") cidr, first_address, last_address = _to_mac_range(cidr) with context.session.begin(): new_range = db_api.mac_address_range_create( context, cidr=cidr, first_address=first_address, last_address=last_address, next_auto_assign_mac=first_address, do_not_use=do_not_use) return v._make_mac_range_dict(new_range)
def get_mac_address_ranges(context): LOG.info("get_mac_address_ranges for tenant %s" % context.tenant_id) ranges = db_api.mac_address_range_find(context) return [v._make_mac_range_dict(m) for m in ranges]