// @Title create // @Description create users // @Param body body models.PostNode true "body for node content" // @Success 200 {object} models.ResponsePostNode // @Failure 400 invalid request message // @router / [post] func (self *NodeController) Post() { var body []models.PostNode err := json.Unmarshal(self.Ctx.Input.RequestBody, &body) if err != nil { self.Data["json"] = models.NewInternalError(400, err) self.Ctx.Output.SetStatus(400) self.ServeJSON() return } resp := make([]models.ResponsePostNode, len(body)) for i := range body { node := models.Node{ ID: "node_" + utils.Generate32UUID(), ClusterID: body[i].ClusterID, SoftwareID: body[i].SoftwareID, Status: models.Enable, Runtime: "running", MaxInstance: body[i].MaxInstance, IPAddress: "12.168.1.1", NCPU: 24, Mem_MB: 102400, } objects.Set(node.ID, &node) resp[i].ID = node.ID resp[i].TaskID = utils.Generate32UUID() resp[i].NodeID = body[i].NodeID } self.Data["json"] = resp self.ServeJSON() }
// @Title create // @Description create cluster // @Param body body models.Cluster true "body for cluste content" // @Success 200 {string} models.ClusterInfo.ID // @Failure 400 invalid request message // @router / [post] func (self *ClusterController) Post() { var body models.PostCluster err := json.Unmarshal(self.Ctx.Input.RequestBody, &body) if err != nil { self.Data["json"] = models.NewInternalError(400, err) self.Ctx.Output.SetStatus(400) self.ServeJSON() return } cluster := models.ClusterInfo{ ID: "cluster_" + utils.Generate32UUID(), Name: body.Name, Type: body.Type, Status: models.Enable, MaxNodeUsageLimit: body.MaxNodeUsageLimit, Storage: models.Storage{ Type: body.StorageType, ID: body.StorageSystemID, }, } objects.Set(cluster.ID, &cluster) self.Data["json"] = map[string]string{"id": cluster.ID} //self.Ctx.Output.SetStatus(201) self.ServeJSON() }
// @Title create // @Description create service // @Param body body models.PostService true "body for service content" // @Success 200 {object} models.TaskResponse // @Failure 400 invalid request message // @router / [post] func (self *ServiceController) Post() { var body models.PostService err := json.Unmarshal(self.Ctx.Input.RequestBody, &body) if err != nil { self.Data["json"] = models.NewInternalError(400, err) self.Ctx.Output.SetStatus(400) self.ServeJSON() return } var service = models.Service{ ID: "service_" + utils.Generate32UUID(), Status: models.StandBy, } objects.Set(service.ID, &service) self.Data["json"] = models.NewTaskResponse(service.ID, "task"+utils.Generate32UUID()) //self.Ctx.Output.SetStatus(201) self.ServeJSON() }
// @Title add // @Description add software // @Param body body models.Software true "body for software content" // @Success 200 {string} taskID // @Failure 400 invalid request message // @router / [post] func (self *SoftwareController) Post() { var body models.Software err := json.Unmarshal(self.Ctx.Input.RequestBody, &body) if err != nil { self.Data["json"] = models.NewInternalError(400, err) self.Ctx.Output.SetStatus(400) self.ServeJSON() return } objects.Set(body.ID, &body) self.Data["json"] = map[string]string{"task_id": "task_" + utils.Generate32UUID()} //self.Ctx.Output.SetStatus(201) self.ServeJSON() }
// @Title create // @Description create network // @Param body body models.IPtable true "body for network content" // @Success 200 {string} models.IPtable.ID // @Failure 400 invalid request message // @router / [post] func (self *NetworkController) Post() { var body models.IPtable err := json.Unmarshal(self.Ctx.Input.RequestBody, &body) if err != nil { self.Data["json"] = models.NewInternalError(400, err) self.Ctx.Output.SetStatus(400) self.ServeJSON() return } body.ID = "network_" + utils.Generate32UUID() body.Status = models.Enable objects.Set(body.ID, &body) self.Data["json"] = map[string]string{"id": body.ID} //self.Ctx.Output.SetStatus(201) self.ServeJSON() }
// @Title add RaidGroup // @Description add RaidGroup // @Param body body models.PostRaidGroup true "body for RaidGroup content" // @Success 200 {string} models.RaidGroup.ID // @Failure 400 invalid request message // @router /san/rg [post] func (self *StorageController) PostRaidGroup() { var body models.PostRaidGroup err := json.Unmarshal(self.Ctx.Input.RequestBody, &body) if err != nil { self.Data["json"] = models.NewInternalError(400, err) self.Ctx.Output.SetStatus(400) self.ServeJSON() return } rg := models.RaidGroup{ ID: "raidgroup_" + utils.Generate32UUID(), SANID: body.SANID, Number: body.Number, Status: models.Enable, } objects.Set(rg.ID, &rg) self.Data["json"] = map[string]string{"id": rg.ID} //self.Ctx.Output.SetStatus(201) self.ServeJSON() }