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

Change bool -> *bool in types.GuestCustomizationSection #291

Merged
merged 8 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
* Added methods `EdgeGateway.GetAllNsxvDhcpLeases()`, `EdgeGateway.GetNsxvActiveDhcpLeaseByMac()`
`VM.WaitForDhcpIpByNicIndexes()`, `VM.GetParentVApp()`, `VM.GetParentVdc()`
[#283](https://github.com/vmware/go-vcloud-director/pull/283)
* `types.GetGuestCustomizationSection` now uses pointers for all bool values to distinguish between empty and false value [#291](https://github.com/vmware/go-vcloud-director/pull/291)
* Deprecated functions `Vapp.Customize()` and `VM.Customize()` in favor of `vm.SetGuestCustomizationSection` [#291](https://github.com/vmware/go-vcloud-director/pull/291)

BUGS FIXED:
* A data race in catalog/media item upload status reporting [#288](https://github.com/vmware/go-vcloud-director/pull/288)

* Vapp.Customize() and VM.Customize() ignores `changeSid` value and always set it to true [#291](https://github.com/vmware/go-vcloud-director/pull/291)

## 2.5.1 (December 12, 2019)

Expand Down
4 changes: 4 additions & 0 deletions govcd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,7 @@ func combinedTaskErrorMessage(task *types.Task, err error) string {
}
return extendedError
}

func takeBoolPointer(value bool) *bool {
return &value
}
6 changes: 1 addition & 5 deletions govcd/api_vcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ func (vcd *TestVCD) removeLeftoverEntities(entity CleanupEntity) {
fastProvisioningValue = true
}

if *adminVdc.AdminVdc.UsesFastProvisioning != fastProvisioningValue {
if adminVdc != nil && *adminVdc.AdminVdc.UsesFastProvisioning != fastProvisioningValue {
adminVdc.AdminVdc.UsesFastProvisioning = &fastProvisioningValue
_, err = adminVdc.Update()
if err != nil {
Expand Down Expand Up @@ -1394,10 +1394,6 @@ func (vcd *TestVCD) findFirstVapp() VApp {
return *vapp
}

func takeBoolPointer(value bool) *bool {
return &value
}

// Test_NewRequestWitNotEncodedParamsWithApiVersion verifies that api version override works
func (vcd *TestVCD) Test_NewRequestWitNotEncodedParamsWithApiVersion(check *C) {
fmt.Printf("Running: %s\n", check.TestName())
Expand Down
7 changes: 5 additions & 2 deletions govcd/vapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ func (vapp *VApp) RunCustomizationScript(computername, script string) (Task, err
return vapp.Customize(computername, script, false)
}

// Customize applies customization to first child VM
//
// Deprecated: Use vm.SetGuestCustomizationSection()
func (vapp *VApp) Customize(computername, script string, changeSid bool) (Task, error) {
err := vapp.Refresh()
if err != nil {
Expand All @@ -384,10 +387,10 @@ func (vapp *VApp) Customize(computername, script string, changeSid bool) (Task,
HREF: vapp.VApp.Children.VM[0].HREF,
Type: types.MimeGuestCustomizationSection,
Info: "Specifies Guest OS Customization Settings",
Enabled: true,
Enabled: takeBoolPointer(true),
vbauzys marked this conversation as resolved.
Show resolved Hide resolved
ComputerName: computername,
CustomizationScript: script,
ChangeSid: false,
ChangeSid: takeBoolPointer(changeSid),
}

apiEndpoint, _ := url.ParseRequestURI(vapp.VApp.Children.VM[0].HREF)
Expand Down
20 changes: 10 additions & 10 deletions govcd/vapp_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ type getGuestCustomizationSectionGetSetter interface {
// out settings on all objects implementing such interface
func guestCustomizationPropertyTester(vcd *TestVCD, check *C, object getGuestCustomizationSectionGetSetter) {
setupedGuestCustomizationSection := &types.GuestCustomizationSection{
Enabled: true, JoinDomainEnabled: false, UseOrgSettings: false,
Enabled: takeBoolPointer(true), JoinDomainEnabled: takeBoolPointer(false), UseOrgSettings: takeBoolPointer(false),
DomainUserName: "", DomainName: "", DomainUserPassword: "",
AdminPasswordEnabled: true, AdminPassword: "adminPass", AdminPasswordAuto: false,
AdminAutoLogonEnabled: true, AdminAutoLogonCount: 15, ResetPasswordRequired: true,
AdminPasswordEnabled: takeBoolPointer(true), AdminPassword: "adminPass", AdminPasswordAuto: takeBoolPointer(false),
AdminAutoLogonEnabled: takeBoolPointer(true), AdminAutoLogonCount: 15, ResetPasswordRequired: takeBoolPointer(true),
CustomizationScript: "ls", ComputerName: "Cname18"}

guestCustomizationSection, err := object.SetGuestCustomizationSection(setupedGuestCustomizationSection)
Expand All @@ -115,18 +115,18 @@ func guestCustomizationPropertyTester(vcd *TestVCD, check *C, object getGuestCus
// Check that values were set from API
check.Assert(guestCustomizationSection, NotNil)

check.Assert(guestCustomizationSection.Enabled, Equals, true)
check.Assert(guestCustomizationSection.JoinDomainEnabled, Equals, false)
check.Assert(guestCustomizationSection.UseOrgSettings, Equals, false)
check.Assert(*guestCustomizationSection.Enabled, Equals, true)
check.Assert(*guestCustomizationSection.JoinDomainEnabled, Equals, false)
check.Assert(*guestCustomizationSection.UseOrgSettings, Equals, false)
check.Assert(guestCustomizationSection.DomainUserName, Equals, "")
check.Assert(guestCustomizationSection.DomainName, Equals, "")
check.Assert(guestCustomizationSection.DomainUserPassword, Equals, "")
check.Assert(guestCustomizationSection.AdminPasswordEnabled, Equals, true)
check.Assert(guestCustomizationSection.AdminPasswordAuto, Equals, false)
check.Assert(*guestCustomizationSection.AdminPasswordEnabled, Equals, true)
check.Assert(*guestCustomizationSection.AdminPasswordAuto, Equals, false)
check.Assert(guestCustomizationSection.AdminPassword, Equals, "adminPass")
check.Assert(guestCustomizationSection.AdminAutoLogonCount, Equals, 15)
check.Assert(guestCustomizationSection.AdminAutoLogonEnabled, Equals, true)
check.Assert(guestCustomizationSection.ResetPasswordRequired, Equals, true)
check.Assert(*guestCustomizationSection.AdminAutoLogonEnabled, Equals, true)
check.Assert(*guestCustomizationSection.ResetPasswordRequired, Equals, true)
check.Assert(guestCustomizationSection.CustomizationScript, Equals, "ls")
check.Assert(guestCustomizationSection.ComputerName, Equals, "Cname18")
}
7 changes: 5 additions & 2 deletions govcd/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ func (vm *VM) BlockWhileGuestCustomizationStatus(unwantedStatus string, timeOutA
}
}

// Customize function allows to set computername, apply customization script and enable or disble the changeSid option
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe:

Suggested change
// Customize function allows to set computername, apply customization script and enable or disble the changeSid option
// Customize function allows to set ComputerName, apply customization script and enable or disable the changeSid option

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

//
// Deprecated: Use vm.SetGuestCustomizationSection()
func (vm *VM) Customize(computername, script string, changeSid bool) (Task, error) {
err := vm.Refresh()
if err != nil {
Expand All @@ -459,10 +462,10 @@ func (vm *VM) Customize(computername, script string, changeSid bool) (Task, erro
HREF: vm.VM.HREF,
Type: types.MimeGuestCustomizationSection,
Info: "Specifies Guest OS Customization Settings",
Enabled: true,
Enabled: takeBoolPointer(true),
vbauzys marked this conversation as resolved.
Show resolved Hide resolved
ComputerName: computername,
CustomizationScript: script,
ChangeSid: false,
ChangeSid: takeBoolPointer(changeSid),
}

apiEndpoint, _ := url.ParseRequestURI(vm.VM.HREF)
Expand Down
16 changes: 8 additions & 8 deletions types/v56/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1603,21 +1603,21 @@ type GuestCustomizationSection struct {
// FIXME: Fix the OVF section
Info string `xml:"ovf:Info"`
// Elements
Enabled bool `xml:"Enabled,omitempty"` // True if guest customization is enabled.
ChangeSid bool `xml:"ChangeSid,omitempty"` // True if customization can change the Windows SID of this virtual machine.
Enabled *bool `xml:"Enabled,omitempty"` // True if guest customization is enabled.
ChangeSid *bool `xml:"ChangeSid,omitempty"` // True if customization can change the Windows SID of this virtual machine.
VirtualMachineID string `xml:"VirtualMachineId,omitempty"` // Virtual machine ID to apply.
JoinDomainEnabled bool `xml:"JoinDomainEnabled,omitempty"` // True if this virtual machine can join a Windows Domain.
UseOrgSettings bool `xml:"UseOrgSettings,omitempty"` // True if customization should use organization settings (OrgGuestPersonalizationSettings) when joining a Windows Domain.
JoinDomainEnabled *bool `xml:"JoinDomainEnabled,omitempty"` // True if this virtual machine can join a Windows Domain.
UseOrgSettings *bool `xml:"UseOrgSettings,omitempty"` // True if customization should use organization settings (OrgGuestPersonalizationSettings) when joining a Windows Domain.
DomainName string `xml:"DomainName,omitempty"` // The name of the Windows Domain to join.
DomainUserName string `xml:"DomainUserName,omitempty"` // User name to specify when joining a Windows Domain.
DomainUserPassword string `xml:"DomainUserPassword,omitempty"` // Password to use with DomainUserName.
MachineObjectOU string `xml:"MachineObjectOU,omitempty"` // The name of the Windows Domain Organizational Unit (OU) in which the computer account for this virtual machine will be created.
AdminPasswordEnabled bool `xml:"AdminPasswordEnabled,omitempty"` // True if guest customization can modify administrator password settings for this virtual machine.
AdminPasswordAuto bool `xml:"AdminPasswordAuto,omitempty"` // True if the administrator password for this virtual machine should be automatically generated.
AdminPasswordEnabled *bool `xml:"AdminPasswordEnabled,omitempty"` // True if guest customization can modify administrator password settings for this virtual machine.
AdminPasswordAuto *bool `xml:"AdminPasswordAuto,omitempty"` // True if the administrator password for this virtual machine should be automatically generated.
AdminPassword string `xml:"AdminPassword,omitempty"` // True if the administrator password for this virtual machine should be set to this string. (AdminPasswordAuto must be false.)
AdminAutoLogonEnabled bool `xml:"AdminAutoLogonEnabled,omitempty"` // True if guest administrator should automatically log into this virtual machine.
AdminAutoLogonEnabled *bool `xml:"AdminAutoLogonEnabled,omitempty"` // True if guest administrator should automatically log into this virtual machine.
AdminAutoLogonCount int `xml:"AdminAutoLogonCount,omitempty"` // Number of times administrator can automatically log into this virtual machine. In case AdminAutoLogon is set to True, this value should be between 1 and 100. Otherwise, it should be 0.
ResetPasswordRequired bool `xml:"ResetPasswordRequired,omitempty"` // True if the administrator password for this virtual machine must be reset after first use.
ResetPasswordRequired *bool `xml:"ResetPasswordRequired,omitempty"` // True if the administrator password for this virtual machine must be reset after first use.
CustomizationScript string `xml:"CustomizationScript,omitempty"` // Script to run on guest customization. The entire script must appear in this element. Use the XML entity 
 to represent a newline. Unicode characters can be represented in the form &#xxxx; where xxxx is the character number.
ComputerName string `xml:"ComputerName,omitempty"` // Computer name to assign to this virtual machine.
Link LinkList `xml:"Link,omitempty"` // A link to an operation on this section.
Expand Down