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


Golang virtualbox.NewDriver函數代碼示例

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


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

示例1: runDriver

func runDriver(driverName string) {
	switch driverName {
	case "amazonec2":
		plugin.RegisterDriver(amazonec2.NewDriver("", ""))
	case "digitalocean":
		plugin.RegisterDriver(digitalocean.NewDriver("", ""))
	case "exoscale":
		plugin.RegisterDriver(exoscale.NewDriver("", ""))
	case "generic":
		plugin.RegisterDriver(generic.NewDriver("", ""))
	case "google":
		plugin.RegisterDriver(google.NewDriver("", ""))
	case "hyperv":
		plugin.RegisterDriver(hyperv.NewDriver("", ""))
	case "none":
		plugin.RegisterDriver(none.NewDriver("", ""))
	case "openstack":
		plugin.RegisterDriver(openstack.NewDriver("", ""))
	case "rackspace":
		plugin.RegisterDriver(rackspace.NewDriver("", ""))
	case "softlayer":
		plugin.RegisterDriver(softlayer.NewDriver("", ""))
	case "virtualbox":
		plugin.RegisterDriver(virtualbox.NewDriver("", ""))
	case "vmwarefusion":
		plugin.RegisterDriver(vmwarefusion.NewDriver("", ""))
	case "vmwarevcloudair":
		plugin.RegisterDriver(vmwarevcloudair.NewDriver("", ""))
	case "vmwarevsphere":
		plugin.RegisterDriver(vmwarevsphere.NewDriver("", ""))
	default:
		fmt.Fprintf(os.Stderr, "Unsupported driver: %s\n", driverName)
		os.Exit(1)
	}
}
開發者ID:robvanmieghem,項目名稱:machine,代碼行數:35,代碼來源:machine.go

示例2: createVirtualboxHost

func createVirtualboxHost(config MachineConfig) drivers.Driver {
	d := virtualbox.NewDriver(constants.MachineName, constants.Minipath)
	d.Boot2DockerURL = config.GetISOFileURI()
	d.Memory = config.Memory
	d.CPU = config.CPUs
	d.DiskSize = int(config.DiskSize)
	return d
}
開發者ID:rawlingsj,項目名稱:gofabric8,代碼行數:8,代碼來源:cluster.go

示例3: NewHost

func NewHost(create bool, force bool) (*Host, error) {
	// Create a Virtualbox host if an existing host doesn't already exist.
	client := libmachine.NewClient(mcndirs.GetBaseDir())

	existing, err := client.Load(DEFAULT_NAME)
	if err != nil {
		switch err.(type) {
		case mcnerror.ErrHostDoesNotExist:
		default:
			log.Fatal(err)
		}
	}

	if existing != nil && create && !force {
		return nil, errors.New("Host already exists.")
	} else if existing != nil && !create {
		log.Debug("Existing host found.")
		return &Host{
			Host:   existing,
			Client: client,
		}, nil
	}

	if create {
		driver := virtualbox.NewDriver(DEFAULT_NAME, mcndirs.GetBaseDir())
		driver.CPU = DEFAULT_CPU
		driver.Memory = DEFAULT_MEMORY
		// Disable the '/Users' mount, we handle that ourselves via
		// `docker-unisync`.
		driver.NoShare = true

		data, err := json.Marshal(driver)
		if err != nil {
			log.Fatal(err)
		}

		pluginDriver, err := client.NewPluginDriver("virtualbox", data)
		if err != nil {
			log.Fatal(err)
		}

		h, err := client.NewHost(pluginDriver)
		if err != nil {
			log.Fatal(err)
		}

		if err := client.Create(h); err != nil {
			log.Fatal(err)
		}

		return &Host{
			Host:   h,
			Client: client,
		}, nil
	}

	return nil, errors.New(fmt.Sprintf("The %v host doesn't exist and create was not specified.", DEFAULT_NAME))
}
開發者ID:Sitback,項目名稱:helm,代碼行數:58,代碼來源:host.go

示例4: StartDriver

// StartDriver starts the desired machine driver if necessary.
func StartDriver() {
	if os.Getenv(localbinary.PluginEnvKey) == localbinary.PluginEnvVal {
		driverName := os.Getenv(localbinary.PluginEnvDriverName)
		switch driverName {
		case "virtualbox":
			plugin.RegisterDriver(virtualbox.NewDriver("", ""))
		case "vmwarefusion":
			plugin.RegisterDriver(vmwarefusion.NewDriver("", ""))
		default:
			glog.Exitf("Unsupported driver: %s\n", driverName)
		}
		return
	}
	localbinary.CurrentBinaryIsDockerMachine = true
}
開發者ID:rawlingsj,項目名稱:gofabric8,代碼行數:16,代碼來源:client.go

示例5: main

