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

VDC supports Flex #285

Merged
merged 34 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
156a05a
POC of versioning
vbauzys Jan 22, 2020
24de7e0
Add another way of handling versions
vbauzys Jan 24, 2020
03019ce
Removed sudo
vbauzys Jan 24, 2020
6ffd88d
Improvements
vbauzys Jan 24, 2020
469bb43
Improvements
vbauzys Jan 24, 2020
008be5e
Add update ability
vbauzys Jan 27, 2020
0bdd938
Update comment
vbauzys Jan 27, 2020
0a4ab92
Update comment
vbauzys Jan 27, 2020
1a1da2c
Update comment
vbauzys Jan 27, 2020
65ccfe8
Improvements
vbauzys Jan 27, 2020
0a21b62
Improvements
vbauzys Jan 27, 2020
853d1ba
Improvements
vbauzys Jan 28, 2020
7ed3661
Improvements
vbauzys Jan 28, 2020
3745d29
Added changelog
vbauzys Jan 29, 2020
c8ba6c6
Improvements
vbauzys Jan 30, 2020
ab5ed1f
Merge branch 'master' into vdc-flex
vbauzys Jan 30, 2020
2dbd012
make unused var to be used
vbauzys Jan 30, 2020
09f4bb6
Improvements
vbauzys Feb 4, 2020
0b58f26
Improvements by review
vbauzys Feb 6, 2020
6309e0d
Improvements
vbauzys Feb 7, 2020
336d66b
Improvements
vbauzys Feb 10, 2020
b67bd01
Improve comment
vbauzys Feb 10, 2020
52c7844
Improve comment
vbauzys Feb 10, 2020
fae4c4b
Improve comment
vbauzys Feb 10, 2020
65965d2
Moved admin VDC functions from adminorg to admindvc
vbauzys Feb 10, 2020
cb07d57
Improvements
vbauzys Feb 11, 2020
94c1684
Renaming
vbauzys Feb 11, 2020
2ffd512
Renaming
vbauzys Feb 11, 2020
c62d23b
Added guideline
vbauzys Feb 11, 2020
feaabcf
Improve guideline
vbauzys Feb 11, 2020
584906f
Rename vdcfuntion
vbauzys Feb 11, 2020
7ceccf9
Improve guideline
vbauzys Feb 12, 2020
c6497a5
Improvements
vbauzys Feb 13, 2020
a4bbb26
Improve comment
vbauzys Feb 13, 2020
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
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ go:
- "1.12.x"

sudo: false
install: false

script:
- env GO111MODULE=on make

after_success:
- echo "Build Successful!"
- echo "Build Successful!"
after_failure:
- echo "Build Failed!"
- echo "Build Failed!"

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Improved functions to not expect XML namespaces provided in argument structure [#284](https://github.com/vmware/go-vcloud-director/pull/284)
* Change `int` and `bool` fields from types.VAppTemplateLeaseSettings and VAppLeaseSettings into pointers
* Added method `catalog.GetVappTemplateByHref`, and expose methods `vdc.GetEdgeGatewayByHref` and `vdc.GetEdgeGatewayRecordsType`
* Added methods `adminOrg.CreateOrgVdc`, `adminOrg.CreateOrgVdcAsync` and improved existing to support Flex VDC model. These new methods are dynamic as they change invocation behind the scenes based on vCD version
* Deprecated functions `adminOrg.CreateVdc` and `adminOrg.CreateVdcWait`

## 2.5.1 (December 12, 2019)

Expand Down
49 changes: 49 additions & 0 deletions CODING_GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,55 @@ prior to attempting a search.
Note: We are in the process of replacing methods that don't adhere to the above principles (for example, return a
structure instead of a pointer, return a nil error on not-found, etc).

## Implementing functions to support different API versions

Functions dealing with different versions should use a matrix structure to identify which calls to run according to the
highest API version supported by vCD. An example can be found in adminvdc.go.

