Skip to content

Commit c4fb097

Browse files
author
Your Name
committed
migrate instance pools.
1 parent 992943c commit c4fb097

17 files changed

+123
-106
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- load-balancer: move to egoscale v3 #687
3030
- anti-affinity-group: moving the logic to the corresponding subfolder #696
3131
- security-group: moving the logic to the corresponding subfolder #702
32+
- instance-pool: moving the logic to the corresponding subfolder #704
3233

3334
## 1.84.1
3435

cmd/blockstorage_snapshot_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (c *blockStorageSnapshotUpdateCmd) CmdRun(cmd *cobra.Command, _ []string) e
6060
var updated bool
6161
updateReq := v3.UpdateBlockStorageSnapshotRequest{}
6262
if cmd.Flags().Changed(MustCLICommandFlagName(c, &c.Labels)) {
63-
updateReq.Labels = convertIfSpecialEmptyMap(c.Labels)
63+
updateReq.Labels = ConvertIfSpecialEmptyMap(c.Labels)
6464

6565
updated = true
6666
}

cmd/blockstorage_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (c *blockStorageUpdateCmd) CmdRun(cmd *cobra.Command, _ []string) error {
7878
var updated bool
7979
updateReq := v3.UpdateBlockStorageVolumeRequest{}
8080
if cmd.Flags().Changed(MustCLICommandFlagName(c, &c.Labels)) {
81-
updateReq.Labels = convertIfSpecialEmptyMap(c.Labels)
81+
updateReq.Labels = ConvertIfSpecialEmptyMap(c.Labels)
8282

8383
updated = true
8484
}

cmd/cmd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ func CmdSetZoneFlagFromDefault(cmd *cobra.Command) {
7676
}
7777
}
7878

