Skip to content

Commit fd2a792

Browse files
committed
Add api.ResolveTTYUrl
1 parent b734ff5 commit fd2a792

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

pkg/api/api.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type ScalewayAPI struct {
7474
client *http.Client
7575
verbose bool
7676
computeAPI string
77+
78+
Region string
7779
//
7880
Logger
7981
}
@@ -889,6 +891,7 @@ func NewScalewayAPI(organization, token, userAgent, region string, options ...fu
889891
default:
890892
return nil, fmt.Errorf("%s isn't a valid region", region)
891893
}
894+
s.Region = region
892895
if url := os.Getenv("SCW_COMPUTE_API"); url != "" {
893896
s.computeAPI = url
894897
}
@@ -2817,3 +2820,12 @@ func (s *ScalewayAPI) DeleteMarketPlaceLocalImage(uuidImage, uuidVersion, uuidLo
28172820
_, err = s.handleHTTPError([]int{http.StatusNoContent}, resp)
28182821
return err
28192822
}
2823+
2824+
// ResolveTTYUrl return an URL to get a tty
2825+
func (s *ScalewayAPI) ResolveTTYUrl() string {
2826+
switch s.Region {
2827+
case "par1", "":
2828+
return "https://tty.scaleway.com/v2/"
2829+
}
2830+
return ""
2831+
}

pkg/api/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ func CreateServer(api *ScalewayAPI, c *ConfigCreateServer) (string, error) {
445445
return "", err
446446
}
447447
currentVolume := createdServer.Volumes["0"]
448-
size := currentVolume.Size.(uint64)
448+
size := uint64(currentVolume.Size.(float64))
449449

450450
var volumePayload ScalewayVolumePutDefinition
451451
newName := fmt.Sprintf("%s-%s", createdServer.Hostname, currentVolume.Name)

pkg/commands/attach.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func RunAttach(ctx CommandContext, args AttachArgs) error {
1818
if err != nil {
1919
return err
2020
}
21-
_, done, err := utils.AttachToSerial(serverID, ctx.API.Token)
21+
_, done, err := utils.AttachToSerial(serverID, ctx.API.Token, ctx.API.ResolveTTYUrl())
2222
if err != nil {
2323
return err
2424
}

pkg/commands/run.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ func addUserData(ctx CommandContext, userdatas []string, serverID string) {
9999
}
100100
}
101101

102-
func runShowBoot(ctx CommandContext, args RunArgs, serverID string, closeTimeout chan struct{}, timeoutExit chan struct{}) error {
102+
func runShowBoot(ctx CommandContext, args RunArgs, serverID, region string, closeTimeout chan struct{}, timeoutExit chan struct{}) error {
103103
// Attach to server serial
104104
logrus.Info("Attaching to server console ...")
105-
gottycli, done, err := utils.AttachToSerial(serverID, ctx.API.Token)
105+
gottycli, done, err := utils.AttachToSerial(serverID, ctx.API.Token, ctx.API.ResolveTTYUrl())
106106
if err != nil {
107107
close(closeTimeout)
108108
return fmt.Errorf("cannot attach to server serial: %v", err)
@@ -242,11 +242,11 @@ func Run(ctx CommandContext, args RunArgs) error {
242242
}()
243243
}
244244
if args.ShowBoot {
245-
return runShowBoot(ctx, args, serverID, closeTimeout, timeoutExit)
245+
return runShowBoot(ctx, args, serverID, ctx.API.Region, closeTimeout, timeoutExit)
246246
} else if args.Attach {
247247
// Attach to server serial
248248
logrus.Info("Attaching to server console ...")
249-
gottycli, done, err := utils.AttachToSerial(serverID, ctx.API.Token)
249+
gottycli, done, err := utils.AttachToSerial(serverID, ctx.API.Token, ctx.API.ResolveTTYUrl())
250250
close(closeTimeout)
251251
if err != nil {
252252
return fmt.Errorf("cannot attach to server serial: %v", err)

pkg/utils/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ func RemoveDuplicates(elements []string) []string {
191191
}
192192

193193
// AttachToSerial tries to connect to server serial using 'gotty-client' and fallback with a help message
194-
func AttachToSerial(serverID string, apiToken string) (*gottyclient.Client, chan bool, error) {
194+
func AttachToSerial(serverID, apiToken, url string) (*gottyclient.Client, chan bool, error) {
195195
gottyURL := os.Getenv("SCW_GOTTY_URL")
196196
if gottyURL == "" {
197-
gottyURL = "https://tty.scaleway.com/v2/"
197+
gottyURL = url
198198
}
199199
URL := fmt.Sprintf("%s?arg=%s&arg=%s", gottyURL, apiToken, serverID)
200200

0 commit comments

Comments
 (0)