当前位置: 首页>>代码示例>>Golang>>正文


Golang connection.New函数代码示例

本文整理汇总了Golang中github.com/cloudfoundry-incubator/garden/client/connection.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ContainerCheck

func ContainerCheck(gardenAddr string, processes []ps.Process) error {
	var errMsg string
	stdout, _, err := RunCommand(`
$proc = Get-CimInstance Win32_Process -Filter "name = 'containerizer.exe'"
$result = Invoke-CimMethod -InputObject $proc -MethodName GetOwner
$result.User
`)
	if err != nil {
		return err
	}
	if strings.HasPrefix(stdout, "SYSTEM") {
		errMsg = batchLogonMessage
	} else {
		errMsg = localLogonMessage
	}

	client := gclient.New(gconnection.New("tcp", gardenAddr))
	container, err := client.Create(garden.ContainerSpec{})
	if container != nil {
		defer client.Destroy(container.Handle())
	}

	if err != nil {
		if err.Error() == logonFailure {
			return errors.New("Failed to create container\n" + errMsg)
		} else {
			return errors.New("Failed to create container\n" + err.Error())
		}
	}
	return nil
}
开发者ID:cloudfoundry-incubator,项目名称:hakim,代码行数:31,代码来源:container_check.go

示例2: main

func main() {
	flag.Parse()

	gclient := client.New(connection.New("tcp", "localhost:7777"))

	var container garden.Container
	containers, err := gclient.Containers(garden.Properties{})
	must(err)
	for _, c := range containers {
		if c.Handle() == *containerHandle {
			container = c
			break
		}
	}
	if container == nil {
		panic("Container not found!")
	}

	process, err := container.Attach(uint32(*processId), garden.ProcessIO{})
	must(err)

	switch *signalType {
	case "term":
		fmt.Println("Signalling term")
		must(process.Signal(garden.SignalTerminate))
		break

	case "kill":
		fmt.Println("Signalling kill")
		must(process.Signal(garden.SignalKill))
		break
	}
}
开发者ID:glestaris,项目名称:garden-stuff,代码行数:33,代码来源:main.go

示例3: start

func start(creator RunnerCreator, network, addr string, argv ...string) *RunningGarden {
	tmpDir := filepath.Join(
		os.TempDir(),
		fmt.Sprintf("test-garden-%d", ginkgo.GinkgoParallelNode()),
	)

	if GraphRoot == "" {
		GraphRoot = filepath.Join(tmpDir, "graph")
	}

	graphPath := filepath.Join(GraphRoot, fmt.Sprintf("node-%d", ginkgo.GinkgoParallelNode()))

	r := &RunningGarden{
		GraphRoot: GraphRoot,
		GraphPath: graphPath,
		tmpdir:    tmpDir,
		logger:    lagertest.NewTestLogger("garden-runner"),

		Client: client.New(connection.New(network, addr)),
	}

	c := cmd(tmpDir, graphPath, network, addr, GardenBin, BinPath, RootFSPath, argv...)
	r.process = ifrit.Invoke(creator.Create(c))
	r.Pid = c.Process.Pid

	return r
}
开发者ID:guanglinlv,项目名称:garden-linux,代码行数:27,代码来源:runner.go

示例4: start

func start(network, addr string, argv ...string) *RunningGarden {
	tmpDir := filepath.Join(
		os.TempDir(),
		fmt.Sprintf("test-garden-%d", ginkgo.GinkgoParallelNode()),
	)
	Expect(os.MkdirAll(tmpDir, 0755)).To(Succeed())

	if GraphRoot == "" {
		GraphRoot = filepath.Join(tmpDir, "graph")
	}

	graphPath := filepath.Join(GraphRoot, fmt.Sprintf("node-%d", ginkgo.GinkgoParallelNode()))
	stateDirPath := filepath.Join(tmpDir, "state")
	depotPath := filepath.Join(tmpDir, "containers")
	snapshotsPath := filepath.Join(tmpDir, "snapshots")

	if err := os.MkdirAll(stateDirPath, 0755); err != nil {
		Expect(err).ToNot(HaveOccurred())
	}

	if err := os.MkdirAll(depotPath, 0755); err != nil {
		Expect(err).ToNot(HaveOccurred())
	}

	if err := os.MkdirAll(snapshotsPath, 0755); err != nil {
		Expect(err).ToNot(HaveOccurred())
	}

	MustMountTmpfs(graphPath)

	r := &RunningGarden{
		GraphRoot:     GraphRoot,
		GraphPath:     graphPath,
		StateDirPath:  stateDirPath,
		DepotPath:     depotPath,
		SnapshotsPath: snapshotsPath,
		tmpdir:        tmpDir,
		logger:        lagertest.NewTestLogger("garden-runner"),

		Client: client.New(connection.New(network, addr)),
	}

	c := cmd(stateDirPath, depotPath, snapshotsPath, graphPath, network, addr, GardenBin, BinPath, RootFSPath, argv...)
	r.runner = ginkgomon.New(ginkgomon.Config{
		Name:              "garden-linux",
		Command:           c,
		AnsiColorCode:     "31m",
		StartCheck:        "garden-linux.started",
		StartCheckTimeout: 30 * time.Second,
	})

	r.process = ifrit.Invoke(r.runner)
	r.Pid = c.Process.Pid

	return r
}
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:56,代码来源:runner.go

