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.
this is getting long enough, I wonder if it would be better to be clear about what the parameters are:
mockedAPIState(true, true, true) doesn't really mean much for anyone.
We could do something like:
mockedAPIState(aspects ...string)
and then you would do:
mockedAPIState("has-environ", "has-host-port", "prefer-IPV6"), and the internal implementation would just iterate over the strings and set the appropriate mock details. (Or set local booleans and leave this code the same?)
Certainly not something you need to do to land this patch, since you're just extending what was there, but I wrote the original one and wasn't very happy about 2 booleans, and now it is a bit worse with even 3.