Skip to content

Commit

Permalink
fix eip and instance-type
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Emmanuel Jacquier <[email protected]>
  • Loading branch information
pierre-emmanuelJ committed Sep 10, 2024
1 parent 5e3766f commit cb69129
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions cmd/instance_pool_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package cmd

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"

"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
"github.com/exoscale/cli/pkg/userdata"
"github.com/exoscale/cli/utils"
v3 "github.com/exoscale/egoscale/v3"
)

Expand Down Expand Up @@ -118,18 +120,24 @@ func (c *instancePoolUpdateCmd) cmdRun(cmd *cobra.Command, _ []string) error { /

if cmd.Flags().Changed(mustCLICommandFlagName(c, &c.ElasticIPs)) {
updateReq.ElasticIPS = make([]v3.ElasticIP, len(c.ElasticIPs))
eIP, err := client.ListElasticIPS(ctx)
eipList, err := client.ListElasticIPS(ctx)
if err != nil {
return fmt.Errorf("error listing Elastic IP: %w", err)
}
for i := range c.ElasticIPs {
elasticIP, err := eIP.FindElasticIP(c.ElasticIPs[i])
if err != nil {
return fmt.Errorf("error retrieving Elastic IP: %w", err)
for i, input := range c.ElasticIPs {
found := false
for _, eip := range eipList.ElasticIPS {
if input == eip.IP || input == string(eip.ID) {
updateReq.ElasticIPS[i] = v3.ElasticIP{ID: eip.ID}
found = true
break
}
}
if !found {
fmt.Fprintf(os.Stderr, "warning: %s not found.\n", input)
}
updateReq.ElasticIPS[i] = v3.ElasticIP{ID: elasticIP.ID}

}

updated = true
}

Expand Down Expand Up @@ -192,16 +200,25 @@ func (c *instancePoolUpdateCmd) cmdRun(cmd *cobra.Command, _ []string) error { /
updated = true
}

//if cmd.Flags().Changed(mustCLICommandFlagName(c, &c.InstanceType)) { //
// instanceTypes, err := client.ListInstanceTypes(ctx)
//
// if err != nil {
// return fmt.Errorf("error listing instance type: %w", err)
// }
//
// updateReq.InstanceTypeID = instanceType.ID
// updated = true
//}
if cmd.Flags().Changed(mustCLICommandFlagName(c, &c.InstanceType)) {
instanceTypes, err := client.ListInstanceTypes(ctx)
if err != nil {
return fmt.Errorf("error listing instance type: %w", err)
}

instanceType := utils.ParseInstanceType(c.InstanceType)
for i, it := range instanceTypes.InstanceTypes {
if it.Family == instanceType.Family && it.Size == instanceType.Size {
updateReq.InstanceType = &v3.InstanceType{ID: instanceTypes.InstanceTypes[i].ID}
break
}
}
if updateReq.InstanceType == nil {
return fmt.Errorf("error retrieving instance type %s: not found", c.InstanceType)
}

updated = true
}

if cmd.Flags().Changed(mustCLICommandFlagName(c, &c.SSHKey)) {
updateReq.SSHKey = &v3.SSHKey{Name: c.SSHKey}
Expand Down

0 comments on commit cb69129

Please sign in to comment.