Skip to content
This repository was archived by the owner on Aug 8, 2025. It is now read-only.

Commit 21f09ce

Browse files
committed
Incorporated recent bug fixes
1 parent 052bf01 commit 21f09ce

File tree

9 files changed

+66
-139
lines changed

9 files changed

+66
-139
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ override.tf.json
5858
.terraformrc
5959
terraform.rc
6060
terraform
61+
62+
dist/

.goreleaser.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Release {{ .Version }} ({{ .Date }})

.goreleaser.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
before:
4+
hooks:
5+
# You may remove this if you don't use go modules.
6+
- go mod tidy
7+
# you may remove this if you don't need go generate
8+
- go generate ./...
9+
builds:
10+
- env:
11+
- CGO_ENABLED=0
12+
goos:
13+
- linux
14+
- windows
15+
- darwin
16+
17+
archives:
18+
- format: tar.gz
19+
# this name template makes the OS and Arch compatible with the results of uname.
20+
name_template: >-
21+
{{ .ProjectName }}_
22+
{{- title .Os }}_
23+
{{- if eq .Arch "amd64" }}x86_64
24+
{{- else if eq .Arch "386" }}i386
25+
{{- else }}{{ .Arch }}{{ end }}
26+
{{- if .Arm }}v{{ .Arm }}{{ end }}
27+
# use zip for windows archives
28+
format_overrides:
29+
- goos: windows
30+
format: zip
31+
checksum:
32+
name_template: 'checksums.txt'
33+
snapshot:
34+
name_template: "{{ incpatch .Version }}-next"
35+
changelog:
36+
sort: asc
37+
filters:
38+
exclude:
39+
- '^docs:'
40+
- '^test:'
41+
42+
# The lines beneath this are called `modelines`. See `:help modeline`
43+
# Feel free to remove those if you don't want/use them.
44+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
45+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ require.
121121

122122
Minimum environment variable :
123123
```sh
124-
$ export NSXT_MANAGER_HOST="10.92.104.56"
124+
$ export NSXT_MANAGER_HOST="10.191.153.238"
125125
$ export NSXT_USERNAME="admin"
126-
$ export NSXT_PASSWORD="u2.OpqZc0Ptd"
126+
$ export NSXT_PASSWORD="e6+DgNzYA5D*"
127127
$ export NSXT_ALLOW_UNVERIFIED_SSL=true
128128
```
129129

