Merge pull request #13826 from hashicorp/b-opc-nat-update

Fixes panic from occuring with unqualifying nats
This commit is contained in:
Matthew Frahry 2017-04-20 16:21:33 -06:00 committed by GitHub
commit 6465d79faa
2 changed files with 24 additions and 13 deletions

View File

@ -364,7 +364,11 @@ func (c *InstancesClient) GetInstance(input *GetInstanceInput) (*InstanceInfo, e
} }
responseBody.SSHKeys = sshKeyNames responseBody.SSHKeys = sshKeyNames
responseBody.Networking = c.unqualifyNetworking(responseBody.Networking) var networkingErr error
responseBody.Networking, networkingErr = c.unqualifyNetworking(responseBody.Networking)
if networkingErr != nil {
return nil, networkingErr
}
responseBody.Storage = c.unqualifyStorage(responseBody.Storage) responseBody.Storage = c.unqualifyStorage(responseBody.Storage)
return &responseBody, nil return &responseBody, nil
@ -481,8 +485,9 @@ func (c *InstancesClient) qualifyNetworking(info map[string]NetworkingInfo) map[
return qualifiedNetworks return qualifiedNetworks
} }
func (c *InstancesClient) unqualifyNetworking(info map[string]NetworkingInfo) map[string]NetworkingInfo { func (c *InstancesClient) unqualifyNetworking(info map[string]NetworkingInfo) (map[string]NetworkingInfo, error) {
// Unqualify ip network // Unqualify ip network
var err error
unqualifiedNetworks := map[string]NetworkingInfo{} unqualifiedNetworks := map[string]NetworkingInfo{}
for k, v := range info { for k, v := range info {
unq := v unq := v
@ -493,7 +498,10 @@ func (c *InstancesClient) unqualifyNetworking(info map[string]NetworkingInfo) ma
unq.Vnic = c.getUnqualifiedName(v.Vnic) unq.Vnic = c.getUnqualifiedName(v.Vnic)
} }
if v.Nat != nil { if v.Nat != nil {
unq.Nat = c.unqualifyNat(v.Nat) unq.Nat, err = c.unqualifyNat(v.Nat)
if err != nil {
return nil, err
}
} }
if v.VnicSets != nil { if v.VnicSets != nil {
unq.VnicSets = c.getUnqualifiedList(v.VnicSets) unq.VnicSets = c.getUnqualifiedList(v.VnicSets)
@ -507,7 +515,7 @@ func (c *InstancesClient) unqualifyNetworking(info map[string]NetworkingInfo) ma
} }
unqualifiedNetworks[k] = unq unqualifiedNetworks[k] = unq
} }
return unqualifiedNetworks return unqualifiedNetworks, nil
} }
func (c *InstancesClient) qualifyNat(nat []string, shared bool) []string { func (c *InstancesClient) qualifyNat(nat []string, shared bool) []string {
@ -526,7 +534,7 @@ func (c *InstancesClient) qualifyNat(nat []string, shared bool) []string {
return qualifiedNats return qualifiedNats
} }
func (c *InstancesClient) unqualifyNat(nat []string) []string { func (c *InstancesClient) unqualifyNat(nat []string) ([]string, error) {
unQualifiedNats := []string{} unQualifiedNats := []string{}
for _, v := range nat { for _, v := range nat {
if strings.HasPrefix(v, "ippool:/oracle") { if strings.HasPrefix(v, "ippool:/oracle") {
@ -534,10 +542,13 @@ func (c *InstancesClient) unqualifyNat(nat []string) []string {
continue continue
} }
n := strings.Split(v, ":") n := strings.Split(v, ":")
if len(n) < 1 {
return nil, fmt.Errorf("Error unqualifying NAT: %s", v)
}
u := n[1] u := n[1]
unQualifiedNats = append(unQualifiedNats, c.getUnqualifiedName(u)) unQualifiedNats = append(unQualifiedNats, c.getUnqualifiedName(u))
} }
return unQualifiedNats return unQualifiedNats, nil
} }
func (c *InstancesClient) unqualifyStorage(attachments []StorageAttachment) []StorageAttachment { func (c *InstancesClient) unqualifyStorage(attachments []StorageAttachment) []StorageAttachment {

14
vendor/vendor.json vendored
View File

@ -1993,22 +1993,22 @@
"revision": "d30f09973e19c1dfcd120b2d9c4f168e68d6b5d5" "revision": "d30f09973e19c1dfcd120b2d9c4f168e68d6b5d5"
}, },
{ {
"checksumSHA1": "yNCeppZjpZqEUgp/4g0AeJ+ee44=", "checksumSHA1": "fOs3GlAj3fAMTlz+6OyllpZV6ow=",
"path": "github.com/hashicorp/go-oracle-terraform/compute", "path": "github.com/hashicorp/go-oracle-terraform/compute",
"revision": "bb3c65caa646927d1ad68b97f77241f48c855ad0", "revision": "c96a23ea6900a1bbf65698abbd1b9a0010576cb5",
"revisionTime": "2017-04-19T14:06:08Z" "revisionTime": "2017-04-20T21:25:45Z"
}, },
{ {
"checksumSHA1": "DzK7lYwHt5Isq5Zf73cnQqBO2LI=", "checksumSHA1": "DzK7lYwHt5Isq5Zf73cnQqBO2LI=",
"path": "github.com/hashicorp/go-oracle-terraform/helper", "path": "github.com/hashicorp/go-oracle-terraform/helper",
"revision": "bb3c65caa646927d1ad68b97f77241f48c855ad0", "revision": "c96a23ea6900a1bbf65698abbd1b9a0010576cb5",
"revisionTime": "2017-04-19T14:06:08Z" "revisionTime": "2017-04-20T21:25:45Z"
}, },
{ {
"checksumSHA1": "AyNRs19Es9pDw2VMxVKWuLx3Afg=", "checksumSHA1": "AyNRs19Es9pDw2VMxVKWuLx3Afg=",
"path": "github.com/hashicorp/go-oracle-terraform/opc", "path": "github.com/hashicorp/go-oracle-terraform/opc",
"revision": "bb3c65caa646927d1ad68b97f77241f48c855ad0", "revision": "c96a23ea6900a1bbf65698abbd1b9a0010576cb5",
"revisionTime": "2017-04-19T14:06:08Z" "revisionTime": "2017-04-20T21:25:45Z"
}, },
{ {
"checksumSHA1": "b0nQutPMJHeUmz4SjpreotAo6Yk=", "checksumSHA1": "b0nQutPMJHeUmz4SjpreotAo6Yk=",