Skip to content

Commit 26954ea

Browse files
committed
Allow normal ACS user to create a cluster
1 parent d1a6ad9 commit 26954ea

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pkg/cloud/instance.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,22 @@ func findVirtualMachine(
452452

453453
// DestroyVMInstance Destroys a VM instance. Assumes machine has been fetched prior and has an instance ID.
454454
func (c *client) DestroyVMInstance(csMachine *infrav1.CloudStackMachine) error {
455+
p := c.cs.Configuration.NewListCapabilitiesParams()
456+
capabilities, err := c.cs.Configuration.ListCapabilities(p)
457+
expunge := true
458+
if err == nil {
459+
expunge = capabilities.Capabilities.Allowuserexpungerecovervm
460+
}
461+
455462
// Attempt deletion regardless of machine state.
456-
p := c.csAsync.VirtualMachine.NewDestroyVirtualMachineParams(*csMachine.Spec.InstanceID)
463+
p2 := c.csAsync.VirtualMachine.NewDestroyVirtualMachineParams(*csMachine.Spec.InstanceID)
457464
volIDs, err := c.listVMInstanceDatadiskVolumeIDs(*csMachine.Spec.InstanceID)
458465
if err != nil {
459466
return err
460467
}
461-
p.SetExpunge(true)
462-
setArrayIfNotEmpty(volIDs, p.SetVolumeids)
463-
if _, err := c.csAsync.VirtualMachine.DestroyVirtualMachine(p); err != nil &&
468+
p2.SetExpunge(expunge)
469+
setArrayIfNotEmpty(volIDs, p2.SetVolumeids)
470+
if _, err := c.csAsync.VirtualMachine.DestroyVirtualMachine(p2); err != nil &&
464471
strings.Contains(strings.ToLower(err.Error()), "unable to find uuid for id") {
465472
// VM doesn't exist. Success...
466473
return nil

pkg/cloud/user_credentials.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ func (c *client) ResolveDomain(domain *Domain) error {
152152
// ResolveAccount resolves an account's information.
153153
func (c *client) ResolveAccount(account *Account) error {
154154
// Resolve domain prior to any account resolution activity.
155-
if err := c.ResolveDomain(&account.Domain); err != nil {
155+
if err := c.ResolveDomain(&account.Domain); err != nil &&
156+
!strings.Contains(err.Error(), "The API [listDomains] does not exist or is not available for the account Account") {
156157
return errors.Wrapf(err, "resolving domain %s details", account.Domain.Name)
157158
}
158159

0 commit comments

Comments
 (0)