Skip to content

Commit

Permalink
Move SG and FIP API wrapper to api.neutron
Browse files Browse the repository at this point in the history
We no longer need to have SG and FIP API wrapper in api.network
as we only supports a single network back-end.

Completes blueprint drop-nova-network

Change-Id: I4e59d897508b497a3cd2ae2fda93b30b786610dc
  • Loading branch information
amotoki committed Jun 4, 2017
1 parent b884618 commit 9067ae8
Show file tree
Hide file tree
Showing 33 changed files with 906 additions and 1,035 deletions.
122 changes: 0 additions & 122 deletions openstack_dashboard/api/network.py
Expand Up @@ -19,132 +19,10 @@
different dashboard implementations.
"""

from horizon.utils.memoized import memoized
from openstack_dashboard.api import base
from openstack_dashboard.api import neutron


class NetworkClient(object):
def __init__(self, request):
# TODO(amotoki): neutron check needs to be dropped.
# The network API wrapper can depend on neutron.
neutron_enabled = base.is_service_enabled(request, 'network')

if neutron_enabled:
self.floating_ips = neutron.FloatingIpManager(request)
else:
self.floating_ips = None

if (neutron_enabled and
neutron.is_extension_supported(request, 'security-group')):
self.secgroups = neutron.SecurityGroupManager(request)
else:
self.secgroups = None

@property
def enabled(self):
return self.floating_ips is not None


def floating_ip_pools_list(request):
return NetworkClient(request).floating_ips.list_pools()


@memoized
def tenant_floating_ip_list(request, all_tenants=False):
return NetworkClient(request).floating_ips.list(all_tenants=all_tenants)


def tenant_floating_ip_get(request, floating_ip_id):
return NetworkClient(request).floating_ips.get(floating_ip_id)


def tenant_floating_ip_allocate(request, pool=None, tenant_id=None, **params):
return NetworkClient(request).floating_ips.allocate(pool,
tenant_id,
**params)


def tenant_floating_ip_release(request, floating_ip_id):
return NetworkClient(request).floating_ips.release(floating_ip_id)


def floating_ip_associate(request, floating_ip_id, port_id):
return NetworkClient(request).floating_ips.associate(floating_ip_id,
port_id)


def floating_ip_disassociate(request, floating_ip_id):
return NetworkClient(request).floating_ips.disassociate(floating_ip_id)


def floating_ip_target_list(request):
return NetworkClient(request).floating_ips.list_targets()


def floating_ip_target_get_by_instance(request, instance_id, cache=None):
return NetworkClient(request).floating_ips.get_target_id_by_instance(
instance_id, cache)


def floating_ip_target_list_by_instance(request, instance_id, cache=None):
floating_ips = NetworkClient(request).floating_ips
return floating_ips.list_target_id_by_instance(instance_id, cache)


def floating_ip_simple_associate_supported(request):
return NetworkClient(request).floating_ips.is_simple_associate_supported()


def floating_ip_supported(request):
nwc = NetworkClient(request)
return nwc.enabled and nwc.floating_ips.is_supported()


@memoized
def security_group_list(request):
return NetworkClient(request).secgroups.list()


def security_group_get(request, sg_id):
return NetworkClient(request).secgroups.get(sg_id)


def security_group_create(request, name, desc):
return NetworkClient(request).secgroups.create(name, desc)


def security_group_delete(request, sg_id):
return NetworkClient(request).secgroups.delete(sg_id)


def security_group_update(request, sg_id, name, desc):
return NetworkClient(request).secgroups.update(sg_id, name, desc)


def security_group_rule_create(request, parent_group_id,
direction, ethertype,
ip_protocol, from_port, to_port,
cidr, group_id):
return NetworkClient(request).secgroups.rule_create(
parent_group_id, direction, ethertype, ip_protocol,
from_port, to_port, cidr, group_id)


def security_group_rule_delete(request, sgr_id):
return NetworkClient(request).secgroups.rule_delete(sgr_id)


def server_security_groups(request, instance_id):
return NetworkClient(request).secgroups.list_by_instance(instance_id)


def server_update_security_groups(request, instance_id,
new_security_group_ids):
return NetworkClient(request).secgroups.update_instance_security_group(
instance_id, new_security_group_ids)


def servers_update_addresses(request, servers, all_tenants=False):
"""Retrieve servers networking information from Neutron if enabled.
Expand Down
95 changes: 95 additions & 0 deletions openstack_dashboard/api/neutron.py
Expand Up @@ -1246,6 +1246,101 @@ def provider_list(request):
return providers['service_providers']


