Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vdc.GetNsxtAppPortProfileByName and VdcGroup.GetNsxtAppPortProfileByName for convenience #460

Merged
merged 4 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changes/v2.15.0/460-improvements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Added `Vdc.GetNsxtAppPortProfileByName` and `VdcGroup.GetNsxtAppPortProfileByName` for NSX-T
Application Port Profile lookup [GH-460]
29 changes: 29 additions & 0 deletions govcd/nsxt_application_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,35 @@ func (org *Org) GetNsxtAppPortProfileByName(name, scope string) (*NsxtAppPortPro
return getNsxtAppPortProfileByName(org.client, name, queryParameters)
}

// GetNsxtAppPortProfileByName allows users to retrieve Application Port Profiles for specific scope.
// More details in documentation for types.NsxtAppPortProfile
//
// Note. Names are enforced to be unique per scope
func (vdc *Vdc) GetNsxtAppPortProfileByName(name, scope string) (*NsxtAppPortProfile, error) {
queryParameters := copyOrNewUrlValues(nil)
queryParameters = queryParameterFilterAnd("_context=="+vdc.Vdc.ID, queryParameters)
if scope != "" {
queryParameters = queryParameterFilterAnd("scope=="+scope, queryParameters)
}

return getNsxtAppPortProfileByName(vdc.client, name, queryParameters)
}

// GetNsxtAppPortProfileByName allows users to retrieve Application Port Profiles for specific scope.
// More details in documentation for types.NsxtAppPortProfile
//
// Note. Names are enforced to be unique per scope
func (vdcGroup *VdcGroup) GetNsxtAppPortProfileByName(name, scope string) (*NsxtAppPortProfile, error) {
queryParameters := copyOrNewUrlValues(nil)
queryParameters = queryParameterFilterAnd("_context=="+vdcGroup.VdcGroup.Id, queryParameters)

if scope != "" {
queryParameters = queryParameterFilterAnd("scope=="+scope, queryParameters)
}

return getNsxtAppPortProfileByName(vdcGroup.client, name, queryParameters)
}

// GetNsxtAppPortProfileById retrieves NSX-T Application Port Profile by ID
func (org *Org) GetNsxtAppPortProfileById(id string) (*NsxtAppPortProfile, error) {
return getNsxtAppPortProfileById(org.client, id)
Expand Down
22 changes: 20 additions & 2 deletions govcd/nsxt_application_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func (vcd *TestVCD) Test_NsxtApplicationPortProfileProvider(check *C) {

appPortProfileConfig := getAppProfileProvider(vcd, check)
testAppPortProfile(appPortProfileConfig, types.ApplicationPortProfileScopeProvider, vcd, check)

}

func (vcd *TestVCD) Test_NsxtApplicationPortProfileTenant(check *C) {
Expand All @@ -26,7 +25,6 @@ func (vcd *TestVCD) Test_NsxtApplicationPortProfileTenant(check *C) {

appPortProfileConfig := getAppProfileTenant(vcd, check)
testAppPortProfile(appPortProfileConfig, types.ApplicationPortProfileScopeTenant, vcd, check)

}

func (vcd *TestVCD) Test_NsxtApplicationPortProfileReadSystem(check *C) {
Expand Down Expand Up @@ -126,6 +124,26 @@ func testAppPortProfile(appPortProfileConfig *types.NsxtAppPortProfile, scope st
check.Assert(err, IsNil)
check.Assert(foundAppProfileByName.NsxtAppPortProfile, DeepEquals, foundAppProfileById.NsxtAppPortProfile)

// Check VDC and VDC Group lookup
adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
check.Assert(err, IsNil)
check.Assert(adminOrg, NotNil)
vdc, vdcGroup := test_CreateVdcGroup(check, adminOrg, vcd)

// Lookup by VDC
foundAppProfileByNameInVdc, err := vdc.GetNsxtAppPortProfileByName(appProfile.NsxtAppPortProfile.Name, scope)
check.Assert(err, IsNil)
check.Assert(foundAppProfileByNameInVdc.NsxtAppPortProfile, DeepEquals, foundAppProfileById.NsxtAppPortProfile)

foundAppProfileByNameInVdcGroup, err := vdcGroup.GetNsxtAppPortProfileByName(appProfile.NsxtAppPortProfile.Name, scope)
check.Assert(err, IsNil)
check.Assert(foundAppProfileByNameInVdcGroup.NsxtAppPortProfile, DeepEquals, foundAppProfileById.NsxtAppPortProfile)
// Remove VDC group
err = vdcGroup.Delete()
check.Assert(err, IsNil)
err = vdc.DeleteWait(true, true)
check.Assert(err, IsNil)

err = appProfile.Delete()
check.Assert(err, IsNil)

Expand Down