Fixed lp:1397376 - api-endpoints behaves as expected

This fixes http://pad.lv/1397376/ by changing how API
server addresses are handled by the CLI/API clients.

Major changes:
 * cmd/juju: api-endpoints - added help text, added --all argument,
 vastly improved tests.
 * network.SortAddresses and network.SortHostPorts changed to apply
 consistent ordering with regards to scope and prefer-ipv6 flag);
 * network.ResolveOrDropHostnames introduced;
 * cmd/juju: bootstrap command - endpoints caching post-bootstrap fixed;
 * juju/api: changed the way API endpoints are cached in the .jenv file.

What's changed? Before caching the API endpoints for use by the CLI (either just
 after bootstrap or with api-endpoints --refresh):
 - All known endpoints are sorted in the following order:
 -- public addresses
 -- hostnames (only localhost as the others are resolved, see below)
 -- cloud-local addresses
 -- link-local addresses (which are then filtered out as unusable)
 -- machine-local addresses
 - Then any hostnames, except localhost (because of the local provider
 and also dummy provider to simplify testing), are resolved using the
 local resolver and (if successful) inserted in the same order in the
 list of endpoints. Unresolvable hostnames are dropped. This means the
 .jenv file won't contain any hostnames (except for maybe localhost), as
 this seems to be the expected behavior - scripts prefer IPs, not hosts.
 - Any duplicates are removed.
 - prefer-ipv6 flag is respected (i.e. when true IPv6 addresses of the
 same scope come before IPv4 ones).
 - The last endpoint used to successfully connect to the API server is
 inserted at the top of the list.

Minor changes:
 * network.Address, HostPort, Port, PortRange now all have String() and
 GoString() methods; tests improved.
 * envtesting.PatchAttemptStrategies() changed to include the (now exported)
 LongAttempt used while waiting for bootstrap instance addresses.
 * A few changes to log messages to fix typos or improve
 readability (easier to test/debug some deeply nested operations).

Live tested extensively on MAAS, Local, Canonistack, EC2.