Add __str__() methods to DesignateObjects
This allows for easy logging of objects * __str__() implemented in base DesignateObject * Builds Message based on 'STRING_KEYS' list in objects * Record has overridden implementation to limit the size of data attr Partially-Implements: blueprint bp/standardize-logging Change-Id: I89bea0a84f3947fae252d51356b00c7c4d0a58c1
This commit is contained in:
parent
86f85d085a
commit
0a983719b6
@ -22,7 +22,7 @@ from oslo_log import log as logging
|
||||
from designate import exceptions
|
||||
from designate.schema import validators
|
||||
from designate.schema import format
|
||||
|
||||
from designate.i18n import _
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -149,6 +149,8 @@ class DesignateObjectMetaclass(type):
|
||||
class DesignateObject(object):
|
||||
FIELDS = {}
|
||||
|
||||
STRING_KEYS = []
|
||||
|
||||
def _obj_check_relation(self, name):
|
||||
if name in self.FIELDS and self.FIELDS[name].get('relation', False):
|
||||
if not self.obj_attr_is_set(name):
|
||||
@ -234,6 +236,18 @@ class DesignateObject(object):
|
||||
raise TypeError("__init__() got an unexpected keyword "
|
||||
"argument '%(name)s'" % {'name': name})
|
||||
|
||||
def __str__(self):
|
||||
return (self._make_obj_str(self.STRING_KEYS)
|
||||
% self)
|
||||
|
||||
@classmethod
|
||||
def _make_obj_str(cls, keys):
|
||||
msg = "<%(name)s" % {'name': cls.obj_name()}
|
||||
for key in keys:
|
||||
msg += " {0}:'%({0})s'".format(key)
|
||||
msg += ">"
|
||||
return msg
|
||||
|
||||
def to_primitive(self):
|
||||
"""
|
||||
Convert the object to primitive types so that the object can be
|
||||
@ -516,6 +530,12 @@ class ListObjectMixin(object):
|
||||
'designate_object.original_values': dict(self._obj_original_values)
|
||||
}
|
||||
|
||||
def __str__(self):
|
||||
return (_("<%(type)s count:'%(count)s' object:'%(list_type)s'>")
|
||||
% {'count': len(self),
|
||||
'type': self.LIST_ITEM_TYPE.obj_name(),
|
||||
'list_type': self.obj_name()})
|
||||
|
||||
def __iter__(self):
|
||||
"""List iterator interface"""
|
||||
return iter(self.objects)
|
||||
@ -616,6 +636,8 @@ class PersistentObjectMixin(object):
|
||||
}
|
||||
}
|
||||
|
||||
STRING_KEYS = ['id']
|
||||
|
||||
|
||||
class SoftDeleteObjectMixin(object):
|
||||
"""
|
||||
|
@ -36,6 +36,10 @@ class Blacklist(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
}
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'pattern'
|
||||
]
|
||||
|
||||
|
||||
class BlacklistList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = Blacklist
|
||||
|
@ -161,6 +161,10 @@ class Domain(base.DictObjectMixin, base.SoftDeleteObjectMixin,
|
||||
},
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'type', 'name', 'pool_id', 'serial', 'action', 'status'
|
||||
]
|
||||
|
||||
@property
|
||||
def masters(self):
|
||||
if self.obj_attr_is_set('attributes'):
|
||||
|
@ -24,6 +24,10 @@ class DomainAttribute(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
'value': {}
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'key', 'value', 'domain_id'
|
||||
]
|
||||
|
||||
|
||||
class DomainAttributeList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = DomainAttribute
|
||||
|
@ -70,6 +70,10 @@ class FloatingIP(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'key', 'address', 'ptrdname'
|
||||
]
|
||||
|
||||
@property
|
||||
def key(self):
|
||||
return '%s:%s' % (self.region, self.id)
|
||||
|
@ -139,6 +139,10 @@ class Pool(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
|
||||
return cls.from_dict(pool)
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'name'
|
||||
]
|
||||
|
||||
|
||||
class PoolList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = Pool
|
||||
|
@ -41,6 +41,10 @@ class PoolAttribute(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
}
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'key', 'value', 'pool_id'
|
||||
]
|
||||
|
||||
|
||||
class PoolAttributeList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = PoolAttribute
|
||||
|
@ -53,6 +53,10 @@ class PoolManagerStatus(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
}
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'action', 'status', 'server_id', 'domain_id'
|
||||
]
|
||||
|
||||
|
||||
class PoolManagerStatusList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = PoolManagerStatus
|
||||
|
@ -45,6 +45,10 @@ class PoolNsRecord(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
}
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'hostname', 'priority', 'pool_id'
|
||||
]
|
||||
|
||||
|
||||
class PoolNsRecordList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = PoolNsRecord
|
||||
|
@ -23,6 +23,10 @@ class Quota(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
'hard_limit': {}
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'resource', 'tenant_id', 'hard_limit'
|
||||
]
|
||||
|
||||
|
||||
class QuotaList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = Quota
|
||||
|
@ -130,6 +130,16 @@ class Record(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
# recordset
|
||||
return {}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'recordset_id', 'data'
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
record = self.to_dict()
|
||||
record['data'] = record['data'][:35]
|
||||
return (self._make_obj_str(self.STRING_KEYS)
|
||||
% record)
|
||||
|
||||
|
||||
class RecordList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = Record
|
||||
|
@ -276,6 +276,10 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
# Send in the traditional Record objects to central / storage
|
||||
self.records = old_records
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'type', 'name', 'domain_id'
|
||||
]
|
||||
|
||||
|
||||
class RecordSetList(base.ListObjectMixin, base.DesignateObject,
|
||||
base.PagedListObjectMixin):
|
||||
|
@ -30,6 +30,10 @@ class Server(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
}
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'name'
|
||||
]
|
||||
|
||||
|
||||
class ServerList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = Server
|
||||
|
@ -22,6 +22,10 @@ class Tenant(base.DictObjectMixin, base.DesignateObject):
|
||||
'domains': {}
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id'
|
||||
]
|
||||
|
||||
|
||||
class TenantList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = Tenant
|
||||
|
@ -35,6 +35,10 @@ class Tld(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
}
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'name'
|
||||
]
|
||||
|
||||
|
||||
class TldList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = Tld
|
||||
|
@ -64,6 +64,10 @@ class TsigKey(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
},
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'name', 'algorithm', 'scope', 'resource_id'
|
||||
]
|
||||
|
||||
|
||||
class TsigKeyList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = TsigKey
|
||||
|
@ -55,6 +55,10 @@ class ZoneTransferAccept(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
},
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'domain_id', 'tenant_id', 'zone_transfer_request_id'
|
||||
]
|
||||
|
||||
|
||||
class ZoneTransferAcceptList(base.ListObjectMixin, base.DesignateObject,
|
||||
base.PagedListObjectMixin):
|
||||
|
@ -66,6 +66,10 @@ class ZoneTransferRequest(base.DictObjectMixin, base.PersistentObjectMixin,
|
||||
},
|
||||
}
|
||||
|
||||
STRING_KEYS = [
|
||||
'id', 'domain_id', 'domain_name', 'target_tenant_id'
|
||||
]
|
||||
|
||||
|
||||
class ZoneTransferRequestList(base.ListObjectMixin, base.DesignateObject):
|
||||
LIST_ITEM_TYPE = ZoneTransferRequest
|
||||
|
Loading…
Reference in New Issue
Block a user