diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index 99b4d0d0d..150455729 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -1,4 +1,5 @@ -// Package docs Code generated by swaggo/swag. DO NOT EDIT +// Package docs GENERATED BY SWAG; DO NOT EDIT +// This file was generated by swaggo/swag package docs import "github.com/swaggo/swag" @@ -7429,34 +7430,6 @@ const docTemplate = `{ } } }, - "mcir.CustomImageStatus": { - "type": "string", - "enum": [ - "Available", - "Unavailable" - ], - "x-enum-varnames": [ - "MyImageAvailable", - "MyImageUnavailable" - ] - }, - "mcir.DiskStatus": { - "type": "string", - "enum": [ - "Creating", - "Available", - "Attached", - "Deleting", - "Error" - ], - "x-enum-varnames": [ - "DiskCreating", - "DiskAvailable", - "DiskAttached", - "DiskDeleting", - "DiskError" - ] - }, "mcir.FilterSpecsByRangeRequest": { "type": "object", "properties": { @@ -7722,11 +7695,7 @@ const docTemplate = `{ }, "iid": { "description": "Fields for response", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "keyValueList": { "type": "array", @@ -7877,11 +7846,7 @@ const docTemplate = `{ "example": "aws-ap-southeast-1-1" }, "status": { - "allOf": [ - { - "$ref": "#/definitions/mcir.CustomImageStatus" - } - ], + "type": "string", "example": "Available" }, "systemLabel": { @@ -7971,11 +7936,7 @@ const docTemplate = `{ }, "status": { "description": "Available, Unavailable, Attached, ...", - "allOf": [ - { - "$ref": "#/definitions/mcir.DiskStatus" - } - ], + "type": "string", "example": "Available" }, "systemLabel": { @@ -8682,11 +8643,7 @@ const docTemplate = `{ }, "postCommand": { "description": "PostCommand is field for providing command to VMs after its creation. example:\"wget https://raw.githubusercontent.com/cloud-barista/cb-tumblebug/main/scripts/setweb.sh -O ~/setweb.sh; chmod +x ~/setweb.sh; sudo ~/setweb.sh\"", - "allOf": [ - { - "$ref": "#/definitions/mcis.McisCmdReq" - } - ] + "$ref": "#/definitions/mcis.McisCmdReq" }, "vmDynamicReq": { "$ref": "#/definitions/mcis.TbVmDynamicReq" @@ -8960,7 +8917,7 @@ const docTemplate = `{ "properties": { "command": { "type": "string", - "example": "sudo apt-get install ..." + "example": "client_ip=$(echo $SSH_CLIENT | awk '{print $1}'); echo SSH client IP is: $client_ip" }, "userName": { "type": "string", @@ -9446,17 +9403,6 @@ const docTemplate = `{ } } }, - "mcis.SpiderImageType": { - "type": "string", - "enum": [ - "PublicImage", - "MyImage" - ], - "x-enum-varnames": [ - "PublicImage", - "MyImage" - ] - }, "mcis.SpiderVMInfo": { "type": "object", "properties": { @@ -9478,11 +9424,7 @@ const docTemplate = `{ }, "iid": { "description": "Fields for response", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "imageIId": { "$ref": "#/definitions/common.IID" @@ -9491,7 +9433,7 @@ const docTemplate = `{ "type": "string" }, "imageType": { - "$ref": "#/definitions/mcis.SpiderImageType" + "type": "string" }, "keyPairIId": { "$ref": "#/definitions/common.IID" @@ -9527,11 +9469,7 @@ const docTemplate = `{ }, "region": { "description": "ex) {us-east1, us-east1-c} or {ap-northeast-2}", - "allOf": [ - { - "$ref": "#/definitions/mcis.RegionInfo" - } - ] + "$ref": "#/definitions/mcis.RegionInfo" }, "rootDeviceName": { "description": "\"/dev/sda1\", ...", @@ -9566,11 +9504,7 @@ const docTemplate = `{ }, "subnetIID": { "description": "AWS, ex) subnet-8c4a53e4", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "subnetName": { "type": "string" @@ -10009,19 +9943,11 @@ const docTemplate = `{ }, "healthChecker": { "description": "HealthChecker", - "allOf": [ - { - "$ref": "#/definitions/mcis.TbNLBHealthCheckerReq" - } - ] + "$ref": "#/definitions/mcis.TbNLBHealthCheckerReq" }, "listener": { "description": "Frontend", - "allOf": [ - { - "$ref": "#/definitions/mcis.NLBListenerReq" - } - ] + "$ref": "#/definitions/mcis.NLBListenerReq" }, "scope": { "description": "REGION(V) | GLOBAL", @@ -10034,11 +9960,7 @@ const docTemplate = `{ }, "targetGroup": { "description": "Backend", - "allOf": [ - { - "$ref": "#/definitions/mcis.TbNLBTargetGroupReq" - } - ] + "$ref": "#/definitions/mcis.TbNLBTargetGroupReq" }, "type": { "description": "PUBLIC(V) | INTERNAL", @@ -10237,11 +10159,7 @@ const docTemplate = `{ }, "region": { "description": "AWS, ex) {us-east1, us-east1-c} or {ap-northeast-2}", - "allOf": [ - { - "$ref": "#/definitions/mcis.RegionInfo" - } - ] + "$ref": "#/definitions/mcis.RegionInfo" }, "rootDeviceName": { "type": "string" @@ -10638,8 +10556,6 @@ var SwaggerInfo = &swag.Spec{ Description: "CB-Tumblebug REST API", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, - LeftDelim: "{{", - RightDelim: "}}", } func init() { diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index 3c44491cd..590fdb878 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -7422,34 +7422,6 @@ } } }, - "mcir.CustomImageStatus": { - "type": "string", - "enum": [ - "Available", - "Unavailable" - ], - "x-enum-varnames": [ - "MyImageAvailable", - "MyImageUnavailable" - ] - }, - "mcir.DiskStatus": { - "type": "string", - "enum": [ - "Creating", - "Available", - "Attached", - "Deleting", - "Error" - ], - "x-enum-varnames": [ - "DiskCreating", - "DiskAvailable", - "DiskAttached", - "DiskDeleting", - "DiskError" - ] - }, "mcir.FilterSpecsByRangeRequest": { "type": "object", "properties": { @@ -7715,11 +7687,7 @@ }, "iid": { "description": "Fields for response", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "keyValueList": { "type": "array", @@ -7870,11 +7838,7 @@ "example": "aws-ap-southeast-1-1" }, "status": { - "allOf": [ - { - "$ref": "#/definitions/mcir.CustomImageStatus" - } - ], + "type": "string", "example": "Available" }, "systemLabel": { @@ -7964,11 +7928,7 @@ }, "status": { "description": "Available, Unavailable, Attached, ...", - "allOf": [ - { - "$ref": "#/definitions/mcir.DiskStatus" - } - ], + "type": "string", "example": "Available" }, "systemLabel": { @@ -8675,11 +8635,7 @@ }, "postCommand": { "description": "PostCommand is field for providing command to VMs after its creation. example:\"wget https://raw.githubusercontent.com/cloud-barista/cb-tumblebug/main/scripts/setweb.sh -O ~/setweb.sh; chmod +x ~/setweb.sh; sudo ~/setweb.sh\"", - "allOf": [ - { - "$ref": "#/definitions/mcis.McisCmdReq" - } - ] + "$ref": "#/definitions/mcis.McisCmdReq" }, "vmDynamicReq": { "$ref": "#/definitions/mcis.TbVmDynamicReq" @@ -8953,7 +8909,7 @@ "properties": { "command": { "type": "string", - "example": "sudo apt-get install ..." + "example": "client_ip=$(echo $SSH_CLIENT | awk '{print $1}'); echo SSH client IP is: $client_ip" }, "userName": { "type": "string", @@ -9439,17 +9395,6 @@ } } }, - "mcis.SpiderImageType": { - "type": "string", - "enum": [ - "PublicImage", - "MyImage" - ], - "x-enum-varnames": [ - "PublicImage", - "MyImage" - ] - }, "mcis.SpiderVMInfo": { "type": "object", "properties": { @@ -9471,11 +9416,7 @@ }, "iid": { "description": "Fields for response", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "imageIId": { "$ref": "#/definitions/common.IID" @@ -9484,7 +9425,7 @@ "type": "string" }, "imageType": { - "$ref": "#/definitions/mcis.SpiderImageType" + "type": "string" }, "keyPairIId": { "$ref": "#/definitions/common.IID" @@ -9520,11 +9461,7 @@ }, "region": { "description": "ex) {us-east1, us-east1-c} or {ap-northeast-2}", - "allOf": [ - { - "$ref": "#/definitions/mcis.RegionInfo" - } - ] + "$ref": "#/definitions/mcis.RegionInfo" }, "rootDeviceName": { "description": "\"/dev/sda1\", ...", @@ -9559,11 +9496,7 @@ }, "subnetIID": { "description": "AWS, ex) subnet-8c4a53e4", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "subnetName": { "type": "string" @@ -10002,19 +9935,11 @@ }, "healthChecker": { "description": "HealthChecker", - "allOf": [ - { - "$ref": "#/definitions/mcis.TbNLBHealthCheckerReq" - } - ] + "$ref": "#/definitions/mcis.TbNLBHealthCheckerReq" }, "listener": { "description": "Frontend", - "allOf": [ - { - "$ref": "#/definitions/mcis.NLBListenerReq" - } - ] + "$ref": "#/definitions/mcis.NLBListenerReq" }, "scope": { "description": "REGION(V) | GLOBAL", @@ -10027,11 +9952,7 @@ }, "targetGroup": { "description": "Backend", - "allOf": [ - { - "$ref": "#/definitions/mcis.TbNLBTargetGroupReq" - } - ] + "$ref": "#/definitions/mcis.TbNLBTargetGroupReq" }, "type": { "description": "PUBLIC(V) | INTERNAL", @@ -10230,11 +10151,7 @@ }, "region": { "description": "AWS, ex) {us-east1, us-east1-c} or {ap-northeast-2}", - "allOf": [ - { - "$ref": "#/definitions/mcis.RegionInfo" - } - ] + "$ref": "#/definitions/mcis.RegionInfo" }, "rootDeviceName": { "type": "string" diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index 686bcd200..e834f4bf9 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -185,28 +185,6 @@ definitions: connectionName: type: string type: object - mcir.CustomImageStatus: - enum: - - Available - - Unavailable - type: string - x-enum-varnames: - - MyImageAvailable - - MyImageUnavailable - mcir.DiskStatus: - enum: - - Creating - - Available - - Attached - - Deleting - - Error - type: string - x-enum-varnames: - - DiskCreating - - DiskAvailable - - DiskAttached - - DiskDeleting - - DiskError mcir.FilterSpecsByRangeRequest: properties: connectionName: @@ -379,8 +357,7 @@ definitions: description: Windows7, Ubuntu etc. type: string iid: - allOf: - - $ref: '#/definitions/common.IID' + $ref: '#/definitions/common.IID' description: Fields for response keyValueList: items: @@ -484,9 +461,8 @@ definitions: example: aws-ap-southeast-1-1 type: string status: - allOf: - - $ref: '#/definitions/mcir.CustomImageStatus' example: Available + type: string systemLabel: description: SystemLabel is for describing the MCIR in a keyword (any string can be used) for special System purpose @@ -549,10 +525,9 @@ definitions: example: aws-ap-southeast-1-datadisk type: string status: - allOf: - - $ref: '#/definitions/mcir.DiskStatus' description: Available, Unavailable, Attached, ... example: Available + type: string systemLabel: description: SystemLabel is for describing the MCIR in a keyword (any string can be used) for special System purpose @@ -1043,8 +1018,7 @@ definitions: example: random type: string postCommand: - allOf: - - $ref: '#/definitions/mcis.McisCmdReq' + $ref: '#/definitions/mcis.McisCmdReq' description: PostCommand is field for providing command to VMs after its creation. example:"wget https://raw.githubusercontent.com/cloud-barista/cb-tumblebug/main/scripts/setweb.sh -O ~/setweb.sh; chmod +x ~/setweb.sh; sudo ~/setweb.sh" @@ -1228,7 +1202,8 @@ definitions: mcis.McisCmdReq: properties: command: - example: sudo apt-get install ... + example: 'client_ip=$(echo $SSH_CLIENT | awk ''{print $1}''); echo SSH client + IP is: $client_ip' type: string userName: example: cb-user @@ -1563,14 +1538,6 @@ definitions: $ref: '#/definitions/mcis.RestPostCmdMcisResponse' type: array type: object - mcis.SpiderImageType: - enum: - - PublicImage - - MyImage - type: string - x-enum-varnames: - - PublicImage - - MyImage mcis.SpiderVMInfo: properties: cspid: @@ -1585,15 +1552,14 @@ definitions: type: string type: array iid: - allOf: - - $ref: '#/definitions/common.IID' + $ref: '#/definitions/common.IID' description: Fields for response imageIId: $ref: '#/definitions/common.IID' imageName: type: string imageType: - $ref: '#/definitions/mcis.SpiderImageType' + type: string keyPairIId: $ref: '#/definitions/common.IID' keyPairName: @@ -1617,8 +1583,7 @@ definitions: publicIP: type: string region: - allOf: - - $ref: '#/definitions/mcis.RegionInfo' + $ref: '#/definitions/mcis.RegionInfo' description: ex) {us-east1, us-east1-c} or {ap-northeast-2} rootDeviceName: description: '"/dev/sda1", ...' @@ -1643,8 +1608,7 @@ definitions: startTime: type: string subnetIID: - allOf: - - $ref: '#/definitions/common.IID' + $ref: '#/definitions/common.IID' description: AWS, ex) subnet-8c4a53e4 subnetName: type: string @@ -1969,12 +1933,10 @@ definitions: description: type: string healthChecker: - allOf: - - $ref: '#/definitions/mcis.TbNLBHealthCheckerReq' + $ref: '#/definitions/mcis.TbNLBHealthCheckerReq' description: HealthChecker listener: - allOf: - - $ref: '#/definitions/mcis.NLBListenerReq' + $ref: '#/definitions/mcis.NLBListenerReq' description: Frontend scope: description: REGION(V) | GLOBAL @@ -1984,8 +1946,7 @@ definitions: example: REGION type: string targetGroup: - allOf: - - $ref: '#/definitions/mcis.TbNLBTargetGroupReq' + $ref: '#/definitions/mcis.TbNLBTargetGroupReq' description: Backend type: description: PUBLIC(V) | INTERNAL @@ -2142,8 +2103,7 @@ definitions: publicIP: type: string region: - allOf: - - $ref: '#/definitions/mcis.RegionInfo' + $ref: '#/definitions/mcis.RegionInfo' description: AWS, ex) {us-east1, us-east1-c} or {ap-northeast-2} rootDeviceName: type: string diff --git a/src/core/mcis/remoteCommand.go b/src/core/mcis/remoteCommand.go index 13fd4585d..9afb82eda 100644 --- a/src/core/mcis/remoteCommand.go +++ b/src/core/mcis/remoteCommand.go @@ -34,7 +34,7 @@ var sshDefaultUserName = []string{"cb-user", "ubuntu", "root", "ec2-user"} // McisCmdReq is struct for remote command type McisCmdReq struct { UserName string `json:"userName" example:"cb-user" default:""` - Command string `json:"command" validate:"required" example:"sudo apt-get install ..."` + Command string `json:"command" validate:"required" example:"client_ip=$(echo $SSH_CLIENT | awk '{print $1}'); echo SSH client IP is: $client_ip"` } // TbMcisCmdReqStructLevelValidation is func to validate fields in McisCmdReq @@ -163,18 +163,42 @@ func RemoteCommandToMcis(nsId string, mcisId string, subGroupId string, vmId str } // RunRemoteCommand is func to execute a SSH command to a VM (sync call) -func RunRemoteCommand(vmIP string, sshPort string, userName string, privateKey string, cmd string) (*string, error) { +func RunRemoteCommand(nsId string, mcisId string, vmId string, givenUserName string, cmd string) (*string, error) { - // Set VM SSH config (serverEndpoint, userName, Private Key) - serverEndpoint := fmt.Sprintf("%s:%s", vmIP, sshPort) - sshInfo := sshInfo{ - EndPoint: serverEndpoint, - UserName: userName, - PrivateKey: []byte(privateKey), + var result string + vmIP, targetSshPort := GetVmIp(nsId, mcisId, vmId) + targetUserName, targetPrivateKey, err := VerifySshUserName(nsId, mcisId, vmId, vmIP, targetSshPort, givenUserName) + + // Set Bastion SSH config (bastionEndpoint, userName, Private Key) + bastionNodes, err := GetBastionNodes(nsId, mcisId, vmId) + if err != nil { + common.CBLog.Error(err) + return &result, err + } + bastionNode := bastionNodes.VmId[0] + bastionIp, bastionSshPort := GetVmIp(nsId, mcisId, bastionNode) + bastionUserName, bastionSshKey, err := VerifySshUserName(nsId, mcisId, bastionNode, bastionIp, bastionSshPort, givenUserName) + bastionEndpoint := fmt.Sprintf("%s:%s", bastionIp, bastionSshPort) + + bastionSshInfo := sshInfo{ + EndPoint: bastionEndpoint, + UserName: bastionUserName, + PrivateKey: []byte(bastionSshKey), + } + + fmt.Println("[SSH] " + mcisId + "." + vmId + "(" + vmIP + ")" + " with userName: " + targetUserName) + fmt.Println("[CMD] " + cmd) + + // Set VM SSH config (targetEndpoint, userName, Private Key) + targetEndpoint := fmt.Sprintf("%s:%s", vmIP, targetSshPort) + targetSshInfo := sshInfo{ + EndPoint: targetEndpoint, + UserName: targetUserName, + PrivateKey: []byte(targetPrivateKey), } // Execute SSH - result, err := runSSH(sshInfo, sshInfo, cmd) + result, err = runSSH(bastionSshInfo, targetSshInfo, cmd) if err != nil { return &result, err } @@ -187,23 +211,14 @@ func RunRemoteCommandAsync(wg *sync.WaitGroup, nsId string, mcisId string, vmId defer wg.Done() //goroutin sync done - vmIp, sshPort := GetVmIp(nsId, mcisId, vmId) - userName, sshKey, err := VerifySshUserName(nsId, mcisId, vmId, vmIp, sshPort, givenUserName) - // Eventhough VerifySshUserName is not complete, Try RunRemoteCommand - // With RunRemoteCommand, error will be checked again - - fmt.Println("") - fmt.Println("[SSH] " + mcisId + "." + vmId + "(" + vmIp + ")" + " with userName: " + userName) - fmt.Println("[CMD] " + cmd) - fmt.Println("") - + vmIP, _ := GetVmIp(nsId, mcisId, vmId) // RunRemoteCommand - result, err := RunRemoteCommand(vmIp, sshPort, userName, sshKey, cmd) + result, err := RunRemoteCommand(nsId, mcisId, vmId, givenUserName, cmd) sshResultTmp := SshCmdResult{} - sshResultTmp.McisId = "" + sshResultTmp.McisId = mcisId sshResultTmp.VmId = vmId - sshResultTmp.VmIp = vmIp + sshResultTmp.VmIp = vmIP if err != nil { sshResultTmp.Result = ("[ERROR: " + err.Error() + "]\n " + *result) @@ -224,58 +239,80 @@ func RunRemoteCommandAsync(wg *sync.WaitGroup, nsId string, mcisId string, vmId // VerifySshUserName is func to verify SSH username func VerifySshUserName(nsId string, mcisId string, vmId string, vmIp string, sshPort string, givenUserName string) (string, string, error) { - // find vaild username - userName, verifiedUserName, privateKey := GetVmSshKey(nsId, mcisId, vmId) - userNames := []string{ - sshDefaultUserName[0], - userName, - givenUserName, - sshDefaultUserName[1], - sshDefaultUserName[2], - sshDefaultUserName[3], - } + // Disable the verification of SSH username (until bastion host is supported) + + // // find vaild username + // userName, verifiedUserName, privateKey := GetVmSshKey(nsId, mcisId, vmId) + // userNames := []string{ + // sshDefaultUserName[0], + // userName, + // givenUserName, + // sshDefaultUserName[1], + // sshDefaultUserName[2], + // sshDefaultUserName[3], + // } - theUserName := "" - cmd := "sudo ls" + // theUserName := "" + // cmd := "sudo ls" + + // if verifiedUserName != "" { + // /* Code for strict check in advance with real SSH (but slow down speed) + // fmt.Printf("\n[Check SSH] (%s) with userName: %s\n", vmIp, verifiedUserName) + // _, err := RunRemoteCommand(vmIp, sshPort, verifiedUserName, privateKey, cmd) + // if err != nil { + // return "", "", fmt.Errorf("Cannot do ssh, with %s, %s", verifiedUserName, err.Error()) + // }*/ + // theUserName = verifiedUserName + // fmt.Printf("[%s] is a valid UserName\n", theUserName) + // return theUserName, privateKey, nil + // } - if verifiedUserName != "" { - /* Code for strict check in advance with real SSH (but slow down speed) - fmt.Printf("\n[Check SSH] (%s) with userName: %s\n", vmIp, verifiedUserName) - _, err := RunRemoteCommand(vmIp, sshPort, verifiedUserName, privateKey, cmd) - if err != nil { - return "", "", fmt.Errorf("Cannot do ssh, with %s, %s", verifiedUserName, err.Error()) - }*/ - theUserName = verifiedUserName - fmt.Printf("[%s] is a valid UserName\n", theUserName) - return theUserName, privateKey, nil - } - - // If we have a varified username, Retrieve ssh username from the given list will not be executed - fmt.Println("[Retrieve ssh username from the given list]") - for _, v := range userNames { - if v != "" { - fmt.Printf("[Check SSH] (%s) with userName: %s\n", vmIp, v) - _, err := RunRemoteCommand(vmIp, sshPort, v, privateKey, cmd) - if err != nil { - fmt.Printf("Cannot do ssh, with %s, %s", verifiedUserName, err.Error()) - } else { - theUserName = v - fmt.Printf("[%s] is a valid UserName\n", theUserName) - break - } - time.Sleep(3 * time.Second) - } - } - if theUserName != "" { - err := UpdateVmSshKey(nsId, mcisId, vmId, theUserName) - if err != nil { - common.CBLog.Error(err) - return "", "", err - } + // // If we have a varified username, Retrieve ssh username from the given list will not be executed + // fmt.Println("[Retrieve ssh username from the given list]") + // for _, v := range userNames { + // if v != "" { + // fmt.Printf("[Check SSH] (%s) with userName: %s\n", vmIp, v) + // _, err := RunRemoteCommand(vmIp, sshPort, v, privateKey, cmd) + // if err != nil { + // fmt.Printf("Cannot do ssh, with %s, %s", verifiedUserName, err.Error()) + // } else { + // theUserName = v + // fmt.Printf("[%s] is a valid UserName\n", theUserName) + // break + // } + // time.Sleep(3 * time.Second) + // } + // } + + userName, _, privateKey := GetVmSshKey(nsId, mcisId, vmId) + + theUserName := "" + if givenUserName != "" { + theUserName = givenUserName + } else if userName != "" { + theUserName = userName } else { - return "", "", fmt.Errorf("Could not find a valid username") + theUserName = sshDefaultUserName[0] // default username: cb-user + } + + if theUserName == "" { + err := fmt.Errorf("Could not find a valid username") + common.CBLog.Error(err) + return "", "", err } + // Disable the verification of SSH username (until bastion host is supported) + + // if theUserName != "" { + // err := UpdateVmSshKey(nsId, mcisId, vmId, theUserName) + // if err != nil { + // common.CBLog.Error(err) + // return "", "", err + // } + // } else { + // return "", "", fmt.Errorf("Could not find a valid username") + // } + return theUserName, privateKey, nil } @@ -310,7 +347,7 @@ func GetVmSshKey(nsId string, mcisId string, vmId string) (string, string, strin SshKeyId string `json:"sshKeyId"` } - fmt.Println("[GetVmSshKey]" + vmId) + //fmt.Println("[GetVmSshKey]" + vmId) key := common.GenMcisKey(nsId, mcisId, vmId) keyValue, err := common.CBStore.Get(key) @@ -323,7 +360,7 @@ func GetVmSshKey(nsId string, mcisId string, vmId string) (string, string, strin json.Unmarshal([]byte(keyValue.Value), &content) - fmt.Printf("%+v\n", content.SshKeyId) + //fmt.Printf("%+v\n", content.SshKeyId) sshKey := common.GenResourceKey(nsId, common.StrSSHKey, content.SshKeyId) keyValue, _ = common.CBStore.Get(sshKey) @@ -384,7 +421,7 @@ type sshInfo struct { } // runSSH func execute a command by SSH -func runSSH(targetInfo sshInfo, bastionInfo sshInfo, cmd string) (string, error) { +func runSSH(bastionInfo sshInfo, targetInfo sshInfo, cmd string) (string, error) { // Parse the private key for the bastion host bastionSigner, err := ssh.ParsePrivateKey(bastionInfo.PrivateKey) if err != nil {