本文整理汇总了Golang中github.com/docker/machine/libmachine/mcnutils.NewB2dUtils函数的典型用法代码示例。如果您正苦于以下问题:Golang NewB2dUtils函数的具体用法?Golang NewB2dUtils怎么用?Golang NewB2dUtils使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewB2dUtils函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CopyIsoToMachineDir
func (d *Driver) CopyIsoToMachineDir(isoURL, machineName string) error {
b2d := b2d.NewB2dUtils(d.StorePath)
mcnutils := mcnutils.NewB2dUtils(d.StorePath)
if err := d.UpdateISOCache(isoURL); err != nil {
return err
}
isoPath := filepath.Join(b2d.ImgCachePath, isoFilename)
if isoStat, err := os.Stat(isoPath); err == nil {
if int(isoStat.Sys().(*syscall.Stat_t).Uid) == 0 {
log.Debugf("Fix %s file permission...", isoStat.Name())
os.Chown(isoPath, syscall.Getuid(), syscall.Getegid())
}
}
// TODO: This is a bit off-color.
machineDir := filepath.Join(d.StorePath, "machines", machineName)
machineIsoPath := filepath.Join(machineDir, isoFilename)
// By default just copy the existing "cached" iso to the machine's directory...
defaultISO := filepath.Join(b2d.ImgCachePath, defaultISOFilename)
if isoURL == "" {
log.Infof("Copying %s to %s...", defaultISO, machineIsoPath)
return CopyFile(defaultISO, machineIsoPath)
}
// if ISO is specified, check if it matches a github releases url or fallback to a direct download
downloadURL, err := b2d.GetReleaseURL(isoURL)
if err != nil {
return err
}
return mcnutils.DownloadISO(machineDir, b2d.Filename(), downloadURL)
}
开发者ID:johanneswuerbach,项目名称:docker-machine-xhyve,代码行数:35,代码来源:xhyve.go
示例2: PreCreateCheck
// PreCreateCheck checks that VBoxManage exists and works
func (d *Driver) PreCreateCheck() error {
// Check that VBoxManage exists and works
version, err := d.vbmOut("--version")
if err != nil {
return err
}
// Check that VBoxManage is of a supported version
if err = checkVBoxManageVersion(strings.TrimSpace(version)); err != nil {
return err
}
if !d.NoVTXCheck && d.IsVTXDisabled() {
return ErrMustEnableVTX
}
// Downloading boot2docker to cache should be done here to make sure
// that a download failure will not leave a machine half created.
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err := b2dutils.UpdateISOCache(d.Boot2DockerURL); err != nil {
return err
}
// Check that Host-only interfaces are ok
if _, err = listHostOnlyNetworks(d.VBoxManager); err != nil {
return err
}
return nil
}
开发者ID:cvstebut,项目名称:machine,代码行数:31,代码来源:virtualbox.go
示例3: PreCreateCheck
// PreCreateCheck checks that the machine creation process can be started safely.
func (d *Driver) PreCreateCheck() error {
// Check that powershell was found
if powershell == "" {
return ErrPowerShellNotFound
}
// Check that hyperv is installed
if err := hypervAvailable(); err != nil {
return err
}
// Check that the user is an Administrator
isAdmin, err := isAdministrator()
if err != nil {
return err
}
if !isAdmin {
return ErrNotAdministrator
}
// Check that there is a virtual switch already configured
if _, err := d.chooseVirtualSwitch(); err != nil {
return err
}
// Downloading boot2docker to cache should be done here to make sure
// that a download failure will not leave a machine half created.
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err := b2dutils.UpdateISOCache(d.Boot2DockerURL); err != nil {
return err
}
return nil
}
开发者ID:sergey-stratoscale,项目名称:machine,代码行数:35,代码来源:hyperv.go
示例4: Create
func (d *Driver) Create() error {
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Creating VM...")
if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return err
}
log.Infof("Extracting vmlinuz64 and initrd.img from %s...", isoFilename)
if err := d.extractKernelImages(); err != nil {
return err
}
log.Infof("Generating %dMB disk image...", d.DiskSize)
if err := d.generateDiskImage(d.DiskSize); err != nil {
return err
}
// Fix file permission root to current user for vmnet.framework
log.Infof("Fix file permission...")
os.Chown(d.ResolveStorePath("."), syscall.Getuid(), syscall.Getegid())
files, _ := ioutil.ReadDir(d.ResolveStorePath("."))
for _, f := range files {
log.Debugf(d.ResolveStorePath(f.Name()))
os.Chown(d.ResolveStorePath(f.Name()), syscall.Getuid(), syscall.Getegid())
}
log.Infof("Generate UUID...")
d.UUID = uuidgen()
log.Debugf("Generated UUID: %s", d.UUID)
log.Infof("Convert UUID to MAC address...")
rawUUID, err := d.getMACAdress()
if err != nil {
return err
}
d.MacAddr = trimMacAddress(rawUUID)
log.Debugf("Converted MAC address: %s", d.MacAddr)
log.Infof("Starting %s...", d.MachineName)
if err := d.Start(); err != nil {
return err
}
// Setup NFS sharing
if d.NFSShare {
log.Infof("NFS share folder must be root. Please insert root password.")
err = d.setupNFSShare()
if err != nil {
log.Errorf("NFS setup failed: %s", err.Error())
}
}
return nil
}
开发者ID:fayep,项目名称:docker-machine-driver-xhyve,代码行数:58,代码来源:xhyve.go
示例5: Create
func (d *Driver) Create() error {
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
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
}
if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return err
}
// Libvirt typically runs as a deprivileged service account and
// needs the execute bit set for directories that contain disks
for dir := d.ResolveStorePath("."); dir != "/"; dir = filepath.Dir(dir) {
log.Debugf("Verifying executable bit set on %s", dir)
info, err := os.Stat(dir)
if err != nil {
return err
}
mode := info.Mode()
if mode&0001 != 1 {
log.Debugf("Setting executable bit set on %s", dir)
mode |= 0001
os.Chmod(dir, mode)
}
}
log.Debugf("Creating VM data disk...")
if err := d.generateDiskImage(d.DiskSize); err != nil {
return err
}
log.Debugf("Defining VM...")
tmpl, err := template.New("domain").Parse(domainXMLTemplate)
if err != nil {
return err
}
var xml bytes.Buffer
err = tmpl.Execute(&xml, d)
if err != nil {
return err
}
vm, err := d.conn.DomainDefineXML(xml.String())
if err != nil {
log.Warnf("Failed to create the VM: %s", err)
return err
}
d.VM = &vm
d.vmLoaded = true
return d.Start()
}
开发者ID:b0d0nne11,项目名称:docker-machine-kvm,代码行数:57,代码来源:kvm.go
示例6: PreCreateCheck
// PreCreateCheck allows for pre-create operations to make sure a driver is ready for creation
func (d *Driver) PreCreateCheck() error {
// Check platform type
if runtime.GOOS != "darwin" {
return fmt.Errorf("Driver \"parallels\" works only on OS X!")
}
// Check Parallels Desktop version
ver, err := getParallelsVersion()
if err != nil {
return err
}
if ver < 10 {
return fmt.Errorf("Driver \"parallels\" supports only Parallels Desktop 10 and higher. You use: Parallels Desktop %d.", ver)
}
if ver < 11 {
log.Debugf("Found Parallels Desktop version: %d", ver)
log.Infof("Driver \"parallels\" integration with Parallels Desktop 10 is maintained by open source community.")
log.Infof("For Parallels supported configuration you should use it with Parallels Desktop 11 or later (Pro or Business edition).")
return nil
}
// Check Parallels Desktop edition
edit, err := getParallelsEdition()
if err != nil {
return err
}
log.Debugf("Found Parallels Desktop version: %d, edition: %s", ver, edit)
switch edit {
case "pro", "business":
break
default:
return fmt.Errorf("Docker Machine can be used only with Parallels Desktop Pro or Business edition. You use: %s edition", edit)
}
// Check whether the host is connected to Shared network
ok, err := isSharedConnected()
if err != nil {
return err
}
if !ok {
return errSharedNotConnected
}
// Downloading boot2docker to cache should be done here to make sure
// that a download failure will not leave a machine half created.
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err := b2dutils.UpdateISOCache(d.Boot2DockerURL); err != nil {
return err
}
return nil
}
开发者ID:Parallels,项目名称:docker-machine-parallels,代码行数:57,代码来源:parallels_darwin.go
示例7: PreCreateCheck
// PreCreateCheck checks that the machine creation process can be started safely.
func (d *Driver) PreCreateCheck() error {
// Downloading boot2docker to cache should be done here to make sure
// that a download failure will not leave a machine half created.
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err := b2dutils.UpdateISOCache(d.Boot2DockerURL); err != nil {
return err
}
return nil
}
开发者ID:robvanmieghem,项目名称:machine,代码行数:11,代码来源:fusion_darwin.go
示例8: Create
func (d *Driver) Create() error {
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
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
}
log.Infof("Using switch %q", virtualSwitch)
diskImage, err := d.generateDiskImage()
if err != nil {
return err
}
if err := cmd("New-VM",
d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.ResolveStorePath(".")),
"-SwitchName", quote(virtualSwitch),
"-MemoryStartupBytes", toMb(d.MemSize)); err != nil {
return err
}
if d.CPU > 1 {
if err := cmd("Set-VMProcessor",
d.MachineName,
"-Count", fmt.Sprintf("%d", d.CPU)); err != nil {
return err
}
}
if err := cmd("Set-VMDvdDrive",
"-VMName", d.MachineName,
"-Path", quote(d.ResolveStorePath("boot2docker.iso"))); err != nil {
return err
}
if err := cmd("Add-VMHardDiskDrive",
"-VMName", d.MachineName,
"-Path", quote(diskImage)); err != nil {
return err
}
log.Infof("Starting VM...")
return d.Start()
}
开发者ID:sergey-stratoscale,项目名称:machine,代码行数:55,代码来源:hyperv.go
示例9: upgradeIso
func (provisioner *Boot2DockerProvisioner) upgradeIso() error {
// TODO: Ideally, we should not read from mcndirs directory at all.
// The driver should be able to communicate how and where to place the
// relevant files.
b2dutils := mcnutils.NewB2dUtils(mcndirs.GetBaseDir())
// Check if the driver has specified a custom b2d url
jsonDriver, err := json.Marshal(provisioner.GetDriver())
if err != nil {
return err
}
var d struct {
Boot2DockerURL string
}
json.Unmarshal(jsonDriver, &d)
log.Info("Downloading latest boot2docker iso...")
// Usually we call this implicitly, but call it here explicitly to get
// the latest default boot2docker ISO.
if d.Boot2DockerURL == "" {
if err := b2dutils.DownloadLatestBoot2Docker(d.Boot2DockerURL); err != nil {
return err
}
}
log.Info("Stopping machine to do the upgrade...")
if err := provisioner.Driver.Stop(); err != nil {
return err
}
if err := mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
return err
}
machineName := provisioner.GetDriver().GetMachineName()
log.Infof("Upgrading machine %q...", machineName)
// Either download the latest version of the b2d url that was explicitly
// specified when creating the VM or copy the (updated) default ISO
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, machineName); err != nil {
return err
}
log.Infof("Starting machine back up...")
if err := provisioner.Driver.Start(); err != nil {
return err
}
return mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))
}
开发者ID:mschygulla,项目名称:machine,代码行数:54,代码来源:boot2docker.go
示例10: 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 := mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
return err
}
machineName := provisioner.GetDriver().GetMachineName()
log.Infof("Upgrading machine %s...", machineName)
// TODO: Ideally, we should not read from mcndirs directory at all.
// The driver should be able to communicate how and where to place the
// relevant files.
b2dutils := mcnutils.NewB2dUtils(mcndirs.GetBaseDir())
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 mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))
}
开发者ID:ChristopherBiscardi,项目名称:machine,代码行数:43,代码来源:rancheros.go
示例11: UpdateISOCache
func (d *Driver) UpdateISOCache(isoURL string) error {
b2d := b2d.NewB2dUtils(d.StorePath)
mcnutils := mcnutils.NewB2dUtils(d.StorePath)
// recreate the cache dir if it has been manually deleted
if _, err := os.Stat(b2d.ImgCachePath); os.IsNotExist(err) {
log.Infof("Image cache directory does not exist, creating it at %s...", b2d.ImgCachePath)
if err := os.Mkdir(b2d.ImgCachePath, 0700); err != nil {
return err
}
}
// Check owner of storage cache directory
cacheStat, _ := os.Stat(b2d.ImgCachePath)
if int(cacheStat.Sys().(*syscall.Stat_t).Uid) == 0 {
log.Debugf("Fix %s directory permission...", cacheStat.Name())
os.Chown(b2d.ImgCachePath, syscall.Getuid(), syscall.Getegid())
}
if isoURL != "" {
// Non-default B2D are not cached
return nil
}
exists := b2d.Exists()
if !exists {
log.Info("No default Boot2Docker ISO found locally, downloading the latest release...")
return mcnutils.DownloadLatestBoot2Docker("")
}
latest := b2d.IsLatest()
if !latest {
log.Info("Default Boot2Docker ISO is out-of-date, downloading the latest release...")
return mcnutils.DownloadLatestBoot2Docker("")
}
return nil
}
开发者ID:johanneswuerbach,项目名称:docker-machine-xhyve,代码行数:39,代码来源:xhyve.go
示例12: 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 := mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
return err
}
machineName := provisioner.GetDriver().GetMachineName()
log.Infof("Upgrading machine %s...", machineName)
// TODO: Ideally, we should not read from mcndirs directory at all.
// The driver should be able to communicate how and where to place the
// relevant files.
b2dutils := mcnutils.NewB2dUtils("", "", mcndirs.GetBaseDir())
// 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 mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))
}
开发者ID:nlamirault,项目名称:docker-machine-scaleway,代码行数:39,代码来源:boot2docker.go
示例13: Create
func (d *Driver) Create() error {
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
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
_ = d.vbm("controlvm", name, "poweroff")
diskInfo, err := getVMDiskInfo(name, d.VBoxManager)
if err != nil {
return err
}
if _, err := os.Stat(diskInfo.Path); err != nil {
return err
}
if err := d.vbm("clonehd", diskInfo.Path, d.diskPath()); err != nil {
return err
}
log.Debugf("Importing VM settings...")
vmInfo, err := getVMInfo(name, d.VBoxManager)
if err != nil {
return err
}
d.CPU = vmInfo.CPUs
d.Memory = vmInfo.Memory
log.Debugf("Importing SSH key...")
keyPath := filepath.Join(mcnutils.GetHomeDir(), ".ssh", "id_boot2docker")
if err := mcnutils.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 := d.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 := d.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",
"--largepages", "on",
"--vtxvpid", "on",
"--accelerate3d", "off",
"--boot1", "dvd"); err != nil {
return err
}
if err := d.vbm("modifyvm", d.MachineName,
"--nic1", "nat",
//.........这里部分代码省略.........
开发者ID:usmanismail,项目名称:machine,代码行数:101,代码来源:virtualbox.go
示例14: Create
// Create has the following implementation:
// 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 {
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
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
}
// Create context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := d.vsphereLogin(ctx)
if err != nil {
return err
}
defer c.Logout(ctx)
// Create a new finder
f := find.NewFinder(c.Client, true)
dc, err := f.DatacenterOrDefault(ctx, d.Datacenter)
if err != nil {
return err
}
f.SetDatacenter(dc)
dss, err := f.DatastoreOrDefault(ctx, d.Datastore)
if err != nil {
return err
}
net, err := f.NetworkOrDefault(ctx, d.Network)
if err != nil {
return err
}
hs, err := f.HostSystemOrDefault(ctx, d.HostSystem)
if err != nil {
return err
}
var rp *object.ResourcePool
if d.Pool != "" {
// Find specified Resource Pool
rp, err = f.ResourcePool(ctx, d.Pool)
if err != nil {
return err
}
} else {
// Pick default Resource Pool for Host System
rp, err = hs.ResourcePool(ctx)
if err != nil {
return err
}
}
spec := types.VirtualMachineConfigSpec{
Name: d.MachineName,
GuestId: "otherLinux64Guest",
Files: &types.VirtualMachineFileInfo{VmPathName: fmt.Sprintf("[%s]", dss.Name())},
NumCPUs: int32(d.CPU),
MemoryMB: int64(d.Memory),
}
scsi, err := object.SCSIControllerTypes().CreateSCSIController("pvscsi")
if err != nil {
return err
}
spec.DeviceChange = append(spec.DeviceChange, &types.VirtualDeviceConfigSpec{
Operation: types.VirtualDeviceConfigSpecOperationAdd,
Device: scsi,
})
log.Infof("Creating VM...")
folders, err := dc.Folders(ctx)
task, err := folders.VmFolder.CreateVM(ctx, spec, rp, hs)
if err != nil {
return err
}
info, err := task.WaitForResult(ctx, nil)
if err != nil {
return err
}
log.Infof("Uploading Boot2docker ISO ...")
dsurl, err := dss.URL(ctx, dc, fmt.Sprintf("%s/%s", d.MachineName, isoFilename))
if err != nil {
return err
//.........这里部分代码省略.........
开发者ID:HewlettPackard,项目名称:oneview-golang,代码行数:101,代码来源:vsphere.go
示例15: Create
// Create a host using the driver's config
func (d *Driver) Create() error {
var (
err error
)
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err = b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Creating SSH key...")
sshKeyPath := d.GetSSHKeyPath()
log.Debugf("SSH key: %s", sshKeyPath)
if err = ssh.GenerateSSHKey(sshKeyPath); err != nil {
return err
}
log.Infof("Creating Parallels Desktop VM...")
ver, err := getParallelsVersion()
if err != nil {
return err
}
distribution := "boot2docker"
if ver < 11 {
distribution = "linux-2.6"
}
absStorePath, _ := filepath.Abs(d.ResolveStorePath("."))
if err = prlctl("create", d.MachineName,
"--distribution", distribution,
"--dst", absStorePath,
"--no-hdd"); err != nil {
return err
}
cpus := d.CPU
if cpus < 1 {
cpus = int(runtime.NumCPU())
}
if cpus > 32 {
cpus = 32
}
if err = prlctl("set", d.MachineName,
"--select-boot-device", "off",
"--cpus", fmt.Sprintf("%d", cpus),
"--memsize", fmt.Sprintf("%d", d.Memory),
"--cpu-hotplug", "off",
"--on-window-close", "keep-running",
"--longer-battery-life", "on",
"--3d-accelerate", "off",
"--device-bootorder", "cdrom0"); err != nil {
return err
}
absISOPath, _ := filepath.Abs(d.ResolveStorePath(isoFilename))
if err = prlctl("set", d.MachineName,
"--device-set", "cdrom0",
"--iface", "sata",
"--position", "0",
"--image", absISOPath,
"--connect"); err != nil {
return err
}
// Create a small plain disk. It will be converted and expanded later
if err = prlctl("set", d.MachineName,
"--device-add", "hdd",
"--iface", "sata",
"--position", "1",
"--image", d.diskPath(),
"--type", "plain",
"--size", fmt.Sprintf("%d", minDiskSize)); err != nil {
return err
}
if err = d.generateDiskImage(d.DiskSize); err != nil {
return err
}
if ver >= 11 {
// Enable headless mode
if err = prlctl("set", d.MachineName,
"--startup-view", "headless"); err != nil {
return err
}
// Don't share any additional folders
if err = prlctl("set", d.MachineName,
"--shf-host-defined", "off"); err != nil {
return err
}
// Enable time sync, don't touch timezone (this part is buggy)
if err = prlctl("set", d.MachineName, "--time-sync", "on"); err != nil {
return err
}
//.........这里部分代码省略.........
开发者ID:Parallels,项目名称:docker-machine-parallels,代码行数:101,代码来源:parallels_darwin.go
示例16: UpdateISOCache
func (u *b2dUtilsUpdater) UpdateISOCache(storePath, isoURL string) error {
return mcnutils.NewB2dUtils(storePath).UpdateISOCache(isoURL)
}
开发者ID:RaulKite,项目名称:machine,代码行数:3,代码来源:misc.go
示例17: CopyIsoToMachineDir
func (u *b2dUtilsUpdater) CopyIsoToMachineDir(storePath, machineName, isoURL string) error {
return mcnutils.NewB2dUtils(storePath).CopyIsoToMachineDir(isoURL, machineName)
}
开发者ID:RaulKite,项目名称:machine,代码行数:3,代码来源:misc.go
示例18: Create
func (d *Driver) Create() error {
var (
err error
b2d_id uint
b2d_image *goca.Image
)
// Import Boot2Docker
b2d_name := fmt.Sprintf("b2d-%s", d.MachineName)
b2d_image, err = goca.NewImageFromName(b2d_name)
if err != nil {
b2dutils := mcnutils.NewB2dUtils("", "", d.StorePath)
if err = b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
b2d_template := goca.NewTemplateBuilder()
b2d_template.AddValue("name", b2d_name)
b2d_template.AddValue("path", d.ResolveStorePath("boot2docker.iso"))
b2d_id, err = goca.CreateImage(b2d_template.String(), 1) // TODO: ds_id != 1
if err != nil {
return err
}
b2d_image = goca.NewImage(b2d_id)
b2d_state := ""
for b2d_state != "READY" {
err = b2d_image.Info()
if err != nil {
return err
}
b2d_state, err = b2d_image.StateString()
if err != nil {
return err
}
switch b2d_state {
case "INIT", "LOCKED":
time.Sleep(1 * time.Second)
case "READY":
default:
log.Errorf("Unexpected image state %s", b2d_state)
return errors.New("Unexpected image state")
}
}
log.Infof("Boot2Docker image registered...")
} else {
b2d_id = b2d_image.Id
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return err
}
// Create template
template := goca.NewTemplateBuilder()
template.AddValue("NAME", d.MachineName)
template.AddValue("CPU", d.CPU)
template.AddValue("MEMORY", d.Memory)
if d.VCPU != "" {
template.AddValue("VCPU", d.VCPU)
}
vector := template.NewVector("NIC")
vector.AddValue("NETWORK", d.Network)
vector = template.NewVector("DISK")
vector.AddValue("IMAGE_ID", b2d_id)
vector.AddValue("DEV_PREFIX", "sd")
vector = template.NewVector("DISK")
vector.AddValue("FORMAT", "raw")
vector.AddValue("TYPE", "fs")
vector.AddValue("SIZE", string(d.DiskSize))
vector.AddValue("DEV_PREFIX", "sd")
vector = template.NewVector("CONTEXT")
vector.AddValue("NETWORK", "YES")
vector.AddValue("SSH_PUBLIC_KEY", string(pubKey))
vector = template.NewVector("GRAPHICS")
vector.AddValue("LISTEN", "0.0.0.0")
vector.AddValue("TYPE", "vnc")
// Instantiate
log.Infof("Starting VM...")
_, err = goca.CreateVM(template.String(), false)
if err != nil {
//.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:machine,代码行数:101,代码来源:opennebula.go
示例19: Create
func (d *Driver) Create() error {
err := hypervAvailable()
if err != nil {
return err
}
d.setMachineNameIfNotSet()
b2dutils := mcnutils.NewB2dUtils("", "", d.StorePath)
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
}
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)}
_, err = execute(command)
if err != nil {
return err
}
command = []string{
"Connect-VMNetworkAdapter",
"-VMName", d.MachineName,
"-SwitchName", fmt.Sprintf("'%s'", virtualSwitch)}
_, err = execute(command)
if err != nil {
return err
}
log.Infof("Starting VM...")
if err := d.Start(); err != nil {
return err
}
return nil
}
开发者ID:Red54,项目名称:machine,代码行数:75,代码来源:hyperv.go
示例20: Create
func (d *Driver) Create() error {
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Creating VM...")
if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return err
}
log.Infof("Extracting vmlinuz64 and initrd.img from %s...", isoFilename)
if err := d.extractKernelImages(); err != nil {
return err
}
log.Infof("Generating %dMB disk image...", d.DiskSize)
if err := d.generateDiskImage(d.DiskSize); err != nil {
return err
}
// Fix file permission root to current user for vmnet.framework
log.Infof("Fix file permission...")
os.Chown(d.ResolveStorePath("."), syscall.Getuid(), syscall.Getegid())
files, _ := ioutil.ReadDir(d.ResolveStorePath("."))
for _, f := range files {
log.Debugf(d.ResolveStorePath(f.Name()))
os.Chown(d.ResolveStorePath(f.Name()), syscall.Getuid(), syscall.Getegid())
}
log.Infof("Generate UUID...")
d.UUID = uuidgen()
log.Debugf("Generated UUID: %s", d.UUID)
log.Infof("Convert UUID to MAC address...")
rawUUID, err := d.getMACAdress()
if err != nil {
return err
}
d.MacAddr = trimMacAddress(rawUUID)
log.Debugf("Converted MAC address: %s", d.MacAddr)
log.Infof("Starting %s...", d.MachineName)
if err := d.Start(); err != nil {
return err
}
log.Infof("Waiting for VM to come online...")
var ip string
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
// Setup NFS sharing
if d.NFSShare {
err = d.setupNFSShare()
if err != nil {
log.Errorf("NFS setup failed: %s", err.Error())
}
}
return nil
}
开发者ID:musha68k,项目名称:docker-machine-driver-xhyve,代码行数:80,代码来源:xhyve.go
注:本文中的github.com/docker/machine/libmachine/mcnutils.NewB2dUtils函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论