Beispiel #1
0
// 创建服务器
func (this *AppHandler) Post(args *types.App, reply *types.Event) error {
	//c := NewkubeClient()
	args.Id = "default"

	/*if len(args.Pods) == 0 {
		reply.Code = 500
		reply.Content = "Pods lenght 0"
		return errors.New("Pods lenght 0")
	}

	pods := c.Pods(args.Id)
	for _, v := range args.Pods {
		// 转换实例配置文件
		conf := utils.PodToKubeStruct(v)
		_, err := pods.Create(conf)
		if err != nil {
			return err
		}
	}

	sers := c.Services(args.Id)
	for _, v := range args.Services {
		// 转换网络配置文件
		conf := utils.ServiceTokubenetStruct(v)
		_, err := sers.Create(conf)
		if err != nil {
			return err
		}
	}*/

	reply.Code = 200
	reply.Content = "ok"

	return nil
}
Beispiel #2
0
func appPut(c echo.Context) error {
	app := new(types.App)
	reply := new(types.Event)
	err := RecvData(c, app)

	if err != nil {
		reply.Code = http.StatusBadRequest
		reply.Content = "数据格式为非protobuf"
		return SendData(c, http.StatusBadRequest, reply)
	}

	err = appHandler.Post(app, reply)

	if err != nil {
		fmt.Println(err)
		fmt.Println(reply)
		return SendData(c, http.StatusInternalServerError, reply)
	}

	return SendData(c, http.StatusOK, reply)
}
Beispiel #3
0
func appPost(c echo.Context) error {
	app := new(types.App)
	reply := new(types.Event)
	err := RecvData(c, app)

	if err != nil {
		reply.Code = http.StatusBadRequest
		reply.Content = "数据序列化错误"
		return SendData(c, http.StatusBadRequest, reply)
	}

	err = appHandler.Post(app, reply)

	if err != nil {
		reply.Code = http.StatusInternalServerError
		reply.Content = err.Error()
		return SendData(c, http.StatusInternalServerError, reply)
	}

	return SendData(c, http.StatusOK, reply)
}
Beispiel #4
0
func (this *PodHandler) Patch(args *types.Pod, reply *types.Event) error {
	c := NewkubeClient()
	pods := c.Pods(args.ParentId)

	// 转换配置文件
	conf := utils.PodToKubeStruct(args)

	reply.Id = conf.GetName()

	_, err := pods.Update(conf)
	if err != nil {
		return err
	}
	return nil
}
Beispiel #5
0
func (this *SerHandler) Put(args *types.Service, reply *types.Event) error {
	c := NewkubeClient()
	sers := c.Services(args.ParentId)

	// 转换配置文件
	conf := utils.ServiceTokubenetStruct(args)

	reply.Id = conf.GetName()

	_, err := sers.Update(conf)
	if err != nil {
		return err
	}
	return nil
}