예제 #1
0
func (this *TemplatesController) Post() {
	action := this.GetString("action")
	switch action {
	case "":
		service := entity.Service{}
		service.Name = this.GetString("name")
		service.Description = this.GetString("description")
		service.Where = this.GetString("where")

		id, err := this.GetInt64("id", 0)
		if err == nil {
			if id == 0 {
				service.Save()
				if service.Where == utils.Deploy_On_PaaS {
					deployOnPaaS := entity.OnPaaS{}
					deployOnPaaS.Api = this.GetString("Api")
					deployOnPaaS.Sid = service.Id
					deployOnPaaS.User = this.GetString("UserName")
					deployOnPaaS.Passwd = this.GetString("Passwd")
					deployOnPaaS.Org = this.GetString("Org")
					deployOnPaaS.Space = this.GetString("Space")
					deployOnPaaS.Save()
				}
				if service.Where == utils.Deploy_On_Vms {
					deployOnCustom := entity.OnCustom{}
					deployOnCustom.Sid = service.Id
					deployOnCustom.Ip = this.GetString("ip")
					deployOnCustom.User = this.GetString("VmUserName")
					deployOnCustom.Passwd = this.GetString("VmPasswd")
					deployOnCustom.Save()
				}
			} else {
				service.Id = id
				service.Update()
				if service.Where == utils.Deploy_On_PaaS {
					paasid, _ := this.GetInt64("paasid", 0)
					deployOnPaaS := entity.OnPaaS{}
					deployOnPaaS.Id = paasid
					deployOnPaaS.Api = this.GetString("Api")
					deployOnPaaS.Sid = service.Id
					deployOnPaaS.User = this.GetString("UserName")
					deployOnPaaS.Passwd = this.GetString("Passwd")
					deployOnPaaS.Org = this.GetString("Org")
					deployOnPaaS.Space = this.GetString("Space")
					deployOnPaaS.Update()
				}
				if service.Where == utils.Deploy_On_Vms {
					vmid, _ := this.GetInt64("vmid", 0)
					deployOnCustom := entity.OnCustom{}
					deployOnCustom.Id = vmid
					deployOnCustom.Sid = service.Id
					deployOnCustom.Ip = this.GetString("ip")
					deployOnCustom.User = this.GetString("VmUserName")
					deployOnCustom.Passwd = this.GetString("VmPasswd")
					deployOnCustom.Update()
				}
			}
		}

	case "delete":
		this.DeleteCustomService()
	}
	this.Redirect("templates", 301) //this.Get()
}
package entity_test

import (
	"github.com/astaxie/beego/orm"
	"github.com/citycloud/citycloud.cf-deploy-ui/entity"
	_ "github.com/go-sql-driver/mysql"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Testing Service CRUD", func() {
	It("Service Save", func() {
		var service entity.Service = entity.Service{Name: "mysql-service", Description: "provide mysql store service"}
		err := service.Save()
		Expect(err).ToNot(HaveOccurred())

		err = service.Delete()
		Expect(err).ToNot(HaveOccurred())
	})
	It("Service Update", func() {
		service := entity.Service{Name: "mysql-service", Description: "provide mysql store service"}
		id, err := orm.NewOrm().Insert(&service)
		Expect(err).ToNot(HaveOccurred())
		service1 := entity.Service{}
		service1.Id = id
		errs := service1.Load()
		Expect(errs).ToNot(HaveOccurred())
		service1.Name = "New-mysql-service"
		errs = service1.Update()
		Expect(errs).ToNot(HaveOccurred())
		errs = service1.Load()