Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #201 from EmoinLanyu/fix-alicloud-ssh
Browse files Browse the repository at this point in the history
fix alicloud ssh
  • Loading branch information
DockToFuture authored May 28, 2020
2 parents 19572f1 + ce0fb78 commit d422d29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func NewSSHCmd(reader TargetReader, ioStreams IOStreams) *cobra.Command {
case "azure":
sshToAZNode(args[0], path, user, pathSSKeypair, sshPublicKey)
case "alicloud":
sshToAlicloudNode(args[0], path, user, sshPublicKey)
sshToAlicloudNode(args[0], path, user, pathSSKeypair, sshPublicKey)
case "openstack":
default:
return fmt.Errorf("infrastructure type %q not found", infraType)
Expand Down
14 changes: 2 additions & 12 deletions pkg/cmd/ssh_alicloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -69,7 +68,7 @@ type AliyunInstanceTypeSpec struct {
}

// sshToAlicloudNode provides cmds to ssh to alicloud via a public ip and clean it up afterwards.
func sshToAlicloudNode(nodeName, path, user string, sshPublicKey []byte) {
func sshToAlicloudNode(nodeName, path, user, pathSSKeypair string, sshPublicKey []byte) {
// Check if this is a cleanup command
if nodeName == "cleanup" {
cleanupAliyunBastionHost()
Expand All @@ -80,15 +79,6 @@ func sshToAlicloudNode(nodeName, path, user string, sshPublicKey []byte) {
configureAliyunCLI()
var target Target
ReadTarget(pathTarget, &target)
gardenName := target.Stack()[0].Name
aliyunPathSSHKey := ""
if target.Target[1].Kind == "project" {
aliyunPathSSHKey = filepath.Join(pathGardenHome, "cache", gardenName, "projects", target.Target[1].Name, target.Target[2].Name, ".aliyun") + string(filepath.Separator)
} else if target.Target[1].Kind == "seed" {
aliyunPathSSHKey = filepath.Join(pathGardenHome, "cache", gardenName, "seeds", target.Target[1].Name, target.Target[2].Name, ".aliyun") + string(filepath.Separator)
}
err := ExecCmd(nil, "mv key "+aliyunPathSSHKey, false)
checkError(err)
fmt.Println("Aliyun cli configured.")

a := &AliyunInstanceAttribute{}
Expand All @@ -115,7 +105,7 @@ func sshToAlicloudNode(nodeName, path, user string, sshPublicKey []byte) {
a.startBastionHostInstance()
fmt.Println("Bastion host started.")

sshCmd := "ssh -i " + aliyunPathSSHKey + "key -o \"ProxyCommand ssh -i " + aliyunPathSSHKey + "key -o StrictHostKeyChecking=no -W " + a.PrivateIP + ":22 " + a.BastionSSHUser + "@" + a.BastionIP + "\" " + user + "@" + a.PrivateIP + " -o StrictHostKeyChecking=no"
sshCmd := "ssh -i " + pathSSKeypair + "key -o \"ProxyCommand ssh -i " + pathSSKeypair + "key -o StrictHostKeyChecking=no -W " + a.PrivateIP + ":22 " + a.BastionSSHUser + "@" + a.BastionIP + "\" " + user + "@" + a.PrivateIP + " -o StrictHostKeyChecking=no"
cmd := exec.Command("bash", "-c", sshCmd)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
Expand Down

0 comments on commit d422d29

Please sign in to comment.