-
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.
Signed-off-by: Mathieu Tortuyaux <[email protected]>
- Loading branch information
Showing
5 changed files
with
160 additions
and
0 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
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,41 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package brightbox | ||
|
||
import ( | ||
"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(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,33 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package brightbox | ||
|
||
import ( | ||
"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(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,34 @@ | ||
// Copyright The Mantle Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package brightbox | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdGC = &cobra.Command{ | ||
Use: "gc", | ||
Short: "GC resources in Brightbox", | ||
Long: `Delete instances 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(gcDuration); err != nil { | ||
return fmt.Errorf("running garbage collection: %w", err) | ||
} | ||
|
||
return nil | ||
} |