Пример #1
0
func StartGarden(gardenBin, containerizerBin string, argv ...string) (ifrit.Process, garden.Client) {
	gardenPort, err := localip.LocalPort()
	Expect(err).NotTo(HaveOccurred())
	gardenAddr := fmt.Sprintf("127.0.0.1:%d", gardenPort)

	tmpDir := os.TempDir()

	// If below fails, try
	// netsh advfirewall firewall add rule name="Open Port 48080"  dir=in action=allow protocol=TCP localport=48080

	containerizerPort, err := localip.LocalPort()
	Expect(err).NotTo(HaveOccurred())
	gardenRunner := garden_runner.New("tcp4", gardenAddr, tmpDir, gardenBin, fmt.Sprintf("http://127.0.0.1:%d", containerizerPort))
	containerizerRunner := ginkgomon.New(ginkgomon.Config{
		Name:              "containerizer",
		Command:           exec.Command(containerizerBin, "127.0.0.1", strconv.Itoa(int(containerizerPort))),
		AnsiColorCode:     "",
		StartCheck:        "Control-C to quit.",
		StartCheckTimeout: 10 * time.Second,
		Cleanup:           func() {},
	})

	group := grouper.NewOrdered(syscall.SIGTERM, []grouper.Member{
		{Name: "containerizer", Runner: containerizerRunner},
		{Name: "garden", Runner: gardenRunner},
	})

	gardenProcess := ifrit.Invoke(group)

	return gardenProcess, gardenRunner.NewClient()
}
Пример #2
0
func (c *VcapComponent) Start() error {
	if c.Type == "" {
		log.Error("Component type is required")
		return errors.New("type is required")
	}

	c.quitCh = make(chan struct{}, 1)
	c.StartTime = Time(time.Now())
	uuid, err := GenerateUUID()
	if err != nil {
		return err
	}
	c.UUID = fmt.Sprintf("%d-%s", c.Index, uuid)

	if c.Host == "" {
		host, err := localip.LocalIP()
		if err != nil {
			log.Error(err.Error())
			return err
		}

		port, err := localip.LocalPort()
		if err != nil {
			log.Error(err.Error())
			return err
		}

		c.Host = fmt.Sprintf("%s:%d", host, port)
	}

	if c.Credentials == nil || len(c.Credentials) != 2 {
		user, err := GenerateUUID()
		if err != nil {
			return err
		}
		password, err := GenerateUUID()
		if err != nil {
			return err
		}

		c.Credentials = []string{user, password}
	}

	if c.Logger != nil {
		log = c.Logger
	}

	c.Varz.NumCores = runtime.NumCPU()
	c.Varz.component = *c

	procStat = NewProcessStatus()

	c.ListenAndServe()
	return nil
}
Пример #3
0
func NewTestApp(urls []route.Uri, rPort uint16, mbusClient yagnats.NATSConn, tags map[string]string) *TestApp {
	app := new(TestApp)

	port, _ := localip.LocalPort()

	app.port = port
	app.rPort = rPort
	app.urls = urls
	app.mbusClient = mbusClient
	app.tags = tags

	app.mux = http.NewServeMux()

	return app
}
Пример #4
0
func NewComponent(logger *gosteno.Logger, componentType string, index uint, heathMonitor HealthMonitor, statusPort uint16, statusCreds []string, instrumentables []instrumentation.Instrumentable) (Component, error) {
	ip, err := localip.LocalIP()
	if err != nil {
		return Component{}, err
	}

	if statusPort == 0 {
		statusPort, err = localip.LocalPort()
		if err != nil {
			return Component{}, err
		}
	}

	uuid, err := uuid.NewV4()
	if err != nil {
		return Component{}, err
	}

	if len(statusCreds) == 0 || statusCreds[username] == "" || statusCreds[password] == "" {
		randUser := make([]byte, 42)
		randPass := make([]byte, 42)
		rand.Read(randUser)
		rand.Read(randPass)
		en := base64.URLEncoding
		user := en.EncodeToString(randUser)
		pass := en.EncodeToString(randPass)

		statusCreds = []string{user, pass}
	}

	return Component{
		Logger:            logger,
		IpAddress:         ip,
		Type:              componentType,
		Index:             index,
		UUID:              uuid.String(),
		HealthMonitor:     heathMonitor,
		StatusPort:        statusPort,
		StatusCredentials: statusCreds,
		Instrumentables:   instrumentables,
	}, nil
}
Пример #5
0
import (
	"net"

	"github.com/pivotal-golang/localip"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Localip", func() {
	Describe("LocalIP", func() {
		It("returns a local IP", func() {
			ip, err := localip.LocalIP()
			Ω(err).ShouldNot(HaveOccurred())

			// http://golang.org/pkg/net/#ParseIP
			// If s is not a valid textual representation of an IP address, ParseIP returns nil.
			Ω(net.ParseIP(ip)).ShouldNot(BeNil())
		})
	})

	Describe("LocalPort", func() {
		It("returns a local port", func() {
			port, err := localip.LocalPort()
			Ω(err).ShouldNot(HaveOccurred())
			Ω(port).Should(BeNumerically(">", 0))
		})
	})
})
Пример #6
0
func NextAvailPort() uint16 {
	port, err := localip.LocalPort()
	Ω(err).ShouldNot(HaveOccurred())

	return port
}
Пример #7
0
func NextAvailPort() uint16 {
	port, err := localip.LocalPort()
	Expect(err).ToNot(HaveOccurred())

	return port
}