Skip to content

Commit

Permalink
Merge pull request #61 from qedsoftware/mac
Browse files Browse the repository at this point in the history
Expose the main interface MAC via server ipv4 list
  • Loading branch information
JamesClonk authored Dec 27, 2018
2 parents 419a8e6 + e3c2b6a commit 882c666
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cmd/commands_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,14 @@ func ipv4List(cmd *cli.Cmd) {
return
}

lengths := []int{24, 24, 24, 32, 48}
tabsPrint(columns{"IP", "NETMASK", "GATEWAY", "TYPE", "REVERSE DNS"}, lengths)
lengths := []int{24, 24, 24, 24, 32, 48}
tabsPrint(columns{"IP", "NETMASK", "GATEWAY", "MAC", "TYPE", "REVERSE DNS"}, lengths)
for _, ip := range list {
tabsPrint(columns{
ip.IP,
ip.Netmask,
ip.Gateway,
ip.MAC,
ip.Type,
ip.ReverseDNS,
}, lengths)
Expand Down
3 changes: 2 additions & 1 deletion lib/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type IPv4 struct {
IP string `json:"ip"`
Netmask string `json:"netmask"`
Gateway string `json:"gateway"`
MAC string `json:"mac_address"`
Type string `json:"type"`
ReverseDNS string `json:"reverse"`
}
Expand Down Expand Up @@ -66,7 +67,7 @@ func (s reverseDNSIPv6s) Less(i, j int) bool { return s[i].IP < s[j].IP }
// ListIPv4 lists the IPv4 information of a virtual machine
func (c *Client) ListIPv4(id string) (list []IPv4, err error) {
var ipMap map[string][]IPv4
if err := c.get(`server/list_ipv4?SUBID=`+id, &ipMap); err != nil {
if err := c.get(`server/list_ipv4?SUBID=`+id+`&public_network=yes`, &ipMap); err != nil {
return nil, err
}

Expand Down
5 changes: 4 additions & 1 deletion lib/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Test_IP_ListIPv4_OK(t *testing.T) {
server, client := getTestServerAndClient(http.StatusOK, `{"576965":[
{"ip":"123.123.123.124","netmask":"255.255.255.248","gateway":"123.123.123.1","type":"secondary_ip","reverse":"host2.example.com"},
{"ip":"10.99.0.10","netmask":"255.255.0.0","gateway":"","type":"private","reverse":""},
{"ip":"123.123.123.123","netmask":"255.255.255.248","gateway":"123.123.123.1","type":"main_ip","reverse":"host1.example.com"}]}`)
{"ip":"123.123.123.123","netmask":"255.255.255.248","gateway":"123.123.123.1","type":"main_ip","reverse":"host1.example.com","mac_address":"56:00:01:ce:dc:0f"}]}`)
defer server.Close()

list, err := client.ListIPv4("123456789")
Expand All @@ -45,17 +45,20 @@ func Test_IP_ListIPv4_OK(t *testing.T) {

assert.Equal(t, "123.123.123.123", list[0].IP)
assert.Equal(t, "255.255.255.248", list[0].Netmask)
assert.Equal(t, "56:00:01:ce:dc:0f", list[0].MAC)
assert.Equal(t, "main_ip", list[0].Type)
assert.Equal(t, "host1.example.com", list[0].ReverseDNS)

assert.Equal(t, "10.99.0.10", list[1].IP)
assert.Equal(t, "255.255.0.0", list[1].Netmask)
assert.Equal(t, "", list[1].Gateway)
assert.Empty(t, "", list[1].MAC)
assert.Equal(t, "private", list[1].Type)
assert.Equal(t, "", list[1].ReverseDNS)

assert.Equal(t, "123.123.123.124", list[2].IP)
assert.Equal(t, "123.123.123.1", list[2].Gateway)
assert.Equal(t, "", list[2].MAC)
assert.Equal(t, "secondary_ip", list[2].Type)
assert.Equal(t, "host2.example.com", list[2].ReverseDNS)
}
Expand Down

0 comments on commit 882c666

Please sign in to comment.