def serialize_device(device):
 device_data = {}
 device_data['id'] = device.id
 device_data['hostname'] = device.hostname
 device_data['tags'] = device.tags
 device_data['locked'] = device.locked
 device_data['ip_addresses'] = [{'address': addr_data['address'], 'address_family': addr_data['address_family'], 'public': addr_data['public']} for addr_data in device.ip_addresses]
 for ipdata in device_data['ip_addresses']:
  if ipdata['public']:
   if (ipdata['address_family'] == 6):
    device_data['public_ipv6'] = ipdata['address']
   elif (ipdata['address_family'] == 4):
    device_data['public_ipv4'] = ipdata['address']
  elif (not ipdata['public']):
   if (ipdata['address_family'] == 6):
    device_data['private_ipv6'] = ipdata['address']
   elif (ipdata['address_family'] == 4):
    device_data['private_ipv4'] = ipdata['address']
 return device_data

def serialize_device ( device ) : device_data = { } device_data [ 'id' ] = device . id device_data [ 'hostname' ] = device . hostname device_data [ 'tags' ] = device . tags device_data [ 'locked' ] = device . locked device_data [ 'ip_addresses' ] = [ { 'address' : addr_data [ 'address' ] , 'address_family' : addr_data [ 'address_family' ] , 'public' : addr_data [ 'public' ] } for addr_data in device . ip_addresses ] for ipdata in device_data [ 'ip_addresses' ] : if ipdata [ 'public' ] : if ( ipdata [ 'address_family' ] == 6 ) : device_data [ 'public_ipv6' ] = ipdata [ 'address' ] elif ( ipdata [ 'address_family' ] == 4 ) : device_data [ 'public_ipv4' ] = ipdata [ 'address' ] elif ( not ipdata [ 'public' ] ) : if ( ipdata [ 'address_family' ] == 6 ) : device_data [ 'private_ipv6' ] = ipdata [ 'address' ] elif ( ipdata [ 'address_family' ] == 4 ) : device_data [ 'private_ipv4' ] = ipdata [ 'address' ] return device_data
standard represenation for a device as returned by various tasks:: id: device_id hostname: device_hostname .