def floating_ip_pools_list(request):
return FloatingIpManager(request).list_pools()


@memoized
def tenant_floating_ip_list(request, all_tenants=False):
return FloatingIpManager(request).list(all_tenants=all_tenants)


def tenant_floating_ip_get(request, floating_ip_id):
return FloatingIpManager(request).get(floating_ip_id)


def tenant_floating_ip_allocate(request, pool=None, tenant_id=None, **params):
return FloatingIpManager(request).allocate(pool, tenant_id, **params)


def tenant_floating_ip_release(request, floating_ip_id):
return FloatingIpManager(request).release(floating_ip_id)


def floating_ip_associate(request, floating_ip_id, port_id):
return FloatingIpManager(request).associate(floating_ip_id, port_id)


def floating_ip_disassociate(request, floating_ip_id):
return FloatingIpManager(request).disassociate(floating_ip_id)


def floating_ip_target_list(request):
return FloatingIpManager(request).list_targets()


def floating_ip_target_get_by_instance(request, instance_id, cache=None):
return FloatingIpManager(request).get_target_id_by_instance(
instance_id, cache)


def floating_ip_target_list_by_instance(request, instance_id, cache=None):
return FloatingIpManager(request).list_target_id_by_instance(
instance_id, cache)


def floating_ip_simple_associate_supported(request):
return FloatingIpManager(request).is_simple_associate_supported()


def floating_ip_supported(request):
return FloatingIpManager(request).is_supported()


@memoized
def security_group_list(request):
return SecurityGroupManager(request).list()


def security_group_get(request, sg_id):
return SecurityGroupManager(request).get(sg_id)


def security_group_create(request, name, desc):
return SecurityGroupManager(request).create(name, desc)


def security_group_delete(request, sg_id):
return SecurityGroupManager(request).delete(sg_id)


def security_group_update(request, sg_id, name, desc):
return SecurityGroupManager(request).update(sg_id, name, desc)


def security_group_rule_create(request, parent_group_id,
direction, ethertype,
ip_protocol, from_port, to_port,
cidr, group_id):
return SecurityGroupManager(request).rule_create(
parent_group_id, direction, ethertype, ip_protocol,
from_port, to_port, cidr, group_id)


def security_group_rule_delete(request, sgr_id):
return SecurityGroupManager(request).rule_delete(sgr_id)


def server_security_groups(request, instance_id):
return SecurityGroupManager(request).list_by_instance(instance_id)


def server_update_security_groups(request, instance_id,
new_security_group_ids):
return SecurityGroupManager(request).update_instance_security_group(
instance_id, new_security_group_ids)


# TODO(pkarikh) need to uncomment when osprofiler will have no
# issues with unicode in:
# openstack_dashboard/test/test_data/nova_data.py#L470 data
Expand Down
12 changes: 6 additions & 6 deletions openstack_dashboard/api/rest/network.py
Expand Up @@ -42,7 +42,7 @@ def get(self, request):
http://localhost/api/network/securitygroups
"""

security_groups = api.network.security_group_list(request)
security_groups = api.neutron.security_group_list(request)

return {'items': [sg.to_dict() for sg in security_groups]}

Expand All @@ -63,7 +63,7 @@ def post(self, request):
:return: JSON representation of the new floating IP address
"""
pool = request.DATA['pool_id']
result = api.network.tenant_floating_ip_allocate(request, pool)
result = api.neutron.tenant_floating_ip_allocate(request, pool)
return result.to_dict()

