func (this *ServiceDeployWebSocketController) operateAppOnPaaS(ws *websocket.Conn, onPaaS entity.OnPaaS, deployDir string, operate string) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Operate app ") var out bytes.Buffer mapps, err := utils.ReadYamlFile(deployDir + "/manifest.yml") var apps []string if err != nil { writeStringMessage(ws, fmt.Sprintf("Operate app failed ,errors :%v", err)) return false } if err == nil { apps, err = utils.GetValuesByKey(mapps, "name") if err != nil { writeStringMessage(ws, fmt.Sprintf("Operate app failed ,errors :%v", err)) return false } if err == nil { for _, app := range apps { if app != "" { cfOperateCommand := utils.Command{Name: "cf", Args: []string{operate, app}, Dir: deployDir, Stdin: "", Env: []string{"CF_COLOR=false"}} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(cfOperateCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) } } writeStringMessage(ws, "Operate app successful") } } writeStringMessage(ws, "============================================") return true }
//delete microbosh func (this *MicroBOSHWebSocketController) deleteMicroBOSH(ws *websocket.Conn) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Deleting MicroBOSH instances") var out bytes.Buffer cmdCommand := utils.Command{Name: "bosh", Args: []string{"micro", "delete"}, Dir: workDir, Stdin: "yes"} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(cmdCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) cleanCmdCommand := utils.Command{Name: "sh", Args: []string{"rm_bosh_deployment.sh"}, Dir: workDir, Stdin: ""} cleanCmdRunner := utils.NewDeployCmdRunner() cleanCmdRunner.RunCommandAsyncCmd(cleanCmdCommand, &out) writeBytesBufferMessage(&out, &cleanCmdRunner, ws) writeStringMessage(ws, "Finished deleting MicroBOSH instances") writeStringMessage(ws, "============================================") return cmdRunner.Success() }
//upload CloudFoundryv2 release func (this *CloudFoundryWebSocketController) uploadRelease(ws *websocket.Conn) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Uploading PaaS v2 release") var out bytes.Buffer cmdCommand := utils.Command{Name: "bosh", Args: []string{"upload", "release", cloudFoundryRelease, "--skip-if-exists"}, Dir: workDir, Stdin: ""} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(cmdCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) writeStringMessage(ws, fmt.Sprintf("Finished uploading PaaS v2 release %s ", cloudFoundryRelease)) writeStringMessage(ws, "============================================") return cmdRunner.Success() }
//bosh vms func (this *CloudFoundryWebSocketController) statsCloudFoundry(ws *websocket.Conn) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Status PaaS Instances") var out bytes.Buffer cmdCommand := utils.Command{Name: "bosh", Args: []string{"vms", cf.CloudFoundryProperties.Name, "--details"}, Dir: workDir, Stdin: ""} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(cmdCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) writeStringMessage(ws, "Finished Status PaaS CloudFoundry Instances") writeStringMessage(ws, "============================================") return cmdRunner.Success() }
//set deployment func (this *MicroBOSHWebSocketController) setMicroBOSHDeployment(ws *websocket.Conn) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Set MicroBOSH Deployment") var out bytes.Buffer cmdCommand := utils.Command{Name: "bosh", Args: []string{"micro", "deployment", microManiest}, Dir: workDir, Stdin: ""} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(cmdCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) writeStringMessage(ws, "Finished Set MicroBOSH Deployment") writeStringMessage(ws, "============================================") return cmdRunner.Success() }
func (this *MicroBOSHWebSocketController) statusMicroBOSH(ws *websocket.Conn) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Status MicroBOSH instances") var out bytes.Buffer loginCommand := utils.Command{Name: "bosh", Args: []string{"status"}, Dir: workDir, Stdin: ""} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(loginCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) writeStringMessage(ws, "Finished Status MicroBOSH") writeStringMessage(ws, "============================================") return cmdRunner.Success() }
func (serviceDeploy *ServiceDeployWebSocketController) pushFiles(ws *websocket.Conn, index int, template entity.Template, sshRunner utils.DeploySSHRunner) { var out bytes.Buffer // writeStringMessage(ws, fmt.Sprintf("%d,检测文件%s", index, template.Name)) dir, filename, isDir, err := utils.Detechfile(template.TemplateFile) if err != nil { writeStringMessage(ws, fmt.Sprintf("%d,检测文件%s 发生错误:Error %s", index, template.Name, err)) return } // writeStringMessage(ws, fmt.Sprintf("%s,%s,%s,%s", dir, filename, isDir, err)) //开始处理文件,压缩打包文件,scp传送 //压缩文件,主要解决scp不拷贝symbolic link if isDir { // writeStringMessage(ws, fmt.Sprintf("%d,检测文件%s是文件夹,准备打包", index, template.Name)) cmdCommand := utils.Command{Name: "tar", Args: []string{"-czf", filename + ".tgz", filename}, Dir: dir, Stdin: ""} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandCmd(cmdCommand, &out) // writeStringMessage(ws, fmt.Sprintf("%d,检测文件%s是文件夹,打包完毕", index, template.Name)) } writeStringMessage(ws, fmt.Sprintf("deploy index:%d,fileName:%s,filePath:%s", index, template.Name, template.TemplateFile)) filetgz := template.TemplateFile if isDir { filetgz = filetgz + ".tgz" } ssherror := sshRunner.Push(filetgz, "~/", &out) if ssherror != nil { writeStringMessage(ws, fmt.Sprintf("传输出错了。%s", ssherror)) return } if isDir { os.Remove(filetgz) } writeBufferMessage(ws, &out) if isDir { cmd := fmt.Sprintf("cd ~/ && tar -xzf %s && rm %s", filename+".tgz", filename+".tgz") ssherror = sshRunner.RunCommand(cmd, &out) if ssherror != nil { writeStringMessage(ws, fmt.Sprintf("解压出错了。%s", ssherror)) return } } }
//target to microbosh func (this *MicroBOSHWebSocketController) targetMicroBOSH(ws *websocket.Conn) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Target to MicroBOSH instances") var out bytes.Buffer var ip string = mi.NetWork.Vip target := fmt.Sprintf("https://%s:25555", ip) loginCommand := utils.Command{Name: "bosh", Args: []string{"target", target}, Dir: workDir, Stdin: "admin\nadmin\n"} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(loginCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) writeStringMessage(ws, "Finished target to MicroBOSH instances") writeStringMessage(ws, "============================================") return cmdRunner.Success() }
func (this *ServiceDeployWebSocketController) pushApp(ws *websocket.Conn, onPaaS entity.OnPaaS, deployDir string) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Deploying app ") var out bytes.Buffer cfDeployCommand := utils.Command{Name: "cf", Args: []string{"push", "-f", "manifest.yml"}, Dir: deployDir, Stdin: "", Env: []string{"CF_COLOR=false"}} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(cfDeployCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) writeStringMessage(ws, "Deploy app successful") writeStringMessage(ws, "============================================") return cmdRunner.Success() }
func (this *ServiceDeployWebSocketController) targetPaaS(ws *websocket.Conn, onPaaS entity.OnPaaS, deployDir string) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Target PaaS ") var out bytes.Buffer cfTargetCommand := utils.Command{Name: "cf", Args: []string{"target", "-o", onPaaS.Org, "-s", onPaaS.Space}, Dir: deployDir, Stdin: "", Env: []string{"CF_COLOR=false"}} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(cfTargetCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) writeStringMessage(ws, "Target PaaS successful") writeStringMessage(ws, "============================================") return cmdRunner.Success() }
func (this *ServiceDeployWebSocketController) loginPaaS(ws *websocket.Conn, onPaaS entity.OnPaaS, deployDir string) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Login PaaS ") var out bytes.Buffer cfLoginCommand := utils.Command{Name: "cf", Args: []string{"login", onPaaS.Api}, Dir: deployDir, Stdin: onPaaS.User + "\n" + onPaaS.Passwd + "\n", Env: []string{"CF_COLOR=false"}} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(cfLoginCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) writeStringMessage(ws, "Login PaaS successful") writeStringMessage(ws, "============================================") return cmdRunner.Success() }
func (this *ServiceDeployWebSocketController) setApi(ws *websocket.Conn, onPaaS entity.OnPaaS, deployDir string) bool { writeStringMessage(ws, "============================================") writeStringMessage(ws, "Set endpoint ") var out bytes.Buffer cfEndpointCommand := utils.Command{Name: "cf", Args: []string{"api", onPaaS.Api}, Dir: deployDir, Stdin: "", Env: []string{"CF_COLOR=false"}} cmdRunner := utils.NewDeployCmdRunner() cmdRunner.RunCommandAsyncCmd(cfEndpointCommand, &out) writeBytesBufferMessage(&out, &cmdRunner, ws) writeStringMessage(ws, "Set endpoint successful") writeStringMessage(ws, "============================================") return cmdRunner.Success() }