• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang libmachine.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestGetScpCmd

func TestGetScpCmd(t *testing.T) {
	mcn, _ := libmachine.New(ScpFakeStore{})

	// TODO: This is a little "integration-ey".  Perhaps
	// make an ScpDispatcher (name?) interface so that the reliant
	// methods can be mocked.
	expectedArgs := append(
		baseSSHArgs,
		"-3",
		"-i",
		"/fake/keypath/id_rsa",
		"/tmp/foo",
		"[email protected]:/home/docker/foo",
	)
	expectedCmd := exec.Command("/usr/bin/scp", expectedArgs...)

	cmd, err := getScpCmd("/tmp/foo", "myfunhost:/home/docker/foo", append(baseSSHArgs, "-3"), *mcn)
	if err != nil {
		t.Fatalf("Unexpected err getting scp command: %s", err)
	}

	correct := reflect.DeepEqual(expectedCmd, cmd)
	if !correct {
		fmt.Println(expectedCmd)
		fmt.Println(cmd)
		t.Fatal("Expected scp cmd structs to be equal but there was mismatch")
	}
}
开发者ID:cdosso,项目名称:machine,代码行数:28,代码来源:scp_test.go


示例2: main

func main() {
	flag.Parse()

	log.Printf("using store: %s\n", storePath)

	store := libmachine.NewFilestore(storePath, "", "")

	m, err := libmachine.New(store)
	if err != nil {
		log.Fatal(err)
	}

	mcn = m

	wsContainer := restful.NewContainer()
	h := HostResource{}
	h.Register(wsContainer)

	config := swagger.Config{
		WebServices:     wsContainer.RegisteredWebServices(),
		WebServicesUrl:  "http://localhost:8080",
		ApiPath:         "/apidocs.json",
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "swagger"}

	swagger.RegisterSwaggerService(config, wsContainer)

	log.Printf("start listening on localhost:8080")
	server := &http.Server{Addr: ":8080", Handler: wsContainer}
	log.Fatal(server.ListenAndServe())
}
开发者ID:carriercomm,项目名称:machine-server,代码行数:31,代码来源:main.go


示例3: NewCluster

func NewCluster(gopt *options.Options) (*Cluster, error) {
	rootPath := gopt.String("storage-path")
	os.Setenv("MACHINE_STORAGE_PATH", rootPath)
	if gopt.Bool("native-ssh") {
		ssh.SetDefaultClient(ssh.Native)
	}

	auth := getTLSAuthOptions(gopt)
	store := libmachine.NewFilestore(rootPath, auth.CaCertPath, auth.CaKeyPath)
	provider, _ := libmachine.New(store)
	hosts, err := provider.List()
	if err != nil {
		return nil, err
	}
	machines := make(map[string]*Machine, len(hosts))
	for _, h := range hosts {
		machines[h.Name] = &Machine{
			Host: h,
		}
	}

	c := &Cluster{
		provider:    provider,
		machines:    machines,
		authOptions: auth,
	}
	c.LoadStates()
	return c, nil
}
开发者ID:sdgdsffdsfff,项目名称:dockerf,代码行数:29,代码来源:cluster.go


示例4: TestGetInfoForScpArg

func TestGetInfoForScpArg(t *testing.T) {
	mcn, _ := libmachine.New(ScpFakeStore{})

	expectedPath := "/tmp/foo"
	host, path, opts, err := getInfoForScpArg("/tmp/foo", *mcn)
	if err != nil {
		t.Fatalf("Unexpected error in local getInfoForScpArg call: %s", err)
	}
	if path != expectedPath {
		t.Fatalf("Path %s not equal to expected path %s", path, expectedPath)
	}
	if host != nil {
		t.Fatal("host should be nil")
	}
	if opts != nil {
		t.Fatal("opts should be nil")
	}

	host, path, opts, err = getInfoForScpArg("myfunhost:/home/docker/foo", *mcn)
	if err != nil {
		t.Fatal("Unexpected error in machine-based getInfoForScpArg call: %s", err)
	}
	expectedOpts := []string{
		"-i",
		"/fake/keypath/id_rsa",
	}
	for i := range opts {
		if expectedOpts[i] != opts[i] {
			t.Fatalf("Mismatch in returned opts: %s != %s", expectedOpts[i], opts[i])
		}
	}
	if host.Name != "myfunhost" {
		t.Fatal("Expected host.Name to be myfunhost, got %s", host.Name)
	}
	if path != "/home/docker/foo" {
		t.Fatalf("Expected path to be /home/docker/foo, got %s", path)
	}

	host, path, opts, err = getInfoForScpArg("foo:bar:widget", *mcn)
	if err != ErrMalformedInput {
		t.Fatalf("Didn't get back an error when we were expecting it for malformed args")
	}
}
开发者ID:cdosso,项目名称:machine,代码行数:43,代码来源:scp_test.go


