opening new sessions works
now it's time to execute commands and working on tarring directories
This commit is contained in:
parent
996aef3c1e
commit
a3e1ca6b2b
9
main.go
9
main.go
@ -1,8 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "fmt"
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//fmt.Println("Hello!")
|
//fmt.Println("Hello!")
|
||||||
@ -10,9 +8,8 @@ func main() {
|
|||||||
//var config Configuration
|
//var config Configuration
|
||||||
|
|
||||||
config := initializeConfig("config.yaml")
|
config := initializeConfig("config.yaml")
|
||||||
//fmt.Println(config.Hosts)
|
|
||||||
sshConn, sshConfig := initializeConnection(config)
|
sshConn, sshConfig := initializeConnection(config)
|
||||||
//fmt.Println(sshConn.Hosts)
|
|
||||||
clientConns := sshConn.dialConnection(sshConfig)
|
clientConns := sshConn.dialConnection(sshConfig)
|
||||||
fmt.Println(clientConns)
|
clientSessions := sshConn.openSession(clientConns)
|
||||||
|
fmt.Println(clientSessions)
|
||||||
}
|
}
|
||||||
|
25
ssh.go
25
ssh.go
@ -21,6 +21,8 @@ type SSHConnection struct {
|
|||||||
|
|
||||||
type SSHCleints []*ssh.Client
|
type SSHCleints []*ssh.Client
|
||||||
|
|
||||||
|
type SSHSessions []*ssh.Session
|
||||||
|
|
||||||
func initializeConnection(config Configuration) (SSHConnection, *ssh.ClientConfig) {
|
func initializeConnection(config Configuration) (SSHConnection, *ssh.ClientConfig) {
|
||||||
var sshConn SSHConnection
|
var sshConn SSHConnection
|
||||||
sshConn.Username = config.Username
|
sshConn.Username = config.Username
|
||||||
@ -44,7 +46,7 @@ func (s SSHConnection) getHostKeys() ssh.HostKeyCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SSHConnection) dialConnection(sshConfig *ssh.ClientConfig) SSHCleints {
|
func (s SSHConnection) dialConnection(sshConfig *ssh.ClientConfig) SSHCleints {
|
||||||
ClientConn := SSHCleints{}
|
clientConn := SSHCleints{}
|
||||||
|
|
||||||
for _, j := range s.Hosts {
|
for _, j := range s.Hosts {
|
||||||
hostPort := fmt.Sprintf("%s:22", j)
|
hostPort := fmt.Sprintf("%s:22", j)
|
||||||
@ -54,8 +56,25 @@ func (s SSHConnection) dialConnection(sshConfig *ssh.ClientConfig) SSHCleints {
|
|||||||
fmt.Errorf("Can't connect", err)
|
fmt.Errorf("Can't connect", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientConn = append(ClientConn, connection)
|
clientConn = append(clientConn, connection)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ClientConn
|
return clientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s SSHConnection) openSession(client SSHCleints) SSHSessions {
|
||||||
|
// don't forget there's a return type here
|
||||||
|
clientSessions := SSHSessions{}
|
||||||
|
|
||||||
|
for _, j := range client {
|
||||||
|
session, err := j.NewSession()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Errorf("Can't open session", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
clientSessions = append(clientSessions, session)
|
||||||
|
}
|
||||||
|
|
||||||
|
return clientSessions
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user