Skip to content

Commit 7cf2bb4

Browse files
committed
feat: update IP
1 parent e79aa86 commit 7cf2bb4

File tree

8 files changed

+1976
-772
lines changed

8 files changed

+1976
-772
lines changed

cmd/headscale/cli/nodes.go

+67
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,73 @@ func init() {
100100
nodeCmd.AddCommand(tagCmd)
101101

102102
nodeCmd.AddCommand(backfillNodeIPsCmd)
103+
104+
updateIPCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")
105+
err = updateIPCmd.MarkFlagRequired("identifier")
106+
if err != nil {
107+
log.Fatal(err.Error())
108+
}
109+
nodeCmd.AddCommand(updateIPCmd)
110+
}
111+
112+
var updateIPCmd = &cobra.Command{
113+
Use: "ip ID NEW_IP",
114+
Short: "Update a node's IP address",
115+
Run: func(cmd *cobra.Command, args []string) {
116+
output, _ := cmd.Flags().GetString("output")
117+
118+
identifier, err := cmd.Flags().GetUint64("identifier")
119+
if err != nil {
120+
ErrorOutput(
121+
err,
122+
fmt.Sprintf("Error converting ID to integer: %s", err),
123+
output,
124+
)
125+
return
126+
}
127+
128+
newIP := ""
129+
130+
if len(args) == 0 {
131+
ErrorOutput(
132+
fmt.Errorf("missing IP address"),
133+
"IP address parameter is required",
134+
output,
135+
)
136+
return
137+
}
138+
139+
newIP = args[0]
140+
if _, err := netip.ParseAddr(newIP); err != nil {
141+
ErrorOutput(
142+
err,
143+
fmt.Sprintf("Invalid IP address: %s", newIP),
144+
output,
145+
)
146+
return
147+
}
148+
149+
ctx, client, conn, cancel := newHeadscaleCLIWithConfig()
150+
defer cancel()
151+
defer conn.Close()
152+
153+
request := &v1.UpdateIPRequest{
154+
NodeId: identifier,
155+
NewIp: newIP,
156+
}
157+
158+
response, err := client.UpdateIP(ctx, request)
159+
if err != nil {
160+
ErrorOutput(
161+
err,
162+
fmt.Sprintf("Cannot update node IP: %s", status.Convert(err).Message()),
163+
output,
164+
)
165+
return
166+
}
167+
168+
SuccessOutput(response.GetNode(), fmt.Sprintf("Node %d IP updated to %s", identifier, newIP), output)
169+
},
103170
}
104171

105172
var nodeCmd = &cobra.Command{

gen/go/headscale/v1/headscale.pb.go

+461-317
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)