-
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 #567 from flatcar/tormath1/akamai
platform: add Akamai to the tested platforms
- Loading branch information
Showing
251 changed files
with
50,681 additions
and
1,285 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/akamai" | ||
) | ||
|
||
func init() { | ||
root.AddCommand(akamai.Akamai) | ||
} |
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,49 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package akamai | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/coreos/pkg/capnslog" | ||
"github.com/flatcar/mantle/cli" | ||
"github.com/flatcar/mantle/platform" | ||
"github.com/flatcar/mantle/platform/api/akamai" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
plog = capnslog.NewPackageLogger("github.com/flatcar/mantle", "ore/akamai") | ||
|
||
Akamai = &cobra.Command{ | ||
Use: "akamai [command]", | ||
Short: "akamai image utilities", | ||
} | ||
|
||
api *akamai.API | ||
region string | ||
token string | ||
) | ||
|
||
func init() { | ||
cli.WrapPreRun(Akamai, preflightCheck) | ||
Akamai.PersistentFlags().StringVar(®ion, "akamai-region", "us-ord", "Akamai region") | ||
Akamai.PersistentFlags().StringVar(&token, "akamai-token", "", "Akamai access token") | ||
} | ||
|
||
func preflightCheck(cmd *cobra.Command, args []string) error { | ||
a, err := akamai.New(&akamai.Options{ | ||
Region: region, | ||
Token: token, | ||
Options: &platform.Options{}, | ||
}) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "could not create Akamai API client: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
api = a | ||
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,43 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package akamai | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdCreate = &cobra.Command{ | ||
Use: "create-image", | ||
Short: "Create Akamai image", | ||
RunE: runCreate, | ||
Example: `IMAGE_ID=$(ore akamai \ | ||
--akamai-token "${AKAMAI_TOKEN}" \ | ||
--akamai-region "${AKAMAI_REGION}" \ | ||
create-image --name my-image --file /path/to/flatcar_production_akamai_image.bin.gz)`, | ||
} | ||
file string | ||
name string | ||
) | ||
|
||
func init() { | ||
Akamai.AddCommand(cmdCreate) | ||
|
||
cmdCreate.Flags().StringVar(&file, "file", "flatcar_production_akamai_image.bin.gz", "path to local Flatcar image (.bin.gz)") | ||
cmdCreate.Flags().StringVar(&name, "name", "flatcar-kola-test", "name of the image") | ||
} | ||
|
||
func runCreate(cmd *cobra.Command, args []string) error { | ||
ID, err := api.UploadImage(context.Background(), name, file) | ||
if err != nil { | ||
return fmt.Errorf("creating Flatcar image: %v", err) | ||
} | ||
|
||
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,35 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package akamai | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdGC = &cobra.Command{ | ||
Use: "gc", | ||
Short: "GC resources in Akamai", | ||
Long: `Delete instances and images created over the given duration ago`, | ||
RunE: runGC, | ||
} | ||
|
||
gcDuration time.Duration | ||
) | ||
|
||
func init() { | ||
Akamai.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(cmd.Context(), 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
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.