Skip to content

Commit

Permalink
fix(instance): list image with image from not found server (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
kindermoumoute authored Apr 17, 2020
1 parent 18cfb6e commit 5d3c3ad
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/mattn/go-colorable v0.1.4
github.com/mattn/go-isatty v0.0.11
github.com/pkg/errors v0.9.1 // indirect
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200409105057-297e3dbdccb5
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200414183251-a6244a393e63
github.com/sergi/go-diff v1.0.0 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200403173805-25a10631420d
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200403173805-25a10631420d/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200409105057-297e3dbdccb5 h1:QmrgbtSAIDKRTnzAjdpop3yFAqHFO4MEc8W+/0Epu88=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200409105057-297e3dbdccb5/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200414183251-a6244a393e63 h1:8tRzNwnY+PK6TD21bvKU0p334p+kApiKdHRO3xsZgpg=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200414183251-a6244a393e63/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
30 changes: 18 additions & 12 deletions internal/namespaces/instance/v1/custom_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,26 @@ func imageListBuilder(c *core.Command) *core.Command {
State: image.State,
Zone: image.Zone,
}
customImages = append(customImages, newCustomImage)

if image.FromServer != "" {
serverReq := instance.GetServerRequest{
Zone: req.Zone,
ServerID: image.FromServer,
}
getServerResponse, err := api.GetServer(&serverReq)
if err != nil {
return nil, err
}
newCustomImage.ServerID = getServerResponse.Server.ID
newCustomImage.ServerName = getServerResponse.Server.Name
if image.FromServer == "" {
continue
}
customImages = append(customImages, newCustomImage)

serverReq := instance.GetServerRequest{
Zone: req.Zone,
ServerID: image.FromServer,
}
getServerResponse, err := api.GetServer(&serverReq)
if _, ok := err.(*scw.ResourceNotFoundError); ok {
newCustomImage.ServerName = "-"
continue
}
if err != nil {
return nil, err
}
newCustomImage.ServerID = getServerResponse.Server.ID
newCustomImage.ServerName = getServerResponse.Server.Name
}

return customImages, nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
WARNING: 2019/12/09 16:04:07 cannot get image 7a892c1a-bbdc-491f-9974-4008e3708664: scaleway-sdk-go: http error 404 Not Found: "7a892c1a-bbdc-491f-9974-4008e3708664" not found
WARNING: 2019/12/09 16:04:07 cannot get image 7a892c1a-bbdc-491f-9974-4008e3708664: scaleway-sdk-go: resource with ID 7a892c1a-bbdc-491f-9974-4008e3708664 is not found
WARNING: 2019/12/09 16:04:07 skipping image server-type compatibility validation
Cannot create the server: scaleway-sdk-go: http error 404 Not Found: "7a892c1a-bbdc-491f-9974-4008e3708664" not found
Cannot create the server: scaleway-sdk-go: resource with ID 7a892c1a-bbdc-491f-9974-4008e3708664 is not found
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"11111111-1111-1111-1111-111111111111" not found
Cannot find resource '' with ID '11111111-1111-1111-1111-111111111111'
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"11111111-1111-1111-1111-111111111111" not found
Cannot find resource '' with ID '11111111-1111-1111-1111-111111111111'
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"11111111-1111-1111-1111-111111111111" not found
Cannot find resource '' with ID '11111111-1111-1111-1111-111111111111'

0 comments on commit 5d3c3ad

Please sign in to comment.