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 import resource
20
from heat.engine import support
23
class ManilaShareNetwork(resource.Resource):
25
Stores network information that will be used by share servers,
26
where shares are hosted.
29
support_status = support.SupportStatus(version='5.0.0')
32
NAME, NEUTRON_NETWORK, NEUTRON_SUBNET, NOVA_NETWORK,
33
DESCRIPTION, SECURITY_SERVICES,
35
'name', 'neutron_network', 'neutron_subnet', 'nova_network',
36
'description', 'security_services',
40
SEGMENTATION_ID, CIDR, IP_VERSION, NETWORK_TYPE,
42
'segmentation_id', 'cidr', 'ip_version', 'network_type',
46
NAME: properties.Schema(
47
properties.Schema.STRING,
48
_('Name of the share network.'),
51
NEUTRON_NETWORK: properties.Schema(
52
properties.Schema.STRING,
53
_('Neutron network id.'),
55
constraints=[constraints.CustomConstraint('neutron.network')]
57
NEUTRON_SUBNET: properties.Schema(
58
properties.Schema.STRING,
59
_('Neutron subnet id.'),
61
constraints=[constraints.CustomConstraint('neutron.subnet')]
63
NOVA_NETWORK: properties.Schema(
64
properties.Schema.STRING,
65
_('Nova network id.'),
67
constraints=[constraints.CustomConstraint('nova.network')]
69
DESCRIPTION: properties.Schema(
70
properties.Schema.STRING,
71
_('Share network description.'),
74
SECURITY_SERVICES: properties.Schema(
75
properties.Schema.LIST,
76
_('A list of security services IDs or names.'),
77
schema=properties.Schema(
78
properties.Schema.STRING
86
SEGMENTATION_ID: attributes.Schema(
87
_('VLAN ID for VLAN networks or tunnel-id for GRE/VXLAN '
89
type=attributes.Schema.STRING
91
CIDR: attributes.Schema(
93
type=attributes.Schema.STRING
95
IP_VERSION: attributes.Schema(
96
_('Version of IP address.'),
97
type=attributes.Schema.STRING
99
NETWORK_TYPE: attributes.Schema(
100
_('The physical mechanism by which the virtual network is '
102
type=attributes.Schema.STRING
106
default_client_name = 'manila'
108
def _request_network(self):
109
return self.client().share_networks.get(self.resource_id)
111
def _resolve_attribute(self, name):
112
network = self._request_network()
113
return getattr(network, name, None)
116
super(ManilaShareNetwork, self).validate()
117
if (self.properties[self.NEUTRON_NETWORK] and
118
self.properties[self.NOVA_NETWORK]):
119
raise exception.ResourcePropertyConflict(self.NEUTRON_NETWORK,
122
if (self.properties[self.NOVA_NETWORK] and
123
self.properties[self.NEUTRON_SUBNET]):
124
raise exception.ResourcePropertyConflict(self.NEUTRON_SUBNET,
127
def handle_create(self):
128
network = self.client().share_networks.create(
129
name=self.properties[self.NAME],
130
neutron_net_id=self.properties[self.NEUTRON_NETWORK],
131
neutron_subnet_id=self.properties[self.NEUTRON_SUBNET],
132
nova_net_id=self.properties[self.NOVA_NETWORK],
133
description=self.properties[self.DESCRIPTION])
134
self.resource_id_set(network.id)
136
for service in self.properties.get(self.SECURITY_SERVICES):
137
self.client().share_networks.add_security_service(
139
self.client_plugin().get_security_service(service).id)
141
def handle_update(self, json_snippet=None, tmpl_diff=None, prop_diff=None):
142
if self.SECURITY_SERVICES in prop_diff:
143
services = prop_diff.pop(self.SECURITY_SERVICES)
144
s_curr = set([self.client_plugin().get_security_service(s).id
145
for s in self.properties.get(
146
self.SECURITY_SERVICES)])
147
s_new = set([self.client_plugin().get_security_service(s).id
149
for service in s_curr - s_new:
150
self.client().share_networks.remove_security_service(
151
self.resource_id, service)
152
for service in s_new - s_curr:
153
self.client().share_networks.add_security_service(
154
self.resource_id, service)
157
self.client().share_networks.update(
159
name=prop_diff.get(self.NAME),
160
neutron_net_id=prop_diff.get(self.NEUTRON_NETWORK),
161
neutron_subnet_id=prop_diff.get(self.NEUTRON_SUBNET),
162
nova_net_id=prop_diff.get(self.NOVA_NETWORK),
163
description=prop_diff.get(self.DESCRIPTION))
165
def handle_delete(self):
167
self.client().share_networks.delete(self.resource_id)
168
except Exception as ex:
169
self.client_plugin().ignore_not_found(ex)
172
def resource_mapping():
173
return {'OS::Manila::ShareNetwork': ManilaShareNetwork}