func main() {
	log.IsDebug = true
	log.SetOutWriter(os.Stdout)
	log.SetErrWriter(os.Stderr)

	client := libmachine.NewClient("/tmp/automatic")

	hostName := "myfunhost"

	// Set some options on the provider...
	driver := virtualbox.NewDriver(hostName, "/tmp/automatic")
	driver.CPU = 2
	driver.Memory = 2048

	data, err := json.Marshal(driver)
	if err != nil {
		log.Fatal(err)
	}

	pluginDriver, err := client.NewPluginDriver("virtualbox", data)
	if err != nil {
		log.Fatal(err)
	}

	h, err := client.NewHost(pluginDriver)
	if err != nil {
		log.Fatal(err)
	}

	h.HostOptions.EngineOptions.StorageDriver = "overlay"

	if err := client.Create(h); err != nil {
		log.Fatal(err)
	}

	out, err := h.RunSSHCommand("df -h")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Results of your disk space query:\n%s\n", out)

	fmt.Println("Powering down machine now...")
	if err := h.Stop(); err != nil {
		log.Fatal(err)
	}
}
開發者ID:usmanismail,項目名稱:machine,代碼行數:47,代碼來源:vbox_create.go

示例6: main

func main() {
	log.SetDebug(true)

	client := libmachine.NewClient("/tmp/automatic", "/tmp/automatic/certs")
	defer client.Close()

	hostName := "myfunhost"

	// Set some options on the provider...
	driver := virtualbox.NewDriver(hostName, "/tmp/automatic")
	driver.CPU = 2
	driver.Memory = 2048

	data, err := json.Marshal(driver)
	if err != nil {
		log.Error(err)
		return
	}

	h, err := client.NewHost("virtualbox", data)
	if err != nil {
		log.Error(err)
		return
	}

	h.HostOptions.EngineOptions.StorageDriver = "overlay"

	if err := client.Create(h); err != nil {
		log.Error(err)
		return
	}

	out, err := h.RunSSHCommand("df -h")
	if err != nil {
		log.Error(err)
		return
	}

	fmt.Printf("Results of your disk space query:\n%s\n", out)

	fmt.Println("Powering down machine now...")
	if err := h.Stop(); err != nil {
		log.Error(err)
		return
	}
}
開發者ID:binarytemple,項目名稱:machine,代碼行數:46,代碼來源:vbox_create.go

示例7: NewDriver

func NewDriver(driverName, hostName, storePath string) (drivers.Driver, error) {
	var (
		driver drivers.Driver
	)

	switch driverName {
	case "virtualbox":
		driver = virtualbox.NewDriver(hostName, storePath)
	case "digitalocean":
		driver = digitalocean.NewDriver(hostName, storePath)
	case "amazonec2":
		driver = amazonec2.NewDriver(hostName, storePath)
	case "azure":
		driver = azure.NewDriver(hostName, storePath)
	case "exoscale":
		driver = exoscale.NewDriver(hostName, storePath)
	case "generic":
		driver = generic.NewDriver(hostName, storePath)
	case "google":
		driver = google.NewDriver(hostName, storePath)
	case "hyperv":
		driver = hyperv.NewDriver(hostName, storePath)
	case "openstack":
		driver = openstack.NewDriver(hostName, storePath)
	case "rackspace":
		driver = rackspace.NewDriver(hostName, storePath)
	case "softlayer":
		driver = softlayer.NewDriver(hostName, storePath)
	case "vmwarefusion":
		driver = vmwarefusion.NewDriver(hostName, storePath)
	case "vmwarevcloudair":
		driver = vmwarevcloudair.NewDriver(hostName, storePath)
	case "vmwarevsphere":
		driver = vmwarevsphere.NewDriver(hostName, storePath)
	case "none":
		driver = none.NewDriver(hostName, storePath)
	case "aiyara":
		driver = aiyara.NewDriver(hostName, storePath)
	default:
		return nil, fmt.Errorf("Driver %q not recognized", driverName)
	}

	return driver, nil
}
開發者ID:chanwit,項目名稱:gattai,代碼行數:44,代碼來源:driverfactory.go

示例8: createHost

func createHost(api libmachine.API, config MachineConfig) (*host.Host, error) {
	var driver interface{}

	switch config.VMDriver {
	case "virtualbox":
		d := virtualbox.NewDriver(constants.MachineName, constants.Minipath)
		d.Boot2DockerURL = config.MinikubeISO
		d.Memory = config.Memory
		d.CPU = config.CPUs
		driver = d
	case "vmwarefusion":
		driver = createVMwareFusionHost(config)
	case "kvm":
		driver = createKVMHost(config)
	default:
		glog.Exitf("Unsupported driver: %s\n", config.VMDriver)
	}

	data, err := json.Marshal(driver)
	if err != nil {
		return nil, err
	}

	h, err := api.NewHost(config.VMDriver, data)
	if err != nil {
		return nil, fmt.Errorf("Error creating new host: %s", err)
	}

	h.HostOptions.AuthOptions.CertDir = constants.Minipath
	h.HostOptions.AuthOptions.StorePath = constants.Minipath
	h.HostOptions.EngineOptions = &engine.Options{}

	if err := api.Create(h); err != nil {
		// Wait for all the logs to reach the client
		time.Sleep(2 * time.Second)
		return nil, fmt.Errorf("Error creating. %s", err)
	}

	if err := api.Save(h); err != nil {
		return nil, fmt.Errorf("Error attempting to save store: %s", err)
	}
	return h, nil
}
開發者ID:tschottdorf,項目名稱:minikube,代碼行數:43,代碼來源:cluster.go

