@@ -27,6 +27,7 @@ import (
2727
2828 "github.com/opencurve/curveadm/cli/cli"
2929 comm "github.com/opencurve/curveadm/internal/common"
30+ "github.com/opencurve/curveadm/internal/errno"
3031 "github.com/opencurve/curveadm/internal/storage"
3132 "github.com/opencurve/curveadm/internal/task/context"
3233 "github.com/opencurve/curveadm/internal/task/step"
@@ -35,11 +36,16 @@ import (
3536 "github.com/opencurve/curveadm/internal/utils"
3637)
3738
39+ const (
40+ MISSING_CLIENT_CONFIG = "-"
41+ )
42+
3843type (
3944 step2FormatClientStatus struct {
4045 client storage.Client
4146 containerId string
4247 status * string
48+ cfgPath * string
4349 memStorage * utils.SafeMap
4450 }
4551
@@ -50,9 +56,32 @@ type (
5056 ContainerId string
5157 Status string
5258 AuxInfo string
59+ CfgPath string
5360 }
5461)
5562
63+ func dumpCfg (curveadm * cli.CurveAdm , id string , cfgPath * string ) step.LambdaType {
64+ return func (ctx * context.Context ) error {
65+ * cfgPath = MISSING_CLIENT_CONFIG
66+ cfgs , err := curveadm .Storage ().GetClientConfig (id )
67+ if err != nil {
68+ return errno .ERR_SELECT_CLIENT_CONFIG_FAILED .E (err )
69+ } else if len (cfgs ) == 0 {
70+ return nil
71+ }
72+
73+ data := cfgs [0 ].Data
74+ path := utils .RandFilename ("/tmp" )
75+ err = utils .WriteFile (path , data , 0644 )
76+ if err != nil {
77+ return errno .ERR_WRITE_FILE_FAILED .E (err )
78+ }
79+
80+ * cfgPath = path
81+ return nil
82+ }
83+ }
84+
5685// TODO(P0): init client status
5786func setClientStatus (memStorage * utils.SafeMap , id string , status ClientStatus ) {
5887 memStorage .TX (func (kv * utils.SafeMap ) error {
@@ -82,6 +111,7 @@ func (s *step2FormatClientStatus) Execute(ctx *context.Context) error {
82111 ContainerId : s .containerId ,
83112 Status : status ,
84113 AuxInfo : client .AuxInfo ,
114+ CfgPath : * s .cfgPath ,
85115 })
86116 return nil
87117}
@@ -99,18 +129,22 @@ func NewGetClientStatusTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task,
99129 t := task .NewTask ("Get Client Status" , subname , hc .GetSSHConfig ())
100130
101131 // add step
102- var status string
132+ var status , cfgPath string
103133 t .AddStep (& step.ListContainers {
104134 ShowAll : true ,
105135 Format : `"{{.Status}}"` ,
106136 Filter : fmt .Sprintf ("id=%s" , containerId ),
107137 Out : & status ,
108138 ExecOptions : curveadm .ExecOptions (),
109139 })
140+ t .AddStep (& step.Lambda {
141+ Lambda : dumpCfg (curveadm , client .Id , & cfgPath ),
142+ })
110143 t .AddStep (& step2FormatClientStatus {
111144 client : client ,
112145 containerId : containerId ,
113146 status : & status ,
147+ cfgPath : & cfgPath ,
114148 memStorage : curveadm .MemStorage (),
115149 })
116150
0 commit comments