From e9cc75ff016532d8b4f60d8a8966843618e5d627 Mon Sep 17 00:00:00 2001 From: Nguyen Van Trung Date: Wed, 7 Jun 2017 17:01:55 +0700 Subject: [PATCH] Migrate object to OVO (5) This commit will migrate: - Blacklist object - Quota objects - Floating_IP objects Co-authored-By: Dai Dang Van Change-Id: I85455e7cbf24da4c7c6302060d5c3d203fdf2fc5 Implements: blueprint designate-rolling-upgrade --- designate/objects/blacklist.py | 29 +++++-------- designate/objects/fields.py | 10 +++-- designate/objects/floating_ip.py | 70 +++++++++----------------------- designate/objects/quota.py | 17 +++++--- 4 files changed, 49 insertions(+), 77 deletions(-) diff --git a/designate/objects/blacklist.py b/designate/objects/blacklist.py index 9e6f04291..1eac5610b 100644 --- a/designate/objects/blacklist.py +++ b/designate/objects/blacklist.py @@ -12,28 +12,16 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from designate.objects import base +from designate.objects import ovo_base as base +from designate.objects import fields +@base.DesignateRegistry.register class Blacklist(base.DictObjectMixin, base.PersistentObjectMixin, base.DesignateObject): - FIELDS = { - '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 - } - } + fields = { + 'pattern': fields.StringFields(maxLength=255), + 'description': fields.StringFields(maxLength=160, nullable=True), } STRING_KEYS = [ @@ -41,5 +29,10 @@ class Blacklist(base.DictObjectMixin, base.PersistentObjectMixin, ] +@base.DesignateRegistry.register class BlacklistList(base.ListObjectMixin, base.DesignateObject): LIST_ITEM_TYPE = Blacklist + + fields = { + 'objects': fields.ListOfObjectsField('Blacklist'), + } diff --git a/designate/objects/fields.py b/designate/objects/fields.py index 77d221e62..53d122113 100644 --- a/designate/objects/fields.py +++ b/designate/objects/fields.py @@ -175,6 +175,8 @@ class DomainField(StringFields): def coerce(self, obj, attr, value): value = super(DomainField, self).coerce(obj, attr, value) + if value is None: + return domain = value.split('.') for host in domain: if len(host) > 63: @@ -206,6 +208,8 @@ class HostField(StringFields): def coerce(self, obj, attr, value): value = super(HostField, self).coerce(obj, attr, value) + if value is None: + return hostname = value.split('.') for host in hostname: if len(host) > 63: @@ -223,6 +227,8 @@ class SRVField(StringFields): def coerce(self, obj, attr, value): value = super(SRVField, self).coerce(obj, attr, value) + if value is None: + return srvtype = value.split('.') for host in srvtype: if len(host) > 63: @@ -302,6 +308,4 @@ class IPOrHost(IPV4AndV6AddressField): except ValueError: if not re.match(StringFields.RE_ZONENAME, value): raise ValueError("%s is not IP address or host name" % value) - # we use this field as a string, not need a netaddr.IPAdress - # as oslo.versionedobjects is using - return str(value) + return value diff --git a/designate/objects/floating_ip.py b/designate/objects/floating_ip.py index ea33d0610..69def488f 100644 --- a/designate/objects/floating_ip.py +++ b/designate/objects/floating_ip.py @@ -13,61 +13,24 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from designate.objects import base +from designate.objects import ovo_base as base +from designate.objects import fields +@base.DesignateRegistry.register class FloatingIP(base.DictObjectMixin, base.PersistentObjectMixin, base.DesignateObject): - FIELDS = { - "address": { - 'schema': { - 'type': 'string', - 'format': ['ipv4', 'ipv6'] - }, - }, - "description": { - 'schema': { - 'type': ['string', 'null'], - 'maxLength': 160 - }, - }, - "id": { - 'schema': { - 'type': 'string', - 'format': 'uuid' - } - }, - "ptrdname": { - 'schema': { - 'type': ['string', 'null'], - 'format': 'domainname' - } - }, - "ttl": { - 'schema': { - 'type': ['integer', 'null'], - 'minimum': 1, - 'maximum': 2147483647 - } - }, - "region": { - 'schema': { - 'type': ['string', 'null'], - } - }, - "action": { - 'schema': { - 'type': 'string', - 'enum': ['CREATE', 'DELETE', 'UPDATE', 'NONE'], - } - }, - "status": { - 'schema': { - 'type': 'string', - 'enum': ['ACTIVE', 'PENDING', 'ERROR'], - } - } - + fields = { + "address": fields.IPV4AddressField(nullable=True), + "description": fields.StringFields(nullable=True, maxLength=160), + "ptrdname": fields.DomainField(nullable=True), + "ttl": fields.IntegerFields(nullable=True, + minimum=1, maximum=2147483647), + "region": fields.StringFields(nullable=True), + "action": fields.EnumField(['CREATE', 'DELETE', + 'UPDATE', 'NONE'], nullable=True), + "status": fields.EnumField(['ACTIVE', + 'PENDING', 'ERROR'], nullable=True) } STRING_KEYS = [ @@ -79,5 +42,10 @@ class FloatingIP(base.DictObjectMixin, base.PersistentObjectMixin, return '%s:%s' % (self.region, self.id) +@base.DesignateRegistry.register class FloatingIPList(base.ListObjectMixin, base.DesignateObject): LIST_ITEM_TYPE = FloatingIP + + fields = { + 'objects': fields.ListOfObjectsField('FloatingIP'), + } diff --git a/designate/objects/quota.py b/designate/objects/quota.py index 6b6e6a302..dcc989040 100644 --- a/designate/objects/quota.py +++ b/designate/objects/quota.py @@ -12,15 +12,17 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from designate.objects import base +from designate.objects import ovo_base as base +from designate.objects import fields +@base.DesignateRegistry.register class Quota(base.DictObjectMixin, base.PersistentObjectMixin, base.DesignateObject): - FIELDS = { - 'tenant_id': {}, - 'resource': {}, - 'hard_limit': {} + fields = { + 'tenant_id': fields.AnyField(nullable=True), + 'resource': fields.AnyField(nullable=True), + 'hard_limit': fields.AnyField(nullable=True) } STRING_KEYS = [ @@ -28,9 +30,14 @@ class Quota(base.DictObjectMixin, base.PersistentObjectMixin, ] +@base.DesignateRegistry.register class QuotaList(base.ListObjectMixin, base.DesignateObject): LIST_ITEM_TYPE = Quota + fields = { + 'objects': fields.ListOfObjectsField('Quota'), + } + @classmethod def from_dict(cls, _dict):