示例9: main

func main() {
	libmachine.SetDebug(true)

	log.SetOutWriter(os.Stdout)
	log.SetErrWriter(os.Stderr)

	// returns the familiar store at $HOME/.docker/machine
	store := libmachine.GetDefaultStore()

	// over-ride this for now (don't want to muck with my default store)
	store.Path = "/tmp/automatic"

	hostName := "myfunhost"

	// Set some options on the provider...
	driver := virtualbox.NewDriver(hostName, "/tmp/automatic")
	driver.CPU = 2
	driver.Memory = 2048

	h, err := store.NewHost(driver)
	if err != nil {
		log.Fatal(err)
	}

	h.HostOptions.EngineOptions.StorageDriver = "overlay"

	if err := libmachine.Create(store, h); err != nil {
		log.Fatal(err)
	}

	out, err := h.RunSSHCommand("df -h")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Results of your disk space query:\n%s\n", out)

	fmt.Println("Powering down machine now...")
	if err := h.Stop(); err != nil {
		log.Fatal(err)
	}
}
開發者ID:mschygulla,項目名稱:machine,代碼行數:42,代碼來源:vbox_create.go

示例10: RunDriver

func RunDriver(driverName string) error {
	switch driverName {
	case "amazonec2":
		plugin.RegisterDriver(amazonec2.NewDriver("", ""))
	case "azure":
		plugin.RegisterDriver(azure.NewDriver("", ""))
	case "digitalocean":
		plugin.RegisterDriver(digitalocean.NewDriver("", ""))
	case "exoscale":
		plugin.RegisterDriver(exoscale.NewDriver("", ""))
	case "generic":
		plugin.RegisterDriver(generic.NewDriver("", ""))
	case "google":
		plugin.RegisterDriver(google.NewDriver("", ""))
	case "hyperv":
		plugin.RegisterDriver(hyperv.NewDriver("", ""))
	case "none":
		plugin.RegisterDriver(none.NewDriver("", ""))
	case "openstack":
		plugin.RegisterDriver(openstack.NewDriver("", ""))
	case "rackspace":
		plugin.RegisterDriver(rackspace.NewDriver("", ""))
	case "softlayer":
		plugin.RegisterDriver(softlayer.NewDriver("", ""))
	case "virtualbox":
		plugin.RegisterDriver(virtualbox.NewDriver("", ""))
	case "vmwarefusion":
		plugin.RegisterDriver(vmwarefusion.NewDriver("", ""))
	case "vmwarevcloudair":
		plugin.RegisterDriver(vmwarevcloudair.NewDriver("", ""))
	case "vmwarevsphere":
		plugin.RegisterDriver(vmwarevsphere.NewDriver("", ""))
	case "cloudstack":
		plugin.RegisterDriver(cloudstack.NewDriver("", ""))
	default:
		return errors.Errorf("Unsupported driver: %s\n", driverName)
	}
	return nil
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:39,代碼來源:drivers.go

示例11: main

func main() {
	plugin.RegisterDriver(virtualbox.NewDriver("", ""))
}
開發者ID:usmanismail,項目名稱:machine,代碼行數:3,代碼來源:machine-driver-virtualbox.go

示例12: streaming

// Streaming the output of an SSH session in virtualbox.
func streaming() {
	log.SetDebug(true)

	client := libmachine.NewClient("/tmp/automatic", "/tmp/automatic/certs")
	defer client.Close()

	hostName := "myfunhost"

	// Set some options on the provider...
	driver := virtualbox.NewDriver(hostName, "/tmp/automatic")
	data, err := json.Marshal(driver)
	if err != nil {
		log.Error(err)
		return
	}

	h, err := client.NewHost("virtualbox", data)
	if err != nil {
		log.Error(err)
		return
	}

	if err := client.Create(h); err != nil {
		log.Error(err)
		return
	}

	h.HostOptions.EngineOptions.StorageDriver = "overlay"

	sshClient, err := h.CreateSSHClient()
	if err != nil {
		log.Error(err)
		return
	}

	stdout, stderr, err := sshClient.Start("yes | head -n 10000")
	if err != nil {
		log.Error(err)
		return
	}
	defer func() {
		_ = stdout.Close()
		_ = stderr.Close()
	}()

	scanner := bufio.NewScanner(stdout)
	for scanner.Scan() {
		fmt.Println(scanner.Text())
	}
	if err := scanner.Err(); err != nil {
		log.Error(err)
	}
	if err := sshClient.Wait(); err != nil {
		log.Error(err)
	}

	fmt.Println("Powering down machine now...")
	if err := h.Stop(); err != nil {
		log.Error(err)
		return
	}
}
開發者ID:RaulKite,項目名稱:machine,代碼行數:63,代碼來源:main.go


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