2
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3
# not use this file except in compliance with the License. You may obtain
4
# a copy of the License at
6
# http://www.apache.org/licenses/LICENSE-2.0
8
# Unless required by applicable law or agreed to in writing, software
9
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
# License for the specific language governing permissions and limitations
14
from heat.common import exception
15
from heat.common.i18n import _
16
from heat.engine import attributes
17
from heat.engine import constraints
18
from heat.engine import properties
19
from heat.engine.resources.neutron import net
20
from heat.engine import support
23
class ProviderNet(net.Net):
25
support_status = support.SupportStatus(version='2014.1')
28
NAME, PROVIDER_NETWORK_TYPE, PROVIDER_PHYSICAL_NETWORK,
29
PROVIDER_SEGMENTATION_ID, ADMIN_STATE_UP, SHARED,
31
'name', 'network_type', 'physical_network',
32
'segmentation_id', 'admin_state_up', 'shared',
36
STATUS, SUBNETS, SHOW,
38
'status', 'subnets', 'show',
42
NAME: net.Net.properties_schema[NAME],
43
PROVIDER_NETWORK_TYPE: properties.Schema(
44
properties.Schema.STRING,
45
_('A string specifying the provider network type for the '
50
constraints.AllowedValues(['vlan', 'flat']),
53
PROVIDER_PHYSICAL_NETWORK: properties.Schema(
54
properties.Schema.STRING,
55
_('A string specifying physical network mapping for the '
60
PROVIDER_SEGMENTATION_ID: properties.Schema(
61
properties.Schema.STRING,
62
_('A string specifying the segmentation id for the '
66
ADMIN_STATE_UP: net.Net.properties_schema[ADMIN_STATE_UP],
67
SHARED: properties.Schema(
68
properties.Schema.BOOLEAN,
69
_('Whether this network should be shared across all tenants.'),
76
STATUS: attributes.Schema(
77
_("The status of the network.")
79
SUBNETS: attributes.Schema(
80
_("Subnets of this network.")
82
SHOW: attributes.Schema(
89
Validates to ensure that segmentation_id is not there for flat
92
super(ProviderNet, self).validate()
94
if (self.properties.get(self.PROVIDER_SEGMENTATION_ID) and
95
self.properties.get(self.PROVIDER_NETWORK_TYPE) != 'vlan'):
96
msg = _('segmentation_id not allowed for flat network type.')
97
raise exception.StackValidationFailed(message=msg)
100
def add_provider_extension(props, key):
101
props['provider:' + key] = props.pop(key)
104
def prepare_provider_properties(self, props):
105
self.add_provider_extension(props, self.PROVIDER_NETWORK_TYPE)
107
self.add_provider_extension(props, self.PROVIDER_PHYSICAL_NETWORK)
109
if self.PROVIDER_SEGMENTATION_ID in props.keys():
110
self.add_provider_extension(props, self.PROVIDER_SEGMENTATION_ID)
112
def handle_create(self):
114
Adds 'provider:' extension to the required properties during create.
116
props = self.prepare_properties(
118
self.physical_resource_name())
120
self.prepare_provider_properties(self, props)
122
prov_net = self.neutron().create_network({'network': props})['network']
123
self.resource_id_set(prov_net['id'])
125
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
127
Adds 'provider:' extension to the required properties during update.
129
props = self.prepare_update_properties(json_snippet)
131
self.prepare_provider_properties(self, props)
133
self.neutron().update_network(self.resource_id, {'network': props})
136
def resource_mapping():
138
'OS::Neutron::ProviderNet': ProviderNet,