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 all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
* 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)
* Added methods `vapp.AddNetwork`, `vapp.AddNetworkAsync`, `vapp.AddOrgNetwork`, `vapp.AddOrgNetworkAsync`, `vapp.UpdateNetwork`, `vapp.UpdateNetworkAsync`, `vapp.UpdateOrgNetwork`, `vapp.UpdateOrgNetworkAsync`, `vapp.RemoveNetwork`, `vapp.RemoveNetworkAsync` and `GetUuidFromHref` [#289](https://github.com/vmware/go-vcloud-director/pull/290)
* Deprecated functions `vapp.RemoveIsolatedNetwork`, `vapp.AddRAWNetworkConfig` and `vapp.AddIsolatedNetwork` [#289](https://github.com/vmware/go-vcloud-director/pull/290)

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 @@ -374,6 +374,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 @@ -393,10 +396,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
35 changes: 25 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,33 @@ 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")

// Double check if GuestCustomizationSection retrieved from separate API is the same as the one
// embedded directly in the VM
vm := object.(*VM)

// Refresh VM to have the latest structure
err = vm.Refresh()
check.Assert(err, IsNil)

// Deep compare values retrieved from separate API to the ones embedded into VM
guestCustomizationSection.Xmlns = "" // embedded VM structure does not have this field
// Links amount may differ between structures
guestCustomizationSection.Link = types.LinkList{}
vm.VM.GuestCustomizationSection.Link = types.LinkList{}
check.Assert(guestCustomizationSection, DeepEquals, vm.VM.GuestCustomizationSection)
}
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 disable the changeSid option
//
// 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
20 changes: 12 additions & 8 deletions types/v56/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,10 @@ type VM struct {

VmSpecSection *VmSpecSection `xml:"VmSpecSection,omitempty"`

// GuestCustomizationSection contains settings for VM customization like admin password, SID
// changes, domain join configuration, etc
GuestCustomizationSection *GuestCustomizationSection `xml:"GuestCustomizationSection,omitempty"`

VMCapabilities *VMCapabilities `xml:"VmCapabilities,omitempty"` // Allows you to specify certain capabilities of this virtual machine.
StorageProfile *Reference `xml:"StorageProfile,omitempty"` // A reference to a storage profile to be used for this object. The specified storage profile must exist in the organization vDC that contains the object. If not specified, the default storage profile for the vDC is used.
ProductSection *ProductSection `xml:"ProductSection,omitempty"`
Expand Down Expand Up @@ -1603,21 +1607,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