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

VDC supports Flex #285

merged 34 commits into from
Feb 14, 2020

Conversation

vbauzys
Copy link
Contributor

@vbauzys vbauzys commented Jan 22, 2020

Ref:https://github.com/terraform-providers/terraform-provider-vcd/issues/423, https://github.com/terraform-providers/terraform-provider-vcd/pull/443
Enhances existing implementation to allow create VDC allocation model Flex:

  • refactored and introduced structure to work with different versions of API using same public function.
  • added Flex and new fields
  • added unit tests

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
@vbauzys vbauzys marked this pull request as ready for review January 29, 2020 12:49
@vbauzys vbauzys requested review from dataclouder, lvirbalas and Didainius and removed request for dataclouder and lvirbalas January 29, 2020 12:49
@vbauzys vbauzys self-assigned this Jan 29, 2020
@vbauzys vbauzys requested a review from lvirbalas January 29, 2020 12:49
Signed-off-by: Vaidotas Bauzys <[email protected]>
Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a look over. There is still a conflict for merge and some inline comments.

CHANGELOG.md Outdated
@@ -4,6 +4,8 @@
* Added methods `VM.AddInternalDisk`, `VM.GetInternalDiskById`, `VM.DeleteInternalDisk`, `VM.UpdateInternalDisks` and `VM.UpdateInternalDisksAsync`
* 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say we need a sentence that there is a dynamic method and version change invocation behind the scenes based on vCD version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>

# Conflicts:
#	govcd/org_test.go
@vbauzys
Copy link
Contributor Author

vbauzys commented Jan 30, 2020

Had a look over. There is still a conflict for merge and some inline comments.

Conflicts solved

Signed-off-by: Vaidotas Bauzys <[email protected]>
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First comments.

Signed-off-by: Vaidotas Bauzys <[email protected]>
Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes required

if err != nil {
return AdminVdc{}, err
}