```
type vdcProducer struct {
SupportedVersion string
CreateVdc func(adminOrg *AdminOrg, vdcConfiguration *types.VdcConfiguration) (*Vdc, error)
CreateVdcAsync func(adminOrg *AdminOrg, vdcConfiguration *types.VdcConfiguration) (Task, error)
UpdateVdc func(adminVdc *AdminVdc) (*AdminVdc, error)
UpdateVdcAsync func(adminVdc *AdminVdc) (Task, error)
}

var vdcCrudV90 = vdcProducer{
SupportedVersion: "29.0",
CreateVdc: createVdc,
CreateVdcAsync: createVdcAsync,
UpdateVdc: updateVdc,
UpdateVdcAsync: updateVdcAsync,
}

var vdcCrudV97 = vdcProducer{
SupportedVersion: "32.0",
CreateVdc: createVdcV97,
CreateVdcAsync: createVdcAsyncV97,
UpdateVdc: updateVdcV97,
UpdateVdcAsync: updateVdcAsyncV97,
}

func (adminOrg *AdminOrg) CreateOrgVdc(vdcConfiguration *types.VdcConfiguration) (*Vdc, error) {
apiVersion, err := adminOrg.client.maxSupportedVersion()
if err != nil {
return nil, err
}
producer, ok := vdcProducerByVersion["vdc"+vcdVersionToApiVersion[apiVersion]]
if !ok {
return nil, fmt.Errorf("no entity type found %s", "vdc"+apiVersion)
}
if producer.CreateVdc == nil {
return nil, fmt.Errorf("function CreateVdc is not defined for %s", "vdc"+apiVersion)
}
util.Logger.Printf("[DEBUG] CreateOrgVdc call function for version %s", producer.SupportedVersion)
return producer.CreateVdc(adminOrg, vdcConfiguration)
}
```



## Testing

Every feature in the library must include testing. See [TESTING.md](https://github.com/vmware/go-vcloud-director/blob/master/TESTING.md) for more info.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/vmware/go-vcloud-director v2.0.0+incompatible h1:3B121XZVdEOxRhv5ARswKVxXt4KznAbun8GoXNbbZWs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
13 changes: 8 additions & 5 deletions govcd/adminorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (adminOrg *AdminOrg) GetVdcByName(vdcname string) (Vdc, error) {
// CreateVdc creates a VDC with the given params under the given organization.
// Returns an AdminVdc.
// API Documentation: https://code.vmware.com/apis/220/vcloud#/doc/doc/operations/POST-VdcConfiguration.html
// Deprecated in favor of adminOrg.CreateOrgVdcAsync
func (adminOrg *AdminOrg) CreateVdc(vdcConfiguration *types.VdcConfiguration) (Task, error) {
err := validateVdcConfiguration(vdcConfiguration)
if err != nil {
Expand All @@ -107,7 +108,7 @@ func (adminOrg *AdminOrg) CreateVdc(vdcConfiguration *types.VdcConfiguration) (T
adminVdc := NewAdminVdc(adminOrg.client)

_, err = adminOrg.client.ExecuteRequest(vdcCreateHREF.String(), http.MethodPost,
"application/vnd.vmware.admin.createVdcParams+xml", "error retrieving vdc: %s", vdcConfiguration, adminVdc.AdminVdc)
"application/vnd.vmware.admin.createVdcParams+xml", "error creating VDC: %s", vdcConfiguration, adminVdc.AdminVdc)
if err != nil {
return Task{}, err
}
Expand All @@ -119,6 +120,7 @@ func (adminOrg *AdminOrg) CreateVdc(vdcConfiguration *types.VdcConfiguration) (T
}

// Creates the vdc and waits for the asynchronous task to complete.
// Deprecated in favor of adminOrg.CreateOrgVdc
func (adminOrg *AdminOrg) CreateVdcWait(vdcDefinition *types.VdcConfiguration) error {
task, err := adminOrg.CreateVdc(vdcDefinition)
if err != nil {
Expand Down Expand Up @@ -662,8 +664,9 @@ func (adminOrg *AdminOrg) GetVDCByHref(vdcHref string) (*Vdc, error) {

vdc := NewVdc(adminOrg.client)

_, err := adminOrg.client.ExecuteRequest(vdcHREF, http.MethodGet,
"", "error getting vdc: %s", nil, vdc.Vdc)
_, err := adminOrg.client.ExecuteRequestWithApiVersion(vdcHREF, http.MethodGet,
"", "error getting vdc: %s", nil, vdc.Vdc,
adminOrg.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0"))

if err != nil {
return nil, err
Expand Down Expand Up @@ -726,8 +729,8 @@ func (adminOrg *AdminOrg) GetAdminVDCByHref(vdcHref string) (*AdminVdc, error) {

adminVdc := NewAdminVdc(adminOrg.client)

_, err := adminOrg.client.ExecuteRequest(vdcHref, http.MethodGet,
"", "error getting vdc: %s", nil, adminVdc.AdminVdc)
_, err := adminOrg.client.ExecuteRequestWithApiVersion(vdcHref, http.MethodGet,
"", "error getting vdc: %s", nil, adminVdc.AdminVdc, adminVdc.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0"))

if err != nil {
return nil, err
Expand Down
Loading