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

Instance: Fix instance protection flag update zone context #648

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
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
Loading