Ejemplo n.º 1
0
// @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) != "" {
		err, node := models.GetNode(id)

		if err != nil {
			self.Data["json"] = models.NewInternalError(403, err)
			self.Ctx.Output.SetStatus(403)
		} else {
			self.Data["json"] = models.ResponseNode{
				ID:        node.ID,
				IPAddress: node.IPAddress,
				NCPU:      node.NCPU,
				Mem_MB:    node.Mem_MB,
				Status:    node.Status,
				Runtime:   node.Runtime,
			}
		}
	} else {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s node_id is empty", id))
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
Ejemplo n.º 2
0
// @Title List
// @Description find cluster by conditions
// @Param	body		body 	models.CommonRequestBody	true		"the rule you want to get"
// @Success 200 {object} models.ClusterInfo
// @Failure 400 invalid request message
// @router /list [post]
func (self *ClusterController) List() {
	var body models.CommonRequestBody
	err := json.Unmarshal(self.Ctx.Input.CopyBody(beego.BConfig.MaxMemory), &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}

	if body.All {
		list := models.GetAllCluster()
		self.Data["json"] = list
		self.ServeJSON()
		return
	}

	list := make([]interface{}, len(body.ID))
	for i, cid := range body.ID {
		if strings.TrimSpace(cid) == "" {
			continue
		}
		if err, c := models.GetCluster(cid); err == nil {
			list[i] = c
		} else {
			list[i] = models.ClusterInfo{
				ID:    cid,
				Error: ErrNotFound.Error(),
			}
		}
	}
	self.Data["json"] = list
	self.ServeJSON()
}
Ejemplo n.º 3
0
// @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.CopyBody(beego.BConfig.MaxMemory), &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 {
		err, node := models.CreateNode(body[i])

		if err == nil {
			resp[i].ID = node.ID
			resp[i].TaskID = utils.Generate32UUID()
			resp[i].NodeID = body[i].NodeID
		} else {
			resp[i].ID = node.ID
			resp[i].Error = "CreateNode " + node.ID + " err"
		}
	}

	self.Data["json"] = resp
	self.ServeJSON()
}
Ejemplo n.º 4
0
// @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 strings.TrimSpace(cid) == "" {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s cluster_id is empty", cid))
		self.Ctx.Output.SetStatus(403)
	} else {
		err := models.DisableCluster(cid)

		if err != nil {
			self.Data["json"] = models.NewInternalError(1, ErrNotFound)
			self.Ctx.Output.SetStatus(403)
		}
	}
	self.ServeJSON()
}
Ejemplo n.º 5
0
// @Title ListSAN
// @Description find  SANs by condition
// @Param	body		body 	models.CommonRequestBody	true		"the SANs you want to get"
// @Success 200 {object} models.SAN
// @Failure 400 invalid request message
// @router /san/list [post]
func (self *StorageController) ListSAN() {
	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
	}

	if body.All {
		list := models.GetAllSAN()
		self.Data["json"] = list
		self.ServeJSON()
		return
	}

	list := make([]models.SAN, len(body.ID))
	for i, id := range body.ID {
		if strings.TrimSpace(id) == "" {
			continue
		}
		if err, c := models.GetSAN(id); err == nil {
			list[i] = c
		} else {
			list[i] = models.SAN{
				ID:    id,
				Error: ErrNotFound.Error(),
			}
		}
	}
	self.Data["json"] = list
	self.ServeJSON()
}
Ejemplo n.º 6
0
// @Title disable
// @Description update the node
// @Param	nodeID		path 	string	true		"The node id you want to disable"
// @Success 200
// @Failure 403 :nid not exist
// @router /:nid/disable [put]
func (self *NodeController) Disable() {
	nid := self.GetString(":nid")

	if strings.TrimSpace(nid) == "" {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s node_id is empty", nid))
		self.Ctx.Output.SetStatus(403)
	} else {
		err := models.DisableNode(nid)
		if err != nil {
			self.Data["json"] = models.NewInternalError(1, ErrNotFound)
			self.Ctx.Output.SetStatus(403)
		}
	}

	self.ServeJSON()
}
Ejemplo n.º 7
0
// @Title enable
// @Description update the object
// @Param	serviceID		path 	string	true		"The serviceID you want to update"
// @Success 200
// @Failure 403 :serviceID is empty
// @router /:id/enable [put]
func (self *ServiceController) Enable() {
	id := self.GetString(":id")

	if strings.TrimSpace(id) == "" {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s service_id is empty", id))
		self.Ctx.Output.SetStatus(403)
	} else {
		err := models.EnableService(id)
		if err != nil {
			self.Data["json"] = models.NewInternalError(1, ErrNotFound)
			self.Ctx.Output.SetStatus(403)
		}
	}

	self.ServeJSON()
}
Ejemplo n.º 8
0
// @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) != "" {
		err, iptable := models.GetIPtable(id)

		if err != nil {
			self.Data["json"] = models.NewInternalError(403, err)
			self.Ctx.Output.SetStatus(403)
		} else {
			self.Data["json"] = iptable
		}
	} else {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s iptable_id is empty", id))
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
Ejemplo n.º 9
0
// @Title delete
// @Description delete the object
// @Param	softwareID		path 	string	true		"The software you want to delete"
// @Success 200
// @router /:id [delete]
func (self *SoftwareController) Delete() {
	id := self.GetString(":id")
	if strings.TrimSpace(id) == "" {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s Software_id is empty", id))
		self.Ctx.Output.SetStatus(403)
		return
	}

	err := models.DeleteSoftware(id)

	if err == nil {
		self.Ctx.Output.SetStatus(200)
	} else {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s Delete fail", id))
		self.Ctx.Output.SetStatus(403)
	}
}
Ejemplo n.º 10
0
// @Title delete
// @Description delete the object
// @Param	clusterID		path 	string	true		"The clusterID you want to delete"
// @Success 200
// @Failure 403 clusterID is empty
// @router /:clusterID [delete]
func (self *ClusterController) Delete() {
	clusterID := self.GetString(":clusterID")
	if strings.TrimSpace(clusterID) == "" {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s cluster_id is empty", clusterID))
		self.Ctx.Output.SetStatus(403)
		return
	}

	err := models.DeleteCluster(clusterID)

	if err == nil {
		self.Ctx.Output.SetStatus(200)
	} else {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s Delete fail", clusterID))
		self.Ctx.Output.SetStatus(403)
	}
}
Ejemplo n.º 11
0
// @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.CopyBody(beego.BConfig.MaxMemory), &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}

	err = models.UpdateNode(nid, body)

	if err != nil {
		self.Data["json"] = models.NewInternalError(1, ErrNotFound)
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
Ejemplo n.º 12
0
// @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 strings.TrimSpace(id) != "" {
		err, nas := models.GetNAS(id)

		if err != nil {
			self.Data["json"] = models.NewInternalError(403, err)
			self.Ctx.Output.SetStatus(403)
		} else {
			self.Data["json"] = nas
		}
	} else {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s nas_id is empty", id))
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
Ejemplo n.º 13
0
// @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.CopyBody(beego.BConfig.MaxMemory), &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}

	err, software := models.CreateSoftware(body)
	if err == nil {
		self.Data["json"] = software
		self.Ctx.Output.SetStatus(200)
	} else {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
	}
	self.ServeJSON()
}
Ejemplo n.º 14
0
// @Title Get
// @Description find cluster by cluster_ID
// @Param	clusterID		path 	string	true		"The clusterID you want to get"
// @Success 200 {object} models.ClusterInfo
// @Failure 403 :clusterID is empty
// @router /:clusterID [get]
func (self *ClusterController) Get() {
	id := self.GetString(":clusterID")

	if strings.TrimSpace(id) != "" {
		err, clusterInfo := models.GetCluster(id)

		if err != nil {
			self.Data["json"] = models.NewInternalError(403, err)
			self.Ctx.Output.SetStatus(403)
		} else {
			self.Data["json"] = clusterInfo
		}

	} else {
		self.Data["json"] = models.NewInternalError(403,
			fmt.Errorf("%s cluster_id is empty", id))
		self.Ctx.Output.SetStatus(403)
	}
	self.ServeJSON()
}
Ejemplo n.º 15
0
// @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
	}

	err, rg := models.CreateRaidGroup(body)
	if err == nil {
		self.Data["json"] = rg
		self.Ctx.Output.SetStatus(200)
	} else {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
	}
	self.ServeJSON()
}
Ejemplo n.º 16
0
// @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
	}

	err, service := models.CreateService(body)
	if err == nil {
		self.Data["json"] = service
		self.Ctx.Output.SetStatus(200)
	} else {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
	}
	self.ServeJSON()
}
Ejemplo n.º 17
0
// @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.CopyBody(beego.BConfig.MaxMemory), &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}

	err, clusterInfo := models.CreateCluster(body)

	if err == nil {
		self.Data["json"] = clusterInfo
		self.Ctx.Output.SetStatus(200)
		self.ServeJSON()
	} else {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
	}
}
Ejemplo n.º 18
0
// @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.CopyBody(beego.BConfig.MaxMemory), &body)
	if err != nil {
		self.Data["json"] = models.NewInternalError(400, err)
		self.Ctx.Output.SetStatus(400)
		self.ServeJSON()
		return
	}
	if body.All {
		list := make([]models.ResponseNode, 0, 100)
		nodes := models.GetAllNode()
		for _, node := range nodes {
			list = append(list, models.ResponseNode{
				ID:        node.ID,
				IPAddress: node.IPAddress,
				NCPU:      node.NCPU,
				Mem_MB:    node.Mem_MB,
				Status:    node.Status,
				Runtime:   node.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 err, node := models.GetNode(id); err == nil {
			list[i] = models.ResponseNode{
				ID:        node.ID,
				IPAddress: node.IPAddress,
				NCPU:      node.NCPU,
				Mem_MB:    node.Mem_MB,
				Status:    node.Status,
				Runtime:   node.Runtime,
			}
		} else {
			list[i] = models.ResponseNode{
				ID:    id,
				Error: ErrNotFound.Error(),
			}
		}
	}
	self.Data["json"] = list
	self.ServeJSON()
}