@rest_utils.ajax(data_required=True)
Expand All @@ -77,9 +77,9 @@ def patch(self, request):
address = request.DATA['address_id']
port = request.DATA.get('port_id')
if port is None:
api.network.floating_ip_disassociate(request, address)
api.neutron.floating_ip_disassociate(request, address)
else:
api.network.floating_ip_associate(request, address, port)
api.neutron.floating_ip_associate(request, address, port)


@urls.register
Expand All @@ -98,7 +98,7 @@ def get(self, request):
Example:
http://localhost/api/network/floatingips
"""
result = api.network.tenant_floating_ip_list(request)
result = api.neutron.tenant_floating_ip_list(request)
return {'items': [ip.to_dict() for ip in result]}


Expand All @@ -118,5 +118,5 @@ def get(self, request):
Example:
http://localhost/api/network/floatingippools
"""
result = api.network.floating_ip_pools_list(request)
result = api.neutron.floating_ip_pools_list(request)
return {'items': [p.to_dict() for p in result]}
2 changes: 1 addition & 1 deletion openstack_dashboard/api/rest/nova.py
Expand Up @@ -233,7 +233,7 @@ def get(self, request, server_id):
Example GET:
http://localhost/api/nova/servers/abcd/security-groups/
"""
groups = api.network.server_security_groups(request, server_id)
groups = api.neutron.server_security_groups(request, server_id)
return {'items': [s.to_dict() for s in groups]}


Expand Down
8 changes: 4 additions & 4 deletions openstack_dashboard/dashboards/admin/aggregates/tests.py
Expand Up @@ -208,8 +208,8 @@ class AggregatesViewTests(test.BaseAdminViewTests):
'availability_zone_list',
'tenant_absolute_limits',),
api.cinder: ('tenant_absolute_limits',),
api.neutron: ('is_extension_supported',),
api.network: ('tenant_floating_ip_list',
api.neutron: ('is_extension_supported',
'tenant_floating_ip_list',
'security_group_list'),
api.keystone: ('tenant_list',)})
def test_panel_not_available(self):
Expand All @@ -220,9 +220,9 @@ def test_panel_not_available(self):
api.neutron.\
is_extension_supported(IsA(http.HttpRequest), 'security-group'). \
MultipleTimes().AndReturn(True)
api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
api.neutron.tenant_floating_ip_list(IsA(http.HttpRequest)) \
.AndReturn(self.floating_ips.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
api.neutron.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.keystone.tenant_list(IsA(http.HttpRequest)) \
.AndReturn(self.tenants.list())
Expand Down
2 changes: 1 addition & 1 deletion openstack_dashboard/dashboards/admin/floating_ips/forms.py
Expand Up @@ -50,7 +50,7 @@ def handle(self, request, data):
param['floating_ip_address'] = data['floating_ip_address']
subnet = api.neutron.subnet_get(request, data['pool'])
param['subnet_id'] = subnet.id
fip = api.network.tenant_floating_ip_allocate(
fip = api.neutron.tenant_floating_ip_allocate(
request,
pool=subnet.network_id,
tenant_id=data['tenant'],
Expand Down
Expand Up @@ -61,7 +61,7 @@ class AdminSimpleDisassociateIP(project_tables.DisassociateIP):
def single(self, table, request, obj_id):
try:
fip = table.get_object_by_id(filters.get_int_or_uuid(obj_id))
api.network.floating_ip_disassociate(request, fip.id)
api.neutron.floating_ip_disassociate(request, fip.id)
LOG.info('Disassociating Floating IP "%s".', obj_id)
messages.success(request,
_('Successfully disassociated Floating IP: %s')
Expand Down

0 comments on commit 9067ae8

Please sign in to comment.