-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathattachinfo.go
87 lines (77 loc) · 1.99 KB
/
attachinfo.go
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
79
80
81
82
83
84
85
86
87
//
// (C) Copyright 2020-2021 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package main
import (
"fmt"
"os"
"github.com/pkg/errors"
"github.com/daos-stack/daos/src/control/common/cmdutil"
"github.com/daos-stack/daos/src/control/lib/control"
"github.com/daos-stack/daos/src/control/lib/txtfmt"
)
type dumpAttachInfoCmd struct {
configCmd
ctlInvokerCmd
cmdutil.LogCmd
cmdutil.JSONOutputCmd
Output string `short:"o" long:"output" default:"stdout" description:"Dump output to this location"`
}
func (cmd *dumpAttachInfoCmd) Execute(_ []string) error {
out := os.Stdout
if cmd.Output != "stdout" {
f, err := os.Create(cmd.Output)
if err != nil {
return errors.Wrapf(err, "failed to create %q", cmd.Output)
}
defer f.Close()
out = f
}
ctx := cmd.MustLogCtx()
req := &control.GetAttachInfoReq{
AllRanks: true,
}
req.SetSystem(cmd.cfg.SystemName)
resp, err := control.GetAttachInfo(ctx, cmd.ctlInvoker, req)
if err != nil {
return errors.Wrap(err, "GetAttachInfo failed")
}
if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, err)
}
system := cmd.cfg.SystemName
if resp.System != "" {
system = resp.System
}
/**
* cart/crt_group.c:crt_group_config_save()
*
* Save attach info to file with the name
* "<singleton_attach_path>/grpid.attach_info_tmp".
* The format of the file is:
* line 1: the process set name
* line 2: process set size
* line 3: "all" or "self"
* "all" means dump all ranks' uri
* "self" means only dump this rank's uri
* line 4 ~ N: <rank> <uri>
*
* An example file named daos_server.attach_info_tmp:
* ========================
* name daos_server
* size 1
* all
* 0 tcp://192.168.0.1:1234
* ========================
*/
ew := txtfmt.NewErrWriter(out)
fmt.Fprintf(ew, "name %s\n", system)
fmt.Fprintf(ew, "size %d\n", len(resp.ServiceRanks))
fmt.Fprintln(ew, "all")
for _, psr := range resp.ServiceRanks {
fmt.Fprintf(ew, "%d %s\n", psr.Rank, psr.Uri)
}
return ew.Err
}