small pixel drawing of a pufferfish cascade

add cascade ls members
Jes Olson j3s@c3f.net
Tue, 21 Feb 2023 03:25:35 -0800
commit

a560dfbf0825c14addf08b4641364e8a2b550737

parent

8153ee2551607e2480556b58abb85f9f83605b6a

M api/agent.goapi/agent.go

@@ -23,6 +23,23 @@ DelegateMax uint8

DelegateCur uint8 } +func (am *AgentMember) StatusPretty() string { + result := "unknown" + switch am.Status { + case 0: + result = "none" + case 1: + result = "alive" + case 2: + result = "leaving" + case 3: + result = "left" + case 4: + result = "failed" + } + return result +} + // XXX: this may be needed for consul compatability, but I'm leaving it // out for now in case it isn't. const AllSegments = "_all"
A command/list/list.go

@@ -0,0 +1,24 @@

+package list + +import ( + "fmt" + "os" + + "git.j3s.sh/cascade/command/list/members" +) + +const usage = `cascade ls nodes +cascade ls members +cascade ls services +` + +func Run(args []string) { + if len(args) == 0 { + fmt.Printf(usage) + os.Exit(1) + } + switch args[0] { + case "members": + members.Run(args[1:]) + } +}
A command/list/members/members.go

@@ -0,0 +1,57 @@

+package members + +import ( + "flag" + "fmt" + "os" + + "git.j3s.sh/cascade/api" +) + +const usage = `cascade ls members [options] + + this command lists the members of the cascade serf + cluster. + +options: + + -api + address of the api to target (default = 127.0.0.1:8500) + + -l | -details + show more details (default = nil) +` + +type Flags struct { + apiAddr string + details bool +} + +var membersFlags Flags + +func Run(args []string) { + flags := flag.NewFlagSet("agent", flag.ContinueOnError) + flags.Usage = func() { fmt.Printf(usage) } + flags.StringVar(&membersFlags.apiAddr, "api", "", "") + flags.BoolVar(&membersFlags.details, "l", false, "") + flags.BoolVar(&membersFlags.details, "details", false, "") + flags.Parse(args) + + cfg := api.DefaultNonPooledConfig() + client, err := api.NewClient(cfg) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + members, err := client.Agent().Members() + for _, m := range members { + if membersFlags.details { + fmt.Printf("%s ", m.Name) + fmt.Printf("%s:%d ", m.Addr, m.Port) + fmt.Printf("%s", m.StatusPretty()) + fmt.Printf("\n") + } else { + fmt.Printf("%s\n", m.Name) + } + } +}
A command/list/services/services.go

@@ -0,0 +1,14 @@

+package list + +import ( + "fmt" +) + +const usage = `cascade list|ls nodes +cascade list|ls members +cascade list|ls services +` + +func Run(args []string) { + fmt.Printf("%+v", usage) +}
M main.gomain.go

@@ -9,7 +9,7 @@ "git.j3s.sh/cascade/command/list"

) const usage = `cascade agent start a cascade agent -cascade list|ls list nodes, services, or members +cascade ls list nodes, services, or members cascade rtt estimate latency between nodes `