~ubuntu-branches/ubuntu/trusty/heat/trusty-security

« back to all changes in this revision

Viewing changes to heat/engine/resources/neutron/vpnservice.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-09-08 21:51:19 UTC
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: package-import@ubuntu.com-20130908215119-7tcek6gn73275x5k
Tags: upstream-2013.2~b3
ImportĀ upstreamĀ versionĀ 2013.2~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
from heat.engine import clients
 
17
from heat.engine.resources.neutron import neutron
 
18
from heat.engine import scheduler
 
19
 
 
20
if clients.neutronclient is not None:
 
21
    from neutronclient.common.exceptions import NeutronClientException
 
22
 
 
23
from heat.openstack.common import log as logging
 
24
 
 
25
logger = logging.getLogger(__name__)
 
26
 
 
27
 
 
28
class VPNService(neutron.NeutronResource):
 
29
    """
 
30
    A resource for VPN service in Neutron.
 
31
    """
 
32
 
 
33
    properties_schema = {'name': {'Type': 'String'},
 
34
                         'description': {'Type': 'String'},
 
35
                         'admin_state_up': {'Type': 'Boolean',
 
36
                                            'Default': True},
 
37
                         'subnet_id': {'Type': 'String',
 
38
                                       'Required': True},
 
39
                         'router_id': {'Type': 'String',
 
40
                                       'Required': True}}
 
41
 
 
42
    attributes_schema = {
 
43
        'admin_state_up': 'the administrative state of the vpn service',
 
44
        'description': 'description of the vpn service',
 
45
        'id': 'unique identifier for the vpn service',
 
46
        'name': 'name for the vpn service',
 
47
        'router_id': 'unique identifier for router used to create the vpn'
 
48
                     ' service',
 
49
        'status': 'the status of the vpn service',
 
50
        'subnet_id': 'unique identifier for subnet used to create the vpn'
 
51
                     ' service',
 
52
        'tenant_id': 'tenant owning the vpn service'
 
53
    }
 
54
 
 
55
    update_allowed_keys = ('Properties',)
 
56
 
 
57
    update_allowed_properties = ('name', 'description', 'admin_state_up',)
 
58
 
 
59
    def _show_resource(self):
 
60
        return self.neutron().show_vpnservice(self.resource_id)['vpnservice']
 
61
 
 
62
    def handle_create(self):
 
63
        props = self.prepare_properties(
 
64
            self.properties,
 
65
            self.physical_resource_name())
 
66
        vpnservice = self.neutron().create_vpnservice({'vpnservice': props})[
 
67
            'vpnservice']
 
68
        self.resource_id_set(vpnservice['id'])
 
69
 
 
70
    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
 
71
        if prop_diff:
 
72
            self.neutron().update_vpnservice(self.resource_id,
 
73
                                             {'vpnservice': prop_diff})
 
74
 
 
75
    def handle_delete(self):
 
76
        client = self.neutron()
 
77
        try:
 
78
            client.delete_vpnservice(self.resource_id)
 
79
        except NeutronClientException as ex:
 
80
            if ex.status_code != 404:
 
81
                raise ex
 
82
        else:
 
83
            return scheduler.TaskRunner(self._confirm_delete)()
 
84
 
 
85
 
 
86
class IPsecSiteConnection(neutron.NeutronResource):
 
87
    """
 
88
    A resource for IPsec site connection in Neutron.
 
89
    """
 
90
 
 
91
    dpd_schema = {
 
92
        'actions': {'Type': 'String',
 
93
                    'AllowedValues': ['clear',
 
94
                                      'disabled',
 
95
                                      'hold',
 
96
                                      'restart',
 
97
                                      'restart-by-peer'],
 
98
                    'Default': 'hold'},
 
99
        'interval': {'Type': 'Integer',
 
100
                     'Default': 30},
 
101
        'timeout': {'Type': 'Integer',
 
102
                    'Default': 120},
 
103
    }
 
