1
0
forked from x/ContextOS

vps add ssh.search 添加路径搜索

This commit is contained in:
shylinux 2018-04-19 08:42:47 +08:00
parent bdb86ead00
commit 24c0290691
3 changed files with 75 additions and 26 deletions

View File

@ -1423,6 +1423,10 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
m.Echo(" %s: %v\n", k, ms[i].Meta[k])
}
if ms[i].callback != nil {
m.Echo("callback: %d\n", ms[i].ncallback)
}
if len(ms[i].Meta["result"]) > 0 {
m.Echo("result: %v\n", ms[i].Meta["result"])
}

View File

@ -95,6 +95,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
for {
line, e := nfs.Reader.ReadString('\n')
m.Assert(e)
// m.Log("debug", nil, "recv(%d): %s", len(line), line)
if line = strings.TrimSpace(line); len(line) > 0 {
ls := strings.SplitN(line, ":", 2)
@ -117,30 +118,36 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
if msg.Log("info", nil, "remote: %v", msg.Meta["option"]); msg.Has("detail") {
msg.Log("info", nil, "%d exec: %v", m.Capi("nrecv", 1), msg.Meta["detail"])
msg.Cmd(msg.Meta["detail"])
target = msg.Target()
func() {
fuck := msg
fuck.Call(func(ok bool) (done bool, up bool) {
target = fuck.Target()
m.Cap("target", target.Name)
for _, v := range msg.Meta["result"] {
for _, v := range fuck.Meta["result"] {
fmt.Fprintf(nfs.Writer, "result: %s\n", url.QueryEscape(v))
}
fmt.Fprintf(nfs.Writer, "nsend: %s\n", msg.Get("nrecv"))
for _, k := range msg.Meta["append"] {
for _, v := range msg.Meta[k] {
fmt.Fprintf(nfs.Writer, "nsend: %s\n", fuck.Get("nrecv"))
for _, k := range fuck.Meta["append"] {
for _, v := range fuck.Meta[k] {
fmt.Fprintf(nfs.Writer, "%s: %s\n", k, v)
}
}
fmt.Fprintf(nfs.Writer, "\n")
nfs.Writer.Flush()
if msg.Has("io") {
if f, ok := msg.Data["io"].(io.ReadCloser); ok {
if fuck.Has("io") {
if f, ok := fuck.Data["io"].(io.ReadCloser); ok {
io.Copy(nfs.Writer, f)
nfs.Writer.Flush()
f.Close()
}
}
return ok, ok
}, false).Cmd(fuck.Meta["detail"])
}()
} else {
msg.Log("info", nil, "%d echo: %v", nsend, msg.Meta["result"])

View File

@ -118,7 +118,7 @@ var Pulse *ctx.Message
var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
Caches: map[string]*ctx.Cache{
"nhost": &ctx.Cache{Name: "主机数量", Value: "0", Help: "主机数量"},
"route": &ctx.Cache{Name: "route", Value: "", Help: "主机数量"},
"route": &ctx.Cache{Name: "route", Value: "ssh", Help: "主机数量"},
},
Configs: map[string]*ctx.Config{
"route": &ctx.Config{Name: "route", Value: "com", Help: "主机数量"},
@ -132,10 +132,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
sub.Start(fmt.Sprintf("host%d", Pulse.Capi("nhost", 1)), "打开文件", sub.Meta["detail"]...)
sub.Cap("stream", msg.Target().Name)
sub.Target().Sessions["file"] = msg
sub.Target(msg.Target())
sub.Echo(sub.Target().Name)
sub.Spawn(sub.Target()).Cmd("send", "context", "ssh")
sub.Spawn(sub.Target()).Cmd("send", "route", sub.Target().Name, msg.Cap("route")+"."+msg.Conf("route"))
sub.Spawn(sub.Target()).Cmd("send", "route", sub.Target().Name, msg.Cap("route"))
}
return false, true
}, false).Cmd(m.Meta["detail"])
@ -145,6 +144,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
msg := m.Sess("file", "nfs")
msg.Call(func(ok bool) (done bool, up bool) {
if ok {
m.Sess("file").Cmd("send", "context", "ssh")
m.Cap("stream", msg.Target().Name)
return true, true
}
@ -154,15 +154,53 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
}},
"send": &ctx.Command{Name: "send arg...", Help: "打开连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
msg := m.Sess("file")
msg.Copy(m, "detail").Cmd()
msg.Copy(m, "detail").Call(func(ok bool) (done bool, up bool) {
return ok, ok
}, false).Cmd()
m.Copy(msg, "result")
}},
"pwd": &ctx.Command{Name: "pwd", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
m.Echo(m.Cap("route"))
}},
"route": &ctx.Command{Name: "route", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
m.Conf("route", arg[0])
m.Cap("route", arg[1]+"."+arg[0])
}},
"dispatch": &ctx.Command{Name: "dispatch cmd arg...", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
"search": &ctx.Command{Name: "search route cmd arg...", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
if _, ok := m.Target().Server.(*SSH); m.Assert(ok) {
if len(arg[0]) == 0 {
msg := m.Spawn(m.Target()).Cmd(arg[1:])
m.Copy(msg, "result")
return
}
miss := true
target := strings.Split(arg[0], ".")
m.Travel(m.Target(), func(m *ctx.Message) bool {
if m.Target().Name == target[0] {
msg := m.Spawn(m.Target())
msg.Call(func(ok bool) (done bool, up bool) {
m.Copy(msg, "result")
return ok, ok
}, false).Cmd("send", "search", strings.Join(target[1:], "."), arg[1:])
miss = false
}
return miss
})
if miss {
msg := m.Spawn(c)
msg.Call(func(ok bool) (done bool, up bool) {
m.Copy(msg, "result")
return ok, ok
}, false).Cmd("send", "search", arg)
}
}
}},
"dispatch": &ctx.Command{Name: "dispatch route cmd arg...", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
m.Travel(m.Target(), func(m *ctx.Message) bool {
msg := m.Spawn(m.Target())
msg.Cmd("send", arg)
return true