Skip to content

Commit

Permalink
Merge pull request #224 from HewlettPackard/fix_vm_provision
Browse files Browse the repository at this point in the history
Ensure that the network integration is refresh after network creation
  • Loading branch information
manjunath-batakurki authored Feb 23, 2024
2 parents 3ebcc72 + b4b99fc commit 33bf3a2
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/HewlettPackard/hpegl-vmaas-terraform-resources
go 1.17

require (
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.4
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.5
github.com/golang/mock v1.6.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-docs v0.9.0
Expand Down
14 changes: 2 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,8 @@ github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.1 h1:OG6FsXwEn3Vt9QeJ0T73jzhF+7iXCucDp1jJjOt+kZI=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.1/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.2-0.20230206060111-b9ce4e0ba12b h1:XioqpC43aRWkNuzkF9oZ/S+/Ok3C0hUdM4/BGSyUzRU=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.2-0.20230206060111-b9ce4e0ba12b/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3-0.20230607070149-edbaab2cecc5 h1:sVx0x6IJ20fV4s6+kQK58Ur7rW8tpVNkS021qxgknBU=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3-0.20230607070149-edbaab2cecc5/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3-0.20230608151449-1fae7d0f2b31 h1:kRhW5VrM18kmdWKgbq0GGkdSqE/QxLmDYWHUW5OL7tA=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3-0.20230608151449-1fae7d0f2b31/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3 h1:UFovE1vu0cj6paebMNZCDZ4v7F654E7OmSOezO7nAog=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.4 h1:nhUgqXKnnBbl/MJNQjHSfyH+Rc4O0quI+TRDYlAnadw=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.4/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.5 h1:LUSZRMK0Bphp9CoIqrVY9NJHgoZxyB2ZRZouqi7zQ1U=
github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.5/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
Expand Down
4 changes: 3 additions & 1 deletion golangci-lint-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#(C) Copyright 2021 Hewlett Packard Enterprise Development LP
#(C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP

run:
deadline: 240s
Expand All @@ -12,6 +12,8 @@ linters-settings:
threshold: 110
lll:
line-length: 128
gofumpt:
module-path: "github.com/HewlettPackard/hpegl-vmaas-terraform-resources"
goimports:
local-prefixes: "github.com"
godox:
Expand Down
69 changes: 66 additions & 3 deletions internal/cmp/resource_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package cmp
import (
"context"
"fmt"
"strings"
"time"

"github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/client"
"github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/models"
Expand Down Expand Up @@ -105,6 +107,55 @@ func (r *resNetwork) Create(ctx context.Context, d *utils.Data, meta interface{}
if err != nil {
return err
}
// Refresh NSX integration
serverRefreshResp, err := r.rClient.RefreshNetworkServices(ctx, createReq.NetworkServer.ID, nil)
if !serverRefreshResp.Success {
return fmt.Errorf("failed refresh NSX integration post NSX object creation")
}
if err != nil {
return err
}
errCount := 0
cRetry := utils.CustomRetry{
Timeout: time.Minute * 10,
RetryDelay: time.Second * 10,
InitialDelay: time.Second * 10,
Cond: func(response interface{}, err error) (bool, error) {
if err != nil {
errCount++
// return false as condition if same error returns 3 times.
if errCount == 3 {
return false, err
}

return false, nil
}

networkResponse, ok := response.(models.GetSpecificNetworkBody)
if !ok {
errCount++
if errCount == 3 {
return false, fmt.Errorf("%s", "error while getting Network")
}

return false, nil
}
errCount = 0

if strings.Contains(networkResponse.Network.ExternalID, utils.PortGroupPrefix) {
return true, nil
}

return false, nil
},
}

_, err = cRetry.Retry(ctx, meta, func(ctx context.Context) (interface{}, error) {
return r.nClient.GetSpecificNetwork(ctx, createResp.Network.ID)
})
if err != nil {
return err
}

return tftags.Set(d, createResp.Network)
}
Expand Down Expand Up @@ -140,9 +191,21 @@ func (r *resNetwork) Update(ctx context.Context, d *utils.Data, meta interface{}
func (r *resNetwork) Delete(ctx context.Context, d *utils.Data, meta interface{}) error {
setMeta(meta, r.rClient.Client)
networkID := d.GetID()
resp, err := r.nClient.DeleteNetwork(ctx, networkID)
if !resp.Success {
return fmt.Errorf("got success as false on delete network, error: %w", err)
// wait until deleted
retry := &utils.CustomRetry{
InitialDelay: time.Second * 10,
RetryDelay: time.Second * 10,
Timeout: time.Minute * 10,
}
resp, err := retry.Retry(ctx, meta, func(ctx context.Context) (interface{}, error) {
return r.nClient.DeleteNetwork(ctx, networkID)
})
response := resp.(models.SuccessOrErrorMessage)
if !response.Success {
return fmt.Errorf("failed to delete the network due to following error: %s", response.Msg)
}
if err != nil {
return err
}

return err
Expand Down
15 changes: 8 additions & 7 deletions internal/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ const (
defaultTimeout = time.Hour * 24
noRetryCount = -1
// power constants
PowerOn = "poweron"
PowerOff = "poweroff"
Restart = "restart"
Suspend = "suspend"
Deleting = "deleting"
Deleted = "deleted"
Failed = "failed"
PowerOn = "poweron"
PowerOff = "poweroff"
Restart = "restart"
Suspend = "suspend"
Deleting = "deleting"
Deleted = "deleted"
Failed = "failed"
PortGroupPrefix = "dvportgroup-"
)

0 comments on commit 33bf3a2

Please sign in to comment.