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.i18n import _
15
from heat.engine import constraints
16
from heat.engine import properties
17
from heat.engine import resource
18
from heat.engine import support
21
class DesignateRecord(resource.Resource):
22
"""Heat Template Resource for Designate Record."""
24
support_status = support.SupportStatus(
28
NAME, TTL, DESCRIPTION, TYPE, DATA, PRIORITY, DOMAIN
30
'name', 'ttl', 'description', 'type', 'data', 'priority', 'domain'
34
A, AAAA, CNAME, MX, SRV, TXT, SPF,
37
'A', 'AAAA', 'CNAME', 'MX', 'SRV', 'TXT', 'SPF',
38
'NS', 'PTR', 'SSHFP', 'SOA'
42
# Based on RFC 1035, length of name is set to max of 255
43
NAME: properties.Schema(
44
properties.Schema.STRING,
47
constraints=[constraints.Length(max=255)]
49
# Based on RFC 1035, range for ttl is set to 0 to signed 32 bit number
50
TTL: properties.Schema(
51
properties.Schema.INTEGER,
52
_('Time To Live (Seconds).'),
54
constraints=[constraints.Range(min=0,
57
# designate mandates to the max length of 160 for description
58
DESCRIPTION: properties.Schema(
59
properties.Schema.STRING,
60
_('Description of record.'),
62
constraints=[constraints.Length(max=160)]
64
TYPE: properties.Schema(
65
properties.Schema.STRING,
66
_('DNS Record type.'),
69
constraints=[constraints.AllowedValues(
73
DATA: properties.Schema(
74
properties.Schema.STRING,
75
_('DNS record data, varies based on the type of record. For more '
76
'details, please refer rfc 1035.'),
80
# Based on RFC 1035, range for priority is set to 0 to signed 16 bit
82
PRIORITY: properties.Schema(
83
properties.Schema.INTEGER,
84
_('DNS record priority. It is considered only for MX and SRV '
85
'types, otherwise, it is ignored.'),
87
constraints=[constraints.Range(min=0,
90
DOMAIN: properties.Schema(
91
properties.Schema.STRING,
92
_('DNS Domain id or name.'),
94
constraints=[constraints.CustomConstraint('designate.domain')]
98
default_client_name = 'designate'
100
def handle_create(self):
102
name=self.properties[self.NAME],
103
type=self.properties[self.TYPE],
104
description=self.properties[self.DESCRIPTION],
105
ttl=self.properties[self.TTL],
106
data=self.properties[self.DATA],
107
# priority is considered only for MX and SRV record.
108
priority=(self.properties[self.PRIORITY]
109
if self.properties[self.TYPE] in (self.MX, self.SRV)
111
domain=self.properties[self.DOMAIN]
114
domain = self.client_plugin().record_create(**args)
116
self.resource_id_set(domain.id)
118
def handle_update(self,
124
if prop_diff.get(self.TTL):
125
args['ttl'] = prop_diff.get(self.TTL)
127
if prop_diff.get(self.DESCRIPTION):
128
args['description'] = prop_diff.get(self.DESCRIPTION)
130
if prop_diff.get(self.TYPE):
131
args['type'] = prop_diff.get(self.TYPE)
133
# priority is considered only for MX and SRV record.
134
if prop_diff.get(self.PRIORITY):
135
args['priority'] = (prop_diff.get(self.PRIORITY)
136
if (prop_diff.get(self.TYPE) or
137
self.properties[self.TYPE]) in
141
if prop_diff.get(self.DATA):
142
args['data'] = prop_diff.get(self.DATA)
144
if len(args.keys()) > 0:
145
args['id'] = self.resource_id
146
args['domain'] = self.properties[self.DOMAIN]
147
self.client_plugin().record_update(**args)
149
def handle_delete(self):
150
if self.resource_id is not None:
152
self.client_plugin().record_delete(
154
domain=self.properties[self.DOMAIN]
156
except Exception as ex:
157
self.client_plugin().ignore_not_found(ex)
160
def resource_mapping():
162
'OS::Designate::Record': DesignateRecord