Network addresses
=================

Network addresses are an important piece of data to configure clients and
servers so they know how to talk to each other. There are a couple of general
recommendations of how to use them in server and client configuration and how to
use batou's  :class:`Address` class to make it convenient and reliable.

Address objects can be created either from a single string or a string and a
port:

.. code-block:: python

    >>> from batou.utils import Address
    >>> Address('localhost:80') 
    >>> Address('localhost', '80')
    >>> Address('localhost', 80)

The address object then can provide you the recommended representation for configuring servers (the "bind" address) or clients (the "connect" address).

We recommend that bind addresses should be given as IP addresses and if you give
a hostname then we'll resolve this to an IP when you ask for a listen
representation during deployment. You can also choose between a compact
':'-separated representation or access the parts individually:

.. code-block:: python

    >>> addr = Address('localhost', 80)
    >>> str(addr.listen)
    '127.0.0.1:80'
    >>> addr.host
    '127.0.0.1'
    >>> addr.port
    '80'

Connect addresses are recommended to be given as names so they can benefit 
from DNS features like fail-over:

.. code-block:: python

    >>> addr = Address('localhost', 80)
    >>> str(addr.connect)
    'localhost:80'
    >>> addr.host
    'localhost'
    >>> addr.port
    '80'

A typical combination is to use a component's host's FQDN and select a port for
a service:

.. code-block:: python

    def configure(self):
        self.address = Address(self.host.fqdn, '8080')
