Skip to content

Commit

Permalink
Allow normal ACS user to create a cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
vishesh92 committed May 23, 2024
1 parent 8abb08d commit b07ffd4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 11 additions & 4 deletions pkg/cloud/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,22 @@ func findVirtualMachine(

// DestroyVMInstance Destroys a VM instance. Assumes machine has been fetched prior and has an instance ID.
func (c *client) DestroyVMInstance(csMachine *infrav1.CloudStackMachine) error {
p := c.cs.Configuration.NewListCapabilitiesParams()
capabilities, err := c.cs.Configuration.ListCapabilities(p)
expunge := true
if err == nil {
expunge = capabilities.Capabilities.Allowuserexpungerecovervm
}

// Attempt deletion regardless of machine state.
p := c.csAsync.VirtualMachine.NewDestroyVirtualMachineParams(*csMachine.Spec.InstanceID)
p2 := c.csAsync.VirtualMachine.NewDestroyVirtualMachineParams(*csMachine.Spec.InstanceID)
volIDs, err := c.listVMInstanceDatadiskVolumeIDs(*csMachine.Spec.InstanceID)
if err != nil {
return err
}
p.SetExpunge(true)
setArrayIfNotEmpty(volIDs, p.SetVolumeids)
if _, err := c.csAsync.VirtualMachine.DestroyVirtualMachine(p); err != nil &&
p2.SetExpunge(expunge)
setArrayIfNotEmpty(volIDs, p2.SetVolumeids)
if _, err := c.csAsync.VirtualMachine.DestroyVirtualMachine(p2); err != nil &&
strings.Contains(strings.ToLower(err.Error()), "unable to find uuid for id") {
// VM doesn't exist. Success...
return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/user_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func (c *client) ResolveDomain(domain *Domain) error {
// ResolveAccount resolves an account's information.
func (c *client) ResolveAccount(account *Account) error {
// Resolve domain prior to any account resolution activity.
if err := c.ResolveDomain(&account.Domain); err != nil {
if err := c.ResolveDomain(&account.Domain); err != nil &&
!strings.Contains(err.Error(), "The API [listDomains] does not exist or is not available for the account Account") {
return errors.Wrapf(err, "resolving domain %s details", account.Domain.Name)
}

Expand Down

0 comments on commit b07ffd4

Please sign in to comment.