-
Notifications
You must be signed in to change notification settings - Fork 75
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 guest properties support for vm
and vapp
#235
Merged
Merged
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
87c3716
Initial guest properties setting for VM
Didainius eb73b30
Adjust fields
Didainius 1676ffb
Tune test
Didainius 0f15492
vApp and VM support guest properties
Didainius 7617826
use interface to share guest property testcases for VM and vApp
Didainius 7308a39
Fix title
Didainius 1de091a
Fix function title
Didainius 14bb6bd
Merge master
Didainius d309448
Add changelog note
Didainius e211100
go mod tidy
Didainius 05025c2
Add PR number to changelog
Didainius 370c4d4
Address comments
Didainius d6547a2
Fix incorrect error message
Didainius fee9625
Do not print nil error in load balancer test
Didainius 4c39ac7
Change naming GuestProperties -> ProductSectionList
Didainius 9ff3419
Improve tests, add ordering
Didainius 6a50cde
Remove types_test.go
Didainius 7f38471
Fix unit test
Didainius 45bab31
make fmt
Didainius 05858ea
Fix changelog
Didainius 7ba6a7f
Tune comments to hint guest property setting
Didainius 5978a76
Fix changelog typo
Didainius 8e85539
Merge branch 'master' into guest-properties
Didainius 1d3f7ab
Merge branch 'master' into guest-properties
Didainius fb4c821
Add note to changelog about PR #200
Didainius 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
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,53 @@ | ||
/* | ||
* Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. | ||
*/ | ||
|
||
package govcd | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/vmware/go-vcloud-director/v2/types/v56" | ||
) | ||
|
||
// setProductSectionList is a shared function for both vApp and VM | ||
func setProductSectionList(client *Client, href string, productSection *types.ProductSectionList) error { | ||
if href == "" { | ||
return fmt.Errorf("href cannot be empty to set product section") | ||
} | ||
|
||
productSection.Xmlns = types.XMLNamespaceVCloud | ||
productSection.Ovf = types.XMLNamespaceOVF | ||
|
||
task, err := client.ExecuteTaskRequest(href+"/productSections", http.MethodPut, | ||
types.MimeProductSection, "error setting product section: %s", productSection) | ||
|
||
if err != nil { | ||
return fmt.Errorf("unable to set product section: %s", err) | ||
} | ||
|
||
err = task.WaitTaskCompletion() | ||
if err != nil { | ||
return fmt.Errorf("task for setting product section failed: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// getProductSectionList is a shared function for both vApp and VM | ||
func getProductSectionList(client *Client, href string) (*types.ProductSectionList, error) { | ||
if href == "" { | ||
return nil, fmt.Errorf("href cannot be empty to get product section") | ||
} | ||
productSection := &types.ProductSectionList{} | ||
|
||
_, err := client.ExecuteRequest(href+"/productSections", http.MethodGet, | ||
types.MimeProductSection, "error retrieving product section : %s", nil, productSection) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("unable to retrieve product section: %s", err) | ||
} | ||
|
||
return productSection, nil | ||
} |
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,94 @@ | ||
// +build vapp vm functional ALL | ||
|
||
/* | ||
* Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. | ||
*/ | ||
|
||
package govcd | ||
|
||
import ( | ||
"github.com/vmware/go-vcloud-director/v2/types/v56" | ||
. "gopkg.in/check.v1" | ||
) | ||
|
||
// guestPropertyGetSetter interface is used for covering tests in both VM and vApp guest property | ||
type productSectionListGetSetter interface { | ||
GetProductSectionList() (*types.ProductSectionList, error) | ||
SetProductSectionList(productSection *types.ProductSectionList) (*types.ProductSectionList, error) | ||
} | ||
|
||
// propertyTester is a guest property setter accepting guestPropertyGetSetter interface for trying | ||
// out settings on all objects implementing such interface | ||
func propertyTester(vcd *TestVCD, check *C, object productSectionListGetSetter) { | ||
productSection := &types.ProductSectionList{ | ||
ProductSection: &types.ProductSection{ | ||
Info: "Custom properties", | ||
Property: []*types.Property{ | ||
&types.Property{ | ||
UserConfigurable: false, | ||
Key: "sys_owner", | ||
Label: "sys_owner_label", | ||
Type: "string", | ||
DefaultValue: "sys_owner_default", | ||
Value: &types.Value{Value: "test"}, | ||
}, | ||
&types.Property{ | ||
UserConfigurable: true, | ||
Key: "asset_tag", | ||
Label: "asset_tag_label", | ||
Type: "string", | ||
DefaultValue: "asset_tag_default", | ||
Value: &types.Value{Value: "xxxyyy"}, | ||
}, | ||
&types.Property{ | ||
UserConfigurable: true, | ||
Key: "guestinfo.config.bootstrap.ip", | ||
Label: "guestinfo.config.bootstrap.ip_label", | ||
Type: "string", | ||
DefaultValue: "default_ip", | ||
Value: &types.Value{Value: "192.168.12.180"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
productSection.SortByPropertyKeyName() | ||
|
||
gotproductSection, err := object.SetProductSectionList(productSection) | ||
check.Assert(err, IsNil) | ||
gotproductSection.SortByPropertyKeyName() | ||
|
||
getproductSection, err := object.GetProductSectionList() | ||
check.Assert(err, IsNil) | ||
getproductSection.SortByPropertyKeyName() | ||
|
||
// Check that values were set in API | ||
vbauzys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
check.Assert(getproductSection, NotNil) | ||
check.Assert(getproductSection.ProductSection, NotNil) | ||
check.Assert(len(getproductSection.ProductSection.Property), Equals, 3) | ||
|
||
check.Assert(getproductSection.ProductSection.Property[0].Key, Equals, "asset_tag") | ||
check.Assert(getproductSection.ProductSection.Property[0].Label, Equals, "asset_tag_label") | ||
check.Assert(getproductSection.ProductSection.Property[0].Type, Equals, "string") | ||
check.Assert(getproductSection.ProductSection.Property[0].Value.Value, Equals, "xxxyyy") | ||
check.Assert(getproductSection.ProductSection.Property[0].DefaultValue, Equals, "asset_tag_default") | ||
check.Assert(getproductSection.ProductSection.Property[0].UserConfigurable, Equals, true) | ||
|
||
check.Assert(getproductSection.ProductSection.Property[1].Key, Equals, "guestinfo.config.bootstrap.ip") | ||
check.Assert(getproductSection.ProductSection.Property[1].Label, Equals, "guestinfo.config.bootstrap.ip_label") | ||
check.Assert(getproductSection.ProductSection.Property[1].Type, Equals, "string") | ||
check.Assert(getproductSection.ProductSection.Property[1].Value.Value, Equals, "192.168.12.180") | ||
check.Assert(getproductSection.ProductSection.Property[1].DefaultValue, Equals, "default_ip") | ||
check.Assert(getproductSection.ProductSection.Property[1].UserConfigurable, Equals, true) | ||
|
||
check.Assert(getproductSection.ProductSection.Property[2].Key, Equals, "sys_owner") | ||
check.Assert(getproductSection.ProductSection.Property[2].Label, Equals, "sys_owner_label") | ||
check.Assert(getproductSection.ProductSection.Property[2].Type, Equals, "string") | ||
check.Assert(getproductSection.ProductSection.Property[2].Value.Value, Equals, "test") | ||
check.Assert(getproductSection.ProductSection.Property[2].DefaultValue, Equals, "sys_owner_default") | ||
check.Assert(getproductSection.ProductSection.Property[2].UserConfigurable, Equals, false) | ||
|
||
// Ensure the object are deeply equal | ||
check.Assert(gotproductSection.ProductSection.Property, DeepEquals, productSection.ProductSection.Property) | ||
check.Assert(getproductSection, DeepEquals, gotproductSection) | ||
} |
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
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 would add a sentence - a hint - that this product section represents guest properties in all comments of the four public 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.
Added
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.
Typo in "maniapulate", sounds funny though :D
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