mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-10 15:14:22 +08:00
add enable/disable failover in nmctl command (#2857)
This commit is contained in:
parent
4871a0dd1c
commit
b59658024c
5 changed files with 88 additions and 0 deletions
20
cli/cmd/failover/disable.go
Normal file
20
cli/cmd/failover/disable.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package failover
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gravitl/netmaker/cli/functions"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var disableFailoverCmd = &cobra.Command{
|
||||||
|
Use: "disable [NODE ID]",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Short: "Disable failover for a given Node",
|
||||||
|
Long: `Disable failover for a given Node`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
functions.PrettyPrint(functions.DisableNodeFailover(args[0]))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(disableFailoverCmd)
|
||||||
|
}
|
20
cli/cmd/failover/enable.go
Normal file
20
cli/cmd/failover/enable.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package failover
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gravitl/netmaker/cli/functions"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var enableFailoverCmd = &cobra.Command{
|
||||||
|
Use: "enable [NODE ID]",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Short: "Enable failover for a given Node",
|
||||||
|
Long: `Enable failover for a given Node`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
functions.PrettyPrint(functions.EnableNodeFailover(args[0]))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(enableFailoverCmd)
|
||||||
|
}
|
28
cli/cmd/failover/root.go
Normal file
28
cli/cmd/failover/root.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package failover
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// rootCmd represents the base command when called without any subcommands
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "failover",
|
||||||
|
Short: "Enable/Disable failover for a node associated with a network",
|
||||||
|
Long: `Enable/Disable failover for a node associated with a network`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRoot returns the root subcommand
|
||||||
|
func GetRoot() *cobra.Command {
|
||||||
|
return rootCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
|
func Execute() {
|
||||||
|
err := rootCmd.Execute()
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/gravitl/netmaker/cli/cmd/dns"
|
"github.com/gravitl/netmaker/cli/cmd/dns"
|
||||||
"github.com/gravitl/netmaker/cli/cmd/enrollment_key"
|
"github.com/gravitl/netmaker/cli/cmd/enrollment_key"
|
||||||
"github.com/gravitl/netmaker/cli/cmd/ext_client"
|
"github.com/gravitl/netmaker/cli/cmd/ext_client"
|
||||||
|
"github.com/gravitl/netmaker/cli/cmd/failover"
|
||||||
"github.com/gravitl/netmaker/cli/cmd/host"
|
"github.com/gravitl/netmaker/cli/cmd/host"
|
||||||
"github.com/gravitl/netmaker/cli/cmd/metrics"
|
"github.com/gravitl/netmaker/cli/cmd/metrics"
|
||||||
"github.com/gravitl/netmaker/cli/cmd/network"
|
"github.com/gravitl/netmaker/cli/cmd/network"
|
||||||
|
@ -53,4 +54,5 @@ func init() {
|
||||||
rootCmd.AddCommand(metrics.GetRoot())
|
rootCmd.AddCommand(metrics.GetRoot())
|
||||||
rootCmd.AddCommand(host.GetRoot())
|
rootCmd.AddCommand(host.GetRoot())
|
||||||
rootCmd.AddCommand(enrollment_key.GetRoot())
|
rootCmd.AddCommand(enrollment_key.GetRoot())
|
||||||
|
rootCmd.AddCommand(failover.GetRoot())
|
||||||
}
|
}
|
||||||
|
|
18
cli/functions/failover.go
Normal file
18
cli/functions/failover.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package functions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gravitl/netmaker/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EnableNodeFailover - Enable failover for a given Node
|
||||||
|
func EnableNodeFailover(nodeID string) *models.SuccessResponse {
|
||||||
|
return request[models.SuccessResponse](http.MethodPost, fmt.Sprintf("/api/v1/node/%s/failover", nodeID), nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableNodeFailover - Disable failover for a given Node
|
||||||
|
func DisableNodeFailover(nodeID string) *models.SuccessResponse {
|
||||||
|
return request[models.SuccessResponse](http.MethodDelete, fmt.Sprintf("/api/v1/node/%s/failover", nodeID), nil)
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue