Repository: hetznercloud/hcloud-go
Pull request #115 (2019-07-18 11:41:11)

Add MacAddress Field to ServerPrivateNet


Patch:
diff --git a/CHANGES.md b/CHANGES.md
index 088b9f6..836d944 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,9 @@
 # Changes
 
+## master
+
+* Add `MacAddress` field to `ServerPrivateNet`
+
 ## v1.14.0
 
 * Add `Created` field to `FloatingIP`
diff --git a/hcloud/schema.go b/hcloud/schema.go
index 2ae5358..e368709 100644
--- a/hcloud/schema.go
+++ b/hcloud/schema.go
@@ -210,8 +210,9 @@ func ServerPublicNetIPv6FromSchema(s schema.ServerPublicNetIPv6) ServerPublicNet
 // ServerPrivateNetFromSchema converts a schema.ServerPrivateNet to a ServerPrivateNet.
 func ServerPrivateNetFromSchema(s schema.ServerPrivateNet) ServerPrivateNet {
 	n := ServerPrivateNet{
-		Network: &Network{ID: s.Network},
-		IP:      net.ParseIP(s.IP),
+		Network:    &Network{ID: s.Network},
+		IP:         net.ParseIP(s.IP),
+		MacAddress: s.MacAddress,
 	}
 	for _, ip := range s.AliasIPs {
 		n.Aliases = append(n.Aliases, net.ParseIP(ip))
diff --git a/hcloud/schema/server.go b/hcloud/schema/server.go
index 1a23647..99255ad 100644
--- a/hcloud/schema/server.go
+++ b/hcloud/schema/server.go
@@ -64,9 +64,10 @@ type ServerPublicNetIPv6DNSPtr struct {
 
 // ServerPrivateNet defines the schema of a server's private network information.
 type ServerPrivateNet struct {
-	Network  int      `json:"network"`
-	IP       string   `json:"ip"`
-	AliasIPs []string `json:"alias_ips"`
+	Network    int      `json:"network"`
+	IP         string   `json:"ip"`
+	AliasIPs   []string `json:"alias_ips"`
+	MacAddress string   `json:"mac_address"`
 }
 
 // ServerGetResponse defines the schema of the response when
diff --git a/hcloud/server.go b/hcloud/server.go
index 26c69d7..0b8ab5b 100644
--- a/hcloud/server.go
+++ b/hcloud/server.go
@@ -98,9 +98,10 @@ type ServerPublicNetIPv6 struct {
 
 // ServerPrivateNet defines the schema of a server's private network information.
 type ServerPrivateNet struct {
-	Network *Network
-	IP      net.IP
-	Aliases []net.IP
+	Network    *Network
+	IP         net.IP
+	Aliases    []net.IP
+	MacAddress string
 }
 
 // DNSPtrForIP returns the reverse dns pointer of the ip address.


Test patch:
diff --git a/hcloud/schema_test.go b/hcloud/schema_test.go
index 606b10d..3792a3f 100644
--- a/hcloud/schema_test.go
+++ b/hcloud/schema_test.go
@@ -637,9 +637,10 @@ func TestServerPrivateNetFromSchema(t *testing.T) {
 	data := []byte(`{
 		"network": 4711,
 		"ip": "10.0.1.1",
-		"aliases": [
+		"alias_ips": [
 			"10.0.1.2"
-		]
+		],
+		"mac_address": "86:00:ff:2a:7d:e1"
 	}`)
 
 	var s schema.ServerPrivateNet
@@ -654,6 +655,15 @@ func TestServerPrivateNetFromSchema(t *testing.T) {
 	if privateNet.IP.String() != "10.0.1.1" {
 		t.Errorf("unexpected IP: %v", privateNet.IP)
 	}
+	if len(privateNet.Aliases) != 1 {
+		t.Errorf("unexpected number of alias IPs: %v", len(privateNet.Aliases))
+	}
+	if privateNet.Aliases[0].String() != "10.0.1.2" {
+		t.Errorf("unexpected alias IP: %v", privateNet.Aliases[0])
+	}
+	if privateNet.MacAddress != "86:00:ff:2a:7d:e1" {
+		t.Errorf("unexpected mac address: %v", privateNet.MacAddress)
+	}
 }
 
 func TestServerTypeFromSchema(t *testing.T) {