Skip to content

Commit

Permalink
added networkobject support to ADDNic (#170)
Browse files Browse the repository at this point in the history
* added networkobject support to ADDNic
* Wrap comment & fix spelling.
  • Loading branch information
Smithx10 authored and twhiteman committed Jun 25, 2019
1 parent df68905 commit 47e17bc
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions compute/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 47e17bc

Please sign in to comment.