Skip to content

Commit e48ece1

Browse files
authored
feat(instance): remove deprecated and duplicated IP fields (#5037)
1 parent eaa737d commit e48ece1

File tree

4 files changed

+552
-373
lines changed

4 files changed

+552
-373
lines changed

internal/namespaces/instance/v1/custom_server.go

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,71 @@ func serverUpdateBuilder(c *core.Command) *core.Command {
380380
return c
381381
}
382382

383-
func volumeIsFromSBS(api *block.API, zone scw.Zone, volumeID string) bool {
384-
_, err := api.GetVolume(&block.GetVolumeRequest{
385-
Zone: zone,
386-
VolumeID: volumeID,
387-
})
383+
// customServer is a copy of instance.Server without the fields that are deprecated or duplicated in another section.
384+
// It is used by the `instance server get` command.
385+
type customServer struct {
386+
ID string `json:"id"`
387+
Name string `json:"name"`
388+
Organization string `json:"organization"`
389+
Project string `json:"project"`
390+
AllowedActions []instance.ServerAction `json:"allowed_actions"`
391+
Tags []string `json:"tags"`
392+
CommercialType string `json:"commercial_type"`
393+
CreationDate *time.Time `json:"creation_date"`
394+
DynamicIPRequired bool `json:"dynamic_ip_required"`
395+
RoutedIPEnabled *bool `json:"routed_ip_enabled"`
396+
Hostname string `json:"hostname"`
397+
Image *instance.Image `json:"image"`
398+
Protected bool `json:"protected"`
399+
PrivateIP *string `json:"private_ip"`
400+
PublicIPs []*instance.ServerIP `json:"public_ips"`
401+
MacAddress string `json:"mac_address"`
402+
ModificationDate *time.Time `json:"modification_date"`
403+
State instance.ServerState `json:"state"`
404+
StateDetail string `json:"state_detail"`
405+
IPv6 *instance.ServerIPv6 `json:"ipv6"`
406+
BootType instance.BootType `json:"boot_type"`
407+
SecurityGroup *instance.SecurityGroupSummary `json:"security_group"`
408+
Arch instance.Arch `json:"arch"`
409+
PlacementGroup *instance.PlacementGroup `json:"placement_group"`
410+
Zone scw.Zone `json:"zone"`
411+
AdminPasswordEncryptionSSHKeyID *string `json:"admin_password_encryption_ssh_key_id"`
412+
AdminPasswordEncryptedValue *string `json:"admin_password_encrypted_value"`
413+
Filesystems []*instance.ServerFilesystem `json:"filesystems"`
414+
EndOfService bool `json:"end_of_service"`
415+
}
388416

389-
return err == nil
417+
func customServerFromInstanceServer(server *instance.Server) *customServer {
418+
return &customServer{
419+
ID: server.ID,
420+
Name: server.Name,
421+
Organization: server.Organization,
422+
Project: server.Project,
423+
AllowedActions: server.AllowedActions,
424+
Tags: server.Tags,
425+
CommercialType: server.CommercialType,
426+
CreationDate: server.CreationDate,
427+
DynamicIPRequired: server.DynamicIPRequired,
428+
RoutedIPEnabled: server.RoutedIPEnabled,
429+
Hostname: server.Hostname,
430+
Image: server.Image,
431+
Protected: server.Protected,
432+
PrivateIP: server.PrivateIP,
433+
PublicIPs: server.PublicIPs,
434+
MacAddress: server.MacAddress,
435+
ModificationDate: server.ModificationDate,
436+
State: server.State,
437+
StateDetail: server.StateDetail,
438+
BootType: server.BootType,
439+
SecurityGroup: server.SecurityGroup,
440+
Arch: server.Arch,
441+
PlacementGroup: server.PlacementGroup,
442+
Zone: server.Zone,
443+
AdminPasswordEncryptionSSHKeyID: server.AdminPasswordEncryptionSSHKeyID,
444+
AdminPasswordEncryptedValue: server.AdminPasswordEncryptedValue,
445+
Filesystems: server.Filesystems,
446+
EndOfService: server.EndOfService,
447+
}
390448
}
391449

392450
func serverGetBuilder(c *core.Command) *core.Command {
@@ -506,12 +564,12 @@ func serverGetBuilder(c *core.Command) *core.Command {
506564
}
507565

508566
return &struct {
509-
*instance.Server
567+
*customServer
510568
Volumes []*customVolume
511569
PrivateNics []customNICs `json:"private_nics"`
512570
Warnings []string `json:"warnings"`
513571
}{
514-
server,
572+
customServerFromInstanceServer(server),
515573
orderVolumes(volumes),
516574
nics,
517575
warnings,
@@ -536,10 +594,6 @@ func serverGetBuilder(c *core.Command) *core.Command {
536594
Title: "Public IPs",
537595
FieldName: "PublicIPs",
538596
},
539-
{
540-
Title: "IPv6",
541-
FieldName: "IPv6",
542-
},
543597
{
544598
FieldName: "PrivateNics",
545599
Title: "Private NICs",

internal/namespaces/instance/v1/helpers_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/fatih/color"
1010
"github.com/scaleway/scaleway-cli/v2/core"
1111
"github.com/scaleway/scaleway-cli/v2/internal/terminal"
12+
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
1213
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
1314
product_catalog "github.com/scaleway/scaleway-sdk-go/api/product_catalog/v2alpha1"
1415
"github.com/scaleway/scaleway-sdk-go/scw"
@@ -51,6 +52,15 @@ func SizeValue(s *scw.Size) scw.Size {
5152
return 0
5253
}
5354

55+
func volumeIsFromSBS(api *block.API, zone scw.Zone, volumeID string) bool {
56+
_, err := api.GetVolume(&block.GetVolumeRequest{
57+
Zone: zone,
58+
VolumeID: volumeID,
59+
})
60+
61+
return err == nil
62+
}
63+
5464
func warningServerTypeDeprecated(
5565
ctx context.Context,
5666
client *scw.Client,

0 commit comments

Comments
 (0)