本文整理汇总了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)
}
}
示例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
}
示例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))
}
示例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
}
示例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)
}
}
示例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
}
}
示例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
}
示例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
}
示例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)
}
}
示例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
}
示例11: main
func main() {
plugin.RegisterDriver(virtualbox.NewDriver("", ""))
}
示例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
}
}