(cmd *cobra.Command, args []string, workspaceInfo workspace.WorkspaceInfo, yamlExecuteFun func(yamlConfig config.SmartIdeConfig))
| 35 | ) |
| 36 | |
| 37 | func VmInit(cmd *cobra.Command, args []string, workspaceInfo workspace.WorkspaceInfo, |
| 38 | yamlExecuteFun func(yamlConfig config.SmartIdeConfig)) { |
| 39 | |
| 40 | appinsight.SetCliTrack(appinsight.Cli_Host_Init, args) |
| 41 | |
| 42 | mode, _ := cmd.Flags().GetString("mode") |
| 43 | isModeServer := strings.ToLower(mode) == "server" |
| 44 | // 错误反馈 |
| 45 | serverFeedback := func(err error) { |
| 46 | if !isModeServer { |
| 47 | return |
| 48 | } |
| 49 | if err != nil { |
| 50 | smartideServer.Feedback_Finish(smartideServer.FeedbackCommandEnum_New, cmd, false, nil, workspace.WorkspaceInfo{}, err.Error(), "") |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if apiHost, _ := cmd.Flags().GetString(smartideServer.Flags_ServerHost); apiHost != "" { |
| 55 | wsURL := fmt.Sprint(strings.ReplaceAll(strings.ReplaceAll(apiHost, "https", "ws"), "http", "ws"), "/ws/smartide/ws") |
| 56 | common.WebsocketStart(wsURL) |
| 57 | token, _ := cmd.Flags().GetString(smartideServer.Flags_ServerToken) |
| 58 | if token != "" { |
| 59 | if workspaceIdStr, _ := cmd.Flags().GetString(smartideServer.Flags_ServerWorkspaceid); workspaceIdStr != "" { |
| 60 | if no, _ := workspace.GetWorkspaceNo(workspaceIdStr, token, apiHost); no != "" { |
| 61 | if pid, err := workspace.GetParentId(no, workspace.ActionEnum_Workspace_Start, token, apiHost); err == nil && pid > 0 { |
| 62 | common.SmartIDELog.Ws_id = no |
| 63 | common.SmartIDELog.ParentId = pid |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | //0. 连接到远程主机 |
| 72 | msg := fmt.Sprintf(" %v@%v:%v ...", workspaceInfo.Remote.UserName, workspaceInfo.Remote.Addr, workspaceInfo.Remote.SSHPort) |
| 73 | common.SmartIDELog.Info(i18nInstance.VmStart.Info_connect_remote + msg) |
| 74 | sshRemote, err := common.NewSSHRemote(workspaceInfo.Remote.Addr, workspaceInfo.Remote.SSHPort, workspaceInfo.Remote.UserName, workspaceInfo.Remote.Password, workspaceInfo.Remote.SSHKey) |
| 75 | common.CheckErrorFunc(err, serverFeedback) |
| 76 | |
| 77 | //1. 检查远程主机是否有docker、docker-compose、git |
| 78 | err = sshRemote.CheckRemoteEnv() |
| 79 | common.CheckErrorFunc(err, serverFeedback) |
| 80 | |
| 81 | // 获取command中的配置 |
| 82 | selectedTemplateSettings, err := getTemplateSetting(cmd, args) |
| 83 | common.CheckError(err) |
| 84 | if selectedTemplateSettings == nil { // 未指定模板类型的时候,提示用户后退出 |
| 85 | return // 退出 |
| 86 | } |
| 87 | |
| 88 | // 文件夹检查 |
| 89 | workspaceDirName, _ := cmd.Flags().GetString("workspacename") // 指定的项目名称 |
| 90 | if workspaceDirName == "" { |
| 91 | common.CheckErrorFunc(errors.New("参数 workspacename 不能为空!"), serverFeedback) |
| 92 | } |
| 93 | err = checkRemoteDir(sshRemote, workspaceInfo.WorkingDirectoryPath, cmd) |
| 94 | common.CheckErrorFunc(err, serverFeedback) |
nothing calls this directly
no test coverage detected