From 47e17bca5435df86c448eeed9e0b0c3cdef7fc95 Mon Sep 17 00:00:00 2001 From: Smithx10 Date: Tue, 25 Jun 2019 17:56:15 -0400 Subject: [PATCH] added networkobject support to ADDNic (#170) * added networkobject support to ADDNic * Wrap comment & fix spelling. --- compute/instances.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/compute/instances.go b/compute/instances.go index e2d6cf5..264f6b4 100644 --- a/compute/instances.go +++ b/compute/instances.go @@ -942,8 +942,30 @@ func (c *InstancesClient) GetNIC(ctx context.Context, input *GetNICInput) (*NIC, } type AddNICInput struct { - InstanceID string `json:"-"` - Network string `json:"network"` + InstanceID string + Network string + NetworkObject NetworkObject +} + +// toAPI is used to build up the JSON Object to send to the API gateway. It +// also will resolve the scenario where a user provides both a NetworkObject +// and a Network. If both are provided, NetworkObject wins. +func (input AddNICInput) toAPI() map[string]interface{} { + result := map[string]interface{}{} + + var network NetworkObject + + if input.NetworkObject.IPv4UUID != "" { + network = input.NetworkObject + } else { + network = NetworkObject{ + IPv4UUID: input.Network, + } + } + + result["network"] = network + + return result } // AddNIC asynchronously adds a NIC to a given instance. If a NIC for a given @@ -956,7 +978,7 @@ func (c *InstancesClient) AddNIC(ctx context.Context, input *AddNICInput) (*NIC, reqInputs := client.RequestInput{ Method: http.MethodPost, Path: fullPath, - Body: input, + Body: input.toAPI(), } response, err := c.client.ExecuteRequestRaw(ctx, reqInputs) if err != nil {