-
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
VDC supports Flex #285
VDC supports Flex #285
Conversation
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]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
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.
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 |
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 would say we need a sentence that there is a dynamic method and version change invocation behind the scenes based on vCD version
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.
added
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]> # Conflicts: # govcd/org_test.go
Conflicts solved |
Signed-off-by: Vaidotas Bauzys <[email protected]>
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.
First comments.
Signed-off-by: Vaidotas Bauzys <[email protected]>
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.
Some small changes required
govcd/adminvdc.go
Outdated
if err != nil { | ||
return AdminVdc{}, err | ||
} | ||
|
||
err = task.WaitTaskCompletion() | ||
realFunction, ok := vdcProducerByVersion["vdc"+apiVersionToVcdVersion[apiVersion]] |
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.
Rather than realFunction
, a better name here would be producer
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.
changed
govcd/adminvdc.go
Outdated
if err != nil { | ||
return Task{}, err | ||
} | ||
realFunction, ok := vdcProducerByVersion["vdc"+apiVersionToVcdVersion[apiVersion]] |
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.
Rather than realFunction
, a better name here would be producer
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.
changed
govcd/adminvdc.go
Outdated
|
||
// CreateOrgVdc creates a VDC with the given params under the given organization | ||
// and waits for the asynchronous task to complete. | ||
// Returns an AdminVdc. |
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.
// Returns an AdminVdc. | |
// Returns an AdminVdc pointer and an error. |
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.
changed
govcd/adminvdc.go
Outdated
} | ||
|
||
// CreateOrgVdcAsync creates a VDC with the given params under the given organization. | ||
// Returns an Task. |
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.
// Returns an Task. | |
// Returns a Task and an error |
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.
changed
govcd/adminvdc.go
Outdated
} | ||
|
||
// createVdc creates a VDC with the given params under the given organization. | ||
// Returns an Vdc. |
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.
// Returns an Vdc. | |
// Returns a Vdc pointer and an error |
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.
changed
govcd/adminvdc_test.go
Outdated
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") |
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.
This comparison seems too strict. Can we just check that there is an API error 400? The message may change in future API versions
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.
changed
govcd/adminvdc_test.go
Outdated
err = adminOrg.Refresh() | ||
check.Assert(err, IsNil) | ||
|
||
adminVdc, err := adminOrg.GetAdminVDCByName(vdcConfiguration.Name, false) |
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.
adminVdc, err := adminOrg.GetAdminVDCByName(vdcConfiguration.Name, false) | |
adminVdc, err := adminOrg.GetAdminVDCByName(vdcConfiguration.Name, true) |
Using this construct will make the explicit refresh above unnecessary
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.
changed
govcd/api_vcd_versions.go
Outdated
@@ -26,6 +26,27 @@ type SupportedVersions struct { | |||
VersionInfos `xml:"VersionInfo"` | |||
} | |||
|
|||
// map allows you get vCD version from max supported API version |
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.
// map allows you get vCD version from max supported API version | |
// apiVersionToVcdVersion gets the vCD version from max supported API version |
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.
changed
govcd/api_vcd_versions.go
Outdated
"33.0": "10.0", | ||
} | ||
|
||
// map allows you get max supported API version from vCD version |
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.
// map allows you get max supported API version from vCD version | |
// vcdVersionToApiVersion gets the max supported API version from vCD version |
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.
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]>
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.
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) { |
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.
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?
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.
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.
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.
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.
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 can move
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.
done
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.
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
Signed-off-by: Vaidotas Bauzys <[email protected]>
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.
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]>
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.
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 |
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.
Nit: please add a new line above this note.
Signed-off-by: Vaidotas Bauzys <[email protected]>
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.
Some discussion needed
CODING_GUIDELINES.md
Outdated
} | ||
|
||
var vdcVersionedFuncsByVcdVersion = map[string]vdcVersionedFuncs{ | ||
"vdc9.0": vdcCrudV90, |
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.
Please note that vcdCrudV90
is not defined.
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.
fixed
govcd/adminvdc.go
Outdated
@@ -23,6 +25,174 @@ func NewAdminVdc(cli *Client) *AdminVdc { | |||
} | |||
} | |||
|
|||
// vdcVersionedFuncs holds interface of functions |
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.
// vdcVersionedFuncs holds interface of functions | |
// vdcVersionedFuncs is a generic representation of a VDC creation across multiple versions |
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.
fixed
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.
@dataclouder "VDC creation" is too specific in this case, because tries to cover all CRUD operations:
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
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.
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
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.
updated
@@ -23,6 +25,174 @@ func NewAdminVdc(cli *Client) *AdminVdc { | |||
} | |||
} | |||
|
|||
// vdcVersionedFuncs holds interface of functions | |||
type vdcVersionedFuncs struct { |
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.
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.
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.
and what I can do about it?
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 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
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.
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, |
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.
If possible, I'd like this function to be implemented similarly to the others defined in vdcVersionedFuncs
, i.e. one function per version.
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.
Possible, yet it won't bring any value just code repetition
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.
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
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 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.
govcd/adminvdc.go
Outdated
return *task, nil | ||
} | ||
|
||
// Creates the vdc and waits for the asynchronous task to complete. |
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.
// Creates the vdc and waits for the asynchronous task to complete. | |
// Creates the VDC and waits for the asynchronous task to complete. |
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.
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")) |
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.
Can't we use GetVDCByHref
here?
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.
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]>
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.
LGTM
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: