本文整理汇总了Golang中github.com/coreos/fleet/ssh.NewSSHClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSSHClient函数的具体用法?Golang NewSSHClient怎么用?Golang NewSSHClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewSSHClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getRegistryClient
func getRegistryClient() (client.API, error) {
var dial func(string, string) (net.Conn, error)
tun := getTunnelFlag()
if tun != "" {
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false)
if err != nil {
return nil, fmt.Errorf("failed initializing SSH client: %v", err)
}
dial = func(network, addr string) (net.Conn, error) {
tcpaddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
return sshClient.DialTCP(network, nil, tcpaddr)
}
}
trans := http.Transport{
Dial: dial,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
return client.NewRegistryClient(&trans, globalFlags.Endpoint, globalFlags.EtcdKeyPrefix)
}
开发者ID:Jitendrakry,项目名称:fleet,代码行数:27,代码来源:fleetctl.go
示例2: getRegistry
func getRegistry() *registry.Registry {
tun := getTunnelFlag()
endpoint := getEndpointFlag()
machines := []string{endpoint}
client := etcd.NewClient(machines)
if tun != "" {
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false)
if err != nil {
log.Fatalf("Failed initializing SSH client: %v", err)
}
dial := func(network, addr string) (net.Conn, error) {
tcpaddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
return sshClient.DialTCP(network, nil, tcpaddr)
}
tr := http.Transport{
Dial: dial,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
client.SetTransport(&tr)
}
return registry.New(client)
}
开发者ID:nullstyle,项目名称:fleet,代码行数:33,代码来源:cmd.go
示例3: getRegistry
func getRegistry(context *cli.Context) *registry.Registry {
tun := getTunnelFlag(context)
endpoint := context.GlobalString("endpoint")
machines := []string{endpoint}
client := etcd.NewClient(machines)
if tun != "" {
sshClient, err := ssh.NewSSHClient("core", tun)
if err != nil {
panic(err)
}
dial := func(network, addr string) (net.Conn, error) {
tcpaddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
return sshClient.DialTCP(network, nil, tcpaddr)
}
tr := http.Transport{
Dial: dial,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
client.SetTransport(&tr)
}
return registry.New(client)
}
开发者ID:natacado,项目名称:fleet,代码行数:33,代码来源:cmd.go
示例4: getRegistry
// getRegistry initializes a connection to the Registry
func getRegistry() registry.Registry {
tun := getTunnelFlag()
machines := []string{globalFlags.Endpoint}
client := etcd.NewClient(machines)
if tun != "" {
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed initializing SSH client: %v\n", err)
os.Exit(1)
}
dial := func(network, addr string) (net.Conn, error) {
tcpaddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
return sshClient.DialTCP(network, nil, tcpaddr)
}
tr := http.Transport{
Dial: dial,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
client.SetTransport(&tr)
}
return registry.New(client, globalFlags.EtcdKeyPrefix)
}
开发者ID:paulczar,项目名称:fleet,代码行数:34,代码来源:fleetctl.go
示例5: runSSH
func runSSH(args []string) (exit int) {
if flagUnit != "" && flagMachine != "" {
fmt.Fprintln(os.Stderr, "Both machine and unit flags provided, please specify only one.")
return 1
}
var err error
var addr string
switch {
case flagMachine != "":
addr, _ = findAddressInMachineList(flagMachine)
case flagUnit != "":
addr, _ = findAddressInRunningUnits(flagUnit)
default:
addr, err = globalMachineLookup(args)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
// trim machine/unit name from args
if len(args) > 0 {
args = args[1:]
}
}
if addr == "" {
fmt.Fprintln(os.Stderr, "Requested machine could not be found.")
return 1
}
args = pkg.TrimToDashes(args)
var sshClient *ssh.SSHForwardingClient
if tun := getTunnelFlag(); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), flagSSHAgentForwarding)
} else {
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), flagSSHAgentForwarding)
}
if err != nil {
fmt.Fprintf(os.Stderr, "Failed building SSH client: %v\n", err)
return 1
}
defer sshClient.Close()
if len(args) > 0 {
cmd := strings.Join(args, " ")
err, exit = ssh.Execute(sshClient, cmd)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed running command over SSH: %v\n", err)
}
} else {
if err := ssh.Shell(sshClient); err != nil {
fmt.Fprintf(os.Stderr, "Failed opening shell over SSH: %v\n", err)
exit = 1
}
}
return
}
开发者ID:Jitendrakry,项目名称:fleet,代码行数:60,代码来源:ssh.go
示例6: printUnitStatus
func printUnitStatus(c *cli.Context, jobName string) {
js := registryCtl.GetJobState(jobName)
if js == nil {
fmt.Printf("%s does not appear to be running\n", jobName)
syscall.Exit(1)
}
addr := fmt.Sprintf("%s:22", js.MachineState.PublicIP)
var err error
var sshClient *ssh.SSHForwardingClient
if tun := getTunnelFlag(); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false)
} else {
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), false)
}
if err != nil {
log.Fatal(err.Error())
}
defer sshClient.Close()
cmd := fmt.Sprintf("systemctl status -l %s", jobName)
channel, err := ssh.Execute(sshClient, cmd)
if err != nil {
log.Fatalf("Unable to execute command over SSH: %s", err.Error())
}
readSSHChannel(channel)
}
开发者ID:nullstyle,项目名称:fleet,代码行数:32,代码来源:status.go
示例7: getRegistryClient
func getRegistryClient() (client.API, error) {
var dial func(string, string) (net.Conn, error)
tun := getTunnelFlag()
if tun != "" {
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false)
if err != nil {
return nil, fmt.Errorf("failed initializing SSH client: %v", err)
}
dial = func(network, addr string) (net.Conn, error) {
tcpaddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
return sshClient.DialTCP(network, nil, tcpaddr)
}
}
tlsConfig, err := etcd.ReadTLSConfigFiles(globalFlags.EtcdCAFile, globalFlags.EtcdCertFile, globalFlags.EtcdKeyFile)
if err != nil {
return nil, err
}
trans := http.Transport{
Dial: dial,
TLSClientConfig: tlsConfig,
}
timeout := time.Duration(globalFlags.RequestTimeout*1000) * time.Millisecond
return client.NewRegistryClient(&trans, globalFlags.Endpoint, globalFlags.EtcdKeyPrefix, timeout)
}
开发者ID:BillTheBest,项目名称:fleet,代码行数:31,代码来源:fleetctl.go
示例8: sshAction
func sshAction(c *cli.Context) {
unit := c.String("unit")
machine := c.String("machine")
if unit != "" && machine != "" {
log.Fatal("Both flags, machine and unit provided, please specify only one")
}
args := c.Args()
var err error
var addr string
switch {
case machine != "":
addr, _ = findAddressInMachineList(machine)
case unit != "":
addr, _ = findAddressInRunningUnits(unit)
default:
addr, err = globalMachineLookup(args)
args = args[1:]
}
if err != nil {
log.Fatal(err)
}
if addr == "" {
log.Fatalf("Requested machine could not be found")
}
agentForwarding := c.Bool("agent")
var sshClient *ssh.SSHForwardingClient
if tun := getTunnelFlag(); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), agentForwarding)
} else {
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), agentForwarding)
}
if err != nil {
log.Fatal(err.Error())
return
}
defer sshClient.Close()
if len(args) > 0 {
cmd := strings.Join(args, " ")
channel, err := ssh.Execute(sshClient, cmd)
if err != nil {
log.Fatalf("Unable to run command over SSH: %s", err.Error())
}
readSSHChannel(channel)
} else {
if err := ssh.Shell(sshClient); err != nil {
log.Fatalf(err.Error())
}
}
}
开发者ID:nullstyle,项目名称:fleet,代码行数:59,代码来源:ssh.go
示例9: getRegistryClient
func getRegistryClient(cCmd *cobra.Command) (client.API, error) {
var dial func(string, string) (net.Conn, error)
SSHUserName, _ := cmdFleet.PersistentFlags().GetString("ssh-username")
tun := getTunnelFlag(cCmd)
if tun != "" {
sshClient, err := ssh.NewSSHClient(SSHUserName, tun, getChecker(cCmd), false, getSSHTimeoutFlag(cCmd))
if err != nil {
return nil, fmt.Errorf("failed initializing SSH client: %v", err)
}
dial = func(network, addr string) (net.Conn, error) {
tcpaddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
return sshClient.DialTCP(network, nil, tcpaddr)
}
}
CAFile, _ := cmdFleet.PersistentFlags().GetString("ca-file")
CertFile, _ := cmdFleet.PersistentFlags().GetString("cert-file")
KeyFile, _ := cmdFleet.PersistentFlags().GetString("key-file")
tlsConfig, err := pkg.ReadTLSConfigFiles(CAFile, CertFile, KeyFile)
if err != nil {
return nil, err
}
trans := &http.Transport{
Dial: dial,
TLSClientConfig: tlsConfig,
}
endPoint, _ := cmdFleet.PersistentFlags().GetString("endpoint")
eCfg := etcd.Config{
Endpoints: strings.Split(endPoint, ","),
Transport: trans,
HeaderTimeoutPerRequest: getRequestTimeoutFlag(cCmd),
}
eClient, err := etcd.New(eCfg)
if err != nil {
return nil, err
}
etcdKeyPrefix, _ := cmdFleet.PersistentFlags().GetString("etcd-key-prefix")
kAPI := etcd.NewKeysAPI(eClient)
reg := registry.NewEtcdRegistry(kAPI, etcdKeyPrefix)
if msg, ok := checkVersion(reg); !ok {
stderr(msg)
}
return &client.RegistryClient{Registry: reg}, nil
}
开发者ID:pulcy,项目名称:j2,代码行数:54,代码来源:fleetctl.go
示例10: journalAction
func journalAction(c *cli.Context) {
if len(c.Args()) != 1 {
fmt.Println("One unit file must be provided.")
syscall.Exit(1)
}
jobName := c.Args()[0]
js := registryCtl.GetJobState(jobName)
if js == nil {
fmt.Printf("%s does not appear to be running\n", jobName)
syscall.Exit(1)
}
addr := fmt.Sprintf("%s:22", js.MachineState.PublicIP)
var err error
var sshClient *gossh.ClientConn
if tun := getTunnelFlag(); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr)
} else {
sshClient, err = ssh.NewSSHClient("core", addr)
}
if err != nil {
log.Fatal(err.Error())
}
defer sshClient.Close()
cmd := fmt.Sprintf("journalctl -u %s --no-pager -l -n %d", jobName, c.Int("lines"))
if c.Bool("follow") {
cmd += " -f"
}
stdout, err := ssh.Execute(sshClient, cmd)
if err != nil {
log.Fatalf("Unable to run command over SSH: %s", err.Error())
}
for true {
bytes, prefix, err := stdout.ReadLine()
if err != nil {
break
}
fmt.Print(string(bytes))
if !prefix {
fmt.Print("\n")
}
}
}
开发者ID:jsdir,项目名称:fleet,代码行数:50,代码来源:journal.go
示例11: runRemoteCommand
// runRemoteCommand runs the given command over SSH on the given IP, and returns
// any error encountered and the exit status of the command
func runRemoteCommand(cmd string, addr string) (err error, exit int) {
var sshClient *ssh.SSHForwardingClient
if tun := getTunnelFlag(); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false)
} else {
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), false)
}
if err != nil {
return err, -1
}
defer sshClient.Close()
return ssh.Execute(sshClient, cmd)
}
开发者ID:Jitendrakry,项目名称:fleet,代码行数:17,代码来源:ssh.go
示例12: getRegistryClient
func getRegistryClient(config FleetConfig) (client.API, error) {
var dial func(string, string) (net.Conn, error)
tun := config.Tunnel
if tun != "" {
sshClient, err := ssh.NewSSHClient(config.SSHUserName, tun, getChecker(config), false, config.SSHTimeout)
if err != nil {
return nil, fmt.Errorf("failed initializing SSH client: %v", err)
}
dial = func(network, addr string) (net.Conn, error) {
tcpaddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
return sshClient.DialTCP(network, nil, tcpaddr)
}
}
tlsConfig, err := pkg.ReadTLSConfigFiles(config.CAFile, config.CertFile, config.KeyFile)
if err != nil {
return nil, err
}
trans := &http.Transport{
Dial: dial,
TLSClientConfig: tlsConfig,
}
eCfg := etcd.Config{
Endpoints: strings.Split(config.EndPoint, ","),
Transport: trans,
HeaderTimeoutPerRequest: config.RequestTimeout,
}
eClient, err := etcd.New(eCfg)
if err != nil {
return nil, err
}
kAPI := etcd.NewKeysAPI(eClient)
reg := registry.NewEtcdRegistry(kAPI, config.EtcdKeyPrefix)
/*if msg, ok := checkVersion(reg); !ok {
stderr(msg)
}*/
return &client.RegistryClient{Registry: reg}, nil
}
开发者ID:pulcy,项目名称:j2,代码行数:48,代码来源:fleet.go
示例13: runRemoteCommand
// runRemoteCommand runs the given command over SSH on the given IP, and returns
// any error encountered and the exit status of the command
func runRemoteCommand(cmd string, addr string, timeout time.Duration) (exit int, err error) {
var sshClient *ssh.SSHForwardingClient
if tun := getTunnelFlag(); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false, timeout)
} else {
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), false, timeout)
}
if err != nil {
return -1, err
}
defer sshClient.Close()
err, exit = ssh.Execute(sshClient, cmd)
return
}
开发者ID:johanneswuerbach,项目名称:deis,代码行数:18,代码来源:ssh.go
示例14: runRemoteCommand
// runRemoteCommand runs the given command over SSH on the given IP, and returns
// any error encountered and the exit status of the command
func runRemoteCommand(cmd string, addr string) (err error, exit int) {
var sshClient *ssh.SSHForwardingClient
timeout := getSSHTimeoutFlag()
if tun := getTunnelFlag(); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient(globalFlags.SSHUserName, tun, addr, getChecker(), false, timeout)
} else {
sshClient, err = ssh.NewSSHClient(globalFlags.SSHUserName, addr, getChecker(), false, timeout)
}
if err != nil {
return err, -1
}
defer sshClient.Close()
return ssh.Execute(sshClient, cmd)
}
开发者ID:ParthDesai,项目名称:fleet,代码行数:18,代码来源:ssh.go
示例15: SSH
// SSH opens an interactive shell to a machine in the cluster
func (c *FleetClient) SSH(name string) (err error) {
var sshClient *ssh.SSHForwardingClient
timeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
ms, err := c.machineState(name)
if err != nil {
return err
}
// If name isn't a machine ID, try it as a unit instead
if ms == nil {
units, err := c.Units(name)
if err != nil {
return err
}
machID, err := c.findUnit(units[0])
if err != nil {
return err
}
ms, err = c.machineState(machID)
if err != nil || ms == nil {
return err
}
}
addr := ms.PublicIP
if tun := getTunnelFlag(); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false, timeout)
} else {
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), false, timeout)
}
if err != nil {
return err
}
defer sshClient.Close()
err = ssh.Shell(sshClient)
return err
}
开发者ID:gpxl,项目名称:deis,代码行数:47,代码来源:ssh.go
示例16: getRegistryClient
func getRegistryClient() (client.API, error) {
var dial func(string, string) (net.Conn, error)
sshTimeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
tun := getTunnelFlag()
if tun != "" {
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false, sshTimeout)
if err != nil {
return nil, fmt.Errorf("failed initializing SSH client: %v", err)
}
dial = func(network, addr string) (net.Conn, error) {
tcpaddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
return sshClient.DialTCP(network, nil, tcpaddr)
}
}
tlsConfig, err := pkg.ReadTLSConfigFiles(Flags.EtcdCAFile, Flags.EtcdCertFile, Flags.EtcdKeyFile)
if err != nil {
return nil, err
}
trans := &http.Transport{
Dial: dial,
TLSClientConfig: tlsConfig,
}
timeout := time.Duration(Flags.RequestTimeout*1000) * time.Millisecond
machines := []string{Flags.Endpoint}
eClient, err := etcd.NewClient(machines, trans, timeout)
if err != nil {
return nil, err
}
reg := registry.NewEtcdRegistry(eClient, Flags.EtcdKeyPrefix)
// if msg, ok := checkVersion(reg); !ok {
// stderr(msg)
// }
return &client.RegistryClient{Registry: reg}, nil
}
开发者ID:CodeJuan,项目名称:deis,代码行数:44,代码来源:registry.go
示例17: getHTTPClient
func getHTTPClient() (client.API, error) {
dialDomainSocket := strings.HasPrefix(globalFlags.Endpoint, "/")
tunnelFunc := net.Dial
tun := getTunnelFlag()
if tun != "" {
sshClient, err := ssh.NewSSHClient(globalFlags.SSHUserName, tun, getChecker(), false)
if err != nil {
return nil, fmt.Errorf("failed initializing SSH client: %v", err)
}
tunnelFunc = func(net, addr string) (net.Conn, error) {
return sshClient.Dial(net, addr)
}
}
dialFunc := tunnelFunc
if dialDomainSocket {
dialFunc = func(net, addr string) (net.Conn, error) {
return tunnelFunc("unix", globalFlags.Endpoint)
}
}
trans := pkg.LoggingHTTPTransport{
http.Transport{
Dial: dialFunc,
},
}
hc := http.Client{
Transport: &trans,
}
endpoint := globalFlags.Endpoint
if dialDomainSocket {
endpoint = "http://domain-sock/"
} else if !strings.HasPrefix(endpoint, "http") {
endpoint = fmt.Sprintf("http://%s", endpoint)
}
return client.NewHTTPClient(&hc, endpoint)
}
开发者ID:jcderr,项目名称:fleet,代码行数:42,代码来源:fleetctl.go
示例18: printUnitStatus
func printUnitStatus(c *cli.Context, r *registry.Registry, jobName string) {
js := r.GetJobState(jobName)
if js == nil {
fmt.Printf("%s does not appear to be running\n", jobName)
syscall.Exit(1)
}
addr := fmt.Sprintf("%s:22", js.MachineState.PublicIP)
var err error
var sshClient *gossh.ClientConn
if tun := getTunnelFlag(c); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr)
} else {
sshClient, err = ssh.NewSSHClient("core", addr)
}
if err != nil {
log.Fatalf("Unable to establish SSH connection: %v", err)
}
defer sshClient.Close()
cmd := fmt.Sprintf("systemctl status -l %s", jobName)
stdout, err := ssh.Execute(sshClient, cmd)
if err != nil {
log.Fatalf("Unable to execute command over SSH: %s", err.Error())
}
for true {
bytes, prefix, err := stdout.ReadLine()
if err != nil {
break
}
print(string(bytes))
if !prefix {
print("\n")
}
}
}
开发者ID:natacado,项目名称:fleet,代码行数:41,代码来源:status.go
示例19: getEtcdClient
func getEtcdClient() (*etcdClient, error) {
var dial func(string, string) (net.Conn, error)
sshTimeout := time.Duration(fleet.Flags.SSHTimeout*1000) * time.Millisecond
tun := getTunnelFlag()
if tun != "" {
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false, sshTimeout)
if err != nil {
return nil, fmt.Errorf("failed initializing SSH client: %v", err)
}
dial = func(network, addr string) (net.Conn, error) {
tcpaddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
return sshClient.DialTCP(network, nil, tcpaddr)
}
}
tlsConfig, err := pkg.ReadTLSConfigFiles(fleet.Flags.EtcdCAFile,
fleet.Flags.EtcdCertFile, fleet.Flags.EtcdKeyFile)
if err != nil {
return nil, err
}
trans := http.Transport{
Dial: dial,
TLSClientConfig: tlsConfig,
}
timeout := time.Duration(fleet.Flags.RequestTimeout*1000) * time.Millisecond
machines := []string{fleet.Flags.Endpoint}
c := etcd.NewClient(machines)
c.SetDialTimeout(timeout)
// use custom transport with SSH tunnel capability
c.SetTransport(&trans)
return &etcdClient{etcd: c}, nil
}
开发者ID:gpxl,项目名称:deis,代码行数:41,代码来源:etcd.go
示例20: runRemoteCommand
// runRemoteCommand runs the given command over SSH on the given IP, and returns
// any error encountered and the exit status of the command
func runRemoteCommand(cCmd *cobra.Command, addr string, cmd string, args ...string) (err error, exit int) {
var sshClient *ssh.SSHForwardingClient
timeout := getSSHTimeoutFlag(cCmd)
if tun := getTunnelFlag(cCmd); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient(globalFlags.SSHUserName, tun, addr, getChecker(cCmd), false, timeout)
} else {
sshClient, err = ssh.NewSSHClient(globalFlags.SSHUserName, addr, getChecker(cCmd), false, timeout)
}
if err != nil {
return err, -1
}
cmdargs := cmd
for _, arg := range args {
cmdargs += fmt.Sprintf(" %q", arg)
}
defer sshClient.Close()
return ssh.Execute(sshClient, cmdargs)
}
开发者ID:pulcy,项目名称:j2,代码行数:23,代码来源:ssh.go
注:本文中的github.com/coreos/fleet/ssh.NewSSHClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论