err = task.WaitTaskCompletion()
realFunction, ok := vdcProducerByVersion["vdc"+apiVersionToVcdVersion[apiVersion]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than realFunction, a better name here would be producer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

if err != nil {
return Task{}, err
}
realFunction, ok := vdcProducerByVersion["vdc"+apiVersionToVcdVersion[apiVersion]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than realFunction, a better name here would be producer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


// CreateOrgVdc creates a VDC with the given params under the given organization
// and waits for the asynchronous task to complete.
// Returns an AdminVdc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Returns an AdminVdc.
// Returns an AdminVdc pointer and an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}

// CreateOrgVdcAsync creates a VDC with the given params under the given organization.
// Returns an Task.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Returns an Task.
// Returns a Task and an error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}

// createVdc creates a VDC with the given params under the given organization.
// Returns an Vdc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Returns an Vdc.
// Returns a Vdc pointer and an error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

check.Assert(task, Equals, Task{})
// From vCD 10+ error changed
if vcd.client.Client.APIVCDMaxVersionIs("> 32.0") {
check.Assert(err.Error(), Equals, "error retrieving vdc: API Error: 400: is not a valid unit. Please use MB")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comparison seems too strict. Can we just check that there is an API error 400? The message may change in future API versions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

err = adminOrg.Refresh()
check.Assert(err, IsNil)

adminVdc, err := adminOrg.GetAdminVDCByName(vdcConfiguration.Name, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
adminVdc, err := adminOrg.GetAdminVDCByName(vdcConfiguration.Name, false)
adminVdc, err := adminOrg.GetAdminVDCByName(vdcConfiguration.Name, true)

Using this construct will make the explicit refresh above unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@@ -26,6 +26,27 @@ type SupportedVersions struct {
VersionInfos `xml:"VersionInfo"`
}

// map allows you get vCD version from max supported API version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// map allows you get vCD version from max supported API version
// apiVersionToVcdVersion gets the vCD version from max supported API version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

"33.0": "10.0",
}

// map allows you get max supported API version from vCD version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// map allows you get max supported API version from vCD version
// vcdVersionToApiVersion gets the max supported API version from vCD version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I like the new multi-version support pattern, but some details need to be polished. Thanks!

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>

// CreateOrgVdcAsync creates a VDC with the given params under the given organization.
// Returns a Task and an error.
func (adminOrg *AdminOrg) CreateOrgVdcAsync(vdcConfiguration *types.VdcConfiguration) (Task, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but previously CRUD functions for VDC were in adminorg.go. With these changes we have functions for older vCD versions in adminorg.go, but functions for vCD 9.7+ in adminvdc.go. Can we have the same type of functions in a single file, or is there a good reason behind such move?

CC: @dataclouder @Didainius

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In early days we try to keep with hierarchy type of storing functions in parent if parent is receiver, but later we chose directly hold functions in files according type. So everything we do new goes to their own file, not in parents. Version 3.0 is good option to cleanup and move functions accordingly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to move the touched functions from adminorg.go to adminvdc.go those functions now, so we have them in a single place and have a tidiness from the perspective of CRUD functions? Now it's pretty hard to navigate the code trying to understand where are 9.7+ functions and where are the older ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In early days we try to keep with hierarchy type of storing functions in parent if parent is receiver, but later we chose directly hold functions in files according type. So everything we do new goes to their own file, not in parents.

I can move

done

I was actually referring only to the CreateVdc and CreateVdc functions, so they'd all be in a single file with other Create... ones, but I'm OK with this move if everyone else is. Summary:

131 lines moved from adminvdc.go to adminorg.go, functions that moved:

  • GetAdminVdcByName
  • GetAdminVDCByHref
  • GetAdminVDCByName
  • GetAdminVDCById
  • GetAdminVDCByNameOrId
  • CreateVdc
  • CreateVdc

Commit: 65965d2

CC: @Didainius @dataclouder

Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test suite worked on 9.5 and 10.
I am ok with the concept. A few more comments inline.

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Really great to have a pattern for handling features available only in the new vCD API versions and unlock the potential!


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.
Note: use this pattern for adding new vCD functionality, which is not available in the earliest API version supported
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please add a new line above this note.

Signed-off-by: Vaidotas Bauzys <[email protected]>
Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some discussion needed

}

var vdcVersionedFuncsByVcdVersion = map[string]vdcVersionedFuncs{
"vdc9.0": vdcCrudV90,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that vcdCrudV90 is not defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -23,6 +25,174 @@ func NewAdminVdc(cli *Client) *AdminVdc {
}
}

// vdcVersionedFuncs holds interface of functions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// vdcVersionedFuncs holds interface of functions
// vdcVersionedFuncs is a generic representation of a VDC creation across multiple versions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dataclouder "VDC creation" is too specific in this case, because tries to cover all CRUD operations:
Screenshot 2020-02-13 at 14 07 24
What about changing "a VDC creation" to "VDC CRUD operations"? That would read:
// vdcVersionedFuncs is a generic representation of VDC CRUD operations across multiple versions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's better. Although we only support creation and update, not all CRUD, since D is missing and the R was explicitly implemented with hidden version choice (see my note under GetAdminVDCByHref ) instead of one function in this structure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -23,6 +25,174 @@ func NewAdminVdc(cli *Client) *AdminVdc {
}
}

// vdcVersionedFuncs holds interface of functions
type vdcVersionedFuncs struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vdcVersionedFuncs describes what the type is at a grammatical level, rather than at functional level.
The reject3ed term vdcProducer was showing the purpose of the structure, while the current name only shows that it contains functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and what I can do about it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that a purposeful name such as provider conveys the meaning better than Funcs. How about changing it to vdcCRUD ? At least it suggests some purpose.
cc: @lvirbalas, @Didainius

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a long discussion about this here:
#285 (comment)

There vdcCrud was proposed too, but at the end we agreed on vdcVersionedFuncs, because:

  • It has a word "versioned", which makes it instantly clear what the pattern's purpose is
  • With such name not only CRUD functions could land here if needed

// the latest version, we're limiting the highest used version to the one we support with
// the GetSpecificApiVersionOnCondition(...) function. Specifically, the API version 32 returns
// two additional fields: IncludeMemoryOverhead and IsElastic for Flex allocation
_, err := adminOrg.client.ExecuteRequestWithApiVersion(vdcHref, http.MethodGet,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, I'd like this function to be implemented similarly to the others defined in vdcVersionedFuncs, i.e. one function per version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible, yet it won't bring any value just code repetition

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code repetition is when we repeat the same code in various places. I am saying we should have a GET for 9.0 to 9.5 and another for 9.7+, same as what we did for Create and Update

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any value here until more changes needed. Now I will create same functions for sake of creating and have to make tests, and so on.

return *task, nil
}

// Creates the vdc and waits for the asynchronous task to complete.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Creates the vdc and waits for the asynchronous task to complete.
// Creates the VDC and waits for the asynchronous task to complete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// the GetSpecificApiVersionOnCondition(...) function. Specifically, the API version 32 returns
// two additional fields: IncludeMemoryOverhead and IsElastic for Flex allocation
_, err := adminVdc.client.ExecuteRequestWithApiVersion(adminVdc.AdminVdc.HREF, http.MethodGet,
"", "error refreshing VDC: %s", nil, unmarshalledAdminVdc, adminVdc.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use GetVDCByHref here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recepients are different. Refresh works with adminVDC and GetVDCByHref is for adminOrg

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vbauzys vbauzys merged commit b235a1d into vmware:master Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants