當前位置: 首頁>>代碼示例>>Golang>>正文


Golang sshclient.SshSetting類代碼示例

本文整理匯總了Golang中github.com/eaciit/sshclient.SshSetting的典型用法代碼示例。如果您正苦於以下問題:Golang SshSetting類的具體用法?Golang SshSetting怎麽用?Golang SshSetting使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SshSetting類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: runWithTimeout

func (a *Application) runWithTimeout(sshSetting sshclient.SshSetting, cmd string) (string, error) {
	timeout := time.Second * time.Duration(5)
	cRunCommand := make(chan string, 1)
	var res string

	go func(res *string) {
		temp, err := sshSetting.RunCommandSshAsMap(cmd)
		*res = temp[0].Output

		if err != nil {
			cRunCommand <- err.Error()
		} else {
			cRunCommand <- ""
		}
	}(&res)

	errorMessage := ""
	select {
	case receiveRunCommandOutput := <-cRunCommand:
		errorMessage = receiveRunCommandOutput
	case <-time.After(time.Second * time.Duration(timeout)):
		errorMessage = ""
	}

	if strings.TrimSpace(errorMessage) != "" {
		return "", errors.New(errorMessage)
	}

	return strings.TrimSpace(res), nil
}
開發者ID:rinosukmandityo,項目名稱:colony-core,代碼行數:30,代碼來源:application.go

示例2: SSHConnect

func (s *ServerController) SSHConnect(payload *colonycore.Server) (sshclient.SshSetting, *ssh.Client, error) {
	client := sshclient.SshSetting{}
	client.SSHHost = payload.Host

	if payload.SSHType == "File" {
		client.SSHAuthType = sshclient.SSHAuthType_Certificate
		client.SSHKeyLocation = payload.SSHFile
	} else {
		client.SSHAuthType = sshclient.SSHAuthType_Password
		client.SSHUser = payload.SSHUser
		client.SSHPassword = payload.SSHPass
	}

	theClient, err := client.Connect()

	return client, theClient, err
}
開發者ID:kranjcarz,項目名稱:colony-manager,代碼行數:17,代碼來源:server.go

示例3: Connect

func (s *Server) Connect() (sshclient.SshSetting, *ssh.Client, error) {
	client := sshclient.SshSetting{}
	client.SSHHost = s.Host

	if s.SSHType == "File" {
		client.SSHAuthType = sshclient.SSHAuthType_Certificate
		client.SSHKeyLocation = s.SSHFile
	} else {
		client.SSHAuthType = sshclient.SSHAuthType_Password
		client.SSHUser = s.SSHUser
		client.SSHPassword = s.SSHPass
	}

	theClient, err := client.Connect()

	return client, theClient, err
}
開發者ID:arfian,項目名稱:colony-core,代碼行數:17,代碼來源:server.go

示例4: SSHConnect

func (s *ServerController) SSHConnect(payload *colonycore.Server) (sshclient.SshSetting, *ssh.Client, error) {
	client := sshclient.SshSetting{}
	client.SSHHost = "192.168.56.103:22"

	client.SSHAuthType = 0
	client.SSHUser = "eaciit1"
	client.SSHPassword = "12345"

	//fmt.Println(client) {192.168.56.103:22 eaciit1 12345  0}

	theClient, err := client.Connect()

	return client, theClient, err
}
開發者ID:novalagung,項目名稱:sedotan,代碼行數:14,代碼來源:z3_test.go

示例5: ProcessSetup