示例5: heartbeatWorker

func (server *registrarSSHServer) heartbeatWorker(logger lager.Logger, worker atc.Worker, channel ssh.Channel) ifrit.Process {
	return ifrit.Background(tsa.NewHeartbeater(
		logger,
		server.heartbeatInterval,
		gclient.New(gconn.New("tcp", worker.Addr)),
		server.atcEndpoint,
		worker,
		channel,
	))
}
开发者ID:savaki,项目名称:tsa,代码行数:10,代码来源:server.go

示例6: main

func main() {
	gardenClient := client.New(connection.New("tcp", "127.0.0.1:7777"))

	_ = gardenClient.Destroy("foo")
	foo, err := gardenClient.Create(garden.ContainerSpec{Handle: "foo"})
	failIf(err, "Create")

	err = foo.NetOut(garden.NetOutRule{
		Protocol: garden.ProtocolICMP,
		Networks: []garden.IPRange{garden.IPRangeFromIP(net.ParseIP("8.8.8.8"))},
	})
	failIf(err, "NetOut")

	restartGarden()

}
开发者ID:cloudfoundry-incubator,项目名称:garden-acceptance,代码行数:16,代码来源:test_netout.go

示例7: main

func main() {
	gardenClient := client.New(connection.New("tcp", "127.0.0.1:7777"))

	_ = gardenClient.Destroy("foo")
	container, err := gardenClient.Create(garden.ContainerSpec{
		Handle:     "foo",
		Env:        []string{"LANG=en_GB.iso885915"},
		RootFSPath: "docker:///debian#8",
	})
	failIf(err, "Create")

	var output bytes.Buffer
	process, err := container.Run(garden.ProcessSpec{
		Path: "sh",
		Args: []string{"-c", "echo $LANG"},
	}, garden.ProcessIO{Stdout: &output})
	failIf(err, "Run")
	process.Wait()
	fmt.Println(output.String())
}
开发者ID:cloudfoundry-incubator,项目名称:garden-acceptance,代码行数:20,代码来源:test_locale.go

示例8: Start

func Start(bin, iodaemonBin, nstarBin string, argv ...string) *RunningGarden {
	network := "unix"
	addr := fmt.Sprintf("/tmp/garden_%d.sock", GinkgoParallelNode())
	tmpDir := filepath.Join(
		os.TempDir(),
		fmt.Sprintf("test-garden-%d", ginkgo.GinkgoParallelNode()),
	)

	if GraphRoot == "" {
		GraphRoot = filepath.Join(tmpDir, "graph")
	}

	graphPath := filepath.Join(GraphRoot, fmt.Sprintf("node-%d", ginkgo.GinkgoParallelNode()))
	depotDir := filepath.Join(tmpDir, "containers")

	MustMountTmpfs(graphPath)

	r := &RunningGarden{
		DepotDir: depotDir,

		GraphRoot: GraphRoot,
		GraphPath: graphPath,
		tmpdir:    tmpDir,
		logger:    lagertest.NewTestLogger("garden-runner"),

		Client: client.New(connection.New(network, addr)),
	}

	c := cmd(tmpDir, depotDir, graphPath, network, addr, bin, iodaemonBin, nstarBin, TarPath, RootFSPath, argv...)
	r.process = ifrit.Invoke(&ginkgomon.Runner{
		Name:              "guardian",
		Command:           c,
		AnsiColorCode:     "31m",
		StartCheck:        "guardian.started",
		StartCheckTimeout: 30 * time.Second,
	})

	r.Pid = c.Process.Pid

	return r
}
开发者ID:digideskio,项目名称:guardian,代码行数:41,代码来源:runner.go

