Translate networks and subnet in cluster template
Translate 'external_network', 'fixed_network', 'fixed_subnet' in cluster template from name to id. Closes-Bug: #1719493 Change-Id: I78670cb4d394597b36c43d53f0f8094cb8bd285a
This commit is contained in:
parent
8818adb0f5
commit
58d9b55147
|
@ -19,6 +19,7 @@ from heat.engine import constraints
|
|||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
from heat.engine import support
|
||||
from heat.engine import translation
|
||||
|
||||
|
||||
class ClusterTemplate(resource.Resource):
|
||||
|
@ -40,7 +41,7 @@ class ClusterTemplate(resource.Resource):
|
|||
DOCKER_VOLUME_SIZE, DOCKER_STORAGE_DRIVER, COE,
|
||||
NETWORK_DRIVER, VOLUME_DRIVER, HTTP_PROXY, HTTPS_PROXY,
|
||||
NO_PROXY, LABELS, TLS_DISABLED, PUBLIC, REGISTRY_ENABLED,
|
||||
SERVER_TYPE, MASTER_LB_ENABLED, FLOATING_IP_ENABLED
|
||||
SERVER_TYPE, MASTER_LB_ENABLED, FLOATING_IP_ENABLED
|
||||
) = (
|
||||
'name', 'image', 'flavor', 'master_flavor', 'keypair',
|
||||
'external_network', 'fixed_network', 'fixed_subnet', 'dns_nameserver',
|
||||
|
@ -93,7 +94,8 @@ class ClusterTemplate(resource.Resource):
|
|||
),
|
||||
EXTERNAL_NETWORK: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('The external neutron network to attach the Cluster.'),
|
||||
_('The external neutron network name or UUID to attach the '
|
||||
'Cluster.'),
|
||||
constraints=[
|
||||
constraints.CustomConstraint('neutron.network')
|
||||
],
|
||||
|
@ -101,14 +103,16 @@ class ClusterTemplate(resource.Resource):
|
|||
),
|
||||
FIXED_NETWORK: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('The fixed neutron network to attach the Cluster.'),
|
||||
_('The fixed neutron network name or UUID to attach the '
|
||||
'Cluster.'),
|
||||
constraints=[
|
||||
constraints.CustomConstraint('neutron.network')
|
||||
]
|
||||
),
|
||||
FIXED_SUBNET: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('The fixed neutron subnet to attach the Cluster.'),
|
||||
_('The fixed neutron subnet name or UUID to attach the '
|
||||
'Cluster.'),
|
||||
constraints=[
|
||||
constraints.CustomConstraint('neutron.subnet')
|
||||
]
|
||||
|
@ -214,6 +218,34 @@ class ClusterTemplate(resource.Resource):
|
|||
),
|
||||
}
|
||||
|
||||
def translation_rules(self, props):
|
||||
return [
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.EXTERNAL_NETWORK],
|
||||
client_plugin=self.client_plugin('neutron'),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='network'
|
||||
),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.FIXED_NETWORK],
|
||||
client_plugin=self.client_plugin('neutron'),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='network'
|
||||
),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.FIXED_SUBNET],
|
||||
client_plugin=self.client_plugin('neutron'),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='subnet'
|
||||
)
|
||||
]
|
||||
|
||||
def validate(self):
|
||||
"""Validate the provided params."""
|
||||
super(ClusterTemplate, self).validate()
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
import copy
|
||||
import mock
|
||||
from neutronclient.neutron import v2_0 as neutronV20
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
|
@ -66,9 +67,9 @@ class TestMagnumClusterTemplate(common.HeatTestCase):
|
|||
'flavor_id': 'm1.small',
|
||||
'master_flavor_id': 'm1.medium',
|
||||
'keypair_id': 'heat_key',
|
||||
'external_network_id': '0244b54d-ae1f-44f0-a24a-442760f1d681',
|
||||
'fixed_network': '0f59a3dd-fac1-4d03-b41a-d4115fbffa89',
|
||||
'fixed_subnet': '27a8c89c-0d28-4946-8c78-82cfec1d670a',
|
||||
'external_network_id': 'id_for_net_or_sub',
|
||||
'fixed_network': 'id_for_net_or_sub',
|
||||
'fixed_subnet': 'id_for_net_or_sub',
|
||||
'dns_nameserver': '8.8.8.8',
|
||||
'docker_volume_size': 5,
|
||||
'docker_storage_driver': 'devicemapper',
|
||||
|
@ -99,6 +100,9 @@ class TestMagnumClusterTemplate(common.HeatTestCase):
|
|||
self.client = mock.Mock()
|
||||
self.patchobject(cluster_template.ClusterTemplate, 'client',
|
||||
return_value=self.client)
|
||||
self.find_mock = self.patchobject(neutronV20,
|
||||
'find_resourceid_by_name_or_id')
|
||||
self.find_mock.return_value = 'id_for_net_or_sub'
|
||||
self.stub_FlavorConstraint_validate()
|
||||
self.stub_KeypairConstraint_validate()
|
||||
self.stub_ImageConstraint_validate()
|
||||
|
|
Loading…
Reference in New Issue