Repository navigation
Expand file tree
/
Copy pathreset.go
More file actions
78 lines (70 loc) · 3 KB
/
Copy pathreset.go
File metadata and controls
78 lines (70 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package cli
import (
"context"
"github.com/urfave/cli/v3"
"github.com/umatare5/cisco-wnc-cli/internal/config"
"github.com/umatare5/cisco-wnc-cli/internal/wnc"
)
// resetCommand groups the actions that restart something. Every leaf names one target, resolves
// it against the controller before acting, and asks first unless --yes was given.
func resetCommand() *cli.Command {
return &cli.Command{
Name: "reset",
Usage: "Restart an access point or its controller session",
Flags: execFlags(),
Action: parentAction,
Commands: []*cli.Command{resetAPCommand(), resetCAPWAPCommand()},
}
}
// resetAPCommand names its target with --ap-name. Both RPCs in this tree declare a mandatory choice
// offering an ap-name or a mac-addr arm, so the name an operator reads out of show ap goes on
// the wire and no address is spelled anywhere.
func resetAPCommand() *cli.Command {
return &cli.Command{
Name: leafAP,
Usage: "Restart one access point",
UsageText: synopsis(config.FlagAPName),
Description: "--ap-name is the ap_name column of wnc show ap. The controller resolves it\n" +
"first, so a name it holds no access point under is refused before the RPC.\n" +
"Pass --dry-run to name the target and change nothing.",
Flags: []cli.Flag{apNameFlag(), yesFlag()},
Action: runResetAP,
}
}
// resetCAPWAPCommand restarts the controller session rather than the access point. The
// access point's own uptime is unchanged across it, which makes this the smaller
// remedy and why it is a separate leaf rather than a flag on reset ap.
func resetCAPWAPCommand() *cli.Command {
return &cli.Command{
Name: "capwap",
Usage: "Reset one access point's controller session",
UsageText: synopsis(config.FlagAPName),
Description: "--ap-name is the ap_name column of wnc show ap. The controller resolves it\n" +
"first, so a name it holds no access point under is refused before the RPC.\n" +
"The access point does not reboot: only its CAPWAP session is re-established.\n" +
"Pass --dry-run to name the target and change nothing.",
Flags: []cli.Flag{apNameFlag(), yesFlag()},
Action: runResetCAPWAP,
}
}
func runResetAP(ctx context.Context, cmd *cli.Command) error {
return runAPAction(ctx, cmd, writeWording{
question: "Reset %s on %s? Its clients disconnect for about four minutes. [y/N]: ",
dryRun: "%s on %s: would reset\n",
sent: "%s on %s: reset sent\n",
failed: "resetting %s on %s",
}, func(ctx context.Context, c *wnc.Client, name string) error {
return c.ResetAP(ctx, name)
})
}
func runResetCAPWAP(ctx context.Context, cmd *cli.Command) error {
return runAPAction(ctx, cmd, writeWording{
question: "Reset the CAPWAP session of %s on %s? " +
"It rejoins within about ten seconds and does not reboot. [y/N]: ",
dryRun: "%s on %s: would reset the CAPWAP session\n",
sent: "%s on %s: CAPWAP reset sent\n",
failed: "resetting the CAPWAP session of %s on %s",
}, func(ctx context.Context, c *wnc.Client, name string) error {
return c.ResetCAPWAP(ctx, name)
})
}