Skip to content

Commit

Permalink
Instance: Fix instance protection flag update zone context (#648)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Emmanuel Jacquier <[email protected]>
  • Loading branch information
pierre-emmanuelJ authored Nov 5, 2024
1 parent e04ba15 commit d5849d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

### Bug fixes

- storage: handle errors in batch objects delete action #627
- Storage: handle errors in batch objects delete action #627
- Instance: Fix instance protection flag update zone context #648

## 1.80.0

### Features
- instance pool: added min-available flag to exo compute #629
- Instance pool: added min-available flag to exo compute #629
- dbaas: external endpoints and external integration commands and sub-commands

## 1.79.1
Expand Down
20 changes: 10 additions & 10 deletions cmd/instance_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import (
"fmt"
"strings"

egoscale3 "github.com/exoscale/egoscale/v3"

"github.com/spf13/cobra"

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
"github.com/exoscale/cli/pkg/userdata"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
)

type instanceUpdateCmd struct {
Expand Down Expand Up @@ -102,25 +101,26 @@ func (c *instanceUpdateCmd) cmdRun(cmd *cobra.Command, _ []string) error {
}

if cmd.Flags().Changed(mustCLICommandFlagName(c, &c.Protection)) {
var value egoscale3.UUID
var op *egoscale3.Operation
value, err = egoscale3.ParseUUID(*instance.ID)
var client *v3.Client
client, err = switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(c.Zone))

var instanceID v3.UUID
var op *v3.Operation
instanceID, err = v3.ParseUUID(*instance.ID)
if err != nil {
return
}
if c.Protection {
op, err = globalstate.EgoscaleV3Client.AddInstanceProtection(ctx, value)
op, err = client.AddInstanceProtection(ctx, instanceID)
} else {
op, err = globalstate.EgoscaleV3Client.RemoveInstanceProtection(ctx, value)
op, err = client.RemoveInstanceProtection(ctx, instanceID)
}
if err != nil {
return
}
_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, egoscale3.OperationStateSuccess)
_, err = client.Wait(ctx, op, v3.OperationStateSuccess)
}

})

if err != nil {
return err
}
Expand Down

0 comments on commit d5849d9

Please sign in to comment.