104
 
 
105
    properties_schema = {'name': {'Type': 'String'},
 
106
                         'description': {'Type': 'String'},
 
107
                         'peer_address': {'Type': 'String',
 
108
                                          'Required': True},
 
109
                         'peer_id': {'Type': 'String',
 
110
                                     'Required': True},
 
111
                         'peer_cidrs': {'Type': 'List',
 
112
                                        'Required': True},
 
113
                         'mtu': {'Type': 'Integer',
 
114
                                 'Default': 1500},
 
115
                         'dpd': {'Type': 'Map', 'Schema': dpd_schema},
 
116
                         'psk': {'Type': 'String',
 
117
                                 'Required': True},
 
118
                         'initiator': {'Type': 'String',
 
119
                                       'AllowedValues': ['bi-directional',
 
120
                                                         'response-only'],
 
121
                                       'Default': 'bi-directional'},
 
122
                         'admin_state_up': {'Type': 'Boolean',
 
123
                                            'Default': True},
 
124
                         'ikepolicy_id': {'Type': 'String',
 
125
                                          'Required': True},
 
126
                         'ipsecpolicy_id': {'Type': 'String',
 
127
                                            'Required': True},
 
128
                         'vpnservice_id': {'Type': 'String',
 
129
                                           'Required': True}}
 
130
 
 
131
    attributes_schema = {
 
132
        'admin_state_up': 'the administrative state of the ipsec site'
 
133
                          ' connection',
 
134
        'auth_mode': 'authentication mode used by the ipsec site connection',
 
135
        'description': 'description of the ipsec site connection',
 
136
        'dpd': 'configuration of dead peer detection protocol',
 
137
        'id': 'unique identifier for the ipsec site connection',
 
138
        'ikepolicy_id': 'unique identifier for ike policy used to create the'
 
139
                        ' ipsec site connection',
 
140
        'initiator': 'initiator of the ipsec site connection',
 
141
        'ipsecpolicy_id': 'unique identifier for ipsec policy used to create'
 
142
                          ' the ipsec site connection',
 
143
        'mtu': 'maximum transmission unit to address fragmentation',
 
144
        'name': 'name for the ipsec site connection',
 
145
        'peer_address': 'peer vpn gateway public address or FQDN',
 
146
        'peer_cidrs': 'peer private cidrs',
 
147
        'peer_id': 'peer identifier (name, string or FQDN)',
 
148
        'psk': 'pre-shared-key used to create the ipsec site connection',
 
149
        'route_mode': 'route mode used to create the ipsec site connection',
 
150
        'status': 'the status of the ipsec site connection',
 
151
        'tenant_id': 'tenant owning the ipsec site connection',
 
152
        'vpnservice_id': 'unique identifier for vpn service used to create the'
 
153
                         ' ipsec site connection'
 
154
    }
 
155
 
 
156
    update_allowed_keys = ('Properties',)
 
157
 
 
158
    update_allowed_properties = ('name', 'description', 'admin_state_up',)
 
159
 
 
160
    def _show_resource(self):
 
161
        return self.neutron().show_ipsec_site_connection(self.resource_id)[
 
162
            'ipsec_site_connection']
 
163
 
 
164
    def handle_create(self):
 
165
        props = self.prepare_properties(
 
166
            self.properties,
 
167
            self.physical_resource_name())
 
168
        ipsec_site_connection = self.neutron().create_ipsec_site_connection(
 
169
            {'ipsec_site_connection': props})['ipsec_site_connection']
 
170
        self.resource_id_set(ipsec_site_connection['id'])
 
171
 
 
172
    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
 
173
        if prop_diff:
 
174
            self.neutron().update_ipsec_site_connection(
 
175
                self.resource_id, {'ipsec_site_connection': prop_diff})
 
176
 
 
177
    def handle_delete(self):
 
178
        client = self.neutron()
 
179
        try:
 
180
            client.delete_ipsec_site_connection(self.resource_id)
 
181
        except NeutronClientException as ex:
 
182
            if ex.status_code != 404:
 
183
                raise ex
 
184
        else:
 
185
            return scheduler.TaskRunner(self._confirm_delete)()
 
186
 
 
187
 
 
188
class IKEPolicy(neutron.NeutronResource):
 
