mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-13 21:22:40 +08:00
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package functions
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gravitl/netmaker/models"
|
|
)
|
|
|
|
type hostNetworksUpdatePayload struct {
|
|
Networks []string `json:"networks"`
|
|
}
|
|
|
|
// GetHosts - fetch all host entries
|
|
func GetHosts() *[]models.ApiHost {
|
|
return request[[]models.ApiHost](http.MethodGet, "/api/hosts", nil)
|
|
}
|
|
|
|
// DeleteHost - delete a host
|
|
func DeleteHost(hostID string) *models.ApiHost {
|
|
return request[models.ApiHost](http.MethodDelete, "/api/hosts/"+hostID, nil)
|
|
}
|
|
|
|
// UpdateHost - update a host
|
|
func UpdateHost(hostID string, body *models.ApiHost) *models.ApiHost {
|
|
return request[models.ApiHost](http.MethodPut, "/api/hosts/"+hostID, body)
|
|
}
|
|
|
|
// AddHostToNetwork - add a network to host
|
|
func AddHostToNetwork(hostID, network string) *hostNetworksUpdatePayload {
|
|
return request[hostNetworksUpdatePayload](http.MethodPost, "/api/hosts/"+hostID+"/networks/"+network, nil)
|
|
}
|
|
|
|
// DeleteHostFromNetwork - deletes a network from host
|
|
func DeleteHostFromNetwork(hostID, network string) *hostNetworksUpdatePayload {
|
|
return request[hostNetworksUpdatePayload](http.MethodDelete, "/api/hosts/"+hostID+"/networks/"+network, nil)
|
|
}
|
|
|
|
// 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)
|
|
}
|