示例5: newProvider

func newProvider(store libmachine.Store) (*libmachine.Provider, error) {
	return libmachine.New(store)
}
开发者ID:rdgreis,项目名称:machine,代码行数:3,代码来源:commands.go


示例6: TestCmdEnvBash

func TestCmdEnvBash(t *testing.T) {
	stdout := os.Stdout
	shell := os.Getenv("SHELL")
	r, w, _ := os.Pipe()

	os.Stdout = w
	os.Setenv("MACHINE_STORAGE_PATH", TestStoreDir)
	os.Setenv("SHELL", "/bin/bash")

	defer func() {
		os.Setenv("MACHINE_STORAGE_PATH", "")
		os.Setenv("SHELL", shell)
		os.Stdout = stdout
	}()

	if err := clearHosts(); err != nil {
		t.Fatal(err)
	}

	flags := getTestDriverFlags()

	store, sErr := getTestStore()
	if sErr != nil {
		t.Fatal(sErr)
	}

	mcn, err := libmachine.New(store)
	if err != nil {
		t.Fatal(err)
	}

	hostOptions := &libmachine.HostOptions{
		EngineOptions: &engine.EngineOptions{},
		SwarmOptions: &swarm.SwarmOptions{
			Master:    false,
			Discovery: "",
			Address:   "",
			Host:      "",
		},
		AuthOptions: &auth.AuthOptions{},
	}

	host, err := mcn.Create("test-a", "none", hostOptions, flags)
	if err != nil {
		t.Fatal(err)
	}

	host, err = mcn.Get("test-a")
	if err != nil {
		t.Fatalf("error loading host: %v", err)
	}

	if err := mcn.SetActive(host); err != nil {
		t.Fatalf("error setting active host: %v", err)
	}

	outStr := make(chan string)

	go func() {
		var testOutput bytes.Buffer
		io.Copy(&testOutput, r)
		outStr <- testOutput.String()
	}()

	set := flag.NewFlagSet("config", 0)
	c := cli.NewContext(nil, set, set)
	cmdEnv(c)

	w.Close()

	out := <-outStr

	// parse the output into a map of envvar:value for easier testing below
	envvars := make(map[string]string)
	for _, e := range strings.Split(strings.TrimSpace(out), "\n") {
		if !strings.HasPrefix(e, "export ") {
			continue
		}
		kv := strings.SplitN(e, "=", 2)
		key, value := kv[0], kv[1]
		envvars[strings.Replace(key, "export ", "", 1)] = value
	}

	testMachineDir := filepath.Join(store.GetPath(), "machines", host.Name)

	expected := map[string]string{
		"DOCKER_TLS_VERIFY": "1",
		"DOCKER_CERT_PATH":  fmt.Sprintf("\"%s\"", testMachineDir),
		"DOCKER_HOST":       "unix:///var/run/docker.sock",
	}

	for k, v := range envvars {
		if v != expected[k] {
			t.Fatalf("Expected %s == <%s>, but was <%s>", k, expected[k], v)
		}
	}
}
开发者ID:Aorjoa,项目名称:Machine-Aiyara,代码行数:97,代码来源:env_test.go


示例7: TestCmdConfig

