<s> from netaddr import IPAddress <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def to_server_dict ( server ) : <EOL> public_ips = [ ip [ '<STR_LIT>' ] for ip in server . addresses [ '<STR_LIT>' ] ] <EOL> private_ips = [ ip [ '<STR_LIT>' ] for ip in server . addresses [ '<STR_LIT>' ] ] <EOL> public_ipv4 = None <EOL> public_ipv6 = None <EOL> for ip in public_ips : <EOL> try : <EOL> ip_obj = IPAddress ( ip ) <EOL> except Exception : <EOL> continue <EOL> if not ip_obj . is_private ( ) : <EOL> if ip_obj . version == <NUM_LIT:4> : <EOL> public_ipv4 = ip <EOL> elif ip_obj . version == <NUM_LIT:6> : <EOL> public_ipv6 = ip <EOL> result = { <EOL> '<STR_LIT:id>' : server . id , <EOL> '<STR_LIT:name>' : server . name , <EOL> '<STR_LIT:status>' : server . status , <EOL> '<STR_LIT>' : server . image [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : server . flavor [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : public_ips , <EOL> '<STR_LIT>' : private_ips , <EOL> '<STR_LIT>' : public_ipv4 , <EOL> '<STR_LIT>' : public_ipv6 , <EOL> '<STR_LIT>' : server . key_name , <EOL> '<STR_LIT>' : server . metadata <EOL> } <EOL> return result <EOL> def to_dns_zone_dict ( zone ) : <EOL> result = { <EOL> '<STR_LIT:id>' : zone . id , <EOL> '<STR_LIT:name>' : zone . name , <EOL> '<STR_LIT>' : zone . emailAddress , <EOL> '<STR_LIT>' : zone . ttl <EOL> } <EOL> return result <EOL> def to_dns_record_dict ( record ) : <EOL> result = { <EOL> '<STR_LIT:id>' : record . id , <EOL> '<STR_LIT:name>' : record . name , <EOL> '<STR_LIT:type>' : record . type , <EOL> '<STR_LIT:data>' : record . data , <EOL> '<STR_LIT>' : record . ttl <EOL> } <EOL> return result </s>