示例9: GardenContainers

func GardenContainers(gardenAddr string, gardenNetwork string, raw bool, out io.Writer) error {
	client := client.New(connection.New(gardenNetwork, gardenAddr))
	containers, err := client.Containers(nil)
	if err != nil {
		return err
	}

	workPool, err := workpool.NewWorkPool(32)
	if err != nil {
		return err
	}

	lock := &sync.Mutex{}
	wg := &sync.WaitGroup{}
	wg.Add(len(containers))

	containerInfos := []ContainerInfo{}
	for _, container := range containers {
		container := container
		workPool.Submit(func() {
			defer wg.Done()
			info, err := container.Info()
			if err != nil {
				say.Println(1, say.Red("Failed to fetch container info: %s\n", container.Handle()))
				return
			}
			metrics, err := container.Metrics()
			if err != nil {
				say.Println(1, say.Red("Failed to fetch container metrics: %s\n", container.Handle()))
				return
			}

			lock.Lock()
			defer lock.Unlock()
			containerInfos = append(containerInfos, ContainerInfo{
				container.Handle(),
				info,
				metrics,
			})
		})
	}
	wg.Wait()

	if raw {
		encoded, err := json.MarshalIndent(containerInfos, "", "  ")

		if err != nil {
			return err
		}

		out.Write(encoded)
		return nil
	}

	if len(containerInfos) == 0 {
		say.Println(0, say.Red("No Containers"))
	}
	for _, containerInfo := range containerInfos {
		printContainer(out, containerInfo)
	}
	return nil
}
开发者ID:mhoran,项目名称:veritas,代码行数:62,代码来源:garden_containers.go

示例10: Initialize

func Initialize(logger lager.Logger, config Configuration, clock clock.Clock) (executor.Client, grouper.Members, error) {
	gardenClient := GardenClient.New(GardenConnection.New(config.GardenNetwork, config.GardenAddr))
	err := waitForGarden(logger, gardenClient, clock)
	if err != nil {
		return nil, nil, err
	}

	containersFetcher := &executorContainers{
		gardenClient: gardenClient,
		owner:        config.ContainerOwnerName,
	}

	destroyContainers(gardenClient, containersFetcher, logger)

	workDir := setupWorkDir(logger, config.TempDir)

	transformer := initializeTransformer(
		logger,
		config.CachePath,
		workDir,
		config.MaxCacheSizeInBytes,
		uint(config.MaxConcurrentDownloads),
		maxConcurrentUploads,
		config.SkipCertVerify,
		config.ExportNetworkEnvVars,
		clock,
	)

	hub := event.NewHub()

	gardenStore, err := gardenstore.NewGardenStore(
		gardenClient,
		config.ContainerOwnerName,
		config.ContainerMaxCpuShares,
		config.ContainerInodeLimit,
		config.HealthyMonitoringInterval,
		config.UnhealthyMonitoringInterval,
		transformer,
		clock,
		hub,
		config.HealthCheckWorkPoolSize,
	)
	if err != nil {
		return nil, grouper.Members{}, err
	}

	allocationStore := allocationstore.NewAllocationStore(clock, hub)

	workPoolSettings := executor.WorkPoolSettings{
		CreateWorkPoolSize:  config.CreateWorkPoolSize,
		DeleteWorkPoolSize:  config.DeleteWorkPoolSize,
		ReadWorkPoolSize:    config.ReadWorkPoolSize,
		MetricsWorkPoolSize: config.MetricsWorkPoolSize,
	}

	depotClientProvider, err := depot.NewClientProvider(
		fetchCapacity(logger, gardenClient, config),
		allocationStore,
		gardenStore,
		hub,
		keyed_lock.NewLockManager(),
		workPoolSettings,
	)
	if err != nil {
		return nil, grouper.Members{}, err
	}

	metricsLogger := logger.Session("metrics-reporter")
	containerMetricsLogger := logger.Session("container-metrics-reporter")

	return depotClientProvider.WithLogger(logger),
		grouper.Members{
			{"metrics-reporter", &metrics.Reporter{
				ExecutorSource: depotClientProvider.WithLogger(metricsLogger),
				Interval:       metricsReportInterval,
				Logger:         metricsLogger,
			}},
			{"hub-closer", closeHub(hub)},
			{"registry-pruner", allocationStore.RegistryPruner(logger, config.RegistryPruningInterval)},
			{"container-metrics-reporter", containermetrics.NewStatsReporter(
				containerMetricsLogger,
				containerMetricsReportInterval,
				clock,
				depotClientProvider.WithLogger(containerMetricsLogger),
			)},
		},
		nil
}
开发者ID:emc-xchallenge,项目名称:executor,代码行数:88,代码来源:initializer.go

