Skip to content

Commit

Permalink
Bypass gateway to access gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jul 17, 2015
1 parent 98e3a64 commit 0782d9f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 21 deletions.
22 changes: 16 additions & 6 deletions commands/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ func TarFromSource(apiClient *api.ScalewayAPI, source string) (*io.ReadCloser, e
remoteCommand = append(remoteCommand, base)

// Resolve gateway
gateway, err := api.ResolveGateway(apiClient, cpGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", cpGateway, err)
var gateway string
if cpGateway == serverID || cpGateway == serverParts[0] {
gateway = ""
} else {
gateway, err = api.ResolveGateway(apiClient, cpGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", cpGateway, err)
}
}

// execCmd contains the ssh connection + the remoteCommand
Expand Down Expand Up @@ -173,9 +178,14 @@ func UntarToDest(apiClient *api.ScalewayAPI, sourceStream *io.ReadCloser, destin
remoteCommand = append(remoteCommand, "-xf", "-")

// Resolve gateway
gateway, err := api.ResolveGateway(apiClient, cpGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", cpGateway, err)
var gateway string
if cpGateway == serverID || cpGateway == serverParts[0] {
gateway = ""
} else {
gateway, err = api.ResolveGateway(apiClient, cpGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", cpGateway, err)
}
}

// execCmd contains the ssh connection + the remoteCommand
Expand Down
12 changes: 9 additions & 3 deletions commands/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ func runExec(cmd *types.Command, args []string) {
serverID := cmd.API.GetServerID(args[0])

// Resolve gateway
gateway, err := api.ResolveGateway(cmd.API, execGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", execGateway, err)
var gateway string
var err error
if execGateway == serverID || execGateway == args[0] {
gateway = ""
} else {
gateway, err = api.ResolveGateway(cmd.API, execGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", execGateway, err)
}
}

var server *api.ScalewayServer
Expand Down
11 changes: 8 additions & 3 deletions commands/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ func runKill(cmd *types.Command, args []string) {
}

// Resolve gateway
gateway, err := api.ResolveGateway(cmd.API, killGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", killGateway, err)
var gateway string
if killGateway == serverID || killGateway == args[0] {
gateway = ""
} else {
gateway, err = api.ResolveGateway(cmd.API, killGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", killGateway, err)
}
}

execCmd := append(utils.NewSSHExecCmd(server.PublicAddress.IP, server.PrivateIP, true, nil, []string{command}, gateway))
Expand Down
11 changes: 8 additions & 3 deletions commands/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ func runLogs(cmd *types.Command, args []string) {
// FIXME: switch to serial history when API is ready

// Resolve gateway
gateway, err := api.ResolveGateway(cmd.API, logsGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", logsGateway, err)
var gateway string
if logsGateway == serverID || logsGateway == args[0] {
gateway = ""
} else {
gateway, err = api.ResolveGateway(cmd.API, logsGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", logsGateway, err)
}
}

command := []string{"dmesg"}
Expand Down
11 changes: 8 additions & 3 deletions commands/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ func runPort(cmd *types.Command, args []string) {
}

// Resolve gateway
gateway, err := api.ResolveGateway(cmd.API, portGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", portGateway, err)
var gateway string
if portGateway == serverID || portGateway == args[0] {
gateway = ""
} else {
gateway, err = api.ResolveGateway(cmd.API, portGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", portGateway, err)
}
}

command := []string{"netstat -lutn 2>/dev/null | grep LISTEN"}
Expand Down
11 changes: 8 additions & 3 deletions commands/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ func runTop(cmd *types.Command, args []string) {
}

// Resolve gateway
gateway, err := api.ResolveGateway(cmd.API, topGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", topGateway, err)
var gateway string
if topGateway == serverID || topGateway == args[0] {
gateway = ""
} else {
gateway, err = api.ResolveGateway(cmd.API, topGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", topGateway, err)
}
}

execCmd := utils.NewSSHExecCmd(server.PublicAddress.IP, server.PrivateIP, true, nil, []string{command}, gateway)
Expand Down

0 comments on commit 0782d9f

Please sign in to comment.