mirror of
https://github.com/gravitl/netmaker.git
synced 2024-09-20 15:26:04 +08:00
implement network delete and update node_limit
This commit is contained in:
parent
fe5ea81550
commit
dddfab263c
22
cli/cmd/network/delete.go
Normal file
22
cli/cmd/network/delete.go
Normal file
|
@ -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)
|
||||
}
|
|
@ -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",
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// networkListCmd represents the networkCreate command
|
||||
var networkListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List all Networks",
|
||||
|
|
27
cli/cmd/network/node_limit.go
Normal file
27
cli/cmd/network/node_limit.go
Normal file
|
@ -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)
|
||||
}
|
33
cli/cmd/network/update.go
Normal file
33
cli/cmd/network/update.go
Normal file
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"defaultpostup": "",
|
||||
"defaultpostdown": "",
|
||||
"defaultkeepalive": 20,
|
||||
"defaultinterface": "nm-test3",
|
||||
"accesskeys": [],
|
||||
"allowmanualsignup": "no",
|
||||
"islocal": "no",
|
||||
|
|
Loading…
Reference in a new issue