func (this *TemplatesDetailController) List(serviceId int64) { service := entity.Service{} service.Id = serviceId service.Load() template, errs := entity.LoadTemplateList(serviceId) this.Data["Template"] = template if errs != nil { this.Data["MessageErr"] = fmt.Sprintf("Errors: %s", errs) } component, componenterrors := entity.LoadComponentList(serviceId) this.Data["Component"] = component if componenterrors != nil { this.Data["MessageErr"] = fmt.Sprintf("Errors: %s", componenterrors) } if service.Where == utils.Deploy_On_Vms { operation := entity.Operation{} operation.Sid = serviceId operationerrors := operation.LoadBySid() this.Data["Operation"] = operation if operationerrors != nil { this.Data["MessageErr"] = fmt.Sprintf("Errors: %s", operationerrors) } } this.TplName = "templates/index_detail.tpl" }
// parse template 2 file func (servicedDeploy *ServiceDeployWebSocketController) ParseTemplate(ws *websocket.Conn, service entity.Service) bool { writeStringMessage(ws, "Load templateList") template, templateLoadErr := entity.LoadTemplateList(service.Id) if templateLoadErr != nil { writeStringMessage(ws, fmt.Sprintf("Error,%s", templateLoadErr)) return false } writeStringMessage(ws, "Load componentList") component, componentErr := entity.LoadComponentList(service.Id) if componentErr != nil { writeStringMessage(ws, fmt.Sprintf("Error,%s", componentErr)) return false } writeStringMessage(ws, "Parse template") data := make(map[string]string) if len(component) > 0 { for _, item := range component { data[item.Name] = item.Value } } for _, templatefile := range template { if templatefile.FileType == utils.FileTypes_Template { if templatefile.TargetFile == "" { writeStringMessage(ws, fmt.Sprintf("%s TargetFile is null,please set the value", templatefile.Name)) } if templatefile.TemplateFile == "" { writeStringMessage(ws, fmt.Sprintf("%s TemplateFile is null,please set the value", templatefile.Name)) } result, err := utils.ParseTemplateFile2File(templatefile.TargetFile, data, templatefile.TemplateFile) if !result { writeStringMessage(ws, fmt.Sprintf("Error,%s", err)) return result } } } writeStringMessage(ws, "Parse template successful") return true }
// deploy 2 vms func (serviceDeploy *ServiceDeployWebSocketController) Deploy2Vms(ws *websocket.Conn, service entity.Service) { //加载serviceDto // writeStringMessage(ws, "Load ServiceDto") serviceDto := entity.ServiceDto{} serviceDto.Service = service err := serviceDto.Load() if err != nil { writeStringMessage(ws, fmt.Sprintf("Error,%s", err)) return } //加载TemplateList writeStringMessage(ws, "Load TemplateList") template, templateLoadErr := entity.LoadTemplateList(service.Id) if templateLoadErr != nil { writeStringMessage(ws, fmt.Sprintf("Error,%s", templateLoadErr)) return } //模板输出文件 result := serviceDeploy.ParseTemplate(ws, service) if !result { return } //模板输出文件 //传输文件 writeStringMessage(ws, "传输文件...") vms := serviceDto.OnCustom sshRunner := utils.NewDeploySSHRunner(vms.Ip, vms.User, vms.Passwd) for index, temp1 := range template { if temp1.FileType != utils.FileTypes_War { continue } serviceDeploy.pushFiles(ws, index, temp1, sshRunner) } writeStringMessage(ws, "Finish deploying") }