nsxt/provider_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ func testAccEnvDefined(t *testing.T, envVar string) {
7474

7575
func testAccPreCheck(t *testing.T) {
7676
log.Printf("start of testAccPreCheck")
77-
os.Setenv("NSXT_MANAGER_HOST", "10.92.104.56")
77+
os.Setenv("NSXT_MANAGER_HOST", "10.191.153.238")
7878
os.Setenv("NSXT_USERNAME", "admin")
79-
os.Setenv("NSXT_PASSWORD", "u2.OpqZc0Ptd")
79+
os.Setenv("NSXT_PASSWORD", "e6+DgNzYA5D*")
8080
os.Setenv("NSXT_ORG", "default")
8181
os.Setenv("NSXT_PROJECT", "Dev_project")
8282
os.Setenv("NSXT_VPC", "dev_vpc")

nsxt/resource_nsxt_customised_dependants.go

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,11 @@ import (
1414
func resourceExpressionsCustomSchema() *schema.Resource {
1515
return &schema.Resource{
1616
Schema: map[string]*schema.Schema{
17-
"_revision": {
18-
Type: schema.TypeString,
19-
Computed: true,
20-
},
21-
"description": {
22-
Type: schema.TypeString,
23-
Optional: true,
24-
},
25-
"display_name": {
26-
Type: schema.TypeString,
27-
Optional: true,
28-
Computed: true,
29-
},
3017
"exclude": {
3118
Type: schema.TypeSet,
3219
Optional: true,
3320
Elem: resourceExcludedMembersListSchema(),
3421
},
35-
"nsx_id": {
36-
Type: schema.TypeString,
37-
Computed: true,
38-
},
3922
"key": {
4023
Type: schema.TypeString,
4124
Optional: true,
@@ -76,73 +59,24 @@ func resourceExpressionsCustomSchema() *schema.Resource {
7659
Optional: true,
7760
Elem: resourceTagSchema(),
7861
},
79-
"relative_path": {
80-
Type: schema.TypeString,
81-
Computed: true,
82-
},
83-
"remote_path": {
84-
Type: schema.TypeString,
85-
Computed: true,
86-
},
87-
"id": {
88-
Type: schema.TypeString,
89-
Computed: true,
90-
},
91-
"_protection": {
92-
Type: schema.TypeString,
93-
Computed: true,
94-
},
9562
"marked_for_delete": {
9663
Type: schema.TypeBool,
9764
Optional: true,
9865
Default: false,
9966
},
100-
"parent_path": {
101-
Type: schema.TypeString,
102-
Computed: true,
103-
},
104-
"overridden": {
105-
Type: schema.TypeBool,
106-
Computed: true,
107-
},
108-
"path": {
109-
Type: schema.TypeString,
110-
Computed: true,
111-
},
11267
},
11368
}
11469
}
11570

11671
func resourceExpressionCustomSchema() *schema.Resource {
11772
return &schema.Resource{
11873
Schema: map[string]*schema.Schema{
119-
"_revision": {
120-
Type: schema.TypeString,
121-
Computed: true,
122-
},
123-
"description": {
124-
Type: schema.TypeString,
125-
Optional: true,
126-
},
127-
"display_name": {
128-
Type: schema.TypeString,
129-
Optional: true,
130-
Computed: true,
131-
},
132-
"nsx_id": {
133-
Type: schema.TypeString,
134-
Computed: true,
135-
},
13674
"tags": {
13775
Type: schema.TypeList,
13876
Optional: true,
13977
Elem: resourceTagSchema(),
14078
MaxItems: 30,
14179
},
142-
"path": {
143-
Type: schema.TypeString,
144-
Computed: true,
145-
},
14680
"resource_type": {
14781
Type: schema.TypeString,
14882
Required: true,
@@ -200,35 +134,11 @@ func resourceExpressionCustomSchema() *schema.Resource {
200134
Type: schema.TypeString,
201135
Optional: true,
202136
},
203-
"relative_path": {
204-
Type: schema.TypeString,
205-
Computed: true,
206-
},
207-
"remote_path": {
208-
Type: schema.TypeString,
209-
Computed: true,
210-
},
211-
"id": {
212-
Type: schema.TypeString,
213-
Computed: true,
214-
},
215-
"_protection": {
216-
Type: schema.TypeString,
217-
Computed: true,
218-
},
219137
"marked_for_delete": {
220138
Type: schema.TypeBool,
221139
Optional: true,
222140
Default: false,
223141
},
224-
"parent_path": {
225-
Type: schema.TypeString,
226-
Computed: true,
227-
},
228-
"overridden": {
229-
Type: schema.TypeBool,
230-
Computed: true,
231-
},
232142
},
233143
}
234144
}

nsxt/session/nsxtsession.go

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -419,26 +419,6 @@ func (nsxtsess *NsxtSession) newNsxtRequest(verb string, url string, payload io.
419419
return req, errorResult
420420
}
421421

422-
// Helper routines for REST calls.
423-
424-
func (nsxtsess *NsxtSession) collectCookiesFromResp(resp *http.Response) {
425-
// collect cookies from the resp
426-
var csrfToken string
427-
var sessionID string
428-
for _, cookie := range resp.Cookies() {
429-
if cookie.Name == "csrftoken" {
430-
csrfToken = cookie.Value
431-
}
432-
if cookie.Name == "sessionid" || cookie.Name == "nsxt-sessionid" {
433-
sessionID = cookie.Value
434-
}
435-
}
436-
if csrfToken != "" && sessionID != "" {
437-
nsxtsess.csrfToken = csrfToken
438-
nsxtsess.sessionid = sessionID
439-
}
440-
}
441-
442422
// RestRequest exports restRequest from the SDK
443423
// Returns http.Response for accessing the whole http Response struct including headers and response body
444424
func (nsxtsess *NsxtSession) RestRequest(verb string, uri string, payload interface{}, lastError error,
@@ -454,10 +434,7 @@ func (nsxtsess *NsxtSession) restRequest(verb string, uri string, payload interf
454434
url := nsxtsess.prefix + uri
455435

456436
// If optional retryNum arg is provided, then count which retry number this is
457-
retry := 0
458-
if len(retryNum) > 0 {
459-
retry = retryNum[0]
460-
}
437+
maxAPIRetries := nsxtsess.maxAPIRetries
461438

462439
var payloadIO io.Reader
463440
if payload != nil {
@@ -487,23 +464,18 @@ func (nsxtsess *NsxtSession) restRequest(verb string, uri string, payload interf
487464
retryReq = true
488465
}
489466

490-
if !retryReq {
491-
glog.Infof("Req for %s uri %v RespCode %v", verb, url, resp.StatusCode)
492-
errorResult.HTTPStatusCode = resp.StatusCode
493-
494-
if uri == "login" {
495-
nsxtsess.collectCookiesFromResp(resp)
496-
}
497-
if resp.StatusCode == 401 && uri != "login" {
498-
resp.Body.Close()
499-
glog.Infof("Retrying url %s; retry %d due to Status Code %d", url, retry, resp.StatusCode)
500-
err := nsxtsess.initiateSession()
501-
if err != nil {
502-
return nil, err
467+
if retryReq {
468+
for i := 0; i < maxAPIRetries; i++ {
469+
glog.Infof("Retrying url %s; retry %d due to Status Code %d", url, i, resp.StatusCode)
470+
glog.Infof("Req for %s uri %v RespCode %v", verb, url, resp.StatusCode)
471+
errorResult.HTTPStatusCode = resp.StatusCode
472+
if resp.StatusCode != 200 {
473+
resp, err := nsxtsess.client.Do(req)
474+
if err == nil && resp != nil {
475+
break
476+
}
503477
}
504-
} else if resp.StatusCode == 419 || (resp.StatusCode >= 500 && resp.StatusCode < 599) {
505-
resp.Body.Close()
506-
glog.Infof("Retrying url: %s; retry: %d due to Status Code %d", url, retry, resp.StatusCode)
478+
time.Sleep(time.Duration(nsxtsess.apiRetryInterval) * time.Millisecond)
507479
}
508480
}
509481
return resp, nil

nsxt/session/nsxtsession_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ func testNsxtSession(t *testing.T, nsxtsess *NsxtSession) {
8484
func TestNsxtSession(t *testing.T) {
8585
var err error
8686
var session *NsxtSession
87-
var NsxtManager = "10.92.104.56"
87+
var NsxtManager = "10.191.153.238"
8888
var NsxtUsername = "admin"
89-
var NsxtPassword = "u2.OpqZc0Ptd"
89+
var NsxtPassword = "e6+DgNzYA5D*"
9090
session, err = NewNsxtSession(NsxtManager, NsxtUsername, nil, true, SetPassword(NsxtPassword), SetInsecure(true))
9191

9292
if err != nil {

nsxt/terraform_policy_utils.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
// create it. In case, it is present then automatically converts to PATCH semantics.
2222
func APICreateOrUpdate(d *schema.ResourceData, meta interface{}, objType string, s map[string]*schema.Schema,
2323
opts ...bool) error {
24-
//TODO: use autogenerated client for each resource for connection instead of direct session usage
2524
log.Printf("[DEBUG] start of APICreateOrUpdate")
2625
var robj interface{}
2726
obj := d
@@ -140,8 +139,6 @@ func DatasourceRead(d *schema.ResourceData, meta interface{}, objType string, s
140139
}
141140
// Some objTypes (should be resource_type value) are differently worded in .yaml, hence correcting them for usage in Search query
142141
switch objType {
143-
case "SubnetPort":
144-
objType = "VpcSubnetPort"
145142
case "SecurityPolicyRule":
146143
objType = "Rule"
147144
case "GatewayPolicyRule":

0 commit comments

Comments
 (0)