Allow external fixed IP address to be set on Router in template
It enables that router have the external interface IP address on setting using Neutron client. But, it isn't able to set the external fixed IP address in Heat Template. Let's allow the external IP address for Router in Heat Template, too. It is needed by creating the VPN network using Heat Template, etc. Implements: blueprint specify-router-ext-ip-template Change-Id: I585c97b828a7c43e04e2ad4c63ddfc587cfcc4fe
This commit is contained in:
parent
0b0e00494e
commit
bb4a06d8f5
|
@ -43,8 +43,15 @@ class Router(neutron.NeutronResource):
|
|||
|
||||
_EXTERNAL_GATEWAY_KEYS = (
|
||||
EXTERNAL_GATEWAY_NETWORK, EXTERNAL_GATEWAY_ENABLE_SNAT,
|
||||
EXTERNAL_GATEWAY_FIXED_IPS,
|
||||
) = (
|
||||
'network', 'enable_snat',
|
||||
'network', 'enable_snat', 'external_fixed_ips',
|
||||
)
|
||||
|
||||
_EXTERNAL_GATEWAY_FIXED_IPS_KEYS = (
|
||||
IP_ADDRESS, SUBNET
|
||||
) = (
|
||||
'ip_address', 'subnet'
|
||||
)
|
||||
|
||||
ATTRIBUTES = (
|
||||
|
@ -78,6 +85,32 @@ class Router(neutron.NeutronResource):
|
|||
'this property to administrative users only.'),
|
||||
update_allowed=True
|
||||
),
|
||||
EXTERNAL_GATEWAY_FIXED_IPS: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
_('External fixed IP addresses for the gateway.'),
|
||||
schema=properties.Schema(
|
||||
properties.Schema.MAP,
|
||||
schema={
|
||||
IP_ADDRESS: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('External fixed IP address.'),
|
||||
constraints=[
|
||||
constraints.CustomConstraint('ip_addr'),
|
||||
]
|
||||
),
|
||||
SUBNET: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Subnet of external fixed IP address.'),
|
||||
constraints=[
|
||||
constraints.CustomConstraint(
|
||||
'neutron.subnet')
|
||||
]
|
||||
),
|
||||
}
|
||||
),
|
||||
update_allowed=True,
|
||||
support_status=support.SupportStatus(version='6.0.0')
|
||||
),
|
||||
},
|
||||
update_allowed=True
|
||||
),
|
||||
|
@ -217,6 +250,10 @@ class Router(neutron.NeutronResource):
|
|||
gateway, self.EXTERNAL_GATEWAY_NETWORK, 'network_id')
|
||||
if gateway[self.EXTERNAL_GATEWAY_ENABLE_SNAT] is None:
|
||||
del gateway[self.EXTERNAL_GATEWAY_ENABLE_SNAT]
|
||||
if gateway[self.EXTERNAL_GATEWAY_FIXED_IPS] is None:
|
||||
del gateway[self.EXTERNAL_GATEWAY_FIXED_IPS]
|
||||
else:
|
||||
self._resolve_subnet(gateway)
|
||||
return props
|
||||
|
||||
def _get_l3_agent_list(self, props):
|
||||
|
@ -227,6 +264,16 @@ class Router(neutron.NeutronResource):
|
|||
|
||||
return l3_agent_ids
|
||||
|
||||
def _resolve_subnet(self, gateway):
|
||||
external_gw_fixed_ips = gateway[self.EXTERNAL_GATEWAY_FIXED_IPS]
|
||||
for fixed_ip in external_gw_fixed_ips:
|
||||
for key, value in six.iteritems(fixed_ip):
|
||||
if value is None:
|
||||
fixed_ip.pop(key)
|
||||
if fixed_ip.get(self.SUBNET):
|
||||
self.client_plugin().resolve_subnet(
|
||||
fixed_ip, self.SUBNET, 'subnet_id')
|
||||
|
||||
def handle_create(self):
|
||||
props = self.prepare_properties(
|
||||
self.properties,
|
||||
|
|
|
@ -63,7 +63,7 @@ resources:
|
|||
'''
|
||||
|
||||
neutron_external_gateway_template = '''
|
||||
heat_template_version: 2015-04-30
|
||||
heat_template_version: 2016-04-08
|
||||
description: Template to test gateway Neutron resource
|
||||
resources:
|
||||
router:
|
||||
|
@ -73,6 +73,9 @@ resources:
|
|||
external_gateway_info:
|
||||
network: public
|
||||
enable_snat: true
|
||||
external_fixed_ips:
|
||||
- ip_address: 192.168.10.99
|
||||
subnet: sub1234
|
||||
'''
|
||||
|
||||
neutron_subnet_and_external_gateway_template = '''
|
||||
|
@ -708,13 +711,23 @@ class NeutronRouterTest(common.HeatTestCase):
|
|||
'public',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnet',
|
||||
'sub1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('sub1234')
|
||||
|
||||
neutronclient.Client.create_router({
|
||||
"router": {
|
||||
"name": "Test Router",
|
||||
"external_gateway_info": {
|
||||
'network_id': 'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
||||
'enable_snat': True
|
||||
'enable_snat': True,
|
||||
'external_fixed_ips': [{
|
||||
'ip_address': '192.168.10.99',
|
||||
'subnet_id': 'sub1234'
|
||||
}]
|
||||
},
|
||||
"admin_state_up": True,
|
||||
}
|
||||
|
@ -736,7 +749,11 @@ class NeutronRouterTest(common.HeatTestCase):
|
|||
"external_gateway_info": {
|
||||
"network_id":
|
||||
"fc68ea2c-b60b-4b4f-bd82-94ec81110766",
|
||||
"enable_snat": True
|
||||
"enable_snat": True,
|
||||
'external_fixed_ips': [{
|
||||
'ip_address': '192.168.10.99',
|
||||
'subnet_id': 'sub1234'
|
||||
}]
|
||||
},
|
||||
"name": "Test Router",
|
||||
"admin_state_up": True,
|
||||
|
@ -756,7 +773,11 @@ class NeutronRouterTest(common.HeatTestCase):
|
|||
"external_gateway_info": {
|
||||
"network_id":
|
||||
"fc68ea2c-b60b-4b4f-bd82-94ec81110766",
|
||||
"enable_snat": True
|
||||
"enable_snat": True,
|
||||
'external_fixed_ips': [{
|
||||
'ip_address': '192.168.10.99',
|
||||
'subnet_id': '9577cafd-8e98-4059-a2e6-8a771b4d318e'
|
||||
}]
|
||||
},
|
||||
"name": "Test Router",
|
||||
"admin_state_up": True,
|
||||
|
@ -769,16 +790,18 @@ class NeutronRouterTest(common.HeatTestCase):
|
|||
self.m.ReplayAll()
|
||||
t = template_format.parse(neutron_external_gateway_template)
|
||||
stack = utils.parse_stack(t)
|
||||
rsrc = self.create_router(t, stack, 'router')
|
||||
|
||||
rsrc.validate()
|
||||
|
||||
ref_id = rsrc.FnGetRefId()
|
||||
self.assertEqual('3e46229d-8fce-4733-819a-b5fe630550f8', ref_id)
|
||||
gateway_info = rsrc.FnGetAtt('external_gateway_info')
|
||||
router = stack['router']
|
||||
scheduler.TaskRunner(router.create)()
|
||||
self.assertEqual('3e46229d-8fce-4733-819a-b5fe630550f8',
|
||||
router.FnGetRefId())
|
||||
gateway_info = router.FnGetAtt('external_gateway_info')
|
||||
self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
||||
gateway_info.get('network_id'))
|
||||
self.assertTrue(gateway_info.get('enable_snat'))
|
||||
self.assertEqual([{'subnet_id': '9577cafd-8e98-4059-a2e6-8a771b4d318e',
|
||||
'ip_address': '192.168.10.99'}],
|
||||
gateway_info.get('external_fixed_ips'))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_create_router_gateway_enable_snat(self):
|
||||
|
@ -829,6 +852,8 @@ class NeutronRouterTest(common.HeatTestCase):
|
|||
t = template_format.parse(neutron_external_gateway_template)
|
||||
t["resources"]["router"]["properties"]["external_gateway_info"].pop(
|
||||
"enable_snat")
|
||||
t["resources"]["router"]["properties"]["external_gateway_info"].pop(
|
||||
"external_fixed_ips")
|
||||
stack = utils.parse_stack(t)
|
||||
rsrc = self.create_router(t, stack, 'router')
|
||||
|
||||
|
|
Loading…
Reference in New Issue