add force flag to host/node delete (#2548)

* add force flag to host/node delete

* review comments

---------

Co-authored-by: Abhishek K <32607604+abhishek9686@users.noreply.github.com>
This commit is contained in:
Matthew R Kasun 2023-09-13 00:40:17 -04:00 committed by GitHub
parent 5074e56e6a
commit 823182cf09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View file

@ -5,16 +5,19 @@ import (
"github.com/spf13/cobra"
)
var force bool
var hostDeleteCmd = &cobra.Command{
Use: "delete HostID",
Args: cobra.ExactArgs(1),
Short: "Delete a host",
Long: `Delete a host`,
Run: func(cmd *cobra.Command, args []string) {
functions.PrettyPrint(functions.DeleteHost(args[0]))
functions.PrettyPrint(functions.DeleteHost(args[0], force))
},
}
func init() {
rootCmd.AddCommand(hostDeleteCmd)
hostDeleteCmd.PersistentFlags().BoolVarP(&force, "force", "f", false, "delete even if part of network(s)")
}

View file

@ -5,16 +5,19 @@ import (
"github.com/spf13/cobra"
)
var force bool
var nodeDeleteCmd = &cobra.Command{
Use: "delete [NETWORK NAME] [NODE ID]",
Args: cobra.ExactArgs(2),
Short: "Delete a Node",
Long: `Delete a Node`,
Run: func(cmd *cobra.Command, args []string) {
functions.PrettyPrint(functions.DeleteNode(args[0], args[1]))
functions.PrettyPrint(functions.DeleteNode(args[0], args[1], force))
},
}
func init() {
rootCmd.AddCommand(nodeDeleteCmd)
nodeDeleteCmd.PersistentFlags().BoolVarP(&force, "force", "f", false, "force delete a node")
}

View file

@ -17,8 +17,8 @@ func GetHosts() *[]models.ApiHost {
}
// DeleteHost - delete a host
func DeleteHost(hostID string) *models.ApiHost {
return request[models.ApiHost](http.MethodDelete, "/api/hosts/"+hostID, nil)
func DeleteHost(hostID string, force bool) *models.ApiHost {
return request[models.ApiHost](http.MethodDelete, fmt.Sprintf("/api/hosts/%s?force=%t", hostID, force), nil)
}
// UpdateHost - update a host

View file

@ -27,8 +27,8 @@ func UpdateNode(networkName, nodeID string, node *models.ApiNode) *models.ApiNod
}
// DeleteNode - delete a node
func DeleteNode(networkName, nodeID string) *models.SuccessResponse {
return request[models.SuccessResponse](http.MethodDelete, fmt.Sprintf("/api/nodes/%s/%s", networkName, nodeID), nil)
func DeleteNode(networkName, nodeID string, force bool) *models.SuccessResponse {
return request[models.SuccessResponse](http.MethodDelete, fmt.Sprintf("/api/nodes/%s/%s?force=%t", networkName, nodeID, force), nil)
}
// CreateEgress - turn a node into an egress