-
Notifications
You must be signed in to change notification settings - Fork 76
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 tm Org and VDC support #710
Open
Didainius
wants to merge
4
commits into
vmware:main
Choose a base branch
from
Didainius:tm1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
* Added `TmOrg` and `types.TmOrg` to structure for OpenAPI management of Organizations with methods | ||
`VCDClient.CreateTmOrg`, `VCDClient.GetAllTmOrgs`, `VCDClient.GetTmOrgByName`, | ||
`VCDClient.GetTmOrgById`, `TmOrg.Update`, `TmOrg.Delete`, `.TmOrg.Disable` [GH-710] | ||
* Added `TmVdc` and `types.TmVdc` to structure for OpenAPI management of Organizations VDCs with | ||
methods `VCDClient.CreateTmVdc`, `VCDClient.GetAllTmVdcs`, `VCDClient.GetTmVdcByName`, | ||
`VCDClient.GetTmVdcById`, `TmVdc.Update`, `TmVdc.Delete`, `.TmVdc.Disable` [GH-710] | ||
* Added types `Region` and `types.Region` for managing regions with methods | ||
`VCDClient.CreateRegion`, `VCDClient.GetAllRegions`, `VCDClient.GetRegionByName`, | ||
`VCDClient.GetRegionById`, `Region.Update`, `Region.Delete` [GH-710] | ||
* Added types `Supervisor` and `types.Supervisor` for reading Supervisors | ||
`VCDClient.GetAllSupervisors`, `VCDClient.GetSupervisorById`, `VCDClient.GetSupervisorByName` | ||
[GH-710] | ||
* Added types `SupervisorZone` and `types.SupervisorZone` for reading Supervisors | ||
`VCDClient.GetAllSupervisorZones`, `VCDClient.GetSupervisorZoneById`, | ||
`VCDClient.GetSupervisorZoneByName` [GH-710] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package govcd | ||
|
||
/* | ||
* Copyright 2024 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. | ||
*/ | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/vmware/go-vcloud-director/v2/types/v56" | ||
) | ||
|
||
const labelOrganization = "Organization" | ||
|
||
type TmOrg struct { | ||
TmOrg *types.TmOrg | ||
vcdClient *VCDClient | ||
} | ||
|
||
// wrap is a hidden helper that facilitates the usage of a generic CRUD function | ||
// | ||
//lint:ignore U1000 this method is used in generic functions, but annoys staticcheck | ||
func (g TmOrg) wrap(inner *types.TmOrg) *TmOrg { | ||
g.TmOrg = inner | ||
return &g | ||
} | ||
|
||
func (vcdClient *VCDClient) CreateTmOrg(config *types.TmOrg) (*TmOrg, error) { | ||
if !vcdClient.Client.IsTm() { | ||
return nil, fmt.Errorf("err") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed this error message, looks incomplete? |
||
} | ||
c := crudConfig{ | ||
entityLabel: labelOrganization, | ||
endpoint: types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointOrgs, | ||
} | ||
outerType := TmOrg{vcdClient: vcdClient} | ||
return createOuterEntity(&vcdClient.Client, outerType, c, config) | ||
} | ||
|
||
func (vcdClient *VCDClient) GetAllTmOrgs(queryParameters url.Values) ([]*TmOrg, error) { | ||
c := crudConfig{ | ||
entityLabel: labelOrganization, | ||
endpoint: types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointOrgs, | ||
queryParameters: queryParameters, | ||
} | ||
|
||
outerType := TmOrg{vcdClient: vcdClient} | ||
return getAllOuterEntities(&vcdClient.Client, outerType, c) | ||
} | ||
|
||
func (vcdClient *VCDClient) GetTmOrgByName(name string) (*TmOrg, error) { | ||
if name == "" { | ||
return nil, fmt.Errorf("%s lookup requires name", labelOrganization) | ||
} | ||
|
||
queryParams := url.Values{} | ||
queryParams.Add("filter", "name=="+name) | ||
|
||
filteredEntities, err := vcdClient.GetAllTmOrgs(queryParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
singleEntity, err := oneOrError("name", name, filteredEntities) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return vcdClient.GetTmOrgById(singleEntity.TmOrg.ID) | ||
} | ||
|
||
func (vcdClient *VCDClient) GetTmOrgById(id string) (*TmOrg, error) { | ||
c := crudConfig{ | ||
entityLabel: labelOrganization, | ||
endpoint: types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointOrgs, | ||
endpointParams: []string{id}, | ||
} | ||
|
||
outerType := TmOrg{vcdClient: vcdClient} | ||
return getOuterEntity(&vcdClient.Client, outerType, c) | ||
} | ||
|
||
func (o *TmOrg) Update(TmOrgConfig *types.TmOrg) (*TmOrg, error) { | ||
c := crudConfig{ | ||
entityLabel: labelOrganization, | ||
endpoint: types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointOrgs, | ||
endpointParams: []string{o.TmOrg.ID}, | ||
} | ||
outerType := TmOrg{vcdClient: o.vcdClient} | ||
return updateOuterEntity(&o.vcdClient.Client, outerType, c, TmOrgConfig) | ||
} | ||
|
||
func (o *TmOrg) Delete() error { | ||
c := crudConfig{ | ||
entityLabel: labelOrganization, | ||
endpoint: types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointOrgs, | ||
endpointParams: []string{o.TmOrg.ID}, | ||
} | ||
return deleteEntityById(&o.vcdClient.Client, c) | ||
} | ||
|
||
func (o *TmOrg) Disable() error { | ||
o.TmOrg.IsEnabled = false | ||
_, err := o.Update(o.TmOrg) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//go:build tm || functional || ALL | ||
|
||
/* | ||
* Copyright 2024 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. | ||
*/ | ||
|
||
package govcd | ||
|
||
import ( | ||
. "gopkg.in/check.v1" | ||
|
||
"github.com/vmware/go-vcloud-director/v2/types/v56" | ||
) | ||
|
||
func (vcd *TestVCD) Test_TmOrg(check *C) { | ||
skipNonTm(vcd, check) | ||
sysadminOnly(vcd, check) | ||
|
||
cfg := &types.TmOrg{ | ||
Name: check.TestName(), | ||
DisplayName: check.TestName(), | ||
CanManageOrgs: true, | ||
} | ||
|
||
tmOrg, err := vcd.client.CreateTmOrg(cfg) | ||
check.Assert(err, IsNil) | ||
check.Assert(tmOrg, NotNil) | ||
|
||
// Add to cleanup list | ||
PrependToCleanupListOpenApi(tmOrg.TmOrg.ID, check.TestName(), types.OpenApiPathVersion1_0_0+types.OpenApiEndpointOrgs+tmOrg.TmOrg.ID) | ||
|
||
// Get By Name | ||
byName, err := vcd.client.GetTmOrgByName(cfg.Name) | ||
check.Assert(err, IsNil) | ||
check.Assert(byName, NotNil) | ||
|
||
// Get By ID | ||
byId, err := vcd.client.GetTmOrgById(tmOrg.TmOrg.ID) | ||
check.Assert(err, IsNil) | ||
check.Assert(byId, NotNil) | ||
|
||
// Get All | ||
allTmOrgs, err := vcd.client.GetAllTmOrgs(nil) | ||
check.Assert(err, IsNil) | ||
check.Assert(allTmOrgs, NotNil) | ||
check.Assert(len(allTmOrgs) > 0, Equals, true) | ||
|
||
// Update | ||
tmOrg.TmOrg.IsEnabled = false | ||
updated, err := tmOrg.Update(tmOrg.TmOrg) | ||
check.Assert(err, IsNil) | ||
check.Assert(updated, NotNil) | ||
|
||
// Delete | ||
err = tmOrg.Delete() | ||
check.Assert(err, IsNil) | ||
|
||
notFoundByName, err := vcd.client.GetTmOrgByName(cfg.Name) | ||
check.Assert(ContainsNotFound(err), Equals, true) | ||
check.Assert(notFoundByName, IsNil) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit hesitant to merge this PR until we can write tests for create/update/delete.