diff --git a/pkg/cloud/instance.go b/pkg/cloud/instance.go index 10956fc0..62778f17 100644 --- a/pkg/cloud/instance.go +++ b/pkg/cloud/instance.go @@ -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 diff --git a/pkg/cloud/user_credentials.go b/pkg/cloud/user_credentials.go index 15d2d22f..2dc6252d 100644 --- a/pkg/cloud/user_credentials.go +++ b/pkg/cloud/user_credentials.go @@ -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) }