示例11: TestGardenAcceptance

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

func TestGardenAcceptance(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Garden Acceptance Suite")
}

var gardenClient client.Client

var hostIP = "10.244.16.6"

var _ = BeforeSuite(func() {
	gardenClient = client.New(connection.New("tcp", hostIP+":7777"))
})

var _ = BeforeEach(func() {
	destroyAllContainers(gardenClient)
})

var _ = AfterEach(func() {
	destroyAllContainers(gardenClient)
})

var lsProcessSpec = garden.ProcessSpec{User: "root", Path: "ls", Args: []string{"-l", "/"}}
var silentProcessIO = garden.ProcessIO{Stdout: GinkgoWriter, Stderr: GinkgoWriter}

func recordedProcessIO(buffer *gbytes.Buffer) garden.ProcessIO {
	return garden.ProcessIO{
开发者ID:cloudfoundry-incubator,项目名称:garden-acceptance,代码行数:31,代码来源:garden_acceptance_suite_test.go

示例12: client

func client(c *cli.Context) garden.Client {
	target := c.GlobalString("target")
	return gclient.New(gconn.New("tcp", target))
}
开发者ID:vito,项目名称:gaol,代码行数:4,代码来源:gaol.go

示例13:

var _ = Describe("Concurrent container creation", func() {

	BeforeEach(func() {
		runtime.GOMAXPROCS(runtime.NumCPU())
	})

	Measure("multiple concurrent creates", func(b Benchmarker) {
		handles := []string{}

		b.Time("concurrent creations", func() {
			chans := []chan string{}
			for i := 0; i < creates; i++ {
				ch := make(chan string, 1)
				go func(c chan string, index int) {
					defer GinkgoRecover()
					client := gclient.New(connection.New("tcp", "localhost:7777"))
					b.Time("create-"+strconv.Itoa(index), func() {
						ctr, err := client.Create(garden.ContainerSpec{})
						Expect(err).ToNot(HaveOccurred())
						c <- ctr.Handle()
					})
				}(ch, i)
				chans = append(chans, ch)
			}

			for _, ch := range chans {
				handle := <-ch
				if handle != "" {
					handles = append(handles, handle)

				}
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:31,代码来源:create_measure_test.go

示例14:

		apiServer = server.New(
			"unix",
			socketPath,
			serverContainerGraceTime,
			serverBackend,
			logger,
		)

		err = apiServer.Start()
		Ω(err).ShouldNot(HaveOccurred())

		isRunning = true

		Eventually(ErrorDialing("unix", socketPath)).ShouldNot(HaveOccurred())

		apiClient = client.New(connection.New("unix", socketPath))
	})

	AfterEach(func() {
		if isRunning {
			apiServer.Stop()
		}
		if tmpdir != "" {
			os.RemoveAll(tmpdir)
		}
	})

	Context("and the client sends a PingRequest", func() {
		Context("and the backend ping succeeds", func() {
			It("does not error", func() {
				Ω(apiClient.Ping()).ShouldNot(HaveOccurred())
开发者ID:julz,项目名称:garden-runc,代码行数:31,代码来源:request_handling_test.go

示例15:

							fakeBackend.ContainersStub = func(garden.Properties) ([]garden.Container, error) {
								return (<-stubs)()
							}
						})

						JustBeforeEach(func() {
							err := json.NewEncoder(sshStdin).Encode(workerPayload)
							Ω(err).ShouldNot(HaveOccurred())
						})

						It("forwards garden API calls through the tunnel", func() {
							registration := <-registered
							addr := registration.worker.Addr

							client := gclient.New(gconn.New("tcp", addr))

							fakeBackend.CreateReturns(new(gfakes.FakeContainer), nil)

							_, err := client.Create(garden.ContainerSpec{})
							Ω(err).ShouldNot(HaveOccurred())

							Ω(fakeBackend.CreateCallCount()).Should(Equal(1))
						})

						It("continuously registers it with the ATC as long as it works", func() {
							a := time.Now()
							registration := <-registered
							Ω(registration.ttl).Should(Equal(2 * heartbeatInterval))

							// shortcut for equality w/out checking addr
开发者ID:savaki,项目名称:tsa,代码行数:30,代码来源:main_test.go


注:本文中的github.com/cloudfoundry-incubator/garden/client/connection.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。