コード例 #1
0
// operate service on vms
func (serviceDeploy *ServiceDeployWebSocketController) OperateOnVms(ws *websocket.Conn, service entity.Service, operate string) {
	//加载serviceDto
	//	writeStringMessage(ws, "Load ServiceDto")
	serviceDto := entity.ServiceDto{}
	serviceDto.Service = service
	err := serviceDto.Load()

	if err != nil {
		writeStringMessage(ws, fmt.Sprintf("Error,%s", err))
		return
	}
	writeStringMessage(ws, "Load custom vms info")
	onCustom := serviceDto.OnCustom
	sshRunner := utils.NewDeploySSHRunner(onCustom.Ip, onCustom.User, onCustom.Passwd)

	operation := entity.Operation{}
	operation.Sid = service.Id
	err = operation.LoadBySid()

	var out bytes.Buffer

	if err == nil {
		switch operate {
		case utils.Service_Restart:
			writeStringMessage(ws, fmt.Sprintf("Start run command: %s app, please wait for a monent", "Restart"))
			err = sshRunner.RunCommand(operation.Restart, &out)
			if err == nil {
				writeStringMessage(ws, fmt.Sprintf("%s app successful", "Restart"))
			}
		case utils.Service_Start:
			writeStringMessage(ws, fmt.Sprintf("Start run command: %s app, please wait for a monent", "Start"))
			err = sshRunner.RunCommand(operation.Start, &out)
			if err == nil {
				writeStringMessage(ws, fmt.Sprintf("%s app successful", "Start"))
			}
		case utils.Service_Stop:
			writeStringMessage(ws, fmt.Sprintf("Start run command: %s app, please wait for a monent", "Stop"))
			err = sshRunner.RunCommand(operation.Stop, &out)
			if err == nil {
				writeStringMessage(ws, fmt.Sprintf("%s app successful", "Stop"))
			}
		}
		if err != nil {
			writeStringMessage(ws, fmt.Sprintf("%s app failed ,errors: %v", operate, err))
		}
	}

}
コード例 #2
0
// deploy 2 vms
func (serviceDeploy *ServiceDeployWebSocketController) Deploy2Vms(ws *websocket.Conn, service entity.Service) {
	//加载serviceDto
	//	writeStringMessage(ws, "Load ServiceDto")
	serviceDto := entity.ServiceDto{}
	serviceDto.Service = service
	err := serviceDto.Load()
	if err != nil {
		writeStringMessage(ws, fmt.Sprintf("Error,%s", err))
		return
	}

	//加载TemplateList
	writeStringMessage(ws, "Load TemplateList")
	template, templateLoadErr := entity.LoadTemplateList(service.Id)

	if templateLoadErr != nil {
		writeStringMessage(ws, fmt.Sprintf("Error,%s", templateLoadErr))
		return
	}

	//模板输出文件
	result := serviceDeploy.ParseTemplate(ws, service)
	if !result {
		return
	}
	//模板输出文件
	//传输文件
	writeStringMessage(ws, "传输文件...")

	vms := serviceDto.OnCustom

	sshRunner := utils.NewDeploySSHRunner(vms.Ip, vms.User, vms.Passwd)

	for index, temp1 := range template {
		if temp1.FileType != utils.FileTypes_War {
			continue
		}
		serviceDeploy.pushFiles(ws, index, temp1, sshRunner)

	}
	writeStringMessage(ws, "Finish deploying")

}
コード例 #3
0
package utils_test

import (
	"bytes"
	"fmt"
	"github.com/citycloud/citycloud.cf-deploy-ui/utils"
	. "github.com/onsi/ginkgo"
)

var _ = Describe("Testing with Ginkgo", func() {
	It("Test SCP", func() {
		var out bytes.Buffer
		scpRunner := utils.NewDeploySSHRunner("10.162.2.146", "root", "4rfv%TGB")
		fmt.Println()
		fmt.Println("=============")
		scpRunner.Push("/home/ubuntu/deploy/jdk1.8.0_40", "~/", &out)
		line, _ := out.ReadString('\n')
		fmt.Println(line)
		//		fmt.Println("=============")
		//		scpRunner.Push("/home/ubuntu/deploy/abc/abcd", "~/", &out)
		//		line, _ = out.ReadString('\n')
		//		fmt.Println(line)
		//		fmt.Println("=============")
		//		scpRunner.Push("/home/ubuntu/deploy/abc/cdef", "~/", &out)
		//		line, _ = out.ReadString('\n')
		//		fmt.Println(line)

	})
})