mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-25 06:36:29 +09:00
cli: add nodes update-client command
This commit is contained in:
1 parent
bb4c690101
commit
931282a137
1 file changed
+53
@@ -2,6 +2,7 @@ package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
clientv1 "github.com/juanfont/headscale/gen/client/v1"
|
||||
clientv2 "github.com/juanfont/headscale/gen/client/v2"
|
||||
"github.com/juanfont/headscale/hscontrol/util"
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/samber/lo"
|
||||
@@ -17,6 +19,8 @@ import (
|
||||
"tailscale.com/types/key"
|
||||
)
|
||||
|
||||
var errClientUpdateNotStarted = errors.New("node did not start the client update")
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(nodeCmd)
|
||||
listNodesCmd.Flags().StringP("user", "u", "", "Filter by user")
|
||||
@@ -55,6 +59,11 @@ func init() {
|
||||
nodeCmd.AddCommand(approveRoutesCmd)
|
||||
|
||||
nodeCmd.AddCommand(backfillNodeIPsCmd)
|
||||
|
||||
updateClientCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")
|
||||
updateClientCmd.Flags().Bool("force", false, "Update even if the node has active Tailscale SSH sessions")
|
||||
mustMarkRequired(updateClientCmd, "identifier")
|
||||
nodeCmd.AddCommand(updateClientCmd)
|
||||
}
|
||||
|
||||
var nodeCmd = &cobra.Command{
|
||||
@@ -258,6 +267,50 @@ var renameNodeCmd = &cobra.Command{
|
||||
}),
|
||||
}
|
||||
|
||||
var updateClientCmd = &cobra.Command{
|
||||
Use: "update-client",
|
||||
Short: "Update the Tailscale client of a connected node",
|
||||
Long: `Ask a connected node to update its Tailscale client to the latest stable release.
|
||||
|
||||
The node only starts the update if it has auto-updates enabled
|
||||
("tailscale set --auto-update") and its platform supports them.
|
||||
The command returns once the update has started, not when it has finished.`,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
identifier, _ := cmd.Flags().GetUint64("identifier")
|
||||
force, _ := cmd.Flags().GetBool("force")
|
||||
|
||||
ctx, client, cancel, err := newV2Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
resp, err := client.UpdateDeviceClientWithResponse(ctx, strconv.FormatUint(identifier, util.Base10), clientv2.UpdateDeviceClientRequest{
|
||||
Force: &force,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("updating node client: %w", err)
|
||||
}
|
||||
|
||||
err = v2Error(resp.HTTPResponse.StatusCode, resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
update := resp.JSON200
|
||||
if !update.Started {
|
||||
reason := update.Error
|
||||
if reason == "" {
|
||||
reason = fmt.Sprintf("enabled=%t, supported=%t", update.Enabled, update.Supported)
|
||||
}
|
||||
|
||||
return fmt.Errorf("%w: %s", errClientUpdateNotStarted, reason)
|
||||
}
|
||||
|
||||
return printOutput(cmd, update, "Client update started")
|
||||
},
|
||||
}
|
||||
|
||||
var deleteNodeCmd = &cobra.Command{
|
||||
Use: cmdDelete,
|
||||
Short: "Delete a node",
|
||||
|
||||
Reference in new issue
Block a user