當前位置: 首頁>>代碼示例>>Golang>>正文


Golang client.New函數代碼示例

本文整理匯總了Golang中github.com/cloudfoundry-incubator/garden/client.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例2: Workers

func (provider *dbProvider) Workers() ([]Worker, error) {
	workerInfos, err := provider.db.Workers()
	if err != nil {
		return nil, err
	}

	tikTok := clock.NewClock()

	workers := make([]Worker, len(workerInfos))
	for i, info := range workerInfos {
		workerLog := provider.logger.Session("worker-connection", lager.Data{
			"addr": info.Addr,
		})

		gardenConn := RetryableConnection{
			Logger:     workerLog,
			Connection: gconn.NewWithLogger("tcp", info.Addr, workerLog.Session("garden-connection")),
			Sleeper:    tikTok,
			RetryPolicy: ExponentialRetryPolicy{
				Timeout: 5 * time.Minute,
			},
		}

		workers[i] = NewGardenWorker(
			gclient.New(gardenConn),
			tikTok,
			info.ActiveContainers,
			info.ResourceTypes,
			info.Platform,
			info.Tags,
		)
	}

	return workers, nil
}
開發者ID:utako,項目名稱:atc,代碼行數:35,代碼來源:db_provider.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: 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

示例5: NewGardenClient

func NewGardenClient() *FakeGardenClient {
	connection := new(fakes.FakeConnection)

	return &FakeGardenClient{
		Connection: connection,

		Client: client.New(connection),
	}
}
開發者ID:snowsnail,項目名稱:executor,代碼行數:9,代碼來源:fake_garden_client.go

示例6: 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

示例7: 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

示例8: New

func New() *FakeClient {
	connection := fake_connection.New()

	return &FakeClient{
		Connection: connection,

		Client: client.New(&FakeConnectionProvider{
			Connection: connection,
		}),
	}
}
開發者ID:vito,項目名稱:warden-linux,代碼行數:11,代碼來源:fake_client.go

示例9: 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

示例10: newGardenWorker

func (provider *dbProvider) newGardenWorker(tikTok clock.Clock, info db.WorkerInfo) Worker {
	workerLog := provider.logger.Session("worker-connection", lager.Data{
		"addr": info.GardenAddr,
	})

	gardenConn := NewRetryableConnection(
		workerLog,
		tikTok,
		provider.retryPolicy,
		NewGardenConnectionFactory(
			provider.db,
			provider.dialer,
			provider.logger.Session("garden-connection"),
			info.Name,
			info.GardenAddr,
		),
	)

	var bClient baggageclaim.Client
	if info.BaggageclaimURL != "" {
		bClient = bclient.New(info.BaggageclaimURL)
	}

	volumeFactory := NewVolumeFactory(
		provider.logger.Session("volume-factory"),
		provider.db,
		tikTok,
	)

	return NewGardenWorker(
		gclient.New(gardenConn),
		bClient,
		volumeFactory,
		provider.db,
		provider,
		tikTok,
		info.ActiveContainers,
		info.ResourceTypes,
		info.Platform,
		info.Tags,
		info.Name,
	)
}
開發者ID:ACPK,項目名稱:atc,代碼行數:43,代碼來源:db_provider.go

示例11: newGardenWorker

func (provider *dbProvider) newGardenWorker(tikTok clock.Clock, savedWorker db.SavedWorker) Worker {
	workerLog := provider.logger.Session("worker-connection", lager.Data{
		"addr": savedWorker.GardenAddr,
	})

	gardenConn := NewRetryableConnection(
		workerLog,
		tikTok,
		provider.retryPolicy,
		NewGardenConnectionFactory(
			provider.db,
			provider.dialer,
			provider.logger.Session("garden-connection"),
			savedWorker.Name,
			savedWorker.GardenAddr,
		),
	)

	var bClient baggageclaim.Client
	if savedWorker.BaggageclaimURL != "" {
		bClient = bclient.New(savedWorker.BaggageclaimURL)
	}

	volumeFactory := NewVolumeFactory(
		provider.db,
		tikTok,
	)

	return NewGardenWorker(
		gclient.New(gardenConn),
		bClient,
		volumeFactory,
		provider.imageFetcher,
		provider.db,
		provider,
		tikTok,
		savedWorker.ActiveContainers,
		savedWorker.ResourceTypes,
		savedWorker.Platform,
		savedWorker.Tags,
		savedWorker.Name,
	)
}
開發者ID:pcfdev-forks,項目名稱:atc,代碼行數:43,代碼來源:db_provider.go

示例12: 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

示例13: 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

示例14:

							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

示例15: 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


注:本文中的github.com/cloudfoundry-incubator/garden/client.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。