// @Title update // @Description update the node // @Param nodeID path string true "The node id you want to update" // @Param body body models.Node true "body for node content" // @Success 200 // @Failure 400 invalid request message // @router /:nid [put] func (self *NodeController) Put() { nid := self.GetString(":nid") var body models.Node 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 } if node, ok := objects.Get(nid).(*models.Node); ok { clone := *node if clone.Status != body.Status && body.Status != 0 { clone.Status = body.Status } if clone.MaxInstance != body.MaxInstance && body.MaxInstance != 0 { clone.MaxInstance = body.MaxInstance } objects.Set(clone.ID, &clone) } else { self.Data["json"] = models.NewInternalError(1, ErrNotFound) self.Ctx.Output.SetStatus(403) } self.ServeJSON() }
// @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 Get // @Description find network by networkID // @Param netwrokID path string true "The networkID you want to get" // @Success 200 {object} models.IPtable // @Failure 403 :networkID is empty // @router /:id [get] func (self *NetworkController) Get() { id := self.GetString(":id") if strings.TrimSpace(id) != "" { if ob, ok := objects.Get(id).(*models.IPtable); ok { self.Data["json"] = ob } else { self.Data["json"] = models.NewInternalError(403, ErrNotFound) self.Ctx.Output.SetStatus(403) } } else { self.Data["json"] = models.NewInternalError(403, fmt.Errorf("%s cluster_id is empty", id)) self.Ctx.Output.SetStatus(403) } 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 List // @Description find node by node_ID // @Param body body models.CommonRequestBody true "the nodes you want to get" // @Success 200 {object} models.ResponseNode // @Failure 400 invalid request message // @router /list [post] func (self *NodeController) List() { var body models.CommonRequestBody 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 } m := objects.Items() if body.All { list := make([]models.ResponseNode, 0, 100) for k, v := range m { if id, ok := k.(string); ok && strings.HasPrefix(id, "node_") { if object, ok := v.(*models.Node); ok { list = append(list, models.ResponseNode{ ID: object.ID, IPAddress: object.IPAddress, NCPU: object.NCPU, Mem_MB: object.Mem_MB, Status: object.Status, Runtime: object.Runtime, }) } } } self.Data["json"] = list self.ServeJSON() return } list := make([]models.ResponseNode, len(body.ID)) for i, id := range body.ID { if strings.TrimSpace(id) == "" { continue } if object, ok := m[id].(*models.Node); ok { list[i] = models.ResponseNode{ ID: object.ID, IPAddress: object.IPAddress, NCPU: object.NCPU, Mem_MB: object.Mem_MB, Status: object.Status, Runtime: object.Runtime, } } else { list[i] = models.ResponseNode{ ID: id, Error: ErrNotFound.Error(), } } } self.Data["json"] = list self.ServeJSON() }
// @Title disable // @Description update the object // @Param RaidGroupID path string true "The RaidGroup you want to update" // @Success 200 // @Failure 403 :id not exist // @router /san/rg/:ID/disable [put] func (self *StorageController) Disable() { id := self.GetString(":ID") if rg, ok := objects.Get(id).(*models.RaidGroup); ok { clone := *rg clone.Status = models.Disable objects.Set(clone.ID, &clone) } else { self.Data["json"] = models.NewInternalError(1, ErrNotFound) self.Ctx.Output.SetStatus(403) } self.ServeJSON() }
// @Title enable // @Description update the object // @Param networkID path string true "The network you want to update" // @Success 200 // @Failure 403 :networkID not exist // @router /:id/enable [put] func (self *NetworkController) Enable() { id := self.GetString(":id") if table, ok := objects.Get(id).(*models.IPtable); ok { clone := *table clone.Status = models.Enable objects.Set(clone.ID, &clone) } else { self.Data["json"] = models.NewInternalError(1, ErrNotFound) self.Ctx.Output.SetStatus(403) } self.ServeJSON() }
// @Title disable // @Description update the object // @Param clusterID path string true "The clusterID you want to update" // @Success 200 // @Failure 403 :clusterID is empty // @router /:clusterID/disable [put] func (self *ClusterController) Disable() { cid := self.GetString(":clusterID") if cluster, ok := objects.Get(cid).(*models.ClusterInfo); ok { clone := *cluster clone.Status = models.Disable objects.Set(clone.ID, &clone) } else { self.Data["json"] = models.NewInternalError(1, ErrNotFound) self.Ctx.Output.SetStatus(403) } self.ServeJSON() }
// @Title disable // @Description update the object // @Param serviceID path string true "The serviceID you want to update" // @Success 200 // @Failure 403 :serviceID is empty // @router /:id/disable [put] func (self *ServiceController) Disable() { id := self.GetString(":id") if svc, ok := objects.Get(id).(*models.Service); ok { clone := *svc clone.Status = models.Disable objects.Set(clone.ID, &clone) } else { self.Data["json"] = models.NewInternalError(1, ErrNotFound) self.Ctx.Output.SetStatus(403) } self.ServeJSON() }
// @Title Get // @Description find node by nodeID // @Param nodeID path string true "The nodeID you want to get" // @Success 200 {object} models.ResponseNode // @Failure 403 :nodeID is empty // @router /:id [get] func (self *NodeController) Get() { id := self.GetString(":id") if strings.TrimSpace(id) != "" { if object, ok := objects.Get(id).(*models.Node); ok { self.Data["json"] = models.ResponseNode{ ID: object.ID, IPAddress: object.IPAddress, NCPU: object.NCPU, Mem_MB: object.Mem_MB, Status: object.Status, Runtime: object.Runtime, } } else { self.Data["json"] = models.NewInternalError(403, ErrNotFound) self.Ctx.Output.SetStatus(403) } } else { self.Data["json"] = models.NewInternalError(403, fmt.Errorf("%s cluster_id is empty", id)) self.Ctx.Output.SetStatus(403) } self.ServeJSON() }
// @Title create // @Description create cluster // @Param body body models.Cluster true "body for cluste content" // @Success 200 {string} models.ClusterInfo.ID // @Failure 403 body is empty // @router /nas [post] func (self *StorageController) PostNAS() { var body models.NAS err := json.Unmarshal(self.Ctx.Input.RequestBody, &body) if err != nil { self.Data["json"] = models.NewInternalError(400, err) self.Ctx.Output.SetStatus(403) self.ServeJSON() return } objects.Set(body.ID, &body) //self.Ctx.Output.SetStatus(201) self.ServeJSON() }
// @Title Get // @Description find SANs by condition // @Param body body models.CommonRequestBody true "the cluster_IDs you want to get" // @Success 200 {object} models.SAN // @router /nas/:id [get] func (self *StorageController) GetNAS() { id := self.GetString(":ID") if nas, ok := objects.Get(id).(*models.NAS); ok { self.Data["json"] = models.ResponseNAS{ ID: nas.ID, TotalMB: 1024000, FreeMB: 100000, } } else { self.Data["json"] = models.NewInternalError(403, ErrNotFound) } 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 List // @Description find networks by condition // @Param body body models.CommonRequestBody true "the networks you want to get" // @Success 200 {object} models.IPtable // @Failure 400 invalid request message // @router /list [post] func (self *NetworkController) List() { var body models.CommonRequestBody err := json.Unmarshal(self.Ctx.Input.RequestBody, &body) if err != nil { self.Data["json"] = models.NewInternalError(400, err) self.Ctx.Output.SetStatus(403) self.ServeJSON() return } m := objects.Items() if body.All { list := make([]*models.IPtable, 0, 100) for k, v := range m { if id, ok := k.(string); ok && strings.HasPrefix(id, "network_") { if ob, ok := v.(*models.IPtable); ok { list = append(list, ob) } } } self.Data["json"] = list self.ServeJSON() return } list := make([]*models.IPtable, len(body.ID)) for i, id := range body.ID { if strings.TrimSpace(id) == "" { continue } if ob, ok := m[id].(*models.IPtable); ok { list[i] = ob } else { list[i] = &models.IPtable{ ID: id, Error: ErrNotFound.Error(), } } } self.Data["json"] = list 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 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() }