Skip to content

Commit 07e3483

Browse files
committed
Support multi-tenancy
Signed-off-by: graysonwu <wgrayson@vmware.com>
1 parent 850ffbb commit 07e3483

8 files changed

+377
-94
lines changed

api/api_list.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,3 +877,30 @@
877877
supported_method:
878878
- New
879879
- List
880+
- api_packages:
881+
- client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra
882+
model: github.com/vmware/vsphere-automation-sdk-go/runtime/data
883+
list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model
884+
type: Local
885+
- client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra
886+
model: github.com/vmware/vsphere-automation-sdk-go/runtime/data
887+
list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model
888+
type: Global
889+
- client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra
890+
model: github.com/vmware/vsphere-automation-sdk-go/runtime/data
891+
list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model
892+
type: Multitenancy
893+
model_name: StructValue
894+
obj_name: FloodProtectionProfiles
895+
client_name: FloodProtectionProfilesClient
896+
list_result_name: FloodProtectionProfileListResult
897+
model_prefix: vapiData_
898+
model_pass_ptr: true
899+
file_name: FloodProtectionProfilesClient
900+
supported_method:
901+
- New
902+
- Get
903+
- Delete
904+
- Patch
905+
- Update
906+
- List
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
//nolint:revive
2+
package infra
3+
4+
// The following file has been autogenerated. Please avoid any changes!
5+
import (
6+
"errors"
7+
8+
model0 "github.com/vmware/vsphere-automation-sdk-go/runtime/data"
9+
vapiProtocolClient_ "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client"
10+
client1 "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra"
11+
lrmodel1 "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model"
12+
client0 "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra"
13+
lrmodel0 "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
14+
client2 "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra"
15+
16+
utl "github.com/vmware/terraform-provider-nsxt/api/utl"
17+
)
18+
19+
type StructValueClientContext utl.ClientContext
20+
21+
func NewFloodProtectionProfilesClient(sessionContext utl.SessionContext, connector vapiProtocolClient_.Connector) *StructValueClientContext {
22+
var client interface{}
23+
24+
switch sessionContext.ClientType {
25+
26+
case utl.Local:
27+
client = client0.NewFloodProtectionProfilesClient(connector)
28+
29+
case utl.Global:
30+
client = client1.NewFloodProtectionProfilesClient(connector)
31+
32+
case utl.Multitenancy:
33+
client = client2.NewFloodProtectionProfilesClient(connector)
34+
35+
default:
36+
return nil
37+
}
38+
return &StructValueClientContext{Client: client, ClientType: sessionContext.ClientType, ProjectID: sessionContext.ProjectID}
39+
}
40+
41+
func (c StructValueClientContext) Get(floodProtectionProfileIdParam string) (*model0.StructValue, error) {
42+
var obj *model0.StructValue
43+
var err error
44+
45+
switch c.ClientType {
46+
47+
case utl.Local:
48+
client := c.Client.(client0.FloodProtectionProfilesClient)
49+
obj, err = client.Get(floodProtectionProfileIdParam)
50+
if err != nil {
51+
return obj, err
52+
}
53+
54+
case utl.Global:
55+
client := c.Client.(client1.FloodProtectionProfilesClient)
56+
obj, err = client.Get(floodProtectionProfileIdParam)
57+
if err != nil {
58+
return obj, err
59+
}
60+
61+
case utl.Multitenancy:
62+
client := c.Client.(client2.FloodProtectionProfilesClient)
63+
obj, err = client.Get(utl.DefaultOrgID, c.ProjectID, floodProtectionProfileIdParam)
64+
if err != nil {
65+
return obj, err
66+
}
67+
68+
default:
69+
return obj, errors.New("invalid infrastructure for model")
70+
}
71+
return obj, err
72+
}
73+
74+
func (c StructValueClientContext) Delete(floodProtectionProfileIdParam string, overrideParam *bool) error {
75+
var err error
76+
77+
switch c.ClientType {
78+
79+
case utl.Local:
80+
client := c.Client.(client0.FloodProtectionProfilesClient)
81+
err = client.Delete(floodProtectionProfileIdParam, overrideParam)
82+
83+
case utl.Global:
84+
client := c.Client.(client1.FloodProtectionProfilesClient)
85+
err = client.Delete(floodProtectionProfileIdParam, overrideParam)
86+
87+
case utl.Multitenancy:
88+
client := c.Client.(client2.FloodProtectionProfilesClient)
89+
err = client.Delete(utl.DefaultOrgID, c.ProjectID, floodProtectionProfileIdParam, overrideParam)
90+
91+
default:
92+
err = errors.New("invalid infrastructure for model")
93+
}
94+
return err
95+
}
96+
97+
func (c StructValueClientContext) Patch(floodProtectionProfileIdParam string, floodProtectionProfileParam *model0.StructValue, overrideParam *bool) error {
98+
var err error
99+
100+
switch c.ClientType {
101+
102+
case utl.Local:
103+
client := c.Client.(client0.FloodProtectionProfilesClient)
104+
err = client.Patch(floodProtectionProfileIdParam, floodProtectionProfileParam, overrideParam)
105+
106+
case utl.Global:
107+
client := c.Client.(client1.FloodProtectionProfilesClient)
108+
err = client.Patch(floodProtectionProfileIdParam, floodProtectionProfileParam, overrideParam)
109+
110+
case utl.Multitenancy:
111+
client := c.Client.(client2.FloodProtectionProfilesClient)
112+
err = client.Patch(utl.DefaultOrgID, c.ProjectID, floodProtectionProfileIdParam, floodProtectionProfileParam, overrideParam)
113+
114+
default:
115+
err = errors.New("invalid infrastructure for model")
116+
}
117+
return err
118+
}
119+
120+
func (c StructValueClientContext) Update(floodProtectionProfileIdParam string, floodProtectionProfileParam *model0.StructValue, overrideParam *bool) (*model0.StructValue, error) {
121+
var err error
122+
var obj *model0.StructValue
123+
124+
switch c.ClientType {
125+
126+
case utl.Local:
127+
client := c.Client.(client0.FloodProtectionProfilesClient)
128+
obj, err = client.Update(floodProtectionProfileIdParam, floodProtectionProfileParam, overrideParam)
129+
130+
case utl.Global:
131+
client := c.Client.(client1.FloodProtectionProfilesClient)
132+
obj, err = client.Update(floodProtectionProfileIdParam, floodProtectionProfileParam, overrideParam)
133+
134+
case utl.Multitenancy:
135+
client := c.Client.(client2.FloodProtectionProfilesClient)
136+
obj, err = client.Update(utl.DefaultOrgID, c.ProjectID, floodProtectionProfileIdParam, floodProtectionProfileParam, overrideParam)
137+
138+
default:
139+
err = errors.New("invalid infrastructure for model")
140+
}
141+
return obj, err
142+
}
143+
144+
func (c StructValueClientContext) List(cursorParam *string, includeMarkForDeleteObjectsParam *bool, includedFieldsParam *string, pageSizeParam *int64, sortAscendingParam *bool, sortByParam *string) (lrmodel0.FloodProtectionProfileListResult, error) {
145+
var err error
146+
var obj lrmodel0.FloodProtectionProfileListResult
147+
148+
switch c.ClientType {
149+
150+
case utl.Local:
151+
client := c.Client.(client0.FloodProtectionProfilesClient)
152+
obj, err = client.List(cursorParam, includeMarkForDeleteObjectsParam, includedFieldsParam, pageSizeParam, sortAscendingParam, sortByParam)
153+
154+
case utl.Global:
155+
client := c.Client.(client1.FloodProtectionProfilesClient)
156+
gmObj, err := client.List(cursorParam, includeMarkForDeleteObjectsParam, includedFieldsParam, pageSizeParam, sortAscendingParam, sortByParam)
157+
if err != nil {
158+
return obj, err
159+
}
160+
obj1, err1 := utl.ConvertModelBindingType(gmObj, lrmodel1.FloodProtectionProfileListResultBindingType(), lrmodel0.FloodProtectionProfileListResultBindingType())
161+
if err1 != nil {
162+
return obj, err1
163+
}
164+
obj = obj1.(lrmodel0.FloodProtectionProfileListResult)
165+
166+
case utl.Multitenancy:
167+
client := c.Client.(client2.FloodProtectionProfilesClient)
168+
obj, err = client.List(utl.DefaultOrgID, c.ProjectID, cursorParam, includeMarkForDeleteObjectsParam, includedFieldsParam, pageSizeParam, sortAscendingParam, sortByParam)
169+
170+
default:
171+
err = errors.New("invalid infrastructure for model")
172+
}
173+
return obj, err
174+
}

