-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support pause and resume clusters (#9)
* cluster creation final * validate map input * support update cluster * support pausing cluster * support resume cluster
- Loading branch information
Showing
5 changed files
with
177 additions
and
2 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,32 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// pauseCmd represents the list command | ||
var pauseCmd = &cobra.Command{ | ||
Use: "pause", | ||
Short: "Pause resources in YB Managed", | ||
Long: "Pause resources in YB Managed", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
//fmt.Println("pause called") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(pauseCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// pauseCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// pauseCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
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,54 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// pauseClusterCmd represents the cluster command | ||
var pauseClusterCmd = &cobra.Command{ | ||
Use: "cluster", | ||
Short: "Pause clusters in YugabyteDB Managed", | ||
Long: "Pause clusters in YugabyteDB Managed", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
apiClient, _ := getApiClient(context.Background()) | ||
accountID, _, _ := getAccountID(context.Background(), apiClient) | ||
projectID, _, _ := getProjectID(context.Background(), apiClient, accountID) | ||
clusterName, _ := cmd.Flags().GetString("cluster-name") | ||
clusterID, clusterIDOK, errMsg := getClusterID(context.Background(), apiClient, accountID, projectID, clusterName) | ||
if !clusterIDOK { | ||
fmt.Fprintf(os.Stderr, "Error when fetching cluster ID: %v\n", errMsg) | ||
return | ||
} | ||
|
||
_, _, err := apiClient.ClusterApi.PauseCluster(context.Background(), accountID, projectID, clusterID).Execute() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error while pausing the cluster %v: %v\n", clusterName, err.Error()) | ||
return | ||
} | ||
|
||
fmt.Fprintf(os.Stdout, "The cluster %v is being paused\n", clusterName) | ||
}, | ||
} | ||
|
||
func init() { | ||
pauseCmd.AddCommand(pauseClusterCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// pauseClusterCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// pauseClusterCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
pauseClusterCmd.Flags().String("cluster-name", "", "The name of the cluster to be paused") | ||
pauseClusterCmd.MarkFlagRequired("cluster-name") | ||
} |
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,32 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// resumeCmd represents the list command | ||
var resumeCmd = &cobra.Command{ | ||
Use: "resume", | ||
Short: "Resume resources in YB Managed", | ||
Long: "Resume resources in YB Managed", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
//fmt.Println("pause called")s | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(resumeCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// resumeCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// resumeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
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,54 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// resumeClusterCmd represents the cluster command | ||
var resumeClusterCmd = &cobra.Command{ | ||
Use: "cluster", | ||
Short: "Pause clusters in YugabyteDB Managed", | ||
Long: "Pause clusters in YugabyteDB Managed", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
apiClient, _ := getApiClient(context.Background()) | ||
accountID, _, _ := getAccountID(context.Background(), apiClient) | ||
projectID, _, _ := getProjectID(context.Background(), apiClient, accountID) | ||
clusterName, _ := cmd.Flags().GetString("cluster-name") | ||
clusterID, clusterIDOK, errMsg := getClusterID(context.Background(), apiClient, accountID, projectID, clusterName) | ||
if !clusterIDOK { | ||
fmt.Fprintf(os.Stderr, "Error when fetching cluster ID: %v\n", errMsg) | ||
return | ||
} | ||
|
||
_, _, err := apiClient.ClusterApi.ResumeCluster(context.Background(), accountID, projectID, clusterID).Execute() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error while resuming the cluster %v\n", clusterName) | ||
return | ||
} | ||
|
||
fmt.Fprintf(os.Stdout, "The cluster %v is being resumed\n", clusterName) | ||
}, | ||
} | ||
|
||
func init() { | ||
resumeCmd.AddCommand(resumeClusterCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// resumeClusterCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// resumeClusterCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
resumeClusterCmd.Flags().String("cluster-name", "", "The name of the cluster to be resumed") | ||
resumeClusterCmd.MarkFlagRequired("cluster-name") | ||
} |