本文整理汇总了Golang中github.com/cloudawan/cloudone_utility/restclient.RequestPostWithStructure函数的典型用法代码示例。如果您正苦于以下问题:Golang RequestPostWithStructure函数的具体用法?Golang RequestPostWithStructure怎么用?Golang RequestPostWithStructure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RequestPostWithStructure函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Post
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")
namespace := Namespace{name, false, false, "", "", "", ""}
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/namespaces"
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
_, err := restclient.RequestPostWithStructure(url, namespace, nil, tokenHeaderMap)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
if err != nil {
// Error
guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
} else {
guimessage.AddSuccess("Namespace " + name + " is edited")
}
c.Ctx.Redirect(302, "/gui/system/namespace/list")
guimessage.RedirectMessage(c)
}
示例2: Post
func (c *EditController) Post() {
guimessage := guimessagedisplay.GetGUIMessage(c)
cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
cloudoneHost := beego.AppConfig.String("cloudoneHost")
cloudonePort := beego.AppConfig.String("cloudonePort")
namespace, _ := c.GetSession("namespace").(string)
selectorName := c.GetString("name")
replicaAmount, _ := c.GetInt("replicaAmount")
image := c.GetString("image")
containerPort, err := c.GetInt("containerPort")
version := ""
name := selectorName + version
portName := "generated"
replicationControllerContainerPortSlice := make([]ReplicationControllerContainerPort, 0)
replicationControllerContainerPortSlice = append(replicationControllerContainerPortSlice, ReplicationControllerContainerPort{portName, containerPort})
replicationControllerContainerSlice := make([]ReplicationControllerContainer, 0)
replicationControllerContainerSlice = append(replicationControllerContainerSlice, ReplicationControllerContainer{name, image, replicationControllerContainerPortSlice})
replicationController := ReplicationController{
name,
replicaAmount,
ReplicationControllerSelector{
selectorName,
version,
},
ReplicationControllerLabel{
name,
},
replicationControllerContainerSlice}
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/replicationcontrollers/" + namespace
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
_, err = restclient.RequestPostWithStructure(url, replicationController, nil, tokenHeaderMap)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
if err != nil {
// Error
guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
} else {
guimessage.AddSuccess("Replication Controller " + name + " is edited")
}
c.Ctx.Redirect(302, "/gui/inventory/replicationcontroller/list")
guimessage.RedirectMessage(c)
}
示例3: Post
func (c *CreateController) Post() {
guimessage := guimessagedisplay.GetGUIMessage(c)
cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
cloudoneHost := beego.AppConfig.String("cloudoneHost")
cloudonePort := beego.AppConfig.String("cloudonePort")
name := c.GetString("name")
account := c.GetString("account")
password := c.GetString("password")
host := c.GetString("host")
port, _ := c.GetInt("port")
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/notifiers/emailserversmtp/"
emailServerSMTP := EmailServerSMTP{
name,
account,
password,
host,
port,
"",
}
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
_, err := restclient.RequestPostWithStructure(url, emailServerSMTP, nil, tokenHeaderMap)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
if err != nil {
// Error
guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
} else {
guimessage.AddSuccess("Email server configuration " + name + " is created")
}
c.Ctx.Redirect(302, "/gui/system/notification/emailserver/list")
guimessage.RedirectMessage(c)
}
示例4: Post
// @Title create
// @Description create service
// @Param body body guirestapi.inventory.service.Service true "body for service"
// @Success 200 {string} {}
// @Failure 404 error reason
// @router / [post]
func (c *EditController) Post() {
inputBody := c.Ctx.Input.CopyBody(limit.InputPostBodyMaximum)
service := Service{}
err := json.Unmarshal(inputBody, &service)
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)
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/services/" + namespace
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
_, err = restclient.RequestPostWithStructure(url, service, 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()
}
}
示例5: Post
func (c *LoginController) Post() {
inputBody := c.Ctx.Input.CopyBody(limit.InputPostBodyMaximum)
userData := UserData{}
err := json.Unmarshal(inputBody, &userData)
if err != nil {
// Error
errorJsonMap := make(map[string]interface{})
errorJsonMap["ErrorMessage"] = err.Error()
c.Data["json"] = errorJsonMap
c.Ctx.Output.Status = 401
c.ServeJSON()
return
}
cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
cloudoneHost := beego.AppConfig.String("cloudoneHost")
cloudonePort := beego.AppConfig.String("cloudonePort")
// User
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/authorizations/tokens/"
tokenData := TokenData{}
errorInterface, err := restclient.RequestPostWithStructure(url, userData, &tokenData, nil)
errorJsonMap, _ := errorInterface.(map[string]interface{})
if err != nil {
// Error
c.Data["json"] = errorJsonMap
c.Ctx.Output.Status = 401
c.ServeJSON()
return
}
jsonMap := make(map[string]interface{})
jsonMap["Token"] = tokenData.Token
c.Data["json"] = jsonMap
c.ServeJSON()
}
示例6: Post
func (c *PushController) Post() {
cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
cloudoneHost := beego.AppConfig.String("cloudoneHost")
cloudonePort := beego.AppConfig.String("cloudonePort")
user := c.GetString("user")
imageInformation := c.GetString("imageInformation")
signature := c.Ctx.Input.Header("X-Hub-Signature")
payload := string(c.Ctx.Input.CopyBody(limit.InputPostBodyMaximum))
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/webhooks/github"
githubPost := GithubPost{
user,
imageInformation,
signature,
payload,
}
errorJsonMap := make(map[string]interface{})
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
_, err := restclient.RequestPostWithStructure(url, githubPost, &errorJsonMap, tokenHeaderMap)
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()
}
示例7: Post
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)
}
示例8: Post
//.........这里部分代码省略.........
}
launchSlice = append(launchSlice, launch)
} else if len(applicationImageInformationName) > 0 {
environmentSlice := make([]ReplicationControllerContainerEnvironment, 0)
for key, value := range applicationEnvironmentMap {
environmentSlice = append(environmentSlice, ReplicationControllerContainerEnvironment{key, value})
}
oldLaunch := Launch{}
for i := 0; i < len(topology.LaunchSlice); i++ {
if topology.LaunchSlice[i].LaunchApplication != nil && launchName == topology.LaunchSlice[i].LaunchApplication.ImageInformationName {
oldLaunch = topology.LaunchSlice[i]
}
}
// Change the assigned Node Port to auto generated
for i, port := range oldLaunch.LaunchApplication.PortSlice {
if port.NodePort > 0 {
oldLaunch.LaunchApplication.PortSlice[i].NodePort = 0
}
}
launchApplication := &LaunchApplication{
applicationImageInformationName,
applicationVersion,
applicationDescription,
applicationReplicaAmount,
oldLaunch.LaunchApplication.PortSlice,
environmentSlice,
oldLaunch.LaunchApplication.ResourceMap,
extraJsonMap,
}
launch := Launch{
launchOrder,
launchApplication,
nil,
"",
"",
nil,
"",
"",
}
launchSlice = append(launchSlice, launch)
}
}
sort.Sort(ByLaunch(launchSlice))
// Clone
namespace, _ := c.GetSession("namespace").(string)
for _, launch := range launchSlice {
if launch.LaunchApplication != nil {
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/deploys/create/" + namespace
_, err = restclient.RequestPostWithStructure(url, launch.LaunchApplication, nil, tokenHeaderMap)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
if err != nil {
// Error
guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
guimessage.RedirectMessage(c)
c.Ctx.Redirect(302, "/gui/repository/topologytemplate/list")
return
}
}
if launch.LaunchClusterApplication != nil {
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/clusterapplications/launch/" + namespace + "/" + launch.LaunchClusterApplication.Name
jsonMap := make(map[string]interface{})
_, err = restclient.RequestPostWithStructure(url, launch.LaunchClusterApplication, &jsonMap, tokenHeaderMap)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
if err != nil {
guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
guimessage.RedirectMessage(c)
c.Ctx.Redirect(302, "/gui/repository/topologytemplate/list")
return
}
}
}
guimessage.AddSuccess("Clone from the template " + name + " to the namespace " + namespace)
c.Ctx.Redirect(302, "/gui/repository/topologytemplate/list")
guimessage.RedirectMessage(c)
}
示例9: Post
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
//.........这里部分代码省略.........
示例10: Post
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)
}
示例11: Post
func (c *LaunchController) Post() {
guimessage := guimessagedisplay.GetGUIMessage(c)
cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
cloudoneHost := beego.AppConfig.String("cloudoneHost")
cloudonePort := beego.AppConfig.String("cloudonePort")
namespace, _ := c.GetSession("namespace").(string)
name := c.GetString("name")
size, _ := c.GetInt("size")
region := c.GetString("region")
zone := c.GetString("zone")
if region == "Any" {
region = ""
}
if zone == "Any" {
zone = ""
}
keySlice := make([]string, 0)
inputMap := c.Input()
if inputMap != nil {
for key, _ := range inputMap {
// Ignore the non environment field
if strings.HasPrefix(key, "environment_") {
keySlice = append(keySlice, key)
}
}
}
environmentSlice := make([]interface{}, 0)
for _, key := range keySlice {
value := c.GetString(key)
if len(value) > 0 {
environmentMap := make(map[string]string)
environmentMap["name"] = key[len("environment_"):]
environmentMap["value"] = value
environmentSlice = append(environmentSlice, environmentMap)
}
}
extraJsonMap := make(map[string]interface{})
if len(region) > 0 {
extraJsonMap["spec"] = make(map[string]interface{})
extraJsonMap["spec"].(map[string]interface{})["template"] = make(map[string]interface{})
extraJsonMap["spec"].(map[string]interface{})["template"].(map[string]interface{})["spec"] = make(map[string]interface{})
extraJsonMap["spec"].(map[string]interface{})["template"].(map[string]interface{})["spec"].(map[string]interface{})["nodeSelector"] = make(map[string]interface{})
extraJsonMap["spec"].(map[string]interface{})["template"].(map[string]interface{})["spec"].(map[string]interface{})["nodeSelector"].(map[string]interface{})["region"] = region
if len(zone) > 0 {
extraJsonMap["spec"].(map[string]interface{})["template"].(map[string]interface{})["spec"].(map[string]interface{})["nodeSelector"].(map[string]interface{})["zone"] = zone
}
} else {
extraJsonMap = nil
}
clusterLaunch := ClusterLaunch{
size,
environmentSlice,
extraJsonMap,
}
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/clusterapplications/launch/" + namespace + "/" + name
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
_, err := restclient.RequestPostWithStructure(url, clusterLaunch, nil, tokenHeaderMap)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
if err != nil {
// Error
guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
} else {
guimessage.AddSuccess("Cluster application " + name + " is launched")
}
// Redirect to list
c.Ctx.Redirect(302, "/gui/deploy/deployclusterapplication/list")
guimessage.RedirectMessage(c)
}
示例12: Post
func (c *CreateController) Post() {
guimessage := guimessagedisplay.GetGUIMessage(c)
cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
cloudoneHost := beego.AppConfig.String("cloudoneHost")
cloudonePort := beego.AppConfig.String("cloudonePort")
name := c.GetString("name")
kind := c.GetString("kind")
description := c.GetString("description")
// Name need to be a DNS 952 label
match, _ := regexp.MatchString("^[a-z]{1}[a-z0-9-]{1,23}$", name)
if match == false {
guimessage.AddDanger("The name need to be a DNS 952 label ^[a-z]{1}[a-z0-9-]{1,23}$")
c.Ctx.Redirect(302, "/gui/repository/imageinformation/list")
guimessage.RedirectMessage(c)
return
}
// Generate random work space
workingDirectory := "/tmp/tmp_" + random.UUID()
buildParameter := make(map[string]string)
buildParameter["workingDirectory"] = workingDirectory
buildParameter["repositoryPath"] = c.GetString("repositoryPath")
buildParameter["sourceCodeProject"] = c.GetString("sourceCodeProject")
buildParameter["sourceCodeDirectory"] = c.GetString("sourceCodeDirectory")
buildParameter["sourceCodeMakeScript"] = c.GetString("sourceCodeMakeScript")
buildParameter["environmentFile"] = c.GetString("environmentFile")
switch kind {
case "git":
buildParameter["sourceCodeURL"] = c.GetString("sourceCodeURL")
buildParameter["versionFile"] = c.GetString("versionFile")
case "scp":
buildParameter["hostAndPort"] = c.GetString("hostAndPort")
buildParameter["username"] = c.GetString("username")
buildParameter["password"] = c.GetString("password")
buildParameter["sourcePath"] = c.GetString("sourcePath")
buildParameter["compressFileName"] = c.GetString("compressFileName")
buildParameter["unpackageCommand"] = c.GetString("unpackageCommand")
buildParameter["versionFile"] = c.GetString("versionFile")
case "sftp":
buildParameter["hostAndPort"] = c.GetString("hostAndPort")
buildParameter["username"] = c.GetString("username")
buildParameter["password"] = c.GetString("password")
buildParameter["sourcePath"] = c.GetString("sourcePath")
buildParameter["versionFile"] = c.GetString("versionFile")
}
imageInformation := ImageInformation{
name,
kind,
description,
"",
buildParameter,
"",
"",
"",
"",
"",
"",
}
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/imageinformations/create/"
resultJsonMap := make(map[string]interface{})
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
_, err := restclient.RequestPostWithStructure(url, imageInformation, &resultJsonMap, tokenHeaderMap)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
if err != nil {
guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
} else {
guimessage.AddSuccess("The build " + name + " is launched asynchronizedly")
}
c.Ctx.Redirect(302, "/gui/repository/imageinformation/log?imageInformation="+imageInformation.Name)
guimessage.RedirectMessage(c)
}
示例13: Post
func (c *CreateController) Post() {
guimessage := guimessagedisplay.GetGUIMessage(c)
cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
cloudoneHost := beego.AppConfig.String("cloudoneHost")
cloudonePort := beego.AppConfig.String("cloudonePort")
clusterName := c.GetString("clusterName")
hostList := c.GetString("hostList")
name := c.GetString("name")
stripe, _ := c.GetInt("stripe")
replica, _ := c.GetInt("replica")
arbiter, _ := c.GetInt("arbiter")
disperse, _ := c.GetInt("disperse")
disperseData, _ := c.GetInt("disperseData")
redundancy, _ := c.GetInt("redundancy")
transport := c.GetString("transport")
allHostSlice := strings.Split(hostList, ",")
hostSlice := make([]string, 0)
for _, host := range allHostSlice {
hostSelected := c.GetString(host)
if hostSelected == "on" {
hostSlice = append(hostSlice, host)
}
}
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/glusterfs/clusters/" + clusterName + "/volumes/"
glusterfsVolumeCreateParameter := GlusterfsVolumeCreateParameter{
clusterName,
name,
stripe,
replica,
arbiter,
disperse,
disperseData,
redundancy,
transport,
hostSlice,
}
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
_, err := restclient.RequestPostWithStructure(url, glusterfsVolumeCreateParameter, nil, tokenHeaderMap)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
if err != nil {
// Error
guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
} else {
guimessage.AddSuccess("Glusterfs volume " + name + " is created and started")
}
c.Ctx.Redirect(302, "/gui/filesystem/glusterfs/volume/list?clusterName="+clusterName)
guimessage.RedirectMessage(c)
}
示例14: Post
// @Title launch
// @Description launch the cluster application template
// @Param body body guirestapi.repository.thirdparty.Cluster true "body for cluster application template"
// @Param name query string true "The name to use"
// @Param size query string true "The size to use"
// @Success 200 {string} {}
// @Failure 404 error reason
// @router /launch/ [post]
func (c *LaunchController) Post() {
name := c.GetString("name")
size, _ := c.GetInt("size")
inputBody := c.Ctx.Input.CopyBody(limit.InputPostBodyMaximum)
environmentSlice := make([]interface{}, 0)
err := json.Unmarshal(inputBody, &environmentSlice)
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)
clusterLaunch := ClusterLaunch{
size,
environmentSlice,
nil,
}
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
"/api/v1/clusterapplications/launch/" + namespace + "/" + name
jsonMap := make(map[string]interface{})
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
_, err = restclient.RequestPostWithStructure(url, clusterLaunch, &jsonMap, tokenHeaderMap)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
if err != nil {
// Error
errorMessage, _ := jsonMap["Error"].(string)
if strings.HasPrefix(errorMessage, "Replication controller already exists") {
// Error
c.Data["json"] = make(map[string]interface{})
c.Data["json"].(map[string]interface{})["error"] = "Replication controller " + name + " already exists"
c.Ctx.Output.Status = 404
c.ServeJSON()
return
} else {
// 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()
}
}
示例15: Post
//.........这里部分代码省略.........
}
}
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})
}
}
deployContainerPortSlice := make([]DeployContainerPort, 0)
i := 0
for index, containerPort := range indexContainerPortMap {
nodePort := -1
if c.GetString("useNodePort"+index) == "on" {
if c.GetString("autoGeneratedNodePort"+index) == "on" {
nodePort = 0
} else {
// If fail to parse, nodePort will be set to 0 that means auto-generated
nodePort, _ = c.GetInt("nodePort" + index)
}
}
protocol := c.GetString("protocol" + index)
deployContainerPortSlice = append(deployContainerPortSlice, DeployContainerPort{portName + strconv.Itoa(i), containerPort, nodePort, protocol})
i++
}
// Resource reservation
resourceMap := make(map[string]interface{})
if resourceCPURequestError == nil || resourceMemoryRequestError == nil {
resourceMap["requests"] = make(map[string]interface{})
if resourceCPURequestError == nil {
resourceMap["requests"].(map[string]interface{})["cpu"] = resourceCPURequest
}
if resourceMemoryRequestError == nil {
resourceMap["requests"].(map[string]interface{})["memory"] = strconv.Itoa(resourceMemoryRequest) + "Mi"
}
}
if resourceCPULimitError == nil || resourceMemoryLimitError == nil {
resourceMap["limits"] = make(map[string]interface{})
if resourceCPULimitError == nil {
resourceMap["limits"].(map[string]interface{})["cpu"] = resourceCPULimit
}
if resourceMemoryLimitError == nil {
resourceMap["limits"].(map[string]interface{})["memory"] = strconv.Itoa(resourceMemoryLimit) + "Mi"
}
}
extraJsonMap := make(map[string]interface{})
if len(region) > 0 {
extraJsonMap["spec"] = make(map[string]interface{})
extraJsonMap["spec"].(map[string]interface{})["template"] = make(map[string]interface{})
extraJsonMap["spec"].(map[string]interface{})["template"].(map[string]interface{})["spec"] = make(map[string]interface{})
extraJsonMap["spec"].(map[string]interface{})["template"].(map[string]interface{})["spec"].(map[string]interface{})["nodeSelector"] = make(map[string]interface{})
extraJsonMap["spec"].(map[string]interface{})["template"].(map[string]interface{})["spec"].(map[string]interface{})["nodeSelector"].(map[string]interface{})["region"] = region
if len(zone) > 0 {
extraJsonMap["spec"].(map[string]interface{})["template"].(map[string]interface{})["spec"].(map[string]interface{})["nodeSelector"].(map[string]interface{})["zone"] = zone
}
} else {
extraJsonMap = nil
}
deployCreateInput := DeployCreateInput{
imageInformationName,
version,
description,
replicaAmount,
deployContainerPortSlice,
environmentSlice,
resourceMap,
extraJsonMap,
autoUpdateForNewBuild,
}
url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/deploys/create/" + namespaces
tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)
_, err := restclient.RequestPostWithStructure(url, deployCreateInput, nil, tokenHeaderMap)
if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
return
}
if err != nil {
// Error
guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
} else {
guimessage.AddSuccess("Create deploy " + imageInformationName + " version " + version + " success")
}
c.Ctx.Redirect(302, "/gui/deploy/deploy/list")
guimessage.RedirectMessage(c)
}