Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
List all machine IP addrs in YAML and JSON output #6424
Conversation
|
AWS example: https://pastebin.canonical.com/167521/ |
|
GCE example: https://pastebin.canonical.com/167528/ |
dimitern
suggested changes
Oct 11, 2016
I didn't manage to review this in detail, but I have some comments that I think need to be addressed. I'll add comments tomorrow, please don't rush to land this yet.
| + } | ||
| + for _, mAddr := range mAddrs { | ||
| + switch mAddr.Value { | ||
| + case "127.0.0.1", "::1": |
| - "dns-name": "controller-0.dns", | ||
| - "instance-id": "controller-0", | ||
| + "dns-name": "controller-0.dns", | ||
| + "ip-addresses": []string{"controller-0.dns"}, |
frobware
Oct 11, 2016
Contributor
I'm confused by the names we use. If it is address then why aren't they IP addresses? Similarly, if we don't want addresses then let's use hostnames.
macgreagoir
Oct 12, 2016
Contributor
Fair point, they are the same strings used in the rest of this test suite in place of address strings, but they can be changed.
dimitern
Oct 12, 2016
Contributor
+1; I'd also suggest adding tests with full IPv6 addresses in the range reserved for documentation purposes (2001:db8::/32).
|
I was looking at the output format: shouldn't we indent the list of ip-addresses:
|
|
Just noting (after chat with babbageclunk) the indentation as standard in go-yaml: |
| + mAddrs = append(mAddrs, addr) | ||
| + } | ||
| + } | ||
| + for _, mAddr := range mAddrs { |
dimitern
Oct 12, 2016
Contributor
This loop is in quite similar to what network.FilterUnusableHostPorts() does, unfortunately not for []network.Address.
Nevertheless, please use the same approach here - switch on mAddr.Scope and filter ScopeMachineLocal and ScopeLinkLocal. This will cover the full loopback ranges 127/8 and ::1/128 on both IPv4 and IPv6 addresses, and will also not show the linkewise-unusable link local addresses.
| - "dns-name": "controller-0.dns", | ||
| - "instance-id": "controller-0", | ||
| + "dns-name": "controller-0.dns", | ||
| + "ip-addresses": []string{"controller-0.dns"}, |
frobware
Oct 11, 2016
Contributor
I'm confused by the names we use. If it is address then why aren't they IP addresses? Similarly, if we don't want addresses then let's use hostnames.
macgreagoir
Oct 12, 2016
Contributor
Fair point, they are the same strings used in the rest of this test suite in place of address strings, but they can be changed.
dimitern
Oct 12, 2016
Contributor
+1; I'd also suggest adding tests with full IPv6 addresses in the range reserved for documentation purposes (2001:db8::/32).
| + switch mAddr.Scope { | ||
| + case network.ScopeMachineLocal, network.ScopeLinkLocal: | ||
| + continue | ||
| + default: |
dimitern
Oct 12, 2016
Contributor
You could drop the default and do the append after the switch:
for _, mAddr := range mAddrs {
switch mAddr.Scope {
case network.ScopeMachineLocal, network.ScopeLinkLocal:
continue
}
status.IPAddresses = append(status.IPAddresses, mAddr.Value)
}| + Hardware string `json:"hardware"` | ||
| + Jobs []multiwatcher.MachineJob `json:"jobs"` | ||
| + HasVote bool `json:"has-vote"` | ||
| + WantsVote bool `json:"wants-vote"` |
| + DNSName string `json:"dns-name"` | ||
| + | ||
| + // IPAddresses holds the IP addresses bound to this machine. | ||
| + IPAddresses []string `json:"ip-addresses"` |
macgreagoir
Oct 12, 2016
Contributor
As discussed in IRC, we are adding another field to the struct, but not changing any existing.
|
$$merge$$ |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
macgreagoir commentedOct 11, 2016
When status or show-machine are run with the YAML or JSON format
options, all IP addresses a machine has will be shown.
Fixes lp:1602840
QA steps:
sudo ip a a <cidr> dev <dev name>using an existing devicejuju show-machine <machine id> [--format=yaml]should display something similar to this:juju show-machine <machine id> --format=tabularshould not show the list of IP addresses, only the 'DNS' name/address:juju statusshould show similar output for each deployed machine