prefer-ipv6 honored by state when setting addresses

Added network.SortAddresses() and network.SortHostPorts()
which use the prefer-ipv6 flag to determine which addresses
or HostPorts come on top.

Changed machine.SetAddresses and SetMachineAddresses to
sort the addresses according to whether prefer-ipv6 flag
is set in the environ config.

A few other places where changed as needed, including the
caching of API endpoints in the CLI client and mongo addresses
used to connect to state.

This is the final step of the prefer-ipv6 flag implementation.
I was thinking about demoting these to Tracef, as they were really useful during debugging. Ok, will rephrase them slightly and leave them as Tracef.