func TestCmdConfig(t *testing.T) {
	defer cleanup()

	stdout := os.Stdout
	r, w, _ := os.Pipe()

	os.Stdout = w

	defer func() {
		os.Stdout = stdout
	}()

	store, err := getTestStore()
	if err != nil {
		t.Fatal(err)
	}

	mcn, err := libmachine.New(store)
	if err != nil {
		t.Fatal(err)
	}

	flags := getTestDriverFlags()
	hostOptions := &libmachine.HostOptions{
		EngineOptions: &engine.EngineOptions{},
		SwarmOptions: &swarm.SwarmOptions{
			Master:    false,
			Discovery: "",
			Address:   "",
			Host:      "",
		},
		AuthOptions: &auth.AuthOptions{},
	}

	host, err := mcn.Create("test-a", "none", hostOptions, flags)
	if err != nil {
		t.Fatal(err)
	}

	outStr := make(chan string)

	go func() {
		var testOutput bytes.Buffer
		io.Copy(&testOutput, r)
		outStr <- testOutput.String()
	}()

	set := flag.NewFlagSet("config", 0)
	set.Parse([]string{"test-a"})
	globalSet := flag.NewFlagSet("test", 0)
	globalSet.String("storage-path", store.GetPath(), "")

	c := cli.NewContext(nil, set, globalSet)

	cmdConfig(c)

	w.Close()

	out := <-outStr

	if !strings.Contains(out, "--tlsverify") {
		t.Fatalf("Expect --tlsverify")
	}

	testMachineDir := filepath.Join(store.GetPath(), "machines", host.Name)

	tlscacert := fmt.Sprintf("--tlscacert=\"%s/ca.pem\"", testMachineDir)
	if !strings.Contains(out, tlscacert) {
		t.Fatalf("Expected to find %s in %s", tlscacert, out)
	}

	tlscert := fmt.Sprintf("--tlscert=\"%s/cert.pem\"", testMachineDir)
	if !strings.Contains(out, tlscert) {
		t.Fatalf("Expected to find %s in %s", tlscert, out)
	}

	tlskey := fmt.Sprintf("--tlskey=\"%s/key.pem\"", testMachineDir)
	if !strings.Contains(out, tlskey) {
		t.Fatalf("Expected to find %s in %s", tlskey, out)
	}

	if !strings.Contains(out, "-H=unix:///var/run/docker.sock") {
		t.Fatalf("Expect docker host URL")
	}
}
开发者ID:cdosso,项目名称:machine,代码行数:85,代码来源:config_test.go


示例8: newMcn

func newMcn(store libmachine.Store) (*libmachine.Machine, error) {
	return libmachine.New(store)
}
开发者ID:tg123,项目名称:machine,代码行数:3,代码来源:commands.go


示例9: runInspectCommand

func runInspectCommand(t *testing.T, args []string) (string, *libmachine.Host) {
	stdout := os.Stdout
	stderr := os.Stderr
	shell := os.Getenv("SHELL")
	r, w, _ := os.Pipe()

	os.Stdout = w
	os.Stderr = w
	os.Setenv("MACHINE_STORAGE_PATH", TestStoreDir)
	os.Setenv("SHELL", "/bin/bash")

	defer func() {
		os.Setenv("MACHINE_STORAGE_PATH", "")
		os.Setenv("SHELL", shell)
		os.Stdout = stdout
		os.Stderr = stderr
	}()

	if err := clearHosts(); err != nil {
		t.Fatal(err)
	}

	store, sErr := getTestStore()
	if sErr != nil {
		t.Fatal(sErr)
	}

	provider, err := libmachine.New(store)
	if err != nil {
		t.Fatal(err)
	}

	hostOptions := &libmachine.HostOptions{
		EngineOptions: &engine.EngineOptions{},
		SwarmOptions: &swarm.SwarmOptions{
			Master:    false,
			Discovery: "",
			Address:   "",
			Host:      "",
		},
		AuthOptions: &auth.AuthOptions{},
	}

	flags := getTestDriverFlags()
	_, err = provider.Create("test-a", "none", hostOptions, flags)
	if err != nil {
		t.Fatal(err)
	}

	outStr := make(chan string)

	go func() {
		var testOutput bytes.Buffer
		io.Copy(&testOutput, r)
		outStr <- testOutput.String()
	}()

	set := flag.NewFlagSet("inspect", 0)
	set.String("format", "", "")
	set.Parse(args)
	c := cli.NewContext(nil, set, set)
	cmdInspect(c)

	w.Close()

	out := <-outStr

	return strings.TrimSpace(out), getHost(c)
}
开发者ID:phusl,项目名称:machine,代码行数:69,代码来源:inspect_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang libmachine.NewClient函数代码示例发布时间:2022-05-23
下一篇:
Golang errors.NewIncompleteVsphereConfigError函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap