本文整理匯總了Golang中github.com/docker/machine/utils.NewB2dUtils函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewB2dUtils函數的具體用法?Golang NewB2dUtils怎麽用?Golang NewB2dUtils使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewB2dUtils函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: upgradeIso
func (provisioner *Boot2DockerProvisioner) upgradeIso() error {
log.Info("Stopping machine to do the upgrade...")
if err := provisioner.Driver.Stop(); err != nil {
return err
}
if err := utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
return err
}
machineName := provisioner.GetDriver().GetMachineName()
log.Infof("Upgrading machine %s...", machineName)
isoFilename := ""
switch provisioner.GetDriver().DriverName() {
case "virtualbox":
isoFilename = "boot2docker-virtualbox.iso"
case "vmwarefusion", "vmwarevsphere", "vmwareworkstation":
isoFilename = "boot2docker-vmware.iso"
case "hyper-v":
isoFilename = "boot2docker-hyperv.iso"
default:
return ErrUnknownDriver
}
b2dutils := utils.NewB2dUtils("", "", isoFilename)
// Usually we call this implicitly, but call it here explicitly to get
// the latest boot2docker ISO.
if err := b2dutils.DownloadLatestBoot2Docker(); err != nil {
return err
}
// Copy the latest version of boot2docker ISO to the machine's directory
if err := b2dutils.CopyIsoToMachineDir("", machineName); err != nil {
return err
}
if err := provisioner.Driver.Start(); err != nil {
return err
}
return utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))
}
示例2: upgradeIso
func (provisioner *Boot2DockerProvisioner) upgradeIso() error {
log.Infof("Stopping machine to do the upgrade...")
switch provisioner.Driver.DriverName() {
case "vmwarefusion", "vmwarevsphere":
return errors.New("Upgrade functionality is currently not supported for these providers, as they use a custom ISO.")
}
if err := provisioner.Driver.Stop(); err != nil {
return err
}
if err := utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
return err
}
machineName := provisioner.GetDriver().GetMachineName()
log.Infof("Upgrading machine %s...", machineName)
b2dutils := utils.NewB2dUtils("", "")
// Usually we call this implicitly, but call it here explicitly to get
// the latest boot2docker ISO.
if err := b2dutils.DownloadLatestBoot2Docker(); err != nil {
return err
}
// Copy the latest version of boot2docker ISO to the machine's directory
if err := b2dutils.CopyIsoToMachineDir("", machineName); err != nil {
return err
}
log.Infof("Starting machine back up...")
if err := provisioner.Driver.Start(); err != nil {
return err
}
return utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))
}
示例3: upgradeIso
func (provisioner *RancherProvisioner) upgradeIso() error {
// Largely copied from Boot2Docker provisioner, we should find a way to share this code
log.Info("Stopping machine to do the upgrade...")
if err := provisioner.Driver.Stop(); err != nil {
return err
}
if err := utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
return err
}
machineName := provisioner.GetDriver().GetMachineName()
log.Infof("Upgrading machine %s...", machineName)
b2dutils := utils.NewB2dUtils("", "", isoFilename)
url, err := provisioner.getLatestISOURL()
if err != nil {
return err
}
if err := b2dutils.DownloadISOFromURL(url); err != nil {
return err
}
// Copy the latest version of boot2docker ISO to the machine's directory
if err := b2dutils.CopyIsoToMachineDir("", machineName); err != nil {
return err
}
log.Infof("Starting machine back up...")
if err := provisioner.Driver.Start(); err != nil {
return err
}
return utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))
}
示例4: upgradeIso
func (provisioner *Boot2DockerProvisioner) upgradeIso() error {
log.Info("Stopping machine to do the upgrade...")
if err := provisioner.Driver.Stop(); err != nil {
return err
}
if err := utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
return err
}
machineName := provisioner.GetDriver().GetMachineName()
log.Infof("Upgrading machine %s...", machineName)
b2dutils := utils.NewB2dUtils("", "")
// Usually we call this implicitly, but call it here explicitly to get
// the latest boot2docker ISO.
if err := b2dutils.DownloadLatestBoot2Docker(); err != nil {
return err
}
// Copy the latest version of boot2docker ISO to the machine's directory
if err := b2dutils.CopyIsoToMachineDir("", machineName); err != nil {
return err
}
log.Infof("Starting machine back up...")
if err := provisioner.Driver.Start(); err != nil {
return err
}
return utils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))
}
示例5: Create
func (d *Driver) Create() error {
b2dutils := utils.NewB2dUtils("", "")
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating VM...")
if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return err
}
if _, err := os.Stat(d.vmxPath()); err == nil {
return ErrMachineExist
}
// Generate vmx config file from template
vmxt := template.Must(template.New("vmx").Parse(vmx))
vmxfile, err := os.Create(d.vmxPath())
if err != nil {
return err
}
vmxt.Execute(vmxfile, d)
// Generate vmdk file
diskImg := d.ResolveStorePath(fmt.Sprintf("%s.vmdk", d.MachineName))
if _, err := os.Stat(diskImg); err != nil {
if !os.IsNotExist(err) {
return err
}
if err := vdiskmanager(diskImg, d.DiskSize); err != nil {
return err
}
}
log.Infof("Starting %s...", d.MachineName)
vmrun("start", d.vmxPath(), "nogui")
var ip string
log.Infof("Waiting for VM to come online...")
for i := 1; i <= 60; i++ {
ip, err = d.getIPfromDHCPLease()
if err != nil {
log.Debugf("Not there yet %d/%d, error: %s", i, 60, err)
time.Sleep(2 * time.Second)
continue
}
if ip != "" {
log.Debugf("Got an ip: %s", ip)
break
}
}
if ip == "" {
return fmt.Errorf("Machine didn't return an IP after 120 seconds, aborting")
}
// we got an IP, let's copy ssh keys over
d.IPAddress = ip
// Generate a tar keys bundle
if err := d.generateKeyBundle(); err != nil {
return err
}
// Test if /var/lib/boot2docker exists
vmrun("-gu", B2DUser, "-gp", B2DPass, "directoryExistsInGuest", d.vmxPath(), "/var/lib/boot2docker")
// Copy SSH keys bundle
vmrun("-gu", B2DUser, "-gp", B2DPass, "CopyFileFromHostToGuest", d.vmxPath(), d.ResolveStorePath("userdata.tar"), "/home/docker/userdata.tar")
// Expand tar file.
vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", "sudo /bin/mv /home/docker/userdata.tar /var/lib/boot2docker/userdata.tar && sudo tar xf /var/lib/boot2docker/userdata.tar -C /home/docker/ > /var/log/userdata.log 2>&1 && sudo chown -R docker:staff /home/docker")
// Enable Shared Folders
vmrun("-gu", B2DUser, "-gp", B2DPass, "enableSharedFolders", d.vmxPath())
var shareName, shareDir string // TODO configurable at some point
switch runtime.GOOS {
case "darwin":
shareName = "Users"
shareDir = "/Users"
// TODO "linux" and "windows"
}
if shareDir != "" {
if _, err := os.Stat(shareDir); err != nil && !os.IsNotExist(err) {
return err
} else if !os.IsNotExist(err) {
// add shared folder, create mountpoint and mount it.
vmrun("-gu", B2DUser, "-gp", B2DPass, "addSharedFolder", d.vmxPath(), shareName, shareDir)
vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", "sudo mkdir "+shareDir+" && sudo mount -t vmhgfs .host:/"+shareName+" "+shareDir)
//.........這裏部分代碼省略.........
示例6: Create
func (d *Driver) Create() error {
var (
err error
)
// Check that VBoxManage exists and works
if err = vbm(); err != nil {
return err
}
b2dutils := utils.NewB2dUtils("", "")
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Creating VirtualBox VM...")
// import b2d VM if requested
if d.Boot2DockerImportVM != "" {
name := d.Boot2DockerImportVM
// make sure vm is stopped
_ = vbm("controlvm", name, "poweroff")
diskInfo, err := getVMDiskInfo(name)
if err != nil {
return err
}
if _, err := os.Stat(diskInfo.Path); err != nil {
return err
}
if err := vbm("clonehd", diskInfo.Path, d.diskPath()); err != nil {
return err
}
log.Debugf("Importing VM settings...")
vmInfo, err := getVMInfo(name)
if err != nil {
return err
}
d.CPU = vmInfo.CPUs
d.Memory = vmInfo.Memory
log.Debugf("Importing SSH key...")
keyPath := filepath.Join(utils.GetHomeDir(), ".ssh", "id_boot2docker")
if err := utils.CopyFile(keyPath, d.GetSSHKeyPath()); err != nil {
return err
}
} else {
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Debugf("Creating disk image...")
if err := d.generateDiskImage(d.DiskSize); err != nil {
return err
}
}
if err := vbm("createvm",
"--basefolder", d.ResolveStorePath("."),
"--name", d.MachineName,
"--register"); err != nil {
return err
}
log.Debugf("VM CPUS: %d", d.CPU)
log.Debugf("VM Memory: %d", d.Memory)
cpus := d.CPU
if cpus < 1 {
cpus = int(runtime.NumCPU())
}
if cpus > 32 {
cpus = 32
}
if err := vbm("modifyvm", d.MachineName,
"--firmware", "bios",
"--bioslogofadein", "off",
"--bioslogofadeout", "off",
"--bioslogodisplaytime", "0",
"--biosbootmenu", "disabled",
"--ostype", "Linux26_64",
"--cpus", fmt.Sprintf("%d", cpus),
"--memory", fmt.Sprintf("%d", d.Memory),
"--acpi", "on",
"--ioapic", "on",
"--rtcuseutc", "on",
"--natdnshostresolver1", "off",
"--natdnsproxy1", "off",
"--cpuhotplug", "off",
"--pae", "on",
"--hpet", "on",
"--hwvirtex", "on",
"--nestedpaging", "on",
//.........這裏部分代碼省略.........
示例7: Create
func (d *Driver) Create() error {
b2dutils := utils.NewB2dUtils("", "", isoFilename)
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating VM...")
if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return err
}
if _, err := os.Stat(d.vmxPath()); err == nil {
return ErrMachineExist
}
// Generate vmx config file from template
vmxt := template.Must(template.New("vmx").Parse(vmx))
vmxfile, err := os.Create(d.vmxPath())
if err != nil {
return err
}
vmxt.Execute(vmxfile, d)
// Generate vmdk file
diskImg := d.ResolveStorePath(fmt.Sprintf("%s.vmdk", d.MachineName))
if _, err := os.Stat(diskImg); err != nil {
if !os.IsNotExist(err) {
return err
}
if err := vdiskmanager(diskImg, d.DiskSize); err != nil {
return err
}
}
log.Infof("Starting %s...", d.MachineName)
vmrun("start", d.vmxPath(), "nogui")
var ip string
log.Infof("Waiting for VM to come online...")
for i := 1; i <= 60; i++ {
ip, err = d.GetIP()
if err != nil {
log.Debugf("Not there yet %d/%d, error: %s", i, 60, err)
time.Sleep(2 * time.Second)
continue
}
if ip != "" {
log.Debugf("Got an ip: %s", ip)
break
}
}
if ip == "" {
return fmt.Errorf("Machine didn't return an IP after 120 seconds, aborting")
}
// we got an IP, let's copy ssh keys over
d.IPAddress = ip
// use ssh to set keys
sshClient, err := d.getLocalSSHClient()
if err != nil {
return err
}
// add pub key for user
pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return err
}
if out, err := sshClient.Output(fmt.Sprintf(
"mkdir -p /home/%s/.ssh",
d.GetSSHUsername(),
)); err != nil {
log.Error(out)
return err
}
if out, err := sshClient.Output(fmt.Sprintf(
"printf '%%s' '%s' | tee /home/%s/.ssh/authorized_keys",
string(pubKey),
d.GetSSHUsername(),
)); err != nil {
log.Error(out)
return err
}
// Enable Shared Folders
vmrun("-gu", B2DUser, "-gp", B2DPass, "enableSharedFolders", d.vmxPath())
//.........這裏部分代碼省略.........
示例8: Create
func (d *Driver) Create() error {
var (
isoURL string
err error
)
b2dutils := utils.NewB2dUtils("", "")
imgPath := utils.GetMachineCacheDir()
commonIsoPath := filepath.Join(imgPath, isoFilename)
// just in case boot2docker.iso has been manually deleted
if _, err := os.Stat(imgPath); os.IsNotExist(err) {
if err := os.Mkdir(imgPath, 0700); err != nil {
return err
}
}
if d.Boot2DockerURL != "" {
isoURL = d.Boot2DockerURL
log.Infof("Downloading boot2docker.iso from %s...", isoURL)
if err := b2dutils.DownloadISO(d.storePath, isoFilename, isoURL); err != nil {
return err
}
} else {
// TODO: until vmw tools are merged into b2d master
// we will use the iso from the vmware team.
//// todo: check latest release URL, download if it's new
//// until then always use "latest"
//isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL()
//if err != nil {
// log.Warnf("Unable to check for the latest release: %s", err)
//}
// see https://github.com/boot2docker/boot2docker/pull/747
isoURL := "https://github.com/cloudnativeapps/boot2docker/releases/download/1.5.0-GH747/boot2docker-1.5.0-GH747.iso"
if _, err := os.Stat(commonIsoPath); os.IsNotExist(err) {
log.Infof("Downloading boot2docker.iso to %s...", commonIsoPath)
// just in case boot2docker.iso has been manually deleted
if _, err := os.Stat(imgPath); os.IsNotExist(err) {
if err := os.Mkdir(imgPath, 0700); err != nil {
return err
}
}
if err := b2dutils.DownloadISO(imgPath, isoFilename, isoURL); err != nil {
return err
}
}
isoDest := filepath.Join(d.storePath, isoFilename)
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
return err
}
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating VM...")
if err := os.MkdirAll(d.storePath, 0755); err != nil {
return err
}
if _, err := os.Stat(d.vmxPath()); err == nil {
return ErrMachineExist
}
// Generate vmx config file from template
vmxt := template.Must(template.New("vmx").Parse(vmx))
vmxfile, err := os.Create(d.vmxPath())
if err != nil {
return err
}
vmxt.Execute(vmxfile, d)
// Generate vmdk file
diskImg := filepath.Join(d.storePath, fmt.Sprintf("%s.vmdk", d.MachineName))
if _, err := os.Stat(diskImg); err != nil {
if !os.IsNotExist(err) {
return err
}
if err := vdiskmanager(diskImg, d.DiskSize); err != nil {
return err
}
}
if err := d.Start(); err != nil {
return err
}
var ip string
log.Infof("Waiting for VM to come online...")
for i := 1; i <= 60; i++ {
ip, err = d.getIPfromDHCPLease()
if err != nil {
//.........這裏部分代碼省略.........
示例9: Create
func (d *Driver) Create() error {
b2dutils := utils.NewB2dUtils("", "")
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
// download cloud-init config drive
if d.ConfigDriveURL != "" {
log.Infof("Downloading %s from %s", isoConfigDrive, d.ConfigDriveURL)
if err := b2dutils.DownloadISO(d.ResolveStorePath("."), isoConfigDrive, d.ConfigDriveURL); err != nil {
return err
}
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating VM...")
if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return err
}
if _, err := os.Stat(d.vmxPath()); err == nil {
return ErrMachineExist
}
// Generate vmx config file from template
vmxt := template.Must(template.New("vmx").Parse(vmx))
vmxfile, err := os.Create(d.vmxPath())
if err != nil {
return err
}
vmxt.Execute(vmxfile, d)
// Generate vmdk file
diskImg := d.ResolveStorePath(fmt.Sprintf("%s.vmdk", d.MachineName))
if _, err := os.Stat(diskImg); err != nil {
if !os.IsNotExist(err) {
return err
}
if err := vdiskmanager(diskImg, d.DiskSize); err != nil {
return err
}
}
log.Infof("Starting %s...", d.MachineName)
vmrun("start", d.vmxPath(), "nogui")
var ip string
log.Infof("Waiting for VM to come online...")
for i := 1; i <= 60; i++ {
ip, err = d.getIPfromDHCPLease()
if err != nil {
log.Debugf("Not there yet %d/%d, error: %s", i, 60, err)
time.Sleep(2 * time.Second)
continue
}
if ip != "" {
log.Debugf("Got an ip: %s", ip)
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, 22), time.Duration(2*time.Second))
if err != nil {
log.Debugf("SSH Daemon not responding yet: %s", err)
time.Sleep(2 * time.Second)
continue
}
conn.Close()
break
}
}
if ip == "" {
return fmt.Errorf("Machine didn't return an IP after 120 seconds, aborting")
}
// we got an IP, let's copy ssh keys over
d.IPAddress = ip
// Do not execute the rest of boot2docker specific configuration
// The uplaod of the public ssh key uses a ssh connection,
// this works without installed vmware client tools
if d.ConfigDriveURL != "" {
var keyfh *os.File
var keycontent []byte
log.Infof("Copy public SSH key to %s [%s]", d.MachineName, d.IPAddress)
// create .ssh folder in users home
if err := executeSSHCommand(fmt.Sprintf("mkdir -p /home/%s/.ssh", d.SSHUser), d); err != nil {
return err
}
// read generated public ssh key
if keyfh, err = os.Open(d.publicSSHKeyPath()); err != nil {
return err
//.........這裏部分代碼省略.........
示例10: Create
// the current implementation does the following:
// 1. check whether the docker directory contains the boot2docker ISO
// 2. generate an SSH keypair and bundle it in a tar.
// 3. create a virtual machine with the boot2docker ISO mounted;
// 4. reconfigure the virtual machine network and disk size;
func (d *Driver) Create() error {
if err := d.checkVsphereConfig(); err != nil {
return err
}
b2dutils := utils.NewB2dUtils("", "")
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Generating SSH Keypair...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
vcConn := NewVcConn(d)
log.Infof("Uploading Boot2docker ISO ...")
if err := vcConn.DatastoreMkdir(d.MachineName); err != nil {
return err
}
if _, err := os.Stat(d.ISO); os.IsNotExist(err) {
log.Errorf("Unable to find boot2docker ISO at %s", d.ISO)
return errors.NewIncompleteVsphereConfigError(d.ISO)
}
if err := vcConn.DatastoreUpload(d.ISO, d.MachineName); err != nil {
return err
}
isoPath := fmt.Sprintf("%s/%s", d.MachineName, isoFilename)
if err := vcConn.VMCreate(isoPath); err != nil {
return err
}
log.Infof("Configuring the virtual machine %s... ", d.MachineName)
if err := vcConn.VMDiskCreate(); err != nil {
return err
}
if err := vcConn.VMAttachNetwork(); err != nil {
return err
}
if err := d.Start(); err != nil {
return err
}
// Generate a tar keys bundle
if err := d.generateKeyBundle(); err != nil {
return err
}
// Copy SSH keys bundle
if err := vcConn.GuestUpload(B2DUser, B2DPass, path.Join(d.storePath, "userdata.tar"), "/home/docker/userdata.tar"); err != nil {
return err
}
// Expand tar file.
if err := vcConn.GuestStart(B2DUser, B2DPass, "/usr/bin/sudo", "/bin/mv /home/docker/userdata.tar /var/lib/boot2docker/userdata.tar && /usr/bin/sudo tar xf /var/lib/boot2docker/userdata.tar -C /home/docker/ > /var/log/userdata.log 2>&1 && /usr/bin/sudo chown -R docker:staff /home/docker"); err != nil {
return err
}
return nil
}
示例11: Create
func (d *Driver) Create() error {
var (
err error
isoURL string
)
// Check that VBoxManage exists and works
if err = vbm(); err != nil {
return err
}
d.SSHPort, err = getAvailableTCPPort()
if err != nil {
return err
}
b2dutils := utils.NewB2dUtils("", "")
imgPath := utils.GetMachineCacheDir()
isoFilename := "boot2docker.iso"
commonIsoPath := filepath.Join(imgPath, "boot2docker.iso")
// just in case boot2docker.iso has been manually deleted
if _, err := os.Stat(imgPath); os.IsNotExist(err) {
if err := os.Mkdir(imgPath, 0700); err != nil {
return err
}
}
if d.Boot2DockerURL != "" {
isoURL = d.Boot2DockerURL
log.Infof("Downloading %s from %s...", isoFilename, isoURL)
if err := b2dutils.DownloadISO(commonIsoPath, isoFilename, isoURL); err != nil {
return err
}
} else {
// todo: check latest release URL, download if it's new
// until then always use "latest"
isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL()
if err != nil {
log.Warnf("Unable to check for the latest release: %s", err)
}
if _, err := os.Stat(commonIsoPath); os.IsNotExist(err) {
log.Infof("Downloading %s to %s...", isoFilename, commonIsoPath)
if err := b2dutils.DownloadISO(imgPath, isoFilename, isoURL); err != nil {
return err
}
}
isoDest := filepath.Join(d.storePath, isoFilename)
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
return err
}
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating VirtualBox VM...")
if err := d.generateDiskImage(d.DiskSize); err != nil {
return err
}
if err := vbm("createvm",
"--basefolder", d.storePath,
"--name", d.MachineName,
"--register"); err != nil {
return err
}
cpus := uint(runtime.NumCPU())
if cpus > 32 {
cpus = 32
}
if err := vbm("modifyvm", d.MachineName,
"--firmware", "bios",
"--bioslogofadein", "off",
"--bioslogofadeout", "off",
"--natdnshostresolver1", "on",
"--bioslogodisplaytime", "0",
"--biosbootmenu", "disabled",
"--ostype", "Linux26_64",
"--cpus", fmt.Sprintf("%d", cpus),
"--memory", fmt.Sprintf("%d", d.Memory),
"--acpi", "on",
"--ioapic", "on",
"--rtcuseutc", "on",
"--cpuhotplug", "off",
"--pae", "on",
"--synthcpu", "off",
"--hpet", "on",
//.........這裏部分代碼省略.........
示例12: Create
func (d *Driver) Create() error {
err := hypervAvailable()
if err != nil {
return err
}
d.setMachineNameIfNotSet()
var isoURL string
b2dutils := utils.NewB2dUtils("", "")
if d.boot2DockerLoc == "" {
if d.boot2DockerURL != "" {
isoURL = d.boot2DockerURL
log.Infof("Downloading boot2docker.iso from %s...", isoURL)
if err := b2dutils.DownloadISO(d.ResolveStorePath("."), "boot2docker.iso", isoURL); err != nil {
return err
}
} else {
// todo: check latest release URL, download if it's new
// until then always use "latest"
isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL()
if err != nil {
log.Warnf("Unable to check for the latest release: %s", err)
}
// todo: use real constant for .docker
rootPath := filepath.Join(utils.GetDockerDir())
imgPath := filepath.Join(rootPath, "images")
commonIsoPath := filepath.Join(imgPath, "boot2docker.iso")
if _, err := os.Stat(commonIsoPath); os.IsNotExist(err) {
log.Infof("Downloading boot2docker.iso to %s...", commonIsoPath)
// just in case boot2docker.iso has been manually deleted
if _, err := os.Stat(imgPath); os.IsNotExist(err) {
if err := os.Mkdir(imgPath, 0700); err != nil {
return err
}
}
if err := b2dutils.DownloadISO(imgPath, "boot2docker.iso", isoURL); err != nil {
return err
}
}
isoDest := d.ResolveStorePath("boot2docker.iso")
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
return err
}
}
} else {
if err := utils.CopyFile(d.boot2DockerLoc, d.ResolveStorePath("boot2docker.iso")); err != nil {
return err
}
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating VM...")
virtualSwitch, err := d.chooseVirtualSwitch()
if err != nil {
return err
}
err = d.generateDiskImage()
if err != nil {
return err
}
command := []string{
"New-VM",
"-Name", d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.ResolveStorePath(".")),
"-MemoryStartupBytes", fmt.Sprintf("%dMB", d.memSize)}
_, err = execute(command)
if err != nil {
return err
}
command = []string{
"Set-VMDvdDrive",
"-VMName", d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.ResolveStorePath("boot2docker.iso"))}
_, err = execute(command)
if err != nil {
return err
}
command = []string{
"Add-VMHardDiskDrive",
"-VMName", d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.diskImage)}
//.........這裏部分代碼省略.........
示例13: Create
func (d *Driver) Create() error {
err := hypervAvailable()
if err != nil {
return err
}
d.setMachineNameIfNotSet()
b2dutils := utils.NewB2dUtils("", "", isoFilename)
if err := b2dutils.CopyIsoToMachineDir(d.boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating VM...")
virtualSwitch, err := d.chooseVirtualSwitch()
if err != nil {
return err
}
if err := d.generateDiskImage(); err != nil {
return err
}
command := []string{
"New-VM",
"-Name", d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.ResolveStorePath(".")),
"-MemoryStartupBytes", fmt.Sprintf("%dMB", d.memSize)}
_, err = execute(command)
if err != nil {
return err
}
command = []string{
"Set-VMDvdDrive",
"-VMName", d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.ResolveStorePath(isoFilename))}
if _, err = execute(command); err != nil {
return err
}
command = []string{
"Add-VMHardDiskDrive",
"-VMName", d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.diskImage)}
if _, err = execute(command); err != nil {
return err
}
command = []string{
"Connect-VMNetworkAdapter",
"-VMName", d.MachineName,
"-SwitchName", fmt.Sprintf("'%s'", virtualSwitch)}
if _, err = execute(command); err != nil {
return err
}
log.Infof("Starting VM...")
if err := d.Start(); err != nil {
return err
}
// use ssh to set keys
sshClient, err := d.getLocalSSHClient()
if err != nil {
return err
}
// add pub key for user
pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return err
}
if out, err := sshClient.Output(fmt.Sprintf(
"mkdir -p /home/%s/.ssh",
d.GetSSHUsername(),
)); err != nil {
log.Error(out)
return err
}
if out, err := sshClient.Output(fmt.Sprintf(
"printf '%%s' '%s' | tee /home/%s/.ssh/authorized_keys",
string(pubKey),
d.GetSSHUsername(),
)); err != nil {
log.Error(out)
return err
}
return nil
}
示例14: Create
// the current implementation does the following:
// 1. check whether the docker directory contains the boot2docker ISO
// 2. generate an SSH keypair and bundle it in a tar.
// 3. create a virtual machine with the boot2docker ISO mounted;
// 4. reconfigure the virtual machine network and disk size;
func (d *Driver) Create() error {
if err := d.checkVsphereConfig(); err != nil {
return err
}
var (
isoURL string
)
b2dutils := utils.NewB2dUtils("", "")
imgPath := utils.GetMachineCacheDir()
commonIsoPath := filepath.Join(imgPath, isoFilename)
// just in case boot2docker.iso has been manually deleted
if _, err := os.Stat(imgPath); os.IsNotExist(err) {
if err := os.Mkdir(imgPath, 0700); err != nil {
return err
}
}
if d.Boot2DockerURL != "" {
isoURL = d.Boot2DockerURL
log.Infof("Downloading boot2docker.iso from %s...", isoURL)
if err := b2dutils.DownloadISO(commonIsoPath, isoFilename, isoURL); err != nil {
return err
}
} else {
// TODO: until vmw tools are merged into b2d master
// we will use the iso from the vmware team
//// todo: check latest release URL, download if it's new
//// until then always use "latest"
//isoURL, err = b2dutils.GetLatestBoot2DockerReleaseURL()
//if err != nil {
// log.Warnf("Unable to check for the latest release: %s", err)
//}
// see https://github.com/boot2docker/boot2docker/pull/747
isoURL := "https://github.com/cloudnativeapps/boot2docker/releases/download/1.5.0-GH747/boot2docker-1.5.0-GH747.iso"
if _, err := os.Stat(commonIsoPath); os.IsNotExist(err) {
log.Infof("Downloading boot2docker.iso to %s...", commonIsoPath)
// just in case boot2docker.iso has been manually deleted
if _, err := os.Stat(imgPath); os.IsNotExist(err) {
if err := os.Mkdir(imgPath, 0700); err != nil {
return err
}
}
if err := b2dutils.DownloadISO(imgPath, isoFilename, isoURL); err != nil {
return err
}
}
isoDest := filepath.Join(d.storePath, isoFilename)
if err := utils.CopyFile(commonIsoPath, isoDest); err != nil {
return err
}
}
log.Infof("Generating SSH Keypair...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
vcConn := NewVcConn(d)
log.Infof("Uploading Boot2docker ISO ...")
if err := vcConn.DatastoreMkdir(DATASTORE_DIR); err != nil {
return err
}
if _, err := os.Stat(d.ISO); os.IsNotExist(err) {
log.Errorf("Unable to find boot2docker ISO at %s", d.ISO)
return errors.NewIncompleteVsphereConfigError(d.ISO)
}
if err := vcConn.DatastoreUpload(d.ISO); err != nil {
return err
}
isoPath := fmt.Sprintf("%s/%s", DATASTORE_DIR, isoFilename)
if err := vcConn.VmCreate(isoPath); err != nil {
return err
}
log.Infof("Configuring the virtual machine %s... ", d.MachineName)
if err := vcConn.VmDiskCreate(); err != nil {
return err
//.........這裏部分代碼省略.........
示例15: Create
func (d *Driver) Create() error {
var (
err error
)
// Check that VBoxManage exists and works
if err = vbm(); err != nil {
return err
}
b2dutils := utils.NewB2dUtils("", "", isoFilename)
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Creating VirtualBox VM...")
// import b2d VM if requested
if d.Boot2DockerImportVM != "" {
name := d.Boot2DockerImportVM
// make sure vm is stopped
_ = vbm("controlvm", name, "poweroff")
diskInfo, err := getVMDiskInfo(name)
if err != nil {
return err
}
if _, err := os.Stat(diskInfo.Path); err != nil {
return err
}
if err := vbm("clonehd", diskInfo.Path, d.diskPath()); err != nil {
return err
}
log.Debugf("Importing VM settings...")
vmInfo, err := getVMInfo(name)
if err != nil {
return err
}
d.CPU = vmInfo.CPUs
d.Memory = vmInfo.Memory
log.Debugf("Importing SSH key...")
keyPath := filepath.Join(utils.GetHomeDir(), ".ssh", "id_boot2docker")
if err := utils.CopyFile(keyPath, d.GetSSHKeyPath()); err != nil {
return err
}
} else {
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Debugf("Creating disk image...")
if err := vbm("createhd", "--size", fmt.Sprintf("%d", d.DiskSize), "--format", "VMDK", "--filename", d.diskPath()); err != nil {
return err
}
}
if err := vbm("createvm",
"--basefolder", d.ResolveStorePath("."),
"--name", d.MachineName,
"--register"); err != nil {
return err
}
log.Debugf("VM CPUS: %d", d.CPU)
log.Debugf("VM Memory: %d", d.Memory)
cpus := d.CPU
if cpus < 1 {
cpus = int(runtime.NumCPU())
}
if cpus > 32 {
cpus = 32
}
if err := vbm("modifyvm", d.MachineName,
"--firmware", "bios",
"--bioslogofadein", "off",
"--bioslogofadeout", "off",
"--bioslogodisplaytime", "0",
"--biosbootmenu", "disabled",
"--ostype", "Linux26_64",
"--cpus", fmt.Sprintf("%d", cpus),
"--memory", fmt.Sprintf("%d", d.Memory),
"--acpi", "on",
"--ioapic", "on",
"--rtcuseutc", "on",
"--natdnshostresolver1", "off",
"--natdnsproxy1", "off",
"--cpuhotplug", "off",
"--pae", "on",
"--hpet", "on",
"--hwvirtex", "on",
//.........這裏部分代碼省略.........