189
    """
 
190
    A resource for IKE policy in Neutron.
 
191
    """
 
192
 
 
193
    lifetime_schema = {
 
194
        'units': {'Type': 'String', 'AllowedValues': ['seconds', 'kilobytes'],
 
195
                  'Default': 'seconds'},
 
196
        'value': {'Type': 'Integer', 'Default': 3600},
 
197
    }
 
198
 
 
199
    properties_schema = {'name': {'Type': 'String'},
 
200
                         'description': {'Type': 'String'},
 
201
                         'auth_algorithm': {'Type': 'String',
 
202
                                            'AllowedValues': ['sha1'],
 
203
                                            'Default': 'sha1'},
 
204
                         'encryption_algorithm': {'Type': 'String',
 
205
                                                  'AllowedValues': ['3des',
 
206
                                                                    'aes-128',
 
207
                                                                    'aes-192',
 
208
                                                                    'aes-256'],
 
209
                                                  'Default': 'aes-128'},
 
210
                         'phase1_negotiation_mode': {'Type': 'String',
 
211
                                                     'AllowedValues': ['main'],
 
212
                                                     'Default': 'main'},
 
213
                         'lifetime': {'Type': 'Map',
 
214
                                      'Schema': lifetime_schema},
 
215
                         'pfs': {'Type': 'String',
 
216
                                 'AllowedValues': ['group2', 'group5',
 
217
                                                   'group14'],
 
218
                                 'Default': 'group5'},
 
219
                         'ike_version': {'Type': 'String',
 
220
                                         'AllowedValues': ['v1', 'v2'],
 
221
                                         'Default': 'v1'}}
 
222
 
 
223
    attributes_schema = {
 
224
        'auth_algorithm': 'authentication hash algorithm used by the ike'
 
225
                          ' policy',
 
226
        'description': 'description of the ike policy',
 
227
        'encryption_algorithm': 'encryption algorithm used by the ike policy',
 
228
        'id': 'unique identifier for the ike policy',
 
229
        'ike_version': 'version of the ike policy',
 
230
        'lifetime': 'configuration of safety assessment lifetime for the ike'
 
231
                    ' policy',
 
232
        'name': 'name for the ike policy',
 
233
        'pfs': 'perfect forward secrecy for the ike policy',
 
234
        'phase1_negotiation_mode': 'negotiation mode for the ike policy',
 
235
        'tenant_id': 'tenant owning the ike policy',
 
236
    }
 
237
 
 
238
    update_allowed_keys = ('Properties',)
 
239
 
 
240
    update_allowed_properties = ('name', 'description',)
 
241
 
 
242
    def _show_resource(self):
 
243
        return self.neutron().show_ikepolicy(self.resource_id)['ikepolicy']
 
244
 
 
245
    def handle_create(self):
 
246
        props = self.prepare_properties(
 
247
            self.properties,
 
248
            self.physical_resource_name())
 
249
        ikepolicy = self.neutron().create_ikepolicy({'ikepolicy': props})[
 
250
            'ikepolicy']
 
251
        self.resource_id_set(ikepolicy['id'])
 
252
 
 
253
    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
 
254
        if prop_diff:
 
255
            self.neutron().update_ikepolicy(self.resource_id,
 
256
                                            {'ikepolicy': prop_diff})
 
257
 
 
258
    def handle_delete(self):
 
259
        client = self.neutron()
 
260
        try:
 
261
            client.delete_ikepolicy(self.resource_id)
 
262
        except NeutronClientException as ex:
 
263
            if ex.status_code != 404:
 
264
                raise ex
 
265
        else:
 
266
            return scheduler.TaskRunner(self._confirm_delete)()
 
267
 
 
268
 
 
269
class IPsecPolicy(neutron.NeutronResource):
 
270
    """
 
271
    A resource for IPsec policy in Neutron.
 
272
    """
 
273
 
 
274
    lifetime_schema = {
 
275
        'units': {'Type': 'String', 'AllowedValues': ['seconds', 'kilobytes'],
 
276
                  'Default': 'seconds'},
 
277
        'value': {'Type': 'Integer', 'Default': 3600},
 
278
    }
 
