[FLOC-3521] Support mapping public IP addresses in API client #2230
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
public_address
field of Nodes returned form theflocker.apiclient.FlockerClient
actually contains the internal cluster IP address, which can be a private IP address.Public IP addresses are very useful for clients using the API client module, but a node has no way of knowing which of its IP addresses is truly public, and in some cases, may not even know about a public IP address that routes to it (e.g. NAT addresses).
However, the code using
apiclient
may know the mapping, especially if it was somehow involved in starting the cluster. This is the case when a cluster is started usingrun-acceptance-tests
where the mapping from internal cluster hostnames to public IP addresses is exported as an environment variable.This PR allows the
apiclient
user, when creating aFlockerClient
, to pass a mapping of internal hostname IP_ addresses to public IP addresses. Expand theNode
class to include both the internal address, now as an additional field calledhostname
(it's usual name in Flocker), and to setpublic_address
to the public IP address provided by a dictionary mapping hostname to public address.For Rackspace, the mapping provided by
run-acceptance-tests
is{}
which makes thehostname
andpublic_address
fields the same. This is appropriate since Rackspace IP addresses are public.For AWS,
run-acceptance-tests
returns a JSON structure{"10.0.0.1": "172.12.12.12"}
which can be parsed into a Python dictionary for passing toFlockerClient
.This will be used by the benchmarking code to SSH to individual cluster nodes to measure benchmark metrics.