Make supported record type configurable
Also made the distinction between 'valid' and 'supported' record types. For example an error of "'foo' is not a valid record type" will return when user tries to create a record type of 'foo'. User will get "'SPF' is not a supported record type" if operator chooses not to expose SPF. Implements blueprint configurable-record-type Change-Id: I22410a760a5ec78270162496ee03f2b2b8ba7d25
This commit is contained in:
parent
aaf0defeb7
commit
79a4af0455
@ -58,6 +58,11 @@ cfg.CONF.register_opts([
|
|||||||
cfg.IntOpt('default-soa-retry', default=600),
|
cfg.IntOpt('default-soa-retry', default=600),
|
||||||
cfg.IntOpt('default-soa-expire', default=86400),
|
cfg.IntOpt('default-soa-expire', default=86400),
|
||||||
cfg.IntOpt('default-soa-minimum', default=3600),
|
cfg.IntOpt('default-soa-minimum', default=3600),
|
||||||
|
|
||||||
|
# Supported record types
|
||||||
|
cfg.ListOpt('supported-record-type', help='Supported record types',
|
||||||
|
default=['A', 'AAAA', 'CNAME', 'MX', 'SRV', 'TXT', 'SPF', 'NS',
|
||||||
|
'PTR', 'SSHFP', 'SOA']),
|
||||||
])
|
])
|
||||||
|
|
||||||
# Set some Oslo Log defaults
|
# Set some Oslo Log defaults
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from designate import exceptions
|
from designate import exceptions
|
||||||
@ -27,6 +28,8 @@ from designate.objects.validation_error import ValidationErrorList
|
|||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
cfg.CONF.import_opt('supported_record_type', 'designate')
|
||||||
|
|
||||||
|
|
||||||
class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin,
|
class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||||
base.DesignateObject):
|
base.DesignateObject):
|
||||||
@ -105,8 +108,6 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin,
|
|||||||
'schema': {
|
'schema': {
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
'description': 'RecordSet type (TODO: Make types extensible)',
|
'description': 'RecordSet type (TODO: Make types extensible)',
|
||||||
'enum': ['A', 'AAAA', 'CNAME', 'MX', 'SRV', 'TXT', 'SPF', 'NS',
|
|
||||||
'PTR', 'SSHFP', 'SOA']
|
|
||||||
},
|
},
|
||||||
'required': True,
|
'required': True,
|
||||||
'immutable': True
|
'immutable': True
|
||||||
@ -137,6 +138,18 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin,
|
|||||||
# },
|
# },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _validate_fail(self, errors, msg):
|
||||||
|
e = ValidationError()
|
||||||
|
e.path = ['recordset', 'type']
|
||||||
|
e.validator = 'value'
|
||||||
|
e.validator_value = [self.type]
|
||||||
|
e.message = msg
|
||||||
|
# Add it to the list for later
|
||||||
|
errors.append(e)
|
||||||
|
raise exceptions.InvalidObject(
|
||||||
|
"Provided object does not match "
|
||||||
|
"schema", errors=errors, object=self)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
|
||||||
LOG.debug("Validating '%(name)s' object with values: %(values)r", {
|
LOG.debug("Validating '%(name)s' object with values: %(values)r", {
|
||||||
@ -151,17 +164,14 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin,
|
|||||||
record_list_cls = self.obj_cls_from_name('%sList' % self.type)
|
record_list_cls = self.obj_cls_from_name('%sList' % self.type)
|
||||||
record_cls = self.obj_cls_from_name(self.type)
|
record_cls = self.obj_cls_from_name(self.type)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
e = ValidationError()
|
err_msg = ("'%(type)s' is not a valid record type"
|
||||||
e.path = ['recordset', 'type']
|
|
||||||
e.validator = 'value'
|
|
||||||
e.validator_value = [self.type]
|
|
||||||
e.message = ("'%(type)s' is not a supported Record type"
|
|
||||||
% {'type': self.type})
|
% {'type': self.type})
|
||||||
# Add it to the list for later
|
self._validate_fail(errors, err_msg)
|
||||||
errors.append(e)
|
|
||||||
raise exceptions.InvalidObject(
|
if self.type not in cfg.CONF.supported_record_type:
|
||||||
"Provided object does not match "
|
err_msg = ("'%(type)s' is not a supported record type"
|
||||||
"schema", errors=errors, object=self)
|
% {'type': self.type})
|
||||||
|
self._validate_fail(errors, err_msg)
|
||||||
|
|
||||||
# Get any rules that the record type imposes on the record
|
# Get any rules that the record type imposes on the record
|
||||||
changes = record_cls.get_recordset_schema_changes()
|
changes = record_cls.get_recordset_schema_changes()
|
||||||
|
@ -22,6 +22,9 @@ notification_driver = messaging
|
|||||||
# Change to "sudo" to skip the filtering and just run the command directly
|
# Change to "sudo" to skip the filtering and just run the command directly
|
||||||
# root_helper = sudo
|
# root_helper = sudo
|
||||||
|
|
||||||
|
# Supported record types
|
||||||
|
#supported_record_type = A, AAAA, CNAME, MX, SRV, TXT, SPF, NS, PTR, SSHFP, SOA
|
||||||
|
|
||||||
# RabbitMQ Config
|
# RabbitMQ Config
|
||||||
rabbit_userid = designate
|
rabbit_userid = designate
|
||||||
rabbit_password = designate
|
rabbit_password = designate
|
||||||
|
@ -34,6 +34,9 @@ debug = False
|
|||||||
# Which networking API to use, Defaults to neutron
|
# Which networking API to use, Defaults to neutron
|
||||||
#network_api = neutron
|
#network_api = neutron
|
||||||
|
|
||||||
|
# Supported record types
|
||||||
|
#supported_record_type = A, AAAA, CNAME, MX, SRV, TXT, SPF, NS, PTR, SSHFP, SOA
|
||||||
|
|
||||||
#-----------------------
|
#-----------------------
|
||||||
# RabbitMQ Config
|
# RabbitMQ Config
|
||||||
#-----------------------
|
#-----------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user