// @Title acknowledge // @Description acknowledge the event // @Param namespace path string true "The namespace where the event is" // @Param id path string true "The id of the event" // @Param acknowledge query string true "acknowledge (true) or unacknowledge (false)" // @Success 200 {string} {} // @Failure 404 error reason // @router /acknowledge/:namespace/:id [put] func (c *AcknowledgeController) Put() { namespace := c.GetString(":namespace") id := c.GetString(":id") acknowledge := c.GetString("acknowledge") cloudoneAnalysisProtocol := beego.AppConfig.String("cloudoneAnalysisProtocol") cloudoneAnalysisHost := beego.AppConfig.String("cloudoneAnalysisHost") cloudoneAnalysisPort := beego.AppConfig.String("cloudoneAnalysisPort") url := cloudoneAnalysisProtocol + "://" + cloudoneAnalysisHost + ":" + cloudoneAnalysisPort + "/api/v1/historicalevents/" + namespace + "/" + id + "?acknowledge=" + acknowledge tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, nil, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error c.Data["json"] = make(map[string]interface{}) c.Data["json"].(map[string]interface{})["error"] = err.Error() c.Ctx.Output.Status = 404 c.ServeJSON() return } else { c.Data["json"] = make(map[string]interface{}) c.ServeJSON() } }
func (c *UpgradeController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") imageInformationName := c.GetString("name") description := c.GetString("description") url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/imageinformations/upgrade" deployUpgradeInput := DeployUpgradeInput{imageInformationName, description} resultJsonMap := make(map[string]interface{}) tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, deployUpgradeInput, &resultJsonMap, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess(imageInformationName + " is launched") } c.Ctx.Redirect(302, "/gui/repository/imageinformation/log?imageInformation="+imageInformationName) guimessage.RedirectMessage(c) }
func (c *UpdateController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") namespaces, _ := c.GetSession("namespace").(string) imageInformationName := c.GetString("name") version := c.GetString("version") description := c.GetString("description") keySlice := make([]string, 0) inputMap := c.Input() if inputMap != nil { for key, _ := range inputMap { // Only collect environment belonging to this version if strings.HasPrefix(key, version) { keySlice = append(keySlice, key) } } } environmentSlice := make([]ReplicationControllerContainerEnvironment, 0) length := len(version) + 1 // + 1 for _ for _, key := range keySlice { value := c.GetString(key) if len(value) > 0 { environmentSlice = append(environmentSlice, ReplicationControllerContainerEnvironment{key[length:], value}) } } url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/deploys/update/" + namespaces deployUpdateInput := DeployUpdateInput{imageInformationName, version, description, environmentSlice} tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, deployUpdateInput, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Update deploy " + imageInformationName + " to version " + version + " success") } // Redirect to list c.Ctx.Redirect(302, "/gui/deploy/deploy/list") guimessage.RedirectMessage(c) }
func (c *UpdateController) Post() { inputBody := c.Ctx.Input.CopyBody(limit.InputPostBodyMaximum) token := c.Ctx.Input.Header("Token") cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") deployUpgradeInput := DeployUpgradeInput{} err := json.Unmarshal(inputBody, &deployUpgradeInput) if err != nil { // Error errorJsonMap := make(map[string]interface{}) errorJsonMap["error"] = err.Error() c.Data["json"] = errorJsonMap c.Ctx.Output.Status = 400 c.ServeJSON() return } url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/imageinformations/upgrade/" tokenHeaderMap := make(map[string]string, 0) tokenHeaderMap["token"] = token _, err = restclient.RequestPutWithStructure(url, deployUpgradeInput, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error errorJsonMap := make(map[string]interface{}) errorJsonMap["error"] = err.Error() c.Data["json"] = errorJsonMap c.Ctx.Output.Status = 400 c.ServeJSON() return } jsonMap := make(map[string]interface{}) c.Data["json"] = jsonMap c.ServeJSON() }
func (c *SelectController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") imageInformation := c.GetString("imageInformation") namespace := c.GetString("namespace") nodePort, _ := c.GetInt("nodePort") description := c.GetString("description") sessionAffinity := c.GetString("sessionAffinity") deployBlueGreen := DeployBlueGreen{ imageInformation, namespace, nodePort, description, sessionAffinity, "", "", "", } url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/deploybluegreens/" tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, deployBlueGreen, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Create blue green deployment " + imageInformation + " success") } c.Ctx.Redirect(302, "/gui/deploy/deploybluegreen/list") guimessage.RedirectMessage(c) }
// @Title update // @Description update the notifier // @Param body body guirestapi.notification.notifier.ReplicationControllerNotifier true "body for notifier" // @Success 200 {string} {} // @Failure 404 error reason // @router / [put] func (c *EditController) Put() { inputBody := c.Ctx.Input.CopyBody(limit.InputPostBodyMaximum) replicationControllerNotifier := ReplicationControllerNotifier{} err := json.Unmarshal(inputBody, &replicationControllerNotifier) if err != nil { // Error c.Data["json"] = make(map[string]interface{}) c.Data["json"].(map[string]interface{})["error"] = err.Error() c.Ctx.Output.Status = 404 c.ServeJSON() return } cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") namespace, _ := c.GetSession("namespace").(string) replicationControllerNotifier.Namespace = namespace url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/notifiers/" tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err = restclient.RequestPutWithStructure(url, replicationControllerNotifier, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error c.Data["json"] = make(map[string]interface{}) c.Data["json"].(map[string]interface{})["error"] = err.Error() c.Ctx.Output.Status = 404 c.ServeJSON() return } else { c.Data["json"] = make(map[string]interface{}) c.ServeJSON() } }
func (c *AcknowledgeController) Get() { guimessage := guimessagedisplay.GetGUIMessage(c) namespace := c.GetString("namespace") id := c.GetString("id") acknowledge := c.GetString("acknowledge") cloudoneAnalysisProtocol := beego.AppConfig.String("cloudoneAnalysisProtocol") cloudoneAnalysisHost := beego.AppConfig.String("cloudoneAnalysisHost") cloudoneAnalysisPort := beego.AppConfig.String("cloudoneAnalysisPort") url := cloudoneAnalysisProtocol + "://" + cloudoneAnalysisHost + ":" + cloudoneAnalysisPort + "/api/v1/historicalevents/" + namespace + "/" + id + "?acknowledge=" + acknowledge jsonMapSlice := make([]map[string]interface{}, 0) tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, nil, &jsonMapSlice, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Acknowledged event") } if acknowledge == "true" { c.Ctx.Redirect(302, "/gui/event/kubernetes/list?acknowledge=false") } else { c.Ctx.Redirect(302, "/gui/event/kubernetes/list?acknowledge=true") } guimessage.RedirectMessage(c) }
func (c *EditController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) indicatorSlice := make([]Indicator, 0) cpu := c.GetString("cpu") if cpu == "on" { cpuAboveAllOrOneText := c.GetString("cpuAboveAllOrOne") var cpuAboveAllOrOne bool if cpuAboveAllOrOneText == "on" { cpuAboveAllOrOne = true } else { cpuAboveAllOrOne = false } cpuAbovePercentageOfData, _ := c.GetFloat("cpuAbovePercentageOfData") cpuAboveThreshold, _ := c.GetInt64("cpuAboveThreshold") cpuBelowAllOrOneText := c.GetString("cpuBelowAllOrOne") var cpuBelowAllOrOne bool if cpuBelowAllOrOneText == "on" { cpuBelowAllOrOne = true } else { cpuBelowAllOrOne = false } cpuBelowPercentageOfData, _ := c.GetFloat("cpuBelowPercentageOfData") cpuBelowThreshold, _ := c.GetInt64("cpuBelowThreshold") indicatorSlice = append(indicatorSlice, Indicator{"cpu", cpuAboveAllOrOne, cpuAbovePercentageOfData / 100.0, cpuAboveThreshold * 1000000, cpuBelowAllOrOne, cpuBelowPercentageOfData / 100.0, cpuBelowThreshold * 1000000}) } memory := c.GetString("memory") if memory == "on" { memoryAboveAllOrOneText := c.GetString("memoryAboveAllOrOne") var memoryAboveAllOrOne bool if memoryAboveAllOrOneText == "on" { memoryAboveAllOrOne = true } else { memoryAboveAllOrOne = false } memoryAbovePercentageOfData, _ := c.GetFloat("memoryAbovePercentageOfData") memoryAboveThreshold, _ := c.GetInt64("memoryAboveThreshold") memoryBelowAllOrOneText := c.GetString("memoryBelowAllOrOne") var memoryBelowAllOrOne bool if memoryBelowAllOrOneText == "on" { memoryBelowAllOrOne = true } else { memoryBelowAllOrOne = false } memoryBelowPercentageOfData, _ := c.GetFloat("memoryBelowPercentageOfData") memoryBelowThreshold, _ := c.GetInt64("memoryBelowThreshold") indicatorSlice = append(indicatorSlice, Indicator{"memory", memoryAboveAllOrOne, memoryAbovePercentageOfData / 100.0, memoryAboveThreshold * 1024 * 1024, memoryBelowAllOrOne, memoryBelowPercentageOfData / 100.0, memoryBelowThreshold * 1024 * 1024}) } cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") namespace, _ := c.GetSession("namespace").(string) kind := c.GetString("kind") name := c.GetString("name") coolDownDuration, _ := c.GetInt("coolDownDuration") maximumReplica, _ := c.GetInt("maximumReplica") minimumReplica, _ := c.GetInt("minimumReplica") replicationControllerAutoScaler := ReplicationControllerAutoScaler{ true, time.Duration(coolDownDuration) * time.Second, 0, "", "", namespace, kind, name, maximumReplica, minimumReplica, indicatorSlice, "", "", } url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/autoscalers/" tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, replicationControllerAutoScaler, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Auto scaler for " + kind + " " + name + " is edited") } c.Ctx.Redirect(302, "/gui/deploy/autoscaler/list") guimessage.RedirectMessage(c) }
func (c *EditController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") name := c.GetString("name") hostList := c.GetString("hostList") path := c.GetString("path") sshDialTimeoutInMilliSecond, _ := c.GetInt("sshDialTimeoutInMilliSecond") sshSessionTimeoutInMilliSecond, _ := c.GetInt("sshSessionTimeoutInMilliSecond") sshPort, _ := c.GetInt("sshPort") sshUser := c.GetString("sshUser") sshPassword := c.GetString("sshPassword") createOrUpdate := c.GetString("createOrUpdate") hostSlice := make([]string, 0) splitSlice := strings.Split(hostList, ",") for _, split := range splitSlice { host := strings.TrimSpace(split) if len(host) > 0 { hostSlice = append(hostSlice, host) } } glusterfsClusterInput := GlusterfsClusterInput{ name, hostSlice, path, sshDialTimeoutInMilliSecond, sshSessionTimeoutInMilliSecond, sshPort, sshUser, sshPassword} if createOrUpdate == "create" { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/glusterfs/clusters/" tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPostWithStructure(url, glusterfsClusterInput, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Glusterfs cluster " + name + " is created") } } else { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/glusterfs/clusters/" + name tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, glusterfsClusterInput, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Glusterfs cluster " + name + " is updated") } } c.Ctx.Redirect(302, "/gui/filesystem/glusterfs/cluster/list") guimessage.RedirectMessage(c) }
func (c *EditController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) name := c.GetString("name") password := c.GetString("password") disabledText := c.GetString("disabled") expiredTimeText := c.GetString("expiredTime") description := c.GetString("description") githubWebhookSecret := c.GetString("githubWebhookSecret") action := c.GetString("action") loginNamespace := c.GetString("loginNamespace") disabled := false if disabledText == "on" { disabled = true } var expiredTime *time.Time = nil expiredTimeData, err := time.Parse(guiWidgetTimePickerFormat, expiredTimeText) if err == nil { expiredTime = &expiredTimeData } cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") roleSlice := make([]*rbac.Role, 0) resourceSlice := make([]*rbac.Resource, 0) namespaceNameSlice := make([]string, 0) hasNamespaceNameAll := false inputMap := c.Input() if inputMap != nil { for key, value := range inputMap { if strings.HasPrefix(key, "role_") { roleName := key[len("role_"):] if value[0] == "on" { roleSlice = append(roleSlice, &rbac.Role{roleName, nil, ""}) } } if strings.HasPrefix(key, "namespace_") { namespaceName := key[len("namespace_"):] if value[0] == "on" { namespaceNameSlice = append(namespaceNameSlice, namespaceName) if namespaceName == "*" { hasNamespaceNameAll = true } } } } } if hasNamespaceNameAll { resourceSlice = append(resourceSlice, &rbac.Resource{"namespace_*", "*", "/namespaces/"}) } else { for _, namespaceName := range namespaceNameSlice { resourceSlice = append(resourceSlice, &rbac.Resource{"namespace_" + namespaceName, "*", "/namespaces/" + namespaceName}) } } metaDataMap := make(map[string]string) if len(loginNamespace) > 0 { metaDataMap["loginNamespace"] = loginNamespace } if len(githubWebhookSecret) > 0 { metaDataMap["githubWebhookSecret"] = githubWebhookSecret } user := rbac.User{ name, password, roleSlice, resourceSlice, description, metaDataMap, expiredTime, disabled, } tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) if action == "create" { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/authorizations/users" _, err = restclient.RequestPostWithStructure(url, user, nil, tokenHeaderMap) } else { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/authorizations/users/" + name _, err = restclient.RequestPutWithStructure(url, user, nil, tokenHeaderMap) } if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("User " + name + " is edited") } c.Ctx.Redirect(302, "/gui/system/rbac/user/list") guimessage.RedirectMessage(c) }
func (c *EditController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") createOrUpdate := c.GetString("createOrUpdate") name := c.GetString("name") description := c.GetString("description") nodeHostSlice := make([]string, 0) inputMap := c.Input() if inputMap != nil { for key, _ := range inputMap { // Only collect host if strings.HasPrefix(key, "nodeHost_") { nodeHostSlice = append(nodeHostSlice, key[len("nodeHost_"):]) } } } endPointList := c.GetString("endPointList") endPointSlice := make([]string, 0) splitSlice := strings.Split(endPointList, ",") for _, split := range splitSlice { endPoint := strings.TrimSpace(split) if len(endPoint) > 0 { endPointSlice = append(endPointSlice, endPoint) } } slbDaemon := SLBDaemon{ name, endPointSlice, nodeHostSlice, description, "", "", "", } if createOrUpdate == "create" { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/slbs/daemons/" tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPostWithStructure(url, slbDaemon, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("SLB daemon " + name + " is created") } } else { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/slbs/daemons/" + name tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, slbDaemon, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("SLB daemon " + name + " is updated") } } c.Ctx.Redirect(302, "/gui/system/slb/daemon/list") guimessage.RedirectMessage(c) }
func (c *EditController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") createOrUpdate := c.GetString("createOrUpdate") ip := c.GetString("ip") sshPort, _ := c.GetInt("sshPort") disabledText := c.GetString("disabled") sshUser := c.GetString("sshUser") sshPassword := c.GetString("sshPassword") disabled := false if disabledText == "on" { disabled = true } credential := Credential{ ip, SSH{ sshPort, sshUser, sshPassword, }, disabled, "", "", } if createOrUpdate == "create" { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/hosts/credentials/" tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPostWithStructure(url, credential, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Host credential " + ip + " is created") } } else { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/hosts/credentials/" + ip tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, credential, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Host credential " + ip + " is updated") } } c.Ctx.Redirect(302, "/gui/system/host/credential/list") guimessage.RedirectMessage(c) }
func (c *EditController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) indicatorSlice := make([]Indicator, 0) cpu := c.GetString("cpu") if cpu == "on" { cpuAboveAllOrOneText := c.GetString("cpuAboveAllOrOne") var cpuAboveAllOrOne bool if cpuAboveAllOrOneText == "on" { cpuAboveAllOrOne = true } else { cpuAboveAllOrOne = false } cpuAbovePercentageOfData, _ := c.GetFloat("cpuAbovePercentageOfData") cpuAboveThreshold, _ := c.GetInt64("cpuAboveThreshold") cpuBelowAllOrOneText := c.GetString("cpuBelowAllOrOne") var cpuBelowAllOrOne bool if cpuBelowAllOrOneText == "on" { cpuBelowAllOrOne = true } else { cpuBelowAllOrOne = false } cpuBelowPercentageOfData, _ := c.GetFloat("cpuBelowPercentageOfData") cpuBelowThreshold, _ := c.GetInt64("cpuBelowThreshold") indicatorSlice = append(indicatorSlice, Indicator{"cpu", cpuAboveAllOrOne, cpuAbovePercentageOfData / 100.0, cpuAboveThreshold * 1000000, cpuBelowAllOrOne, cpuBelowPercentageOfData / 100.0, cpuBelowThreshold * 1000000}) } memory := c.GetString("memory") if memory == "on" { memoryAboveAllOrOneText := c.GetString("memoryAboveAllOrOne") var memoryAboveAllOrOne bool if memoryAboveAllOrOneText == "on" { memoryAboveAllOrOne = true } else { memoryAboveAllOrOne = false } memoryAbovePercentageOfData, _ := c.GetFloat("memoryAbovePercentageOfData") memoryAboveThreshold, _ := c.GetInt64("memoryAboveThreshold") memoryBelowAllOrOneText := c.GetString("memoryBelowAllOrOne") var memoryBelowAllOrOne bool if memoryBelowAllOrOneText == "on" { memoryBelowAllOrOne = true } else { memoryBelowAllOrOne = false } memoryBelowPercentageOfData, _ := c.GetFloat("memoryBelowPercentageOfData") memoryBelowThreshold, _ := c.GetInt64("memoryBelowThreshold") indicatorSlice = append(indicatorSlice, Indicator{"memory", memoryAboveAllOrOne, memoryAbovePercentageOfData / 100.0, memoryAboveThreshold * 1024 * 1024, memoryBelowAllOrOne, memoryBelowPercentageOfData / 100.0, memoryBelowThreshold * 1024 * 1024}) } cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") namespace, _ := c.GetSession("namespace").(string) kind := c.GetString("kind") name := c.GetString("name") coolDownDuration, _ := c.GetInt("coolDownDuration") emailField := c.GetString("email") emailServerName := c.GetString("emailServerName") smsNexmoSender := c.GetString("smsNexmoSender") smsNexmoPhoneField := c.GetString("smsNexmoPhone") smsNexmoName := c.GetString("smsNexmoName") if len(emailServerName) == 0 { guimessage.AddDanger("Email server configuration name can't be empty") c.Ctx.Redirect(302, "/gui/notification/notifier/list") guimessage.RedirectMessage(c) return } if len(smsNexmoName) == 0 { guimessage.AddDanger("SMS Nexom configuration name can't be empty") c.Ctx.Redirect(302, "/gui/notification/notifier/list") guimessage.RedirectMessage(c) return } notifierSlice := make([]Notifier, 0) if emailField != "" { emailSlice := make([]string, 0) for _, email := range strings.Split(emailField, ",") { value := strings.TrimSpace(email) if len(value) > 0 { emailSlice = append(emailSlice, value) } } notifierEmail := NotifierEmail{ emailServerName, emailSlice, } byteSlice, err := json.Marshal(notifierEmail) if err != nil { guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) guimessage.OutputMessage(c.Data) return } notifierSlice = append(notifierSlice, Notifier{"email", string(byteSlice)}) } if smsNexmoSender != "" && smsNexmoPhoneField != "" { smsNexmoPhoneSlice := make([]string, 0) for _, smsNexmoPhone := range strings.Split(smsNexmoPhoneField, ",") { value := strings.TrimSpace(smsNexmoPhone) if len(value) > 0 { smsNexmoPhoneSlice = append(smsNexmoPhoneSlice, value) } } notifierSMSNexmo := NotifierSMSNexmo{ smsNexmoName, smsNexmoSender, smsNexmoPhoneSlice, } byteSlice, err := json.Marshal(notifierSMSNexmo) if err != nil { guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) guimessage.OutputMessage(c.Data) return } notifierSlice = append(notifierSlice, Notifier{"smsNexmo", string(byteSlice)}) } replicationControllerNotifier := ReplicationControllerNotifier{ true, time.Duration(coolDownDuration) * time.Second, 0, "", "", namespace, kind, name, notifierSlice, indicatorSlice, "", "", } url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/notifiers/" tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, replicationControllerNotifier, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Email notifier for " + kind + " " + name + " is edited") } c.Ctx.Redirect(302, "/gui/notification/notifier/list") guimessage.RedirectMessage(c) }
func (c *BookmarkController) Get() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") name := c.GetString("name") sessionUser, _ := c.GetSession("user").(*rbac.User) if sessionUser == nil { // Error guimessage.AddDanger("User in seesion does not exist") c.Ctx.Redirect(302, "/gui/system/namespace/list") guimessage.RedirectMessage(c) return } userName := sessionUser.Name url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/authorizations/users/" + userName user := rbac.User{} tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestGetWithStructure(url, &user, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) c.Ctx.Redirect(302, "/gui/system/namespace/list") guimessage.RedirectMessage(c) return } metaDataMap := user.MetaDataMap if metaDataMap == nil { metaDataMap = make(map[string]string) } metaDataMap["loginNamespace"] = name url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/authorizations/users/" + userName + "/metadata" _, err = restclient.RequestPutWithStructure(url, metaDataMap, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) c.Ctx.Redirect(302, "/gui/system/namespace/list") guimessage.RedirectMessage(c) return } // Set session sessionUser.MetaDataMap = metaDataMap c.SetSession("user", sessionUser) guimessage.AddSuccess("Bookmark the namespace " + name + " as the login namespace") // Redirect to list c.Ctx.Redirect(302, "/gui/system/namespace/list") guimessage.RedirectMessage(c) }
func ProxyServer(ws *websocket.Conn) { cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") cloudoneAnalysisProtocol := beego.AppConfig.String("cloudoneAnalysisProtocol") cloudoneAnalysisHost := beego.AppConfig.String("cloudoneAnalysisHost") cloudoneAnalysisPort := beego.AppConfig.String("cloudoneAnalysisPort") parameterMap := ws.Request().URL.Query() upgradeCloudone := getParameter(parameterMap, "upgradeCloudone") upgradeCloudoneImagePath := getParameter(parameterMap, "upgradeCloudoneImagePath") upgradeCloudoneVersion := getParameter(parameterMap, "upgradeCloudoneVersion") upgradeCloudoneGUI := getParameter(parameterMap, "upgradeCloudoneGUI") upgradeCloudoneGUIImagePath := getParameter(parameterMap, "upgradeCloudoneGUIImagePath") upgradeCloudoneGUIVersion := getParameter(parameterMap, "upgradeCloudoneGUIVersion") upgradeCloudoneAnalysis := getParameter(parameterMap, "upgradeCloudoneAnalysis") upgradeCloudoneAnalysisImagePath := getParameter(parameterMap, "upgradeCloudoneAnalysisImagePath") upgradeCloudoneAnalysisVersion := getParameter(parameterMap, "upgradeCloudoneAnalysisVersion") upgradeTopologyConfiguration := getParameter(parameterMap, "upgradeTopologyConfiguration") upgradeNamespace := getParameter(parameterMap, "upgradeNamespace") upgradeReplicationControllerName := getParameter(parameterMap, "upgradeReplicationControllerName") upgradeReplicationControllerContent := getParameter(parameterMap, "upgradeReplicationControllerContent") upgradeServiceName := getParameter(parameterMap, "upgradeServiceName") upgradeServiceContent := getParameter(parameterMap, "upgradeServiceContent") httpsCertFileContent := getParameter(parameterMap, "httpsCertFile") httpsKeyFileContent := getParameter(parameterMap, "httpsKeyFile") token := getParameter(parameterMap, "token") headerMap := make(map[string]string) headerMap["token"] = token // Configre certificate certificateChanged, err := configureCertificate(ws, httpsCertFileContent, httpsKeyFileContent) if err != nil { errorMessage := "Configure certificates with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } if certificateChanged { upgradeCloudoneGUI = "true" } replicationControllerJsonMap := make(map[string]interface{}) serviceJsonMap := make(map[string]interface{}) if upgradeTopologyConfiguration == "true" { if upgradeReplicationControllerContent != "" { err := json.Unmarshal([]byte(upgradeReplicationControllerContent), &replicationControllerJsonMap) if err != nil { errorMessage := "Can't unmarshal upgradeReplicationControllerContent with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } } if upgradeServiceContent != "" { err := json.Unmarshal([]byte(upgradeServiceContent), &serviceJsonMap) if err != nil { errorMessage := "Can't unmarshal upgradeServiceContent with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } } } // Get credential url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/hosts/credentials/" credentialSlice := make([]Credential, 0) _, err = restclient.RequestGetWithStructure(url, &credentialSlice, headerMap) if identity.IsTokenInvalid(err) { ws.Write([]byte(err.Error())) ws.Close() return } if err != nil { errorMessage := "Can't get credential data with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } // Pull images if upgradeCloudone == "true" { err := UpgradeDockerImage(ws, credentialSlice, upgradeCloudoneImagePath, upgradeCloudoneVersion) if err != nil { errorMessage := "Can't upgrade image cloudone with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } } if upgradeCloudoneGUI == "true" { err := UpgradeDockerImage(ws, credentialSlice, upgradeCloudoneGUIImagePath, upgradeCloudoneGUIVersion) if err != nil { errorMessage := "Can't upgrade image cloudone gui with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } } if upgradeCloudoneAnalysis == "true" { err := UpgradeDockerImage(ws, credentialSlice, upgradeCloudoneAnalysisImagePath, upgradeCloudoneAnalysisVersion) if err != nil { errorMessage := "Can't upgrade image cloudone analysis with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } } // Update service if len(serviceJsonMap) > 0 { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/services/json/" + upgradeNamespace + "/" + upgradeReplicationControllerName ws.Write([]byte("Start to update service\n")) _, err := restclient.RequestPutWithStructure(url, serviceJsonMap, nil, headerMap) if identity.IsTokenInvalid(err) { ws.Write([]byte(err.Error())) ws.Close() return } if err != nil { errorMessage := "Can't upgrade service with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } else { ws.Write([]byte("The service is updated\n")) } } if len(replicationControllerJsonMap) > 0 { // Update replication controller to change all instances url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/replicationcontrollers/json/" + upgradeNamespace + "/" + upgradeServiceName ws.Write([]byte("Stop and recreate the replication controller. Please refresh the page after tens of seconds\n")) _, err := restclient.RequestPutWithStructure(url, replicationControllerJsonMap, nil, headerMap) if identity.IsTokenInvalid(err) { ws.Write([]byte(err.Error())) ws.Close() return } if err != nil { errorMessage := "Can't upgrade replication controller with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } else { ws.Write([]byte("The replication controller is updated\n")) } } else { // Only update the specific docker containers url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/replicationcontrollers/" + upgradeNamespace replicationControllerAndRelatedPodSlice := make([]ReplicationControllerAndRelatedPod, 0) _, err := restclient.RequestGetWithStructure(url, &replicationControllerAndRelatedPodSlice, headerMap) if identity.IsTokenInvalid(err) { ws.Write([]byte(err.Error())) ws.Close() return } if err != nil { errorMessage := "Can't get replication controller and related pod data with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } selectedReplicationControllerAndRelatedPod := ReplicationControllerAndRelatedPod{} for _, replicationControllerAndRelatedPod := range replicationControllerAndRelatedPodSlice { if replicationControllerAndRelatedPod.Name == upgradeReplicationControllerName { selectedReplicationControllerAndRelatedPod = replicationControllerAndRelatedPod } } for _, pod := range selectedReplicationControllerAndRelatedPod.PodSlice { usedCredential := Credential{} for _, credential := range credentialSlice { if credential.IP == pod.HostIP { usedCredential = credential break } } cloudoneContainer := PodContainer{} cloudoneAnalysisContainer := PodContainer{} cloudoneGUIContainer := PodContainer{} for _, container := range pod.ContainerSlice { if container.Name == "cloudone" { cloudoneContainer = container } if container.Name == "cloudone-analysis" { cloudoneAnalysisContainer = container } if container.Name == "cloudone-gui" { cloudoneGUIContainer = container } } if upgradeCloudone == "true" && cloudoneContainer.ContainerID != "" { containerID := cloudoneContainer.ContainerID[9:] ws.Write([]byte("Stop and recreate cloudone\n")) err := stopDockerContainer(usedCredential, containerID) if err != nil { errorMessage := "Can't stop container " + cloudoneContainer.Name + " with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } } if upgradeCloudoneAnalysis == "true" && cloudoneAnalysisContainer.ContainerID != "" { containerID := cloudoneAnalysisContainer.ContainerID[9:] ws.Write([]byte("Stop and recreate cloudone_analysis\n")) err := stopDockerContainer(usedCredential, containerID) if err != nil { errorMessage := "Can't stop container " + cloudoneAnalysisContainer.Name + " with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } } if upgradeCloudoneGUI == "true" && cloudoneGUIContainer.ContainerID != "" { containerID := cloudoneGUIContainer.ContainerID[9:] ws.Write([]byte("Stop and recreate cloudone_gui. Please refresh the page after tens of seconds\n")) err := stopDockerContainer(usedCredential, containerID) if err != nil { errorMessage := "Can't stop container " + cloudoneGUIContainer.Name + " with error " + err.Error() + "\n" ws.Write([]byte(errorMessage)) ws.Close() return } } } if upgradeCloudone == "true" { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/healthchecks/" cloudoneJsonMap := make(map[string]interface{}, 0) for { time.Sleep(time.Second) _, err := restclient.RequestGetWithStructure(url, &cloudoneJsonMap, headerMap) if identity.IsTokenInvalid(err) { ws.Write([]byte(err.Error())) ws.Close() return } if err == nil { break } else { ws.Write([]byte("Wait for Cloudone to come up\n")) } } } if upgradeCloudoneAnalysis == "true" { url := cloudoneAnalysisProtocol + "://" + cloudoneAnalysisHost + ":" + cloudoneAnalysisPort + "/api/v1/healthchecks/" cloudoneAnalysisJsonMap := make(map[string]interface{}, 0) for { time.Sleep(time.Second) _, err := restclient.RequestGetWithStructure(url, &cloudoneAnalysisJsonMap, headerMap) if identity.IsTokenInvalid(err) { ws.Write([]byte(err.Error())) ws.Close() return } if err == nil { break } else { ws.Write([]byte("Wait for Cloudone Analysis to come up\n")) } } } } ws.Write([]byte("Upgrade is done\n")) ws.Close() }
func (c *EditController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") name := c.GetString("name") host := c.GetString("host") port, _ := c.GetInt("port") createOrUpdate := c.GetString("createOrUpdate") privateRegistry := PrivateRegistry{ name, host, port, "", "", "", } if createOrUpdate == "create" { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/privateregistries/servers/" tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPostWithStructure(url, privateRegistry, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Private register server configuration " + name + " is created") } } else { url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/privateregistries/servers/" + name tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPutWithStructure(url, privateRegistry, nil, tokenHeaderMap) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Private register server configuration " + name + " is updated") } } c.Ctx.Redirect(302, "/gui/system/privateregistry/server/list") guimessage.RedirectMessage(c) }