256
256
// SelectPeerHostPort returns the HostPort to use as the mongo replica set peer
257
257
// by selecting it from the given hostPorts.
258
258
func SelectPeerHostPort(hostPorts []network.HostPort) string {
259
logger.Debugf("selecting mongo peer hostPort from %+v", hostPorts)
259
logger.Debugf("selecting mongo peer hostPort by scope from %+v", hostPorts)
260
return network.SelectMongoHostPortsByScope(hostPorts, true)[0]
263
// SelectPeerHostPortBySpace returns the HostPort to use as the mongo replica set peer
264
// by selecting it from the given hostPorts.
265
func SelectPeerHostPortBySpace(hostPorts []network.HostPort, space network.SpaceName) string {
266
logger.Debugf("selecting mongo peer hostPort in space %s from %+v", space, hostPorts)
260
267
// ScopeMachineLocal addresses are OK if we can't pick by space.
261
return network.SelectControllerHostPort(hostPorts, true)
268
suitableHostPorts, foundHostPortsInSpaces := network.SelectMongoHostPortsBySpaces(hostPorts, []network.SpaceName{space})
270
if !foundHostPortsInSpaces {
271
logger.Debugf("Failed to select hostPort by space - trying by scope from %+v", hostPorts)
272
suitableHostPorts = network.SelectMongoHostPortsByScope(hostPorts, true)
274
return suitableHostPorts[0]
264
277
// GenerateSharedSecret generates a pseudo-random shared secret (keyfile)