279
 
 
280
    properties_schema = {'name': {'Type': 'String'},
 
281
                         'description': {'Type': 'String'},
 
282
                         'transform_protocol': {'Type': 'String',
 
283
                                                'AllowedValues': ['esp', 'ah',
 
284
                                                                  'ah-esp'],
 
285
                                                'Default': 'esp'},
 
286
                         'encapsulation_mode': {'Type': 'String',
 
287
                                                'AllowedValues': ['tunnel',
 
288
                                                                  'transport'],
 
289
                                                'Default': 'tunnel'},
 
290
                         'auth_algorithm': {'Type': 'String',
 
291
                                            'AllowedValues': ['sha1'],
 
292
                                            'Default': 'sha1'},
 
293
                         'encryption_algorithm': {'Type': 'String',
 
294
                                                  'AllowedValues': ['3des',
 
295
                                                                    'aes-128',
 
296
                                                                    'aes-192',
 
297
                                                                    'aes-256'],
 
298
                                                  'Default': 'aes-128'},
 
299
                         'lifetime': {'Type': 'Map',
 
300
                                      'Schema': lifetime_schema},
 
301
                         'pfs': {'Type': 'String',
 
302
                                 'AllowedValues': ['group2', 'group5',
 
303
                                                   'group14'],
 
304
                                 'Default': 'group5'}}
 
305
 
 
306
    attributes_schema = {
 
307
        'auth_algorithm': 'authentication hash algorithm used by the ipsec'
 
308
                          ' policy',
 
309
        'description': 'description of the ipsec policy',
 
310
        'encapsulation_mode': 'encapsulation mode for the ipsec policy',
 
311
        'encryption_algorithm': 'encryption algorithm for the ipsec policy',
 
312
        'id': 'unique identifier for this ipsec policy',
 
313
        'lifetime': 'configuration of safety assessment lifetime for the ipsec'
 
314
                    ' policy',
 
315
        'name': 'name for the ipsec policy',
 
316
        'pfs': 'perfect forward secrecy for the ipsec policy',
 
317
        'tenant_id': 'tenant owning the ipsec policy',
 
318
        'transform_protocol': 'transform protocol for the ipsec policy'
 
319
    }
 
320
 
 
321
    update_allowed_keys = ('Properties',)
 
322
 
 
323
    update_allowed_properties = ('name', 'description',)
 
324
 
 
325
    def _show_resource(self):
 
326
        return self.neutron().show_ipsecpolicy(self.resource_id)['ipsecpolicy']
 
327
 
 
328
    def handle_create(self):
 
329
        props = self.prepare_properties(
 
330
            self.properties,
 
331
            self.physical_resource_name())
 
332
        ipsecpolicy = self.neutron().create_ipsecpolicy(
 
333
            {'ipsecpolicy': props})['ipsecpolicy']
 
334
        self.resource_id_set(ipsecpolicy['id'])
 
335
 
 
336
    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
 
337
        if prop_diff:
 
338
            self.neutron().update_ipsecpolicy(self.resource_id,
 
339
                                              {'ipsecpolicy': prop_diff})
 
340
 
 
341
    def handle_delete(self):
 
342
        client = self.neutron()
 
343
        try:
 
344
            client.delete_ipsecpolicy(self.resource_id)
 
345
        except NeutronClientException as ex:
 
346
            if ex.status_code != 404:
 
347
                raise ex
 
348
        else:
 
349
            return scheduler.TaskRunner(self._confirm_delete)()
 
350
 
 
351
 
 
352
def resource_mapping():
 
353
    if clients.neutronclient is None:
 
354
        return {}
 
355
 
 
356
    return {
 
357
        'OS::Neutron::VPNService': VPNService,
 
358
        'OS::Neutron::IPsecSiteConnection': IPsecSiteConnection,
 
359
        'OS::Neutron::IKEPolicy': IKEPolicy,
 
360
        'OS::Neutron::IPsecPolicy': IPsecPolicy,
 
361
    }