-
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 #484 from flatcar/tormath1/brightbox
kola: add brightbox support
- Loading branch information
Showing
556 changed files
with
7,913 additions
and
1,261 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,11 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package main | ||
|
||
import ( | ||
"github.com/flatcar/mantle/cmd/ore/brightbox" | ||
) | ||
|
||
func init() { | ||
root.AddCommand(brightbox.Brightbox) | ||
} |
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,41 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package brightbox | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/coreos/pkg/capnslog" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/flatcar/mantle/cli" | ||
"github.com/flatcar/mantle/platform/api/brightbox" | ||
) | ||
|
||
var ( | ||
plog = capnslog.NewPackageLogger("github.com/flatcar/mantle", "ore/brightbox") | ||
|
||
Brightbox = &cobra.Command{ | ||
Use: "brightbox [command]", | ||
Short: "Brightbox machine utilities", | ||
} | ||
|
||
API *brightbox.API | ||
options brightbox.Options | ||
) | ||
|
||
func init() { | ||
Brightbox.PersistentFlags().StringVar(&options.ClientID, "brightbox-client-id", "", "Brightbox client ID") | ||
Brightbox.PersistentFlags().StringVar(&options.ClientSecret, "brightbox-client-secret", "", "Brightbox client secret") | ||
cli.WrapPreRun(Brightbox, preflightCheck) | ||
} | ||
|
||
func preflightCheck(cmd *cobra.Command, args []string) error { | ||
api, err := brightbox.New(&options) | ||
if err != nil { | ||
return fmt.Errorf("creating Brightbox client: %w", err) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package brightbox | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdCreate = &cobra.Command{ | ||
Use: "create-image", | ||
Short: "Create image on Brightbox", | ||
Long: `Upload an image to Brigthbox. | ||
After a successful run, the final line of output will be the ID of the image. | ||
`, | ||
RunE: runCreate, | ||
} | ||
|
||
url, name string | ||
) | ||
|
||
func init() { | ||
Brightbox.AddCommand(cmdCreate) | ||
cmdCreate.Flags().StringVar(&url, "url", | ||
"https://stable.release.flatcar-linux.net/amd64-usr/current/flatcar_production_openstack_image.img", | ||
"Flatcar image URL") | ||
cmdCreate.Flags().StringVar(&name, "name", "", "image name") | ||
} | ||
|
||
func runCreate(cmd *cobra.Command, args []string) error { | ||
id, err := API.UploadImage(context.Background(), name, url) | ||
if err != nil { | ||
return fmt.Errorf("creating an image: %w", 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,34 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package brightbox | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdDelete = &cobra.Command{ | ||
Use: "delete-image", | ||
Short: "Delete image on Brightbox", | ||
Long: `Delete an image from Brightbox.`, | ||
RunE: runDelete, | ||
} | ||
|
||
id string | ||
) | ||
|
||
func init() { | ||
Brightbox.AddCommand(cmdDelete) | ||
cmdDelete.Flags().StringVar(&id, "id", "", "image ID") | ||
} | ||
|
||
func runDelete(cmd *cobra.Command, args []string) error { | ||
if err := API.DeleteImage(context.Background(), id); err != nil { | ||
return fmt.Errorf("deleting image: %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,35 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package brightbox | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdGC = &cobra.Command{ | ||
Use: "gc", | ||
Short: "GC resources in Brightbox", | ||
Long: `Delete instances and images created over the given duration ago`, | ||
RunE: runGC, | ||
} | ||
|
||
gcDuration time.Duration | ||
) | ||
|
||
func init() { | ||
Brightbox.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,31 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package brightbox | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdRemoveCloudIPs = &cobra.Command{ | ||
Use: "remove-ips", | ||
Short: "Remove any remaining cloud IPs", | ||
Long: `Remove left overs IP from previous garbage collection`, | ||
RunE: removeCloudIPs, | ||
} | ||
) | ||
|
||
func init() { | ||
Brightbox.AddCommand(cmdRemoveCloudIPs) | ||
} | ||
|
||
func removeCloudIPs(cmd *cobra.Command, args []string) error { | ||
if err := API.RemoveCloudIPs(context.Background()); err != nil { | ||
return fmt.Errorf("removing cloud IPs: %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,31 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package brightbox | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdRemoveServers = &cobra.Command{ | ||
Use: "remove-servers", | ||
Short: "Remove any remaining servers", | ||
Long: `Remove left overs server from previous garbage collection`, | ||
RunE: removeServers, | ||
} | ||
) | ||
|
||
func init() { | ||
Brightbox.AddCommand(cmdRemoveServers) | ||
} | ||
|
||
func removeServers(cmd *cobra.Command, args []string) error { | ||
if err := API.RemoveServers(context.Background()); err != nil { | ||
return fmt.Errorf("removing servers: %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
Oops, something went wrong.