Skip to content

Commit

Permalink
#158 support for network objects
Browse files Browse the repository at this point in the history
Reviewed by: Joshua M. Clulow <[email protected]>
Approved by: Joshua M. Clulow <[email protected]>
  • Loading branch information
Bruce Smith authored and jclulow committed Jun 17, 2019
1 parent e816338 commit 66b96d7
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions compute/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ type InstanceVolume struct {
Mountpoint string `json:"mountpoint,omitempty"`
}

type NetworkObject struct {
IPv4UUID string `json:"ipv4_uuid"`
IPv4IPs []string `json:"ipv4_ips,omitempty"`
}

type Instance struct {
ID string `json:"id"`
Name string `json:"name"`
Expand Down Expand Up @@ -278,6 +283,7 @@ type CreateInstanceInput struct {
Package string
Image string
Networks []string
NetworkObjects []NetworkObject
Affinity []string
LocalityStrict bool
LocalityNear []string
Expand Down Expand Up @@ -315,8 +321,31 @@ func (input *CreateInstanceInput) toAPI() (map[string]interface{}, error) {
result["image"] = input.Image
}

if len(input.Networks) > 0 {
result["networks"] = input.Networks
// If we are passed []string from input.Networks that do not conflict with networks provided by NetworkObjects, add them to the request sent to CloudAPI
var networks []NetworkObject

if len(input.NetworkObjects) > 0 {
networks = append(networks, input.NetworkObjects...)
}

for _, netuuid := range input.Networks {
found := false

for _, net := range networks {
if net.IPv4UUID == netuuid {
found = true
}
}

if !found {
networks = append(networks, NetworkObject{
IPv4UUID: netuuid,
})
}
}

if len(networks) > 0 {
result["networks"] = networks
}

if len(input.Volumes) > 0 {
Expand Down

0 comments on commit 66b96d7

Please sign in to comment.