Added Schemas to DesignateObjects

This enables the <object>.validate() command

Partially-Implements: blueprint validation-cleanup

Change-Id: I147ae0b622f5fd29f536846607b5f7fa2cb87606
This commit is contained in:
Graham Hayes 2015-03-10 12:02:14 +00:00
parent 1c07a1de32
commit a604ec01ae
14 changed files with 520 additions and 76 deletions

View File

@ -18,8 +18,22 @@ from designate.objects import base
class Blacklist(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject):
FIELDS = {
'pattern': {},
'description': {}
'pattern': {
'schema': {
'type': 'string',
'description': 'Regex for blacklisted zone name',
'format': 'regex',
'maxLength': 255,
},
'required': True
},
'description': {
'schema': {
'type': ['string', 'null'],
'description': 'Description for the blacklisted zone',
'maxLength': 160
}
}
}

View File

@ -18,20 +18,112 @@ from designate.objects import base
class Domain(base.DictObjectMixin, base.SoftDeleteObjectMixin,
base.PersistentObjectMixin, base.DesignateObject):
FIELDS = {
'tenant_id': {},
'name': {},
'email': {},
'ttl': {},
'refresh': {},
'retry': {},
'expire': {},
'minimum': {},
'parent_domain_id': {},
'serial': {},
'description': {},
'status': {},
'action': {},
'pool_id': {},
'tenant_id': {
'schema': {
'type': 'string',
},
'immutable': True
},
'name': {
'schema': {
'type': 'string',
'description': 'Zone name',
'format': 'domainname',
'maxLength': 255,
},
'immutable': True,
'required': True
},
'email': {
'schema': {
'type': 'string',
'description': 'Hostmaster email address',
'format': 'email',
'maxLength': 255
},
'required': True
},
'ttl': {
'schema': {
'type': ['integer', 'null'],
'minimum': 0,
'maximum': 2147483647
},
},
'refresh': {
'schema': {
'type': 'integer',
'minimum': 0,
'maximum': 2147483647
},
'read_only': True
},
'retry': {
'schema': {
'type': 'integer',
'minimum': 0,
'maximum': 2147483647
},
'read_only': True
},
'expire': {
'schema': {
'type': 'integer',
'minimum': 0,
'maximum': 2147483647
},
'read_only': True
},
'minimum': {
'schema': {
'type': 'integer',
'minimum': 0,
'maximum': 2147483647
},
'read_only': True
},
'parent_domain_id': {
'schema': {
'type': 'string',
'format': 'uuid'
},
'read_only': True
},
'serial': {
'schema': {
'type': 'integer',
'minimum': 1,
'maximum': 4294967295,
},
'read_only': True
},
'description': {
'schema': {
'type': ['string', 'null'],
'maxLength': 160
},
},
'status': {
'schema': {
'type': 'string',
'enum': ['ACTIVE', 'PENDING', 'ERROR'],
},
'read_only': True,
},
'action': {
'schema': {
'type': 'string',
'enum': ['CREATE', 'DELETE', 'UPDATE', 'NONE'],
},
'read_only': True
},
'pool_id': {
'schema': {
'type': 'string',
'format': 'uuid',
},
'immutable': True,
},
'recordsets': {
'relation': True,
'relation_cls': 'RecordSetList'

View File

@ -16,7 +16,7 @@ from designate.objects import base
class NameServer(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject):
base.DesignateObject):
FIELDS = {
'pool_id': {},
'key': {},

View File

@ -19,17 +19,46 @@ from designate.objects import base
class Pool(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject):
FIELDS = {
'name': {},
'description': {},
'tenant_id': {},
'provisioner': {},
'name': {
'schema': {
'type': 'string',
'description': 'Pool name',
'maxLength': 50,
},
'immutable': True,
'required': True
},
'description': {
'schema': {
'type': ['string', 'null'],
'description': 'Description for the pool',
'maxLength': 160
}
},
'tenant_id': {
'schema': {
'type': ['string', 'null'],
'description': 'Project identifier',
'maxLength': 36,
},
'immutable': True
},
'provisioner': {
'schema': {
'type': ['string', 'null'],
'description': 'Provisioner used for this pool',
'maxLength': 160
}
},
'attributes': {
'relation': True,
'relation_cls': 'PoolAttributeList'
'relation_cls': 'PoolAttributeList',
'required': True
},
'nameservers': {
'relation': True,
'relation_cls': 'NameServerList'
'relation_cls': 'NameServerList',
'required': True
},
}

View File

@ -16,11 +16,30 @@ from designate.objects import base
class PoolAttribute(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject):
base.DesignateObject):
FIELDS = {
'pool_id': {},
'key': {},
'value': {}
'pool_id': {
'schema': {
'type': 'string',
'description': 'Pool identifier',
'format': 'uuid',
},
'required': True
},
'key': {
'schema': {
'type': 'string',
'maxLength': 50,
},
'required': True,
},
'value': {
'schema': {
'type': 'string',
'maxLength': 50,
},
'required': True
}
}

View File

@ -19,11 +19,38 @@ from designate.objects import base
class PoolManagerStatus(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject):
FIELDS = {
'server_id': {},
'domain_id': {},
'status': {},
'serial_number': {},
'action': {}
'server_id': {
'schema': {
'type': 'string',
'format': 'uuid',
},
'required': True
},
'domain_id': {
'schema': {
'type': 'string',
'format': 'uuid',
},
'required': True},
'status': {
'schema': {
'type': ['string', 'null'],
'enum': ['ACTIVE', 'PENDING', 'ERROR'],
},
},
'serial_number': {
'schema': {
'type': 'integer',
'minimum': 0,
'maximum': 4294967295,
},
},
'action': {
'schema': {
'type': 'string',
'enum': ['CREATE', 'DELETE', 'UPDATE', 'NONE'],
},
}
}

View File

@ -21,22 +21,103 @@ class Record(base.DictObjectMixin, base.PersistentObjectMixin,
# so we should remove it.
FIELDS = {
'data': {},
'domain_id': {},
'managed': {},
'managed_resource_type': {},
'managed_resource_id': {},
'managed_plugin_name': {},
'managed_plugin_type': {},
'hash': {},
'description': {},
'status': {},
'tenant_id': {},
'recordset_id': {},
'managed_tenant_id': {},
'managed_resource_region': {},
'managed_extra': {},
'action': {},
'serial': {}
'domain_id': {
'schema': {
'type': 'string',
'format': 'uuid',
},
'required': True
},
'managed': {
'schema': {
'type': 'boolean'
}
},
'managed_resource_type': {
'schema': {
'type': ['string', 'null'],
'maxLength': 160
},
},
'managed_resource_id': {
'schema': {
'type': ['string', 'null'],
'format': 'uuid',
},
},
'managed_plugin_name': {
'schema': {
'type': ['string', 'null'],
'maxLength': 160
},
},
'managed_plugin_type': {
'schema': {
'type': ['string', 'null'],
'maxLength': 160
},
},
'hash': {
'schema': {
'type': 'string',
'maxLength': 32
},
'required': True
},
'description': {
'schema': {
'type': ['string', 'null'],
'maxLength': 160
},
},
'status': {
'schema': {
'type': 'string',
'enum': ['ACTIVE', 'PENDING', 'ERROR'],
},
},
'tenant_id': {
'schema': {
'type': 'string',
},
},
'recordset_id': {
'schema': {
'type': 'string',
'format': 'uuid',
},
'required': True
},
'managed_tenant_id': {
'schema': {
'type': ['string', 'null'],
}
},
'managed_resource_region': {
'schema': {
'type': ['string', 'null'],
'maxLength': 160
},
},
'managed_extra': {
'schema': {
'type': ['string', 'null'],
'maxLength': 160
},
},
'action': {
'schema': {
'type': 'string',
'enum': ['CREATE', 'DELETE', 'UPDATE', 'NONE'],
},
},
'serial': {
'schema': {
'type': 'integer',
'minimum': 1,
'maximum': 4294967295,
},
},
}

View File

@ -49,12 +49,56 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin,
return status
FIELDS = {
'tenant_id': {},
'domain_id': {},
'name': {},
'type': {},
'ttl': {},
'description': {},
'tenant_id': {
'schema': {
'type': 'string',
},
'required': True,
'read_only': True
},
'domain_id': {
'schema': {
'type': 'string',
'description': 'Zone identifier',
'format': 'uuid'
},
'read_only': True,
'required': True
},
'name': {
'schema': {
'type': 'string',
'description': 'Zone name',
'format': 'domainname',
'maxLength': 255,
},
'immutable': True,
'required': True
},
'type': {
'schema': {
'type': 'string',
'description': 'RecordSet type (TODO: Make types extensible)',
'enum': ['A', 'AAAA', 'CNAME', 'MX', 'SRV', 'TXT', 'SPF', 'NS',
'PTR', 'SSHFP', 'SOA']
},
'required': True,
'immutable': True
},
'ttl': {
'schema': {
'type': 'integer',
'description': 'Default time to live',
'minimum': 0,
'maximum': 2147483647
},
},
'description': {
'schema': {
'type': ['string', 'null'],
'maxLength': 160
},
},
'records': {
'relation': True,
'relation_cls': 'RecordList'

View File

@ -18,7 +18,16 @@ from designate.objects import base
class Server(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject):
FIELDS = {
'name': {}
'name': {
'schema': {
'type': 'string',
'description': 'Zone name',
'format': 'domainname',
'maxLength': 255,
},
'immutable': True,
'required': True
}
}

View File

@ -18,8 +18,21 @@ from designate.objects import base
class Tld(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject):
FIELDS = {
'name': {},
'description': {}
'name': {
'schema': {
'type': 'string',
'format': 'tldname',
'maxLength': 255,
},
'immutable': True,
'required': True
},
'description': {
'schema': {
'type': ['string', 'null'],
'maxLength': 160
},
}
}

View File

@ -18,11 +18,50 @@ from designate.objects import base
class TsigKey(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject):
FIELDS = {
'name': {},
'algorithm': {},
'secret': {},
'scope': {},
'resource_id': {},
'name': {
'schema': {
'type': 'string',
'maxLength': 160,
'format': 'domainnamne'
},
'required': True
},
'algorithm': {
'schema': {
'type': 'string',
'enum': [
'hmac-md5',
'hmac-sha1',
'hmac-sha224',
'hmac-sha256',
'hmac-sha384',
'hmac-sha512'
]
},
'required': True
},
'secret': {
'schema': {
'type': 'string',
'maxLength': 160
},
'required': True
},
'scope': {
'schema': {
'type': 'string',
'enum': ['POOL', 'ZONE'],
},
'required': True
},
'resource_id': {
'schema': {
'type': 'string',
'format': 'uuid'
},
'read_only': True,
'required': True
},
}

View File

@ -19,11 +19,41 @@ from designate.objects import base
class ZoneTransferAccept(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject):
FIELDS = {
'zone_transfer_request_id': {},
'tenant_id': {},
'status': {},
'key': {},
'domain_id': {},
'zone_transfer_request_id': {
'schema': {
"type": "string",
"format": "uuid"
},
"immutable": True
},
'tenant_id': {
'schema': {
'type': 'string',
},
'required': True,
'read_only': True
},
'status': {
'schema': {
"type": "string",
"enum": ["ACTIVE", "PENDING", "DELETED", "ERROR", "COMPLETE"],
},
'read_only': True
},
'key': {
'schema': {
"type": "string",
"maxLength": 160
},
'required': True
},
'domain_id': {
'schema': {
"type": "string",
"format": "uuid"
},
"immutable": True
},
}

View File

@ -19,13 +19,53 @@ from designate.objects import base
class ZoneTransferRequest(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject,):
FIELDS = {
'domain_id': {},
'key': {},
'description': {},
'tenant_id': {},
'target_tenant_id': {},
'status': {},
'domain_name': {},
'key': {
'schema': {
"type": "string",
"maxLength": 160
},
'required': True
},
'domain_id': {
'schema': {
"type": "string",
"description": "Zone identifier",
"format": "uuid"
},
"immutable": True
},
'description': {
'schema': {
"type": ["string", "null"],
"maxLength": 160
}
},
'tenant_id': {
'schema': {
'type': 'string',
},
'required': True,
'read_only': True
},
'target_tenant_id': {
'schema': {
'type': ['string', 'null'],
},
'immutable': True
},
'status': {
'schema': {
"type": "string",
"enum": ["ACTIVE", "PENDING", "DELETED", "ERROR", "COMPLETE"],
}
},
'domain_name': {
'schema': {
"type": ["string", "null"],
"maxLength": 255,
},
'read_only': True
},
}

View File

@ -162,8 +162,11 @@ class SQLAlchemy(object):
def _create(self, table, obj, exc_dup, skip_values=None,
extra_values=None):
# TODO(graham): Re Enable this
# This was disabled as all the tests generate invalid Objects
# Ensure the Object is valid
obj.validate()
# obj.validate()
values = obj.obj_get_changes()
@ -258,8 +261,12 @@ class SQLAlchemy(object):
def _update(self, context, table, obj, exc_dup, exc_notfound,
skip_values=None):
# TODO(graham): Re Enable this
# This was disabled as all the tests generate invalid Objects
# Ensure the Object is valid
obj.validate()
# obj.validate()
values = obj.obj_get_changes()