diff --git a/cli/cmd/network/delete.go b/cli/cmd/network/delete.go new file mode 100644 index 00000000..a5f9bcf4 --- /dev/null +++ b/cli/cmd/network/delete.go @@ -0,0 +1,22 @@ +package network + +import ( + "fmt" + + "github.com/gravitl/netmaker/cli/functions" + "github.com/spf13/cobra" +) + +var networkDeleteCmd = &cobra.Command{ + Use: "delete [NAME]", + Short: "Delete a Network", + Long: `Delete a Network`, + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(*functions.DeleteNetwork(args[0])) + }, +} + +func init() { + rootCmd.AddCommand(networkDeleteCmd) +} diff --git a/cli/cmd/network/get.go b/cli/cmd/network/get.go index 9a91aeb4..fbeef51f 100644 --- a/cli/cmd/network/get.go +++ b/cli/cmd/network/get.go @@ -5,7 +5,6 @@ import ( "github.com/spf13/cobra" ) -// networkGetCmd represents the networkCreate command var networkGetCmd = &cobra.Command{ Use: "get [NAME]", Short: "Get a Network", diff --git a/cli/cmd/network/list.go b/cli/cmd/network/list.go index 51de86e9..cbaa1bac 100644 --- a/cli/cmd/network/list.go +++ b/cli/cmd/network/list.go @@ -9,7 +9,6 @@ import ( "github.com/spf13/cobra" ) -// networkListCmd represents the networkCreate command var networkListCmd = &cobra.Command{ Use: "list", Short: "List all Networks", diff --git a/cli/cmd/network/node_limit.go b/cli/cmd/network/node_limit.go new file mode 100644 index 00000000..514bcf05 --- /dev/null +++ b/cli/cmd/network/node_limit.go @@ -0,0 +1,27 @@ +package network + +import ( + "log" + "strconv" + + "github.com/gravitl/netmaker/cli/functions" + "github.com/spf13/cobra" +) + +var networkNodeLimitCmd = &cobra.Command{ + Use: "node_limit [NAME] [NEW LIMIT]", + Short: "Update network nodel limit", + Long: `Update network nodel limit`, + Args: cobra.ExactArgs(2), + Run: func(cmd *cobra.Command, args []string) { + nodelimit, err := strconv.ParseInt(args[1], 10, 32) + if err != nil { + log.Fatal(err) + } + functions.PrettyPrint(functions.UpdateNetworkNodeLimit(args[0], int32(nodelimit))) + }, +} + +func init() { + rootCmd.AddCommand(networkNodeLimitCmd) +} diff --git a/cli/cmd/network/update.go b/cli/cmd/network/update.go new file mode 100644 index 00000000..ca67e2d5 --- /dev/null +++ b/cli/cmd/network/update.go @@ -0,0 +1,33 @@ +package network + +import ( + "encoding/json" + "io/ioutil" + "log" + + "github.com/gravitl/netmaker/cli/functions" + "github.com/gravitl/netmaker/models" + "github.com/spf13/cobra" +) + +var networkUpdateCmd = &cobra.Command{ + Use: "update [NAME] [/path/to/network_definition.json]", + Short: "Update a Network", + Long: `Update a Network`, + Args: cobra.ExactArgs(2), + Run: func(cmd *cobra.Command, args []string) { + content, err := ioutil.ReadFile(args[1]) + if err != nil { + log.Fatal("Error when opening file: ", err) + } + network := &models.Network{} + if err := json.Unmarshal(content, network); err != nil { + log.Fatal(err) + } + functions.PrettyPrint(functions.UpdateNetwork(args[0], network)) + }, +} + +func init() { + rootCmd.AddCommand(networkUpdateCmd) +} diff --git a/cli/functions/network.go b/cli/functions/network.go index b1f7fcc2..3d2f0ef2 100644 --- a/cli/functions/network.go +++ b/cli/functions/network.go @@ -1,6 +1,7 @@ package functions import ( + "fmt" "net/http" "github.com/gravitl/netmaker/models" @@ -16,6 +17,13 @@ func UpdateNetwork(name string, payload *models.Network) *models.Network { return request[models.Network](http.MethodPut, "/api/networks/"+name, payload) } +// UpdateNetworkNodeLimit - updates a network +func UpdateNetworkNodeLimit(name string, nodeLimit int32) *models.Network { + return request[models.Network](http.MethodPut, fmt.Sprintf("/api/networks/%s/nodelimit", name), &models.Network{ + NodeLimit: nodeLimit, + }) +} + // GetNetworks - fetch all networks func GetNetworks() *[]models.Network { return request[[]models.Network](http.MethodGet, "/api/networks", nil) @@ -25,3 +33,8 @@ func GetNetworks() *[]models.Network { func GetNetwork(name string) *models.Network { return request[models.Network](http.MethodGet, "/api/networks/"+name, nil) } + +// DeleteNetwork - delete a network +func DeleteNetwork(name string) *string { + return request[string](http.MethodDelete, "/api/networks/"+name, nil) +} diff --git a/cli/samples/network.json b/cli/samples/network.json index 3ffc3288..d939fcd4 100644 --- a/cli/samples/network.json +++ b/cli/samples/network.json @@ -7,6 +7,7 @@ "defaultpostup": "", "defaultpostdown": "", "defaultkeepalive": 20, + "defaultinterface": "nm-test3", "accesskeys": [], "allowmanualsignup": "no", "islocal": "no",