Returns the :class:`dict` representation of a server object.

    The returned :class:`dict` is meant to be consumed by
    :class:`~bang.deployers.cloud.ServerDeployer` objects.

def server_to_dict(server):
    """
    Returns the :class:`dict` representation of a server object.

    The returned :class:`dict` is meant to be consumed by
    :class:`~bang.deployers.cloud.ServerDeployer` objects.

    """
    def get_ips_for_server(server):
        public_ips = []
        private_ips = []
        def address_is_public(address):
            return address['OS-EXT-IPS:type'] == 'floating'
        def address_is_private(address):
            return not address_is_public(address)

        for network, addresses in server.addresses.iteritems():
            # TODO: is this right? Can have private floating ips
            public = filter(address_is_public, addresses)
            private = filter(address_is_private, addresses)
            public_ips.extend(public)
            private_ips.extend(private)
        return private_ips, public_ips

    addresses = server.addresses
    pub = addresses.get('public', [])
    priv = addresses.get('private', [])

    if not pub and not priv:
        # Openstack 13.5?
        priv, pub = get_ips_for_server(server)

    return {
            A.server.ID: server.id,
            A.server.PUBLIC_IPS: [a['addr'] for a in pub],
            A.server.PRIVATE_IPS: [a['addr'] for a in priv],
            }