mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-06 13:14:24 +08:00
move relay logic to hosts
This commit is contained in:
parent
030d1c4ae3
commit
02ba1ce6ae
6 changed files with 56 additions and 56 deletions
22
cli/cmd/host/create_relay.go
Normal file
22
cli/cmd/host/create_relay.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gravitl/netmaker/cli/functions"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var hostCreateRelayCmd = &cobra.Command{
|
||||
Use: "create_relay [HOST ID] [RELAYED HOST IDS (comma separated)]",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Short: "Turn a Host into a Relay",
|
||||
Long: `Turn a Host into a Relay`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
functions.PrettyPrint(functions.CreateRelay(args[0], strings.Split(args[1], ",")))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(hostCreateRelayCmd)
|
||||
}
|
20
cli/cmd/host/delete_relay.go
Normal file
20
cli/cmd/host/delete_relay.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
"github.com/gravitl/netmaker/cli/functions"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var hostDeleteRelayCmd = &cobra.Command{
|
||||
Use: "delete_relay [HOST ID]",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Short: "Delete Relay role from a host",
|
||||
Long: `Delete Relay role from a host`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
functions.PrettyPrint(functions.DeleteRelay(args[0]))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(hostDeleteRelayCmd)
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package node
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gravitl/netmaker/cli/functions"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var nodeCreateRelayCmd = &cobra.Command{
|
||||
Use: "create_relay [NETWORK NAME] [NODE ID] [RELAY ADDRESSES (comma separated)]",
|
||||
Args: cobra.ExactArgs(3),
|
||||
Short: "Turn a Node into a Relay",
|
||||
Long: `Turn a Node into a Relay`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
functions.PrettyPrint(functions.CreateRelay(args[0], args[1], strings.Split(args[2], ",")))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(nodeCreateRelayCmd)
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package node
|
||||
|
||||
import (
|
||||
"github.com/gravitl/netmaker/cli/functions"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var nodeDeleteRelayCmd = &cobra.Command{
|
||||
Use: "delete_relay [NETWORK NAME] [NODE ID]",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Short: "Delete Relay role from a Node",
|
||||
Long: `Delete Relay role from a Node`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
functions.PrettyPrint(functions.DeleteRelay(args[0], args[1]))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(nodeDeleteRelayCmd)
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package functions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gravitl/netmaker/models"
|
||||
|
@ -31,3 +32,16 @@ func UpdateHostNetworks(hostID string, networks []string) *hostNetworksUpdatePay
|
|||
Networks: networks,
|
||||
})
|
||||
}
|
||||
|
||||
// CreateRelay - turn a host into a relay
|
||||
func CreateRelay(hostID string, relayedHosts []string) *models.ApiHost {
|
||||
return request[models.ApiHost](http.MethodPost, fmt.Sprintf("/api/hosts/%s/relay", hostID), &models.HostRelayRequest{
|
||||
HostID: hostID,
|
||||
RelayedHosts: relayedHosts,
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteRelay - remove relay role from a host
|
||||
func DeleteRelay(hostID string) *models.ApiHost {
|
||||
return request[models.ApiHost](http.MethodDelete, fmt.Sprintf("/api/hosts/%s/relay", hostID), nil)
|
||||
}
|
||||
|
|
|
@ -31,20 +31,6 @@ func DeleteNode(networkName, nodeID string) *models.SuccessResponse {
|
|||
return request[models.SuccessResponse](http.MethodDelete, fmt.Sprintf("/api/nodes/%s/%s", networkName, nodeID), nil)
|
||||
}
|
||||
|
||||
// CreateRelay - turn a node into a relay
|
||||
func CreateRelay(networkName, nodeID string, relayAddresses []string) *models.ApiNode {
|
||||
return request[models.ApiNode](http.MethodPost, fmt.Sprintf("/api/nodes/%s/%s/createrelay", networkName, nodeID), &models.RelayRequest{
|
||||
NetID: networkName,
|
||||
NodeID: nodeID,
|
||||
RelayAddrs: relayAddresses,
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteRelay - remove relay role from a node
|
||||
func DeleteRelay(networkName, nodeID string) *models.ApiNode {
|
||||
return request[models.ApiNode](http.MethodDelete, fmt.Sprintf("/api/nodes/%s/%s/deleterelay", networkName, nodeID), nil)
|
||||
}
|
||||
|
||||
// CreateEgress - turn a node into an egress
|
||||
func CreateEgress(networkName, nodeID string, payload *models.EgressGatewayRequest) *models.ApiNode {
|
||||
return request[models.ApiNode](http.MethodPost, fmt.Sprintf("/api/nodes/%s/%s/creategateway", networkName, nodeID), payload)
|
||||
|
|
Loading…
Add table
Reference in a new issue