Files
netmaker/cli/cmd/host/update.go
Gabriel de Souza Seibel cb4b99ffcb [NET-562] Persistent Keep Alive from node to host (#2604)
* Move PKA field from models node to host level

* Move PKA field from api models node to host level

* Adapt logic package to node->host PKA

* Adapt migration-related code to node->host PKA

* Adapt cli code to node->host PKA

* Change host PKA default to 20s

* On IfaceDelta, check for PKA on host

* On handleHostRegister, set default PKA

* Use a default PKA

* Use int64 for api host pka

* Reorder imports

* Don't use host pka in iface delta

* Fix ConvertAPIHostToNMHost

* Add swagger doc for host PKA field

* Fix swagger.yml

* Set default PKA only for new hosts

* Remove TODO comment

* Remove redundant check

* Have api-host pka be specified in seconds
2023-10-06 10:09:19 +04:00

65 lines
1.8 KiB
Go

package host
import (
"encoding/json"
"log"
"os"
"github.com/spf13/cobra"
"github.com/gravitl/netmaker/cli/functions"
"github.com/gravitl/netmaker/models"
)
var (
apiHostFilePath string
endpoint string
name string
listenPort int
mtu int
isStatic bool
isDefault bool
keepAlive int
)
var hostUpdateCmd = &cobra.Command{
Use: "update HostID",
Args: cobra.ExactArgs(1),
Short: "Update a host",
Long: `Update a host`,
Run: func(cmd *cobra.Command, args []string) {
apiHost := &models.ApiHost{}
if apiHostFilePath != "" {
content, err := os.ReadFile(apiHostFilePath)
if err != nil {
log.Fatal("Error when opening file: ", err)
}
if err := json.Unmarshal(content, apiHost); err != nil {
log.Fatal(err)
}
} else {
apiHost.ID = args[0]
apiHost.EndpointIP = endpoint
apiHost.Name = name
apiHost.ListenPort = listenPort
apiHost.MTU = mtu
apiHost.IsStatic = isStatic
apiHost.IsDefault = isDefault
apiHost.PersistentKeepalive = keepAlive
}
functions.PrettyPrint(functions.UpdateHost(args[0], apiHost))
},
}
func init() {
hostUpdateCmd.Flags().StringVar(&apiHostFilePath, "file", "", "Path to host_definition.json")
hostUpdateCmd.Flags().StringVar(&endpoint, "endpoint", "", "Endpoint of the Host")
hostUpdateCmd.Flags().StringVar(&name, "name", "", "Host name")
hostUpdateCmd.Flags().IntVar(&listenPort, "listen_port", 0, "Listen port of the host")
hostUpdateCmd.Flags().IntVar(&mtu, "mtu", 0, "Host MTU size")
hostUpdateCmd.Flags().IntVar(&keepAlive, "keep_alive", 0, "Interval (seconds) in which packets are sent to keep connections open with peers")
hostUpdateCmd.Flags().BoolVar(&isStatic, "static", false, "Make Host Static ?")
hostUpdateCmd.Flags().BoolVar(&isDefault, "default", false, "Make Host Default ?")
rootCmd.AddCommand(hostUpdateCmd)
}