nsxt/resource_nsxt_policy_distributed_flood_protection_profile.go

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212
"github.com/vmware/vsphere-automation-sdk-go/runtime/bindings"
1313
"github.com/vmware/vsphere-automation-sdk-go/runtime/data"
1414
"github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client"
15-
gm_infra "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra"
16-
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra"
1715
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
16+
17+
"github.com/vmware/terraform-provider-nsxt/api/infra"
18+
utl "github.com/vmware/terraform-provider-nsxt/api/utl"
1819
)
1920

2021
func resourceNsxtPolicyDistributedFloodProtectionProfile() *schema.Resource {
@@ -38,6 +39,7 @@ func getFloodProtectionProfile() map[string]*schema.Schema {
3839
"description": getDescriptionSchema(),
3940
"revision": getRevisionSchema(),
4041
"tag": getTagsSchema(),
42+
"context": getContextSchema(),
4143
"icmp_active_flow_limit": {
4244
Type: schema.TypeInt,
4345
Description: "Active ICMP connections limit",
@@ -82,15 +84,10 @@ func getDistributedFloodProtectionProfile() map[string]*schema.Schema {
8284
return baseProfile
8385
}
8486

85-
func resourceNsxtPolicyFloodProtectionProfileExists(id string, connector client.Connector, isGlobalManager bool) (bool, error) {
86-
var err error
87-
if isGlobalManager {
88-
client := gm_infra.NewFloodProtectionProfilesClient(connector)
89-
_, err = client.Get(id)
90-
} else {
91-
client := infra.NewFloodProtectionProfilesClient(connector)
92-
_, err = client.Get(id)
93-
}
87+
func resourceNsxtPolicyFloodProtectionProfileExists(sessionContext utl.SessionContext, id string, connector client.Connector) (bool, error) {
88+
89+
client := infra.NewFloodProtectionProfilesClient(sessionContext, connector)
90+
_, err := client.Get(id)
9491
if err == nil {
9592
return true, nil
9693
}
@@ -144,18 +141,14 @@ func resourceNsxtPolicyDistributedFloodProtectionProfilePatch(d *schema.Resource
144141
profileStruct := profileValue.(*data.StructValue)
145142

146143
log.Printf("[INFO] Patching DistributedFloodProtectionProfile with ID %s", id)
147-
if isPolicyGlobalManager(m) {
148-
client := gm_infra.NewFloodProtectionProfilesClient(connector)
149-
return client.Patch(id, profileStruct, nil)
150-
}
151-
client := infra.NewFloodProtectionProfilesClient(connector)
144+
client := infra.NewFloodProtectionProfilesClient(getSessionContext(d, m), connector)
152145
return client.Patch(id, profileStruct, nil)
153146
}
154147

155148
func resourceNsxtPolicyDistributedFloodProtectionProfileCreate(d *schema.ResourceData, m interface{}) error {
156149

157150
// Initialize resource Id and verify this ID is not yet used
158-
id, err := getOrGenerateID(d, m, resourceNsxtPolicyFloodProtectionProfileExists)
151+
id, err := getOrGenerateID2(d, m, resourceNsxtPolicyFloodProtectionProfileExists)
159152
if err != nil {
160153
return err
161154
}
@@ -180,21 +173,13 @@ func resourceNsxtPolicyDistributedFloodProtectionProfileRead(d *schema.ResourceD
180173
return fmt.Errorf("Error obtaining FloodProtectionProfile ID")
181174
}
182175

183-
var profileStruct *data.StructValue
184-
var err error
185-
if isPolicyGlobalManager(m) {
186-
client := gm_infra.NewFloodProtectionProfilesClient(connector)
187-
profileStruct, err = client.Get(id)
188-
} else {
189-
client := infra.NewFloodProtectionProfilesClient(connector)
190-
profileStruct, err = client.Get(id)
191-
}
192-
176+
client := infra.NewFloodProtectionProfilesClient(getSessionContext(d, m), connector)
177+
dpffData, err := client.Get(id)
193178
if err != nil {
194179
return handleReadError(d, "FloodProtectionProfile", id, err)
195180
}
196181

197-
dfppInterface, errs := converter.ConvertToGolang(profileStruct, model.DistributedFloodProtectionProfileBindingType())
182+
dfppInterface, errs := converter.ConvertToGolang(dpffData, model.DistributedFloodProtectionProfileBindingType())
198183
if errs != nil {
199184
return errs[0]
200185
}
@@ -239,18 +224,10 @@ func resourceNsxtPolicyFloodProtectionProfileDelete(d *schema.ResourceData, m in
239224
}
240225

241226
connector := getPolicyConnector(m)
242-
var err error
243-
if isPolicyGlobalManager(m) {
244-
client := gm_infra.NewFloodProtectionProfilesClient(connector)
245-
err = client.Delete(id, nil)
246-
} else {
247-
client := infra.NewFloodProtectionProfilesClient(connector)
248-
err = client.Delete(id, nil)
249-
}
250-
227+
client := infra.NewFloodProtectionProfilesClient(getSessionContext(d, m), connector)
228+
err := client.Delete(id, nil)
251229
if err != nil {
252230
return handleDeleteError("FloodProtectionProfile", id, err)
253231
}
254-
255232
return nil
256233
}

0 commit comments

Comments
 (0)