1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
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
8
# http://www.apache.org/licenses/LICENSE-2.0
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
16
from heat.engine import clients
17
from heat.openstack.common import log as logging
18
from heat.engine.resources.neutron import neutron
19
from heat.engine import scheduler
21
if clients.neutronclient is not None:
22
from neutronclient.common.exceptions import NeutronClientException
24
logger = logging.getLogger(__name__)
27
class Subnet(neutron.NeutronResource):
29
allocation_schema = {'start': {'Type': 'String',
31
'end': {'Type': 'String',
34
properties_schema = {'network_id': {'Type': 'String',
36
'cidr': {'Type': 'String',
38
'value_specs': {'Type': 'Map',
40
'name': {'Type': 'String'},
41
'ip_version': {'Type': 'Integer',
42
'AllowedValues': [4, 6],
44
'dns_nameservers': {'Type': 'List'},
45
'gateway_ip': {'Type': 'String'},
46
'enable_dhcp': {'Type': 'Boolean'},
47
'allocation_pools': {'Type': 'List',
50
'Schema': allocation_schema
53
"name": "friendly name of the subnet",
54
"network_id": "parent network of the subnet",
55
"tenant_id": "tenant owning the subnet",
56
"allocation_pools": "ip allocation pools and their ranges",
57
"gateway_ip": "ip of the subnet's gateway",
58
"ip_version": "ip version for the subnet",
59
"cidr": "CIDR block notation for this subnet",
60
"id": "unique identifier for this subnet",
61
# dns_nameservers isn't in the api docs; is it right?
62
"dns_nameservers": "list of dns nameservers",
63
"enable_dhcp": ("'true' if DHCP is enabled for this subnet; 'false'"
67
def handle_create(self):
68
props = self.prepare_properties(
70
self.physical_resource_name())
71
subnet = self.neutron().create_subnet({'subnet': props})['subnet']
72
self.resource_id_set(subnet['id'])
74
def handle_delete(self):
75
client = self.neutron()
77
client.delete_subnet(self.resource_id)
78
except NeutronClientException as ex:
79
if ex.status_code != 404:
82
return scheduler.TaskRunner(self._confirm_delete)()
84
def _show_resource(self):
85
return self.neutron().show_subnet(self.resource_id)['subnet']
88
def resource_mapping():
89
if clients.neutronclient is None:
93
'OS::Neutron::Subnet': Subnet,
94
'OS::Quantum::Subnet': Subnet,