-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #501 from flatcar/tormath1/scaleway
platform: add scaleway platform
- Loading branch information
Showing
79 changed files
with
25,490 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/flatcar/mantle/cmd/ore/scaleway" | ||
) | ||
|
||
func init() { | ||
root.AddCommand(scaleway.Scaleway) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package scaleway | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const bucket = "flatcar-testing" | ||
|
||
var ( | ||
cmdCreate = &cobra.Command{ | ||
Use: "create-image", | ||
Short: "Create Scaleway image", | ||
RunE: runCreate, | ||
Example: `IMAGE_ID=$(ore scaleway \ | ||
--scaleway-access-key "${SCALEWAY_ACCESS_KEY}" \ | ||
--scaleway-secret-key "${SCALEWAY_SECRET_KEY}" \ | ||
--scaleway-organization-id "${SCALEWAY_ORGANIZATION_ID}" \ | ||
create-image --channel beta)`, | ||
} | ||
channel string | ||
version string | ||
board string | ||
file string | ||
) | ||
|
||
func init() { | ||
Scaleway.AddCommand(cmdCreate) | ||
|
||
cmdCreate.Flags().StringVar(&channel, "channel", "stable", "Flatcar channel") | ||
cmdCreate.Flags().StringVar(&version, "version", "current", "Flatcar version") | ||
cmdCreate.Flags().StringVar(&board, "board", "amd64-usr", "board used for naming with default prefix and AMI architecture") | ||
cmdCreate.Flags().StringVar(&file, "file", "flatcar_production_scaleway_image.qcow2", "path to local Flatcar image (.qcow2)") | ||
} | ||
|
||
func runCreate(cmd *cobra.Command, args []string) error { | ||
if err := API.InitializeBucket(bucket); err != nil { | ||
return fmt.Errorf("creating bucket %s: %v", bucket, err) | ||
} | ||
|
||
f, err := os.Open(file) | ||
if err != nil { | ||
return fmt.Errorf("opening Flatcar image file %s: %v", file, err) | ||
} | ||
|
||
defer f.Close() | ||
|
||
key := fmt.Sprintf("%s/%s/%s/%s", channel, version, board, filepath.Base(file)) | ||
if err := API.UploadObject(f, bucket, key, true); err != nil { | ||
return fmt.Errorf("uploading Flatcar image file %s: %v", file, err) | ||
} | ||
|
||
ID, err := API.CreateSnapshot(context.Background(), bucket, key) | ||
if err != nil { | ||
return fmt.Errorf("creating Flatcar image: %v", err) | ||
} | ||
|
||
if err := API.DeleteObject(bucket, key); err != nil { | ||
return fmt.Errorf("deleting Flatcar image from s3 bucket: %s", fmt.Sprintf("s3://%s/%s", bucket, key)) | ||
} | ||
|
||
fmt.Println(ID) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package scaleway | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdGC = &cobra.Command{ | ||
Use: "gc", | ||
Short: "GC resources in Scaleway", | ||
Long: `Delete instances and images created over the given duration ago`, | ||
RunE: runGC, | ||
} | ||
|
||
gcDuration time.Duration | ||
) | ||
|
||
func init() { | ||
Scaleway.AddCommand(cmdGC) | ||
cmdGC.Flags().DurationVar(&gcDuration, "duration", 5*time.Hour, "how old resources must be before they're considered garbage") | ||
} | ||
|
||
func runGC(cmd *cobra.Command, args []string) error { | ||
if err := API.GC(context.Background(), gcDuration); err != nil { | ||
return fmt.Errorf("running garbage collection: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package scaleway | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/coreos/pkg/capnslog" | ||
"github.com/flatcar/mantle/cli" | ||
"github.com/flatcar/mantle/platform" | ||
"github.com/flatcar/mantle/platform/api/scaleway" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
plog = capnslog.NewPackageLogger("github.com/flatcar/mantle", "ore/scaleway") | ||
|
||
Scaleway = &cobra.Command{ | ||
Use: "scaleway [command]", | ||
Short: "scaleway image utilities", | ||
} | ||
|
||
API *scaleway.API | ||
region string | ||
zone string | ||
accessKey string | ||
secretKey string | ||
organizationID string | ||
projectID string | ||
) | ||
|
||
func init() { | ||
cli.WrapPreRun(Scaleway, preflightCheck) | ||
Scaleway.PersistentFlags().StringVar(®ion, "scaleway-region", "fr-par", "Scaleway region") | ||
Scaleway.PersistentFlags().StringVar(&zone, "scaleway-zone", "fr-par-1", "Scaleway region") | ||
Scaleway.PersistentFlags().StringVar(&accessKey, "scaleway-access-key", "", "Scaleway access key") | ||
Scaleway.PersistentFlags().StringVar(&secretKey, "scaleway-secret-key", "", "Scaleway secret key") | ||
Scaleway.PersistentFlags().StringVar(&organizationID, "scaleway-organization-id", "", "Scaleway organization ID") | ||
Scaleway.PersistentFlags().StringVar(&projectID, "scaleway-project-id", "", "Scaleway project ID") | ||
} | ||
|
||
func preflightCheck(cmd *cobra.Command, args []string) error { | ||
api, err := scaleway.New(&scaleway.Options{ | ||
Region: region, | ||
Zone: zone, | ||
AccessKey: accessKey, | ||
SecretKey: secretKey, | ||
OrganizationID: organizationID, | ||
ProjectID: projectID, | ||
Options: &platform.Options{}, | ||
}) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "could not create Scaleway API client: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
API = api | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.