The all_subnets field
- when used, reduces follow-up calls on list_ports. RM#6295 original author: mpath
This commit is contained in:
@@ -13,8 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import netaddr
|
||||
|
||||
from neutron.common import exceptions
|
||||
from neutron.extensions import providernet as pnet
|
||||
from neutron.openstack.common import importutils
|
||||
@@ -33,7 +31,6 @@ from quark import plugin_views as v
|
||||
from quark import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
DEFAULT_ROUTE = netaddr.IPNetwork("0.0.0.0/0")
|
||||
LOG = logging.getLogger(__name__)
|
||||
STRATEGY = network_strategy.STRATEGY
|
||||
|
||||
@@ -159,7 +156,7 @@ def get_network(context, id, fields=None):
|
||||
scope=db_api.ONE)
|
||||
if not network:
|
||||
raise exceptions.NetworkNotFound(net_id=id)
|
||||
return v._make_network_dict(network)
|
||||
return v._make_network_dict(network, fields=fields)
|
||||
|
||||
|
||||
def get_networks(context, filters=None, fields=None):
|
||||
@@ -184,7 +181,7 @@ def get_networks(context, filters=None, fields=None):
|
||||
LOG.info("get_networks for tenant %s with filters %s, fields %s" %
|
||||
(context.tenant_id, filters, fields))
|
||||
nets = db_api.network_find(context, join_subnets=True, **filters) or []
|
||||
nets = [v._make_network_dict(net) for net in nets]
|
||||
nets = [v._make_network_dict(net, fields=fields) for net in nets]
|
||||
return nets
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ from quark import plugin_views as v
|
||||
from quark import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
DEFAULT_ROUTE = netaddr.IPNetwork("0.0.0.0/0")
|
||||
LOG = logging.getLogger(__name__)
|
||||
STRATEGY = network_strategy.STRATEGY
|
||||
|
||||
@@ -164,8 +163,7 @@ def create_subnet(context, subnet):
|
||||
new_subnet["ip_policy"] = db_api.ip_policy_create(context,
|
||||
exclude=cidrs)
|
||||
|
||||
subnet_dict = v._make_subnet_dict(new_subnet,
|
||||
default_route=routes.DEFAULT_ROUTE)
|
||||
subnet_dict = v._make_subnet_dict(new_subnet)
|
||||
subnet_dict["gateway_ip"] = gateway_ip
|
||||
|
||||
notifier_api.notify(context,
|
||||
@@ -236,7 +234,7 @@ def update_subnet(context, id, subnet):
|
||||
context, cidr=route["destination"], gateway=route["nexthop"]))
|
||||
|
||||
subnet = db_api.subnet_update(context, subnet_db, **s)
|
||||
return v._make_subnet_dict(subnet, default_route=routes.DEFAULT_ROUTE)
|
||||
return v._make_subnet_dict(subnet)
|
||||
|
||||
|
||||
def get_subnet(context, id, fields=None):
|
||||
@@ -261,7 +259,7 @@ def get_subnet(context, id, fields=None):
|
||||
net_id = STRATEGY.get_parent_network(net_id)
|
||||
subnet["network_id"] = net_id
|
||||
|
||||
return v._make_subnet_dict(subnet, default_route=routes.DEFAULT_ROUTE)
|
||||
return v._make_subnet_dict(subnet)
|
||||
|
||||
|
||||
def get_subnets(context, filters=None, fields=None):
|
||||
@@ -287,8 +285,7 @@ def get_subnets(context, filters=None, fields=None):
|
||||
(context.tenant_id, filters, fields))
|
||||
subnets = db_api.subnet_find(context, join_dns=True, join_routes=True,
|
||||
**filters)
|
||||
return v._make_subnets_list(subnets, fields=fields,
|
||||
default_route=routes.DEFAULT_ROUTE)
|
||||
return v._make_subnets_list(subnets, fields=fields)
|
||||
|
||||
|
||||
def get_subnets_count(context, filters=None):
|
||||
|
||||
@@ -42,6 +42,10 @@ quark_view_opts = [
|
||||
CONF.register_opts(quark_view_opts, "QUARK")
|
||||
|
||||
|
||||
def _is_default_route(route):
|
||||
return route.value == 0
|
||||
|
||||
|
||||
def _make_network_dict(network, fields=None):
|
||||
shared_net = STRATEGY.is_parent_network(network["id"])
|
||||
res = {"id": network["id"],
|
||||
@@ -50,11 +54,12 @@ def _make_network_dict(network, fields=None):
|
||||
"admin_state_up": None,
|
||||
"ipam_strategy": network.get("ipam_strategy"),
|
||||
"status": "ACTIVE",
|
||||
"shared": shared_net,
|
||||
#TODO(mdietz): this is the expected return. Then the client
|
||||
# foolishly turns around and asks for the entire
|
||||
# subnet list anyway! Plz2fix
|
||||
"subnets": [s["id"] for s in network.get("subnets", [])]}
|
||||
"shared": shared_net}
|
||||
if fields and "all_subnets" in fields:
|
||||
res["subnets"] = [_make_subnet_dict(s)
|
||||
for s in network.get("subnets", [])]
|
||||
else:
|
||||
res["subnets"] = [s["id"] for s in network.get("subnets", [])]
|
||||
return res
|
||||
|
||||
|
||||
@@ -80,7 +85,7 @@ def _pools_from_cidr(cidr):
|
||||
return pools
|
||||
|
||||
|
||||
def _make_subnet_dict(subnet, default_route=None, fields=None):
|
||||
def _make_subnet_dict(subnet, fields=None):
|
||||
dns_nameservers = [str(netaddr.IPAddress(dns["ip"]))
|
||||
for dns in subnet.get("dns_nameservers")]
|
||||
net_id = STRATEGY.get_parent_network(subnet["network_id"])
|
||||
@@ -116,7 +121,7 @@ def _make_subnet_dict(subnet, default_route=None, fields=None):
|
||||
default_found = False
|
||||
for route in subnet["routes"]:
|
||||
netroute = netaddr.IPNetwork(route["cidr"])
|
||||
if netroute.value == default_route.value:
|
||||
if _is_default_route(netroute):
|
||||
#NOTE(mdietz): This has the potential to find more than one default
|
||||
# route. Quark normally won't allow you to create
|
||||
# more than one, but it's plausible one exists
|
||||
@@ -201,11 +206,10 @@ def _make_ports_list(query, fields=None):
|
||||
return ports
|
||||
|
||||
|
||||
def _make_subnets_list(query, default_route=None, fields=None):
|
||||
def _make_subnets_list(query, fields=None):
|
||||
subnets = []
|
||||
for subnet in query:
|
||||
subnet_dict = _make_subnet_dict(subnet, default_route=default_route,
|
||||
fields=fields)
|
||||
subnet_dict = _make_subnet_dict(subnet, fields=fields)
|
||||
subnets.append(subnet_dict)
|
||||
return subnets
|
||||
|
||||
|
||||
Reference in New Issue
Block a user