diff --git a/cmd/commands_servers.go b/cmd/commands_servers.go index 120d55c..fb5474e 100644 --- a/cmd/commands_servers.go +++ b/cmd/commands_servers.go @@ -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) diff --git a/lib/ip.go b/lib/ip.go index 4d169cb..aeee592 100644 --- a/lib/ip.go +++ b/lib/ip.go @@ -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"` } @@ -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 } diff --git a/lib/ip_test.go b/lib/ip_test.go index 0116457..d39f35e 100644 --- a/lib/ip_test.go +++ b/lib/ip_test.go @@ -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") @@ -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) }