Commit e9cc75ff authored by Nguyen Van Trung's avatar Nguyen Van Trung Committed by Graham Hayes

Migrate object to OVO (5)

This commit will migrate:
- Blacklist object
- Quota objects
- Floating_IP objects
Co-authored-By: default avatarDai Dang Van <daidv@vn.fujitsu.com>

Change-Id: I85455e7cbf24da4c7c6302060d5c3d203fdf2fc5
Implements: blueprint designate-rolling-upgrade
parent 274c2cb8
...@@ -12,28 +12,16 @@ ...@@ -12,28 +12,16 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # 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, class Blacklist(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject): base.DesignateObject):
FIELDS = { fields = {
'pattern': { 'pattern': fields.StringFields(maxLength=255),
'schema': { 'description': fields.StringFields(maxLength=160, nullable=True),
'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
}
}
} }
STRING_KEYS = [ STRING_KEYS = [
...@@ -41,5 +29,10 @@ class Blacklist(base.DictObjectMixin, base.PersistentObjectMixin, ...@@ -41,5 +29,10 @@ class Blacklist(base.DictObjectMixin, base.PersistentObjectMixin,
] ]
@base.DesignateRegistry.register
class BlacklistList(base.ListObjectMixin, base.DesignateObject): class BlacklistList(base.ListObjectMixin, base.DesignateObject):
LIST_ITEM_TYPE = Blacklist LIST_ITEM_TYPE = Blacklist
fields = {
'objects': fields.ListOfObjectsField('Blacklist'),
}
...@@ -175,6 +175,8 @@ class DomainField(StringFields): ...@@ -175,6 +175,8 @@ class DomainField(StringFields):
def coerce(self, obj, attr, value): def coerce(self, obj, attr, value):
value = super(DomainField, self).coerce(obj, attr, value) value = super(DomainField, self).coerce(obj, attr, value)
if value is None:
return
domain = value.split('.') domain = value.split('.')
for host in domain: for host in domain:
if len(host) > 63: if len(host) > 63:
...@@ -206,6 +208,8 @@ class HostField(StringFields): ...@@ -206,6 +208,8 @@ class HostField(StringFields):
def coerce(self, obj, attr, value): def coerce(self, obj, attr, value):
value = super(HostField, self).coerce(obj, attr, value) value = super(HostField, self).coerce(obj, attr, value)
if value is None:
return
hostname = value.split('.') hostname = value.split('.')
for host in hostname: for host in hostname:
if len(host) > 63: if len(host) > 63:
...@@ -223,6 +227,8 @@ class SRVField(StringFields): ...@@ -223,6 +227,8 @@ class SRVField(StringFields):
def coerce(self, obj, attr, value): def coerce(self, obj, attr, value):
value = super(SRVField, self).coerce(obj, attr, value) value = super(SRVField, self).coerce(obj, attr, value)
if value is None:
return
srvtype = value.split('.') srvtype = value.split('.')
for host in srvtype: for host in srvtype:
if len(host) > 63: if len(host) > 63:
...@@ -302,6 +308,4 @@ class IPOrHost(IPV4AndV6AddressField): ...@@ -302,6 +308,4 @@ class IPOrHost(IPV4AndV6AddressField):
except ValueError: except ValueError:
if not re.match(StringFields.RE_ZONENAME, value): if not re.match(StringFields.RE_ZONENAME, value):
raise ValueError("%s is not IP address or host name" % value) raise ValueError("%s is not IP address or host name" % value)
# we use this field as a string, not need a netaddr.IPAdress return value
# as oslo.versionedobjects is using
return str(value)
...@@ -13,61 +13,24 @@ ...@@ -13,61 +13,24 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # 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, class FloatingIP(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject): base.DesignateObject):
FIELDS = { fields = {
"address": { "address": fields.IPV4AddressField(nullable=True),
'schema': { "description": fields.StringFields(nullable=True, maxLength=160),
'type': 'string', "ptrdname": fields.DomainField(nullable=True),
'format': ['ipv4', 'ipv6'] "ttl": fields.IntegerFields(nullable=True,
}, minimum=1, maximum=2147483647),
}, "region": fields.StringFields(nullable=True),
"description": { "action": fields.EnumField(['CREATE', 'DELETE',
'schema': { 'UPDATE', 'NONE'], nullable=True),
'type': ['string', 'null'], "status": fields.EnumField(['ACTIVE',
'maxLength': 160 'PENDING', 'ERROR'], nullable=True)
},
},
"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'],
}
}
} }
STRING_KEYS = [ STRING_KEYS = [
...@@ -79,5 +42,10 @@ class FloatingIP(base.DictObjectMixin, base.PersistentObjectMixin, ...@@ -79,5 +42,10 @@ class FloatingIP(base.DictObjectMixin, base.PersistentObjectMixin,
return '%s:%s' % (self.region, self.id) return '%s:%s' % (self.region, self.id)
@base.DesignateRegistry.register
class FloatingIPList(base.ListObjectMixin, base.DesignateObject): class FloatingIPList(base.ListObjectMixin, base.DesignateObject):
LIST_ITEM_TYPE = FloatingIP LIST_ITEM_TYPE = FloatingIP
fields = {
'objects': fields.ListOfObjectsField('FloatingIP'),
}
...@@ -12,15 +12,17 @@ ...@@ -12,15 +12,17 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # 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, class Quota(base.DictObjectMixin, base.PersistentObjectMixin,
base.DesignateObject): base.DesignateObject):
FIELDS = { fields = {
'tenant_id': {}, 'tenant_id': fields.AnyField(nullable=True),
'resource': {}, 'resource': fields.AnyField(nullable=True),
'hard_limit': {} 'hard_limit': fields.AnyField(nullable=True)
} }
STRING_KEYS = [ STRING_KEYS = [
...@@ -28,9 +30,14 @@ class Quota(base.DictObjectMixin, base.PersistentObjectMixin, ...@@ -28,9 +30,14 @@ class Quota(base.DictObjectMixin, base.PersistentObjectMixin,
] ]
@base.DesignateRegistry.register
class QuotaList(base.ListObjectMixin, base.DesignateObject): class QuotaList(base.ListObjectMixin, base.DesignateObject):
LIST_ITEM_TYPE = Quota LIST_ITEM_TYPE = Quota
fields = {
'objects': fields.ListOfObjectsField('Quota'),
}
@classmethod @classmethod
def from_dict(cls, _dict): def from_dict(cls, _dict):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment