Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Prompting for validation before deleting deployments and models (dedicated-inference)
- Ability to delete multiple deployments and models at once (dedicated-inference)
- Add IPv6 public IP assignment support for SKS Nodepools #774
- Avoid redundant calls to `list-zones` #775

## 1.88.0

Expand Down
13 changes: 2 additions & 11 deletions cmd/compute/blockstorage/blockstorage_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
exocmd "github.com/exoscale/cli/cmd"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
"github.com/exoscale/cli/utils"
v3 "github.com/exoscale/egoscale/v3"
)

Expand Down Expand Up @@ -54,20 +55,10 @@ func (c *blockStorageListCmd) CmdRun(_ *cobra.Command, _ []string) error {
client := globalstate.EgoscaleV3Client
ctx := exocmd.GContext

resp, err := client.ListZones(ctx)
zones, err := utils.AllZonesV3(ctx, client, c.Zone)
if err != nil {
return err
}
zones := resp.Zones

if c.Zone != "" {
endpoint, err := client.GetZoneAPIEndpoint(ctx, c.Zone)
if err != nil {
return err
}

zones = []v3.Zone{{APIEndpoint: endpoint}}
}

output := make(blockStorageListOutput, 0)
for _, zone := range zones {
Expand Down
40 changes: 14 additions & 26 deletions cmd/compute/deploy_target/deploy_target_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
)

type deployTargetListItemOutput struct {
Zone string `json:"zone"`
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Zone v3.ZoneName `json:"zone"`
ID v3.UUID `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
}

type deployTargetListOutput []deployTargetListItemOutput
Expand All @@ -32,7 +32,7 @@ type deployTargetListCmd struct {

_ bool `cli-cmd:"list"`

Zone string `cli-short:"z" cli-usage:"zone to filter results to"`
Zone v3.ZoneName `cli-short:"z" cli-usage:"zone to filter results to"`
}

func (c *deployTargetListCmd) CmdAliases() []string { return nil }
Expand All @@ -51,20 +51,12 @@ func (c *deployTargetListCmd) CmdPreRun(cmd *cobra.Command, args []string) error
}

func (c *deployTargetListCmd) CmdRun(_ *cobra.Command, _ []string) error {
var zones []v3.ZoneName
client := globalstate.EgoscaleV3Client
ctx := exocmd.GContext

if c.Zone != "" {
zones = []v3.ZoneName{v3.ZoneName(c.Zone)}
} else {
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(c.Zone))
if err != nil {
return err
}
zones, err = utils.AllZonesV3(ctx, client)
if err != nil {
return err
}
zones, err := utils.AllZonesV3(ctx, client, c.Zone)
if err != nil {
return err
}

out := make(deployTargetListOutput, 0)
Expand All @@ -77,24 +69,20 @@ func (c *deployTargetListCmd) CmdRun(_ *cobra.Command, _ []string) error {
}
done <- struct{}{}
}()
err := utils.ForEachZone(zones, func(zone v3.ZoneName) error {

client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(zone))
if err != nil {
return err
}

list, err := client.ListDeployTargets(ctx)
err = utils.ForEveryZone(zones, func(zone v3.Zone) error {
c := client.WithEndpoint(zone.APIEndpoint)
list, err := c.ListDeployTargets(ctx)
if err != nil {
return fmt.Errorf("unable to list Deploy Targets in zone %s: %w", zone, err)
}

for _, dt := range list.DeployTargets {
res <- deployTargetListItemOutput{
ID: dt.ID.String(),
ID: dt.ID,
Name: dt.Name,
Type: string(dt.Type),
Zone: string(zone),
Zone: zone.Name,
}
}

Expand Down
37 changes: 13 additions & 24 deletions cmd/compute/elastic_ip/elastic_ip_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
)

type elasticIPListItemOutput struct {
ID string `json:"id"`
IPAddress string `json:"ip_address"`
Zone string `json:"zone"`
ID v3.UUID `json:"id"`
IPAddress string `json:"ip_address"`
Zone v3.ZoneName `json:"zone"`
}

type elasticIPListOutput []elasticIPListItemOutput
Expand All @@ -31,7 +31,7 @@ type elasticIPListCmd struct {

_ bool `cli-cmd:"list"`

Zone string `cli-short:"z" cli-usage:"zone to filter results to"`
Zone v3.ZoneName `cli-short:"z" cli-usage:"zone to filter results to"`
}

func (c *elasticIPListCmd) CmdAliases() []string { return exocmd.GListAlias }
Expand All @@ -50,20 +50,12 @@ func (c *elasticIPListCmd) CmdPreRun(cmd *cobra.Command, args []string) error {
}

func (c *elasticIPListCmd) CmdRun(_ *cobra.Command, _ []string) error {
var zones []v3.ZoneName
client := globalstate.EgoscaleV3Client
ctx := exocmd.GContext

if c.Zone != "" {
zones = []v3.ZoneName{v3.ZoneName(c.Zone)}
} else {
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(c.Zone))
if err != nil {
return err
}
zones, err = utils.AllZonesV3(ctx, client)
if err != nil {
return err
}
zones, err := utils.AllZonesV3(ctx, client, c.Zone)
if err != nil {
return err
}

out := make(elasticIPListOutput, 0)
Expand All @@ -76,23 +68,20 @@ func (c *elasticIPListCmd) CmdRun(_ *cobra.Command, _ []string) error {
}
done <- struct{}{}
}()
err := utils.ForEachZone(zones, func(zone v3.ZoneName) error {
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(zone))
if err != nil {
return err
}
err = utils.ForEveryZone(zones, func(zone v3.Zone) error {
c := client.WithEndpoint(zone.APIEndpoint)
list, err := c.ListElasticIPS(ctx)

list, err := client.ListElasticIPS(ctx)
if err != nil {
return fmt.Errorf("unable to list Elastic IP addresses in zone %s: %w", zone, err)
}

if list != nil {
for _, e := range list.ElasticIPS {
res <- elasticIPListItemOutput{
ID: e.ID.String(),
ID: e.ID,
IPAddress: e.IP,
Zone: string(zone),
Zone: zone.Name,
}
}

Expand Down
52 changes: 21 additions & 31 deletions cmd/compute/instance/instance_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import (
)

type instanceListItemOutput struct {
ID string `json:"id"`
Name string `json:"name"`
Zone string `json:"zone"`
Type string `json:"type"`
IPAddress string `json:"ip_address"`
IPv6Address string `json:"ipv6_address"`
State string `json:"state"`
ID v3.UUID `json:"id"`
Name string `json:"name"`
Zone v3.ZoneName `json:"zone"`
Type string `json:"type"`
IPAddress string `json:"ip_address"`
IPv6Address string `json:"ipv6_address"`
State string `json:"state"`
}

type instanceListOutput []instanceListItemOutput
Expand All @@ -46,9 +46,9 @@ func (o *instanceListOutput) ToTable() {

for _, instance := range *o {
t.Append([]string{
instance.ID,
string(instance.ID),
instance.Name,
instance.Zone,
string(instance.Zone),
instance.Type,
instance.IPAddress,
instance.IPv6Address,
Expand All @@ -62,7 +62,7 @@ type instanceListCmd struct {

_ bool `cli-cmd:"list"`

Zone string `cli-short:"z" cli-usage:"zone to filter results to"`
Zone v3.ZoneName `cli-short:"z" cli-usage:"zone to filter results to"`
}

func (c *instanceListCmd) CmdAliases() []string { return exocmd.GListAlias }
Expand All @@ -81,20 +81,12 @@ func (c *instanceListCmd) CmdPreRun(cmd *cobra.Command, args []string) error {
}

func (c *instanceListCmd) CmdRun(_ *cobra.Command, _ []string) error {
var zones []v3.ZoneName
client := globalstate.EgoscaleV3Client
ctx := exocmd.GContext

if c.Zone != "" {
zones = []v3.ZoneName{v3.ZoneName(c.Zone)}
} else {
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(c.Zone))
if err != nil {
return err
}
zones, err = utils.AllZonesV3(ctx, client)
if err != nil {
return err
}
zones, err := utils.AllZonesV3(ctx, client, c.Zone)
if err != nil {
return err
}

out := make(instanceListOutput, 0)
Expand All @@ -109,14 +101,11 @@ func (c *instanceListCmd) CmdRun(_ *cobra.Command, _ []string) error {
}
done <- struct{}{}
}()
err := utils.ForEachZone(zones, func(zone v3.ZoneName) error {
ctx := exocmd.GContext
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(zone))
if err != nil {
return err
}
err = utils.ForEveryZone(zones, func(zone v3.Zone) error {

c := client.WithEndpoint(zone.APIEndpoint)
instances, err := c.ListInstances(ctx)

instances, err := client.ListInstances(ctx)
if err != nil {
return err
}
Expand All @@ -138,9 +127,9 @@ func (c *instanceListCmd) CmdRun(_ *cobra.Command, _ []string) error {
}

res <- instanceListItemOutput{
ID: i.ID.String(),
ID: i.ID,
Name: i.Name,
Zone: string(zone),
Zone: zone.Name,
Type: fmt.Sprintf("%s.%s", instanceType.Family, instanceType.Size),
IPAddress: utils.DefaultIP(&i.PublicIP, utils.EmptyIPAddressVisualization),
IPv6Address: utils.DefaultIP(i.Ipv6Address, utils.EmptyIPAddressVisualization),
Expand All @@ -150,6 +139,7 @@ func (c *instanceListCmd) CmdRun(_ *cobra.Command, _ []string) error {

return nil
})

if err != nil {
_, _ = fmt.Fprintf(os.Stderr,
"warning: errors during listing, results might be incomplete.\n%s\n", err) // nolint:golint
Expand Down
43 changes: 15 additions & 28 deletions cmd/compute/instance/instance_snapshot_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
)

type instanceSnapshotListItemOutput struct {
ID string `json:"id"`
CreationDate string `json:"creation_date"`
Instance string `json:"instance"`
State string `json:"state"`
Zone string `json:"zone"`
ID v3.UUID `json:"id"`
CreationDate string `json:"creation_date"`
Instance string `json:"instance"`
State string `json:"state"`
Zone v3.ZoneName `json:"zone"`
}

type instanceSnapshotListOutput []instanceSnapshotListItemOutput
Expand All @@ -34,7 +34,7 @@ type instanceSnapshotListCmd struct {

_ bool `cli-cmd:"list"`

Zone string `cli-short:"z" cli-usage:"zone to filter results to"`
Zone v3.ZoneName `cli-short:"z" cli-usage:"zone to filter results to"`
}

func (c *instanceSnapshotListCmd) CmdAliases() []string { return nil }
Expand All @@ -53,20 +53,12 @@ func (c *instanceSnapshotListCmd) CmdPreRun(cmd *cobra.Command, args []string) e
}

func (c *instanceSnapshotListCmd) CmdRun(_ *cobra.Command, _ []string) error {
var zones []v3.ZoneName
client := globalstate.EgoscaleV3Client
ctx := exocmd.GContext

if c.Zone != "" {
zones = []v3.ZoneName{v3.ZoneName(c.Zone)}
} else {
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(c.Zone))
if err != nil {
return err
}
zones, err = utils.AllZonesV3(ctx, client)
if err != nil {
return err
}
zones, err := utils.AllZonesV3(ctx, client, c.Zone)
if err != nil {
return err
}

out := make(instanceSnapshotListOutput, 0)
Expand All @@ -81,14 +73,9 @@ func (c *instanceSnapshotListCmd) CmdRun(_ *cobra.Command, _ []string) error {
}
done <- struct{}{}
}()
err := utils.ForEachZone(zones, func(zone v3.ZoneName) error {
ctx := exocmd.GContext
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(zone))
if err != nil {
return err
}

snapshots, err := client.ListSnapshots(ctx)
err = utils.ForEveryZone(zones, func(zone v3.Zone) error {
c := client.WithEndpoint(zone.APIEndpoint)
snapshots, err := c.ListSnapshots(ctx)
if err != nil {
return err
}
Expand All @@ -107,11 +94,11 @@ func (c *instanceSnapshotListCmd) CmdRun(_ *cobra.Command, _ []string) error {
}

res <- instanceSnapshotListItemOutput{
ID: s.ID.String(),
ID: s.ID,
CreationDate: s.CreatedAT.String(),
Instance: instance.Name,
State: string(s.State),
Zone: string(zone),
Zone: zone.Name,
}
}

Expand Down
Loading