def serialize(self, nested=False):
"""Serializes an object
Pulls all the attributes in an object and creates a dict that
can be turned into the json that netbox is expecting.
If an attribute's value is a ``Record`` or ``IPRecord`` type
it's replaced with the ``id`` field of that object.
:returns: dict of values the NetBox API is expecting.
"""
if nested:
return _get_return(self)
ret = {}
for i in dict(self):
current_val = getattr(self, i)
if isinstance(current_val, Record):
current_val = getattr(current_val, 'serialize')(nested=True)
if isinstance(current_val, netaddr.ip.IPNetwork):
current_val = str(current_val)
ret.update({i: current_val})
return ret
评论列表
文章目录