Merge "Show external networks"
This commit is contained in:
commit
a23a7e0b6c
@ -170,6 +170,11 @@ class APIDictWrapper(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: %s>" % (self.__class__.__name__, self._apidict)
|
return "<%s: %s>" % (self.__class__.__name__, self._apidict)
|
||||||
|
|
||||||
|
def __cmp__(self, other):
|
||||||
|
if hasattr(other, '_apidict'):
|
||||||
|
return cmp(self._apidict, other._apidict)
|
||||||
|
return cmp(self._apidict, other)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return self._apidict
|
return self._apidict
|
||||||
|
|
||||||
|
@ -635,13 +635,13 @@ def network_get(request, network_id, expand_subnet=True, **params):
|
|||||||
LOG.debug("network_get(): netid=%s, params=%s" % (network_id, params))
|
LOG.debug("network_get(): netid=%s, params=%s" % (network_id, params))
|
||||||
network = neutronclient(request).show_network(network_id,
|
network = neutronclient(request).show_network(network_id,
|
||||||
**params).get('network')
|
**params).get('network')
|
||||||
# Since the number of subnets per network must be small,
|
|
||||||
# call subnet_get() for each subnet instead of calling
|
|
||||||
# subnet_list() once.
|
|
||||||
if expand_subnet:
|
if expand_subnet:
|
||||||
network['subnets'] = [subnet_get(request, sid)
|
if request.user.tenant_id == network['tenant_id'] or network['shared']:
|
||||||
for sid in network['subnets']]
|
# Since the number of subnets per network must be small,
|
||||||
|
# call subnet_get() for each subnet instead of calling
|
||||||
|
# subnet_list() once.
|
||||||
|
network['subnets'] = [subnet_get(request, sid)
|
||||||
|
for sid in network['subnets']]
|
||||||
return Network(network)
|
return Network(network)
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,6 +175,8 @@ class NetworksTable(tables.DataTable):
|
|||||||
verbose_name=_("Subnets Associated"),)
|
verbose_name=_("Subnets Associated"),)
|
||||||
shared = tables.Column("shared", verbose_name=_("Shared"),
|
shared = tables.Column("shared", verbose_name=_("Shared"),
|
||||||
filters=(filters.yesno, filters.capfirst))
|
filters=(filters.yesno, filters.capfirst))
|
||||||
|
external = tables.Column("router:external", verbose_name=_("External"),
|
||||||
|
filters=(filters.yesno, filters.capfirst))
|
||||||
status = tables.Column("status", verbose_name=_("Status"),
|
status = tables.Column("status", verbose_name=_("Status"),
|
||||||
display_choices=STATUS_DISPLAY_CHOICES)
|
display_choices=STATUS_DISPLAY_CHOICES)
|
||||||
admin_state = tables.Column("admin_state",
|
admin_state = tables.Column("admin_state",
|
||||||
|
@ -99,7 +99,31 @@ def _str_host_routes(host_routes):
|
|||||||
for route in host_routes])
|
for route in host_routes])
|
||||||
|
|
||||||
|
|
||||||
class NetworkTests(test.TestCase):
|
class NetworkStubMixin(object):
|
||||||
|
def _stub_net_list(self):
|
||||||
|
all_networks = self.networks.list()
|
||||||
|
api.neutron.network_list(
|
||||||
|
IsA(http.HttpRequest),
|
||||||
|
tenant_id=self.tenant.id,
|
||||||
|
shared=False).AndReturn([
|
||||||
|
network for network in all_networks
|
||||||
|
if network['tenant_id'] == self.tenant.id
|
||||||
|
])
|
||||||
|
api.neutron.network_list(
|
||||||
|
IsA(http.HttpRequest),
|
||||||
|
shared=True).AndReturn([
|
||||||
|
network for network in all_networks
|
||||||
|
if network.get('shared')
|
||||||
|
])
|
||||||
|
api.neutron.network_list(
|
||||||
|
IsA(http.HttpRequest),
|
||||||
|
**{'router:external': True}).AndReturn([
|
||||||
|
network for network in all_networks
|
||||||
|
if network.get('router:external')
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
class NetworkTests(test.TestCase, NetworkStubMixin):
|
||||||
|
|
||||||
@test.create_stubs({api.neutron: ('network_list',),
|
@test.create_stubs({api.neutron: ('network_list',),
|
||||||
quotas: ('tenant_quota_usages',)})
|
quotas: ('tenant_quota_usages',)})
|
||||||
@ -107,13 +131,7 @@ class NetworkTests(test.TestCase):
|
|||||||
quota_data = self.quota_usages.first()
|
quota_data = self.quota_usages.first()
|
||||||
quota_data['networks']['available'] = 5
|
quota_data['networks']['available'] = 5
|
||||||
quota_data['subnets']['available'] = 5
|
quota_data['subnets']['available'] = 5
|
||||||
api.neutron.network_list(
|
self._stub_net_list()
|
||||||
IsA(http.HttpRequest),
|
|
||||||
tenant_id=self.tenant.id,
|
|
||||||
shared=False).AndReturn(self.networks.list())
|
|
||||||
api.neutron.network_list(
|
|
||||||
IsA(http.HttpRequest),
|
|
||||||
shared=True).AndReturn([])
|
|
||||||
quotas.tenant_quota_usages(
|
quotas.tenant_quota_usages(
|
||||||
IsA(http.HttpRequest)) \
|
IsA(http.HttpRequest)) \
|
||||||
.MultipleTimes().AndReturn(quota_data)
|
.MultipleTimes().AndReturn(quota_data)
|
||||||
@ -830,13 +848,7 @@ class NetworkTests(test.TestCase):
|
|||||||
network.id,
|
network.id,
|
||||||
expand_subnet=False)\
|
expand_subnet=False)\
|
||||||
.AndReturn(network)
|
.AndReturn(network)
|
||||||
api.neutron.network_list(IsA(http.HttpRequest),
|
self._stub_net_list()
|
||||||
tenant_id=network.tenant_id,
|
|
||||||
shared=False)\
|
|
||||||
.AndReturn([network])
|
|
||||||
api.neutron.network_list(IsA(http.HttpRequest),
|
|
||||||
shared=True)\
|
|
||||||
.AndReturn([])
|
|
||||||
api.neutron.network_delete(IsA(http.HttpRequest), network.id)
|
api.neutron.network_delete(IsA(http.HttpRequest), network.id)
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
@ -857,12 +869,7 @@ class NetworkTests(test.TestCase):
|
|||||||
network.id,
|
network.id,
|
||||||
expand_subnet=False)\
|
expand_subnet=False)\
|
||||||
.AndReturn(network)
|
.AndReturn(network)
|
||||||
api.neutron.network_list(IsA(http.HttpRequest),
|
self._stub_net_list()
|
||||||
tenant_id=network.tenant_id,
|
|
||||||
shared=False)\
|
|
||||||
.AndReturn([network])
|
|
||||||
api.neutron.network_list(IsA(http.HttpRequest), shared=True)\
|
|
||||||
.AndReturn([])
|
|
||||||
api.neutron.subnet_delete(IsA(http.HttpRequest), subnet_id)
|
api.neutron.subnet_delete(IsA(http.HttpRequest), subnet_id)
|
||||||
api.neutron.network_delete(IsA(http.HttpRequest), network.id)
|
api.neutron.network_delete(IsA(http.HttpRequest), network.id)
|
||||||
|
|
||||||
@ -885,13 +892,7 @@ class NetworkTests(test.TestCase):
|
|||||||
network.id,
|
network.id,
|
||||||
expand_subnet=False)\
|
expand_subnet=False)\
|
||||||
.AndReturn(network)
|
.AndReturn(network)
|
||||||
api.neutron.network_list(IsA(http.HttpRequest),
|
self._stub_net_list()
|
||||||
tenant_id=network.tenant_id,
|
|
||||||
shared=False)\
|
|
||||||
.AndReturn([network])
|
|
||||||
api.neutron.network_list(IsA(http.HttpRequest),
|
|
||||||
shared=True)\
|
|
||||||
.AndReturn([])
|
|
||||||
api.neutron.subnet_delete(IsA(http.HttpRequest), subnet_id)
|
api.neutron.subnet_delete(IsA(http.HttpRequest), subnet_id)
|
||||||
api.neutron.network_delete(IsA(http.HttpRequest), network.id)\
|
api.neutron.network_delete(IsA(http.HttpRequest), network.id)\
|
||||||
.AndRaise(self.exceptions.neutron)
|
.AndRaise(self.exceptions.neutron)
|
||||||
@ -2137,7 +2138,7 @@ class NetworkPortTests(test.TestCase):
|
|||||||
self.assertRedirectsNoFollow(res, redir_url)
|
self.assertRedirectsNoFollow(res, redir_url)
|
||||||
|
|
||||||
|
|
||||||
class NetworkViewTests(test.TestCase):
|
class NetworkViewTests(test.TestCase, NetworkStubMixin):
|
||||||
|
|
||||||
def _test_create_button_shown_when_quota_disabled(
|
def _test_create_button_shown_when_quota_disabled(
|
||||||
self, expected_string):
|
self, expected_string):
|
||||||
@ -2148,13 +2149,7 @@ class NetworkViewTests(test.TestCase):
|
|||||||
quota_data['networks'].pop('available')
|
quota_data['networks'].pop('available')
|
||||||
quota_data['subnets'].pop('available')
|
quota_data['subnets'].pop('available')
|
||||||
|
|
||||||
api.neutron.network_list(
|
self._stub_net_list()
|
||||||
IsA(http.HttpRequest),
|
|
||||||
tenant_id=self.tenant.id,
|
|
||||||
shared=False).AndReturn(self.networks.list())
|
|
||||||
api.neutron.network_list(
|
|
||||||
IsA(http.HttpRequest),
|
|
||||||
shared=True).AndReturn([])
|
|
||||||
quotas.tenant_quota_usages(
|
quotas.tenant_quota_usages(
|
||||||
IsA(http.HttpRequest)) \
|
IsA(http.HttpRequest)) \
|
||||||
.MultipleTimes().AndReturn(quota_data)
|
.MultipleTimes().AndReturn(quota_data)
|
||||||
@ -2177,13 +2172,7 @@ class NetworkViewTests(test.TestCase):
|
|||||||
quota_data['networks']['available'] = network_quota
|
quota_data['networks']['available'] = network_quota
|
||||||
quota_data['subnets']['available'] = subnet_quota
|
quota_data['subnets']['available'] = subnet_quota
|
||||||
|
|
||||||
api.neutron.network_list(
|
self._stub_net_list()
|
||||||
IsA(http.HttpRequest),
|
|
||||||
tenant_id=self.tenant.id,
|
|
||||||
shared=False).AndReturn(self.networks.list())
|
|
||||||
api.neutron.network_list(
|
|
||||||
IsA(http.HttpRequest),
|
|
||||||
shared=True).AndReturn([])
|
|
||||||
quotas.tenant_quota_usages(
|
quotas.tenant_quota_usages(
|
||||||
IsA(http.HttpRequest)) \
|
IsA(http.HttpRequest)) \
|
||||||
.MultipleTimes().AndReturn(quota_data)
|
.MultipleTimes().AndReturn(quota_data)
|
||||||
|
@ -49,6 +49,13 @@ class IndexView(tables.DataTableView):
|
|||||||
tenant_id = self.request.user.tenant_id
|
tenant_id = self.request.user.tenant_id
|
||||||
networks = api.neutron.network_list_for_tenant(self.request,
|
networks = api.neutron.network_list_for_tenant(self.request,
|
||||||
tenant_id)
|
tenant_id)
|
||||||
|
# List Public networks
|
||||||
|
for network in api.neutron.network_list(
|
||||||
|
self.request, **{'router:external': True}
|
||||||
|
):
|
||||||
|
if network not in networks:
|
||||||
|
networks.append(network)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
networks = []
|
networks = []
|
||||||
msg = _('Network list can not be retrieved.')
|
msg = _('Network list can not be retrieved.')
|
||||||
|
Loading…
Reference in New Issue
Block a user