79-
// cmdSetTemplateFlagFromDefault attempts to set the "--template" flag value based on the current active account's
79+
// CmdSetTemplateFlagFromDefault attempts to set the "--template" flag value based on the current active account's
8080
// default template setting if set. This is a convenience helper, there is no guarantee that the flag will be
8181
// set once this function returns.
82-
func cmdSetTemplateFlagFromDefault(cmd *cobra.Command) {
82+
func CmdSetTemplateFlagFromDefault(cmd *cobra.Command) {
8383
if cmd.Flag("template").Value.String() == "" {
8484
if account.CurrentAccount.DefaultTemplate != "" {
8585
cmd.Flag("template").Value.Set(account.CurrentAccount.DefaultTemplate) // nolint:errcheck
@@ -173,7 +173,7 @@ func cliCommandFlagName(c cliCommand, field interface{}) (string, error) {
173173
return "", fmt.Errorf("field not found in struct %s", cv.Type())
174174
}
175175

176-
func convertIfSpecialEmptyMap(m map[string]string) map[string]string {
176+
func ConvertIfSpecialEmptyMap(m map[string]string) map[string]string {
177177
// since it is not possible to pass an empty map
178178
// with a spf13/pflag https://github.com/spf13/pflag/issues/312
179179
// we use the special value of a map with only

cmd/instance_pool.go renamed to cmd/compute/instance_pool/instance_pool.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package cmd
1+
package instance_pool
22

33
import (
4+
exocmd "github.com/exoscale/cli/cmd"
45
"github.com/spf13/cobra"
56
)
67

@@ -11,5 +12,5 @@ var instancePoolCmd = &cobra.Command{
1112
}
1213

1314
func init() {
14-
ComputeCmd.AddCommand(instancePoolCmd)
15+
exocmd.ComputeCmd.AddCommand(instancePoolCmd)
1516
}

cmd/instance_pool_create.go renamed to cmd/compute/instance_pool/instance_pool_create.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmd
1+
package instance_pool
22

33
import (
44
"fmt"
@@ -7,6 +7,7 @@ import (
77

88
"github.com/spf13/cobra"
99

10+
exocmd "github.com/exoscale/cli/cmd"
1011
"github.com/exoscale/cli/pkg/account"
1112
"github.com/exoscale/cli/pkg/globalstate"
1213
"github.com/exoscale/cli/pkg/output"
@@ -16,7 +17,7 @@ import (
1617
)
1718

1819
type instancePoolCreateCmd struct {
19-
CliCommandSettings `cli-cmd:"-"`
20+
exocmd.CliCommandSettings `cli-cmd:"-"`
2021

2122
_ bool `cli-cmd:"create"`
2223

@@ -43,7 +44,7 @@ type instancePoolCreateCmd struct {
4344
Zone v3.ZoneName `cli-short:"z" cli-usage:"Instance Pool zone"`
4445
}
4546

46-
func (c *instancePoolCreateCmd) CmdAliases() []string { return GCreateAlias }
47+
func (c *instancePoolCreateCmd) CmdAliases() []string { return exocmd.GCreateAlias }
4748

4849
func (c *instancePoolCreateCmd) CmdShort() string { return "Create an Instance Pool" }
4950

@@ -56,15 +57,15 @@ Supported output template annotations: %s`,
5657

5758
func (c *instancePoolCreateCmd) CmdPreRun(cmd *cobra.Command, args []string) error {
5859

59-
CmdSetZoneFlagFromDefault(cmd)
60-
cmdSetTemplateFlagFromDefault(cmd)
61-
return CliCommandDefaultPreRun(c, cmd, args)
60+
exocmd.CmdSetZoneFlagFromDefault(cmd)
61+
exocmd.CmdSetTemplateFlagFromDefault(cmd)
62+
return exocmd.CliCommandDefaultPreRun(c, cmd, args)
6263
}
6364

6465
func (c *instancePoolCreateCmd) CmdRun(_ *cobra.Command, _ []string) error {
6566

66-
ctx := GContext
67-
client, err := SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone)
67+
ctx := exocmd.GContext
68+
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone)
6869
if err != nil {
6970
return err
7071
}
@@ -208,7 +209,7 @@ func (c *instancePoolCreateCmd) CmdRun(_ *cobra.Command, _ []string) error {
208209

209210
var instancePoolID v3.UUID
210211

211-
decorateAsyncOperation(fmt.Sprintf("Creating Instance Pool %q...", c.Name), func() {
212+
utils.DecorateAsyncOperation(fmt.Sprintf("Creating Instance Pool %q...", c.Name), func() {
212213
var op *v3.Operation
213214
op, err = client.CreateInstancePool(ctx, instancePoolReq)
214215
if err != nil {
@@ -241,13 +242,13 @@ func (c *instancePoolCreateCmd) CmdRun(_ *cobra.Command, _ []string) error {
241242
}
242243

243244
func init() {
244-
cobra.CheckErr(RegisterCLICommand(instancePoolCmd, &instancePoolCreateCmd{
245-
CliCommandSettings: DefaultCLICmdSettings(),
245+
cobra.CheckErr(exocmd.RegisterCLICommand(instancePoolCmd, &instancePoolCreateCmd{
246+
CliCommandSettings: exocmd.DefaultCLICmdSettings(),
246247

247248
DiskSize: 50,
248-
InstanceType: fmt.Sprintf("%s.%s", DefaultInstanceTypeFamily, DefaultInstanceType),
249+
InstanceType: fmt.Sprintf("%s.%s", exocmd.DefaultInstanceTypeFamily, exocmd.DefaultInstanceType),
249250
Size: 1,
250251
MinAvailable: 0,
251-
TemplateVisibility: defaultTemplateVisibility,
252+
TemplateVisibility: exocmd.DefaultTemplateVisibility,
252253
}))
253254
}

cmd/instance_pool_delete.go renamed to cmd/compute/instance_pool/instance_pool_delete.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
package cmd
1+
package instance_pool
22

33
import (
44
"errors"
55
"fmt"
66

77
"github.com/spf13/cobra"
88

9+
exocmd "github.com/exoscale/cli/cmd"
910
"github.com/exoscale/cli/pkg/account"
1011
"github.com/exoscale/cli/pkg/globalstate"
12+
"github.com/exoscale/cli/utils"
1113
exoapi "github.com/exoscale/egoscale/v2/api"
1214
)
1315

1416
type instancePoolDeleteCmd struct {
15-
CliCommandSettings `cli-cmd:"-"`
17+
exocmd.CliCommandSettings `cli-cmd:"-"`
1618

1719
_ bool `cli-cmd:"delete"`
1820

@@ -22,19 +24,19 @@ type instancePoolDeleteCmd struct {
2224
Zone string `cli-short:"z" cli-usage:"Instance Pool zone"`
2325
}
2426

25-
func (c *instancePoolDeleteCmd) CmdAliases() []string { return GRemoveAlias }
27+
func (c *instancePoolDeleteCmd) CmdAliases() []string { return exocmd.GRemoveAlias }
2628

2729
func (c *instancePoolDeleteCmd) CmdShort() string { return "Delete an Instance Pool" }
2830

2931
func (c *instancePoolDeleteCmd) CmdLong() string { return "" }
3032

3133
func (c *instancePoolDeleteCmd) CmdPreRun(cmd *cobra.Command, args []string) error {
32-
CmdSetZoneFlagFromDefault(cmd)
33-
return CliCommandDefaultPreRun(c, cmd, args)
34+
exocmd.CmdSetZoneFlagFromDefault(cmd)
35+
return exocmd.CliCommandDefaultPreRun(c, cmd, args)
3436
}
3537

3638
func (c *instancePoolDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error {
37-
ctx := exoapi.WithEndpoint(GContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))
39+
ctx := exoapi.WithEndpoint(exocmd.GContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))
3840

3941
instancePool, err := globalstate.EgoscaleClient.FindInstancePool(ctx, c.Zone, c.InstancePool)
4042
if err != nil {
@@ -51,7 +53,7 @@ func (c *instancePoolDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error {
5153
}
5254

5355
if !c.Force {
54-
if !askQuestion(fmt.Sprintf("Are you sure you want to delete Instance Pool %q?", c.InstancePool)) {
56+
if !utils.AskQuestion(ctx, fmt.Sprintf("Are you sure you want to delete Instance Pool %q?", c.InstancePool)) {
5557
return nil
5658
}
5759
}
@@ -69,7 +71,7 @@ func (c *instancePoolDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error {
6971
}
7072
}
7173

72-
decorateAsyncOperation(fmt.Sprintf("Deleting Instance Pool %q...", c.InstancePool), func() {
74+
utils.DecorateAsyncOperation(fmt.Sprintf("Deleting Instance Pool %q...", c.InstancePool), func() {
7375
err = globalstate.EgoscaleClient.DeleteInstancePool(ctx, c.Zone, instancePool)
7476
})
7577
if err != nil {
@@ -80,7 +82,7 @@ func (c *instancePoolDeleteCmd) CmdRun(_ *cobra.Command, _ []string) error {
8082
}
8183

8284
func init() {
83-
cobra.CheckErr(RegisterCLICommand(instancePoolCmd, &instancePoolDeleteCmd{
84-
CliCommandSettings: DefaultCLICmdSettings(),
85+
cobra.CheckErr(exocmd.RegisterCLICommand(instancePoolCmd, &instancePoolDeleteCmd{
86+
CliCommandSettings: exocmd.DefaultCLICmdSettings(),
8587
}))
8688
}

cmd/instance_pool_evict.go renamed to cmd/compute/instance_pool/instance_pool_evict.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
package cmd
1+
package instance_pool
22

33
import (
44
"errors"
55
"fmt"
66

77
"github.com/spf13/cobra"
88

9+
exocmd "github.com/exoscale/cli/cmd"
910
"github.com/exoscale/cli/pkg/account"
1011
"github.com/exoscale/cli/pkg/globalstate"
12+
"github.com/exoscale/cli/utils"
1113
exoapi "github.com/exoscale/egoscale/v2/api"
1214
)
1315

1416
type instancePoolEvictCmd struct {
15-
CliCommandSettings `cli-cmd:"-"`
17+
exocmd.CliCommandSettings `cli-cmd:"-"`
1618

1719
_ bool `cli-cmd:"evict"`
1820

@@ -34,27 +36,29 @@ command.`
3436
}
3537

3638
func (c *instancePoolEvictCmd) CmdPreRun(cmd *cobra.Command, args []string) error {
37-
CmdSetZoneFlagFromDefault(cmd)
38-
return CliCommandDefaultPreRun(c, cmd, args)
39+
exocmd.CmdSetZoneFlagFromDefault(cmd)
40+
return exocmd.CliCommandDefaultPreRun(c, cmd, args)
3941
}
4042

4143
func (c *instancePoolEvictCmd) CmdRun(cmd *cobra.Command, _ []string) error {
44+
ctx := exoapi.WithEndpoint(exocmd.GContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))
45+
4246
if len(c.Instances) == 0 {
43-
CmdExitOnUsageError(cmd, "no instances specified")
47+
exocmd.CmdExitOnUsageError(cmd, "no instances specified")
4448
}
4549

4650
if !c.Force {
47-
if !askQuestion(fmt.Sprintf(
48-
"Are you sure you want to evict %v from Instance Pool %q?",
49-
c.Instances,
50-
c.InstancePool,
51-
)) {
51+
if !utils.AskQuestion(
52+
ctx,
53+
fmt.Sprintf(
54+
"Are you sure you want to evict %v from Instance Pool %q?",
55+
c.Instances,
56+
c.InstancePool,
57+
)) {
5258
return nil
5359
}
5460
}
5561

56-
ctx := exoapi.WithEndpoint(GContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))
57-
5862
instancePool, err := globalstate.EgoscaleClient.FindInstancePool(ctx, c.Zone, c.InstancePool)
5963
if err != nil {
6064
if errors.Is(err, exoapi.ErrNotFound) {
@@ -72,7 +76,7 @@ func (c *instancePoolEvictCmd) CmdRun(cmd *cobra.Command, _ []string) error {
7276
instances[i] = *instance.ID
7377
}
7478

75-
decorateAsyncOperation(
79+
utils.DecorateAsyncOperation(
7680
fmt.Sprintf("Evicting instances from Instance Pool %q...", c.InstancePool),
7781
func() {
7882
err = globalstate.EgoscaleClient.EvictInstancePoolMembers(ctx, c.Zone, instancePool, instances)
@@ -94,7 +98,7 @@ func (c *instancePoolEvictCmd) CmdRun(cmd *cobra.Command, _ []string) error {
9498
}
9599

96100
func init() {
97-
cobra.CheckErr(RegisterCLICommand(instancePoolCmd, &instancePoolEvictCmd{
98-
CliCommandSettings: DefaultCLICmdSettings(),
101+
cobra.CheckErr(exocmd.RegisterCLICommand(instancePoolCmd, &instancePoolEvictCmd{
102+
CliCommandSettings: exocmd.DefaultCLICmdSettings(),
99103
}))
100104
}

cmd/instance_pool_list.go renamed to cmd/compute/instance_pool/instance_pool_list.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmd
1+
package instance_pool
22

33
import (
44
"fmt"
@@ -7,6 +7,7 @@ import (
77

88
"github.com/spf13/cobra"
99

10+
exocmd "github.com/exoscale/cli/cmd"
1011
"github.com/exoscale/cli/pkg/account"
1112
"github.com/exoscale/cli/pkg/globalstate"
1213
"github.com/exoscale/cli/pkg/output"
@@ -29,14 +30,14 @@ func (o *instancePoolListOutput) ToText() { output.Text(o) }
2930
func (o *instancePoolListOutput) ToTable() { output.Table(o) }
3031

3132
type instancePoolListCmd struct {
32-
CliCommandSettings `cli-cmd:"-"`
33+
exocmd.CliCommandSettings `cli-cmd:"-"`
3334

3435
_ bool `cli-cmd:"list"`
3536

3637
Zone string `cli-short:"z" cli-usage:"zone to filter results to"`
3738
}
3839

39-
func (c *instancePoolListCmd) CmdAliases() []string { return GListAlias }
40+
func (c *instancePoolListCmd) CmdAliases() []string { return exocmd.GListAlias }
4041

4142
func (c *instancePoolListCmd) CmdShort() string { return "List Instance Pools" }
4243

@@ -48,7 +49,7 @@ Supported output template annotations: %s`,
4849
}
4950

5051
func (c *instancePoolListCmd) CmdPreRun(cmd *cobra.Command, args []string) error {
51-
return CliCommandDefaultPreRun(c, cmd, args)
52+
return exocmd.CliCommandDefaultPreRun(c, cmd, args)
5253
}
5354

5455
func (c *instancePoolListCmd) CmdRun(_ *cobra.Command, _ []string) error {
@@ -71,7 +72,7 @@ func (c *instancePoolListCmd) CmdRun(_ *cobra.Command, _ []string) error {
7172
done <- struct{}{}
7273
}()
7374
err := utils.ForEachZone(zones, func(zone string) error {
74-
ctx := exoapi.WithEndpoint(GContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, zone))
75+
ctx := exoapi.WithEndpoint(exocmd.GContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, zone))
7576

7677
list, err := globalstate.EgoscaleClient.ListInstancePools(ctx, zone)
7778
if err != nil {
@@ -102,7 +103,7 @@ func (c *instancePoolListCmd) CmdRun(_ *cobra.Command, _ []string) error {
102103
}
103104

104105
func init() {
105-
cobra.CheckErr(RegisterCLICommand(instancePoolCmd, &instancePoolListCmd{
106-
CliCommandSettings: DefaultCLICmdSettings(),
106+
cobra.CheckErr(exocmd.RegisterCLICommand(instancePoolCmd, &instancePoolListCmd{
107+
CliCommandSettings: exocmd.DefaultCLICmdSettings(),
107108
}))
108109
}

0 commit comments

Comments
 (0)