func (l *LangenvironmentController) ProcessSetup(dataServers *colonycore.Server, query *dbox.Filter, serverPathSeparator string, sshSetting sshclient.SshSetting) ([]sshclient.RunCommandResult, error) {
	outputCmd := []sshclient.RunCommandResult{}

	dataLanguage := []colonycore.LanguageEnviroment{}
	cursor, err := colonycore.Find(new(colonycore.LanguageEnviroment), query)
	cursor.Fetch(&dataLanguage, 0, false)
	if err != nil {
		return outputCmd, err
	}
	defer cursor.Close()

	if cursor.Count() > 0 {
		for _, eachLang := range dataLanguage {
			for _, dataInstaller := range eachLang.Installer {
				var sourcePath string
				var destinationPath string
				pathstring := []string{dataServers.DataPath, "langenvironment", "installer"}

				var installShPath, uninstallShPath string

				if strings.ToLower(dataServers.OS) == strings.ToLower(dataInstaller.OS) {
					// targetLang := new(colonycore.InstalledLang)
					// targetLang.Lang = eachLang.Language

					// for _, eachLang := range dataServers.InstalledLang {
					// 	if eachLang.Lang == targetLang.Lang {
					// 		targetLang = eachLang
					// 		break
					// 	}
					// }

					if eachLang.Language == LANG_GO {
						pathstring = append(pathstring, LANG_GO)
						pathstring = append(pathstring, dataServers.OS)
						sourcePath = filepath.Join(leSourcePath, LANG_GO, dataServers.OS, dataInstaller.InstallerSource)
						destinationPath = strings.Join(pathstring, serverPathSeparator)
						installShPath = filepath.Join(leSourcePath, LANG_GO, dataServers.OS, "install.sh")
						uninstallShPath = filepath.Join(leSourcePath, LANG_GO, dataServers.OS, "uninstall.sh")
					} else if eachLang.Language == LANG_JAVA {
						pathstring = append(pathstring, LANG_JAVA)
						pathstring = append(pathstring, dataServers.OS)
						sourcePath = filepath.Join(leSourcePath, LANG_JAVA, dataServers.OS, dataInstaller.InstallerSource)
						destinationPath = strings.Join(pathstring, serverPathSeparator)
						installShPath = filepath.Join(leSourcePath, LANG_JAVA, dataServers.OS, "install.sh")
						uninstallShPath = filepath.Join(leSourcePath, LANG_JAVA, dataServers.OS, "uninstall.sh")
					} else if eachLang.Language == LANG_SCALA {
						pathstring = append(pathstring, LANG_SCALA)
						pathstring = append(pathstring, dataServers.OS)
						sourcePath = filepath.Join(leSourcePath, LANG_SCALA, dataServers.OS, dataInstaller.InstallerSource)
						destinationPath = strings.Join(pathstring, serverPathSeparator)
						installShPath = filepath.Join(leSourcePath, LANG_SCALA, dataServers.OS, "install.sh")
						uninstallShPath = filepath.Join(leSourcePath, LANG_SCALA, dataServers.OS, "uninstall.sh")
					}
					installShdestPath := strings.Join(append(pathstring, "install.sh"), serverPathSeparator)
					uninstallShdestPath := strings.Join(append(pathstring, "uninstall.sh"), serverPathSeparator)
					// installFilePath := strings.Join(append(pathstring, dataInstaller.InstallerSource), serverPathSeparator)

					err = sshSetting.SshCopyByPath(sourcePath, destinationPath)
					if err != nil {
						return outputCmd, err
					}

					err = sshSetting.SshCopyByPath(installShPath, destinationPath)
					if err != nil {
						return outputCmd, err
					}

					err = sshSetting.SshCopyByPath(uninstallShPath, destinationPath)
					if err != nil {
						return outputCmd, err
					}

					//sed -i 's/^M//' install.sh
					cmdSedInstall := fmt.Sprintf("sed -i 's/\r//g' %s", installShdestPath)
					_, err = sshSetting.GetOutputCommandSsh(cmdSedInstall)
					if err != nil {
						return outputCmd, err
					}
					//sed -i 's/^M//' uninstall.sh
					cmdSedUninstall := fmt.Sprintf("sed -i 's/\r//g' %s", uninstallShdestPath)
					_, err = sshSetting.GetOutputCommandSsh(cmdSedUninstall)
					if err != nil {
						return outputCmd, err
					}

					// // chmod +x install.sh
					cmdChmodCliInstall := fmt.Sprintf("chmod +x %s", installShdestPath)
					_, err = sshSetting.GetOutputCommandSsh(cmdChmodCliInstall)
					if err != nil {
						return outputCmd, err
					}
					// // chmod +x uninstall.sh
					cmdChmodCliUninstall := fmt.Sprintf("chmod +x %s", uninstallShdestPath)
					_, err = sshSetting.GetOutputCommandSsh(cmdChmodCliUninstall)
					if err != nil {
						return outputCmd, err
					}

					// // sh install.sh installFilePath DESTINSTALL_PATH projectpath
					cmdShCli := fmt.Sprintf("bash %s %s", uninstallShdestPath, DESTINSTALL_PATH)
//.........這裏部分代碼省略.........
開發者ID:eaciit,項目名稱:colony-manager,代碼行數:101,代碼來源:langenvironment.go


注:本文中的github.com/eaciit/sshclient.SshSetting類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。