Commit 0682f043 by Szabolcs Gelencser Committed by Szabolcs Gelencsér

Fix external network connectivity

parent 6c9a7148
......@@ -595,7 +595,7 @@ DEFAULT_SUBNETPOOL_PREFIXES = (
)
DEFAULT_SUBNETPOOL_PREFIX_LEN = 20
DEFAULT_PUBLIC_NETWORK_NAME = "public"
DEFAULT_EXTERNAL_NETWORK_NAME = "Smart1"
DEFAULT_PUBLIC_ROUTER_NAME_FOR_USER = "default_public"
DEFAULT_PUBLIC_ROUTED_NET_NAME_FOR_USER = "default_public_routed"
......
......@@ -102,9 +102,9 @@ class SubnetPool(object):
class DefaultPublicRouter(object):
@classmethod
def __get_default_public_network(cls, request):
def __get_external_network(cls, request):
nets = openstack_api.neutron.network_list(request)
nets = [n for n in nets if n.name == settings.DEFAULT_PUBLIC_NETWORK_NAME]
nets = [n for n in nets if n.name == settings.DEFAULT_EXTERNAL_NETWORK_NAME]
return nets[0] if len(nets) > 0 else None
@classmethod
......@@ -114,30 +114,26 @@ class DefaultPublicRouter(object):
return routers[0] if len(routers) > 0 else None
@classmethod
def create_if_not_exists(cls, request, subnet_id):
def create_if_not_exists(cls, request, network):
default_public_router = DefaultPublicRouter.__get(request)
if default_public_router is None:
default_public_router = openstack_api.neutron.router_create(
request,
name=settings.DEFAULT_PUBLIC_ROUTER_NAME_FOR_USER,
external_gateway_info={
"network_id": DefaultPublicRouter.__get_default_public_network(request).id
"network_id": DefaultPublicRouter.__get_external_network(request).id
}
)
openstack_api.neutron.router_add_interface(
request,
default_public_router.id,
subnet_id=subnet_id
subnet_id=network.subnets[0].id
)
return default_public_router
class DefaultPublicRoutedNet(object):
@classmethod
def __connect_router(cls, request, default_routed_net):
DefaultPublicRouter.create_if_not_exists(request, default_routed_net.subnets[0].id)
@classmethod
def __create_network(cls, request):
network_created = openstack_api.neutron.network_create(
request,
......@@ -169,7 +165,7 @@ class DefaultPublicRoutedNet(object):
default_routed_net = DefaultPublicRoutedNet.__get(request)
if default_routed_net is None:
default_routed_net = DefaultPublicRoutedNet.__create_network(request)
DefaultPublicRoutedNet.__connect_router(request, default_routed_net)
DefaultPublicRouter.create_if_not_exists(request, default_routed_net)
return default_routed_net
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment