当前位置: 首页>>代码示例>>Golang>>正文


Golang object.Datastore类代码示例

如果您正苦于以下问题:Golang Datastore类的具体用法?Golang Datastore怎么用?Golang Datastore使用的例子?那么, 这里精选的代码示例或许可以为您提供帮助。

以下是Datastore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为感觉有用的代码点赞,您的评价将有助于系统推荐出更好的Golang代码示例。


示例1: newVm

// newVm creates a new virtual machine.
func (vm *VirtualMachine) newVm(f *object.Folder, p *object.ResourcePool, ds *object.Datastore, h *object.HostSystem) error {
    if vm.Hardware == nil {
        return errors.New("Missing hardware configuration")
    }

    Logf("%s creating virtual machine\n", vm.ID())

    spec := types.VirtualMachineConfigSpec{
        Name:              vm.Name,
        Version:           vm.Hardware.Version,
        GuestId:           vm.GuestID,
        Annotation:        vm.Annotation,
        NumCPUs:           vm.Hardware.Cpu,
        NumCoresPerSocket: vm.Hardware.Cores,
        MemoryMB:          vm.Hardware.Memory,
        MaxMksConnections: vm.MaxMksConnections,
        Files: &types.VirtualMachineFileInfo{
            VmPathName: ds.Path(vm.Name),
        },
    }

    task, err := f.CreateVM(vm.ctx, spec, p, h)
    if err != nil {
        return err
    }

    return task.Wait(vm.ctx)
}
开发者ID:dnaeon,项目名称:gru,代码行数:29,代码来源:vsphere_vm.go

示例2: buildVMRelocateSpec

// buildVMRelocateSpec builds VirtualMachineRelocateSpec to set a place for a new VirtualMachine.
func buildVMRelocateSpec(rp *object.ResourcePool, ds *object.Datastore, vm *object.VirtualMachine) (types.VirtualMachineRelocateSpec, error) {
    var key int

    devices, err := vm.Device(context.TODO())
    if err != nil {
        return types.VirtualMachineRelocateSpec{}, err
    }
    for _, d := range devices {
        if devices.Type(d) == "disk" {
            key = d.GetVirtualDevice().Key
        }
    }

    rpr := rp.Reference()
    dsr := ds.Reference()
    return types.VirtualMachineRelocateSpec{
        Datastore: &dsr,
        Pool:      &rpr,
        Disk: []types.VirtualMachineRelocateSpecDiskLocator{
            types.VirtualMachineRelocateSpecDiskLocator{
                Datastore: dsr,
                DiskBackingInfo: &types.VirtualDiskFlatVer2BackingInfo{
                    DiskMode:        "persistent",
                    ThinProvisioned: types.NewBool(false),
                    EagerlyScrub:    types.NewBool(true),
                },
                DiskId: key,
            },
        },
    }, nil
}
开发者ID:AssertSelenium,项目名称:terraform,代码行数:32,代码来源:resource_vsphere_virtual_machine.go

示例3: lsFolder

func (d *Dispatcher) lsFolder(ds *object.Datastore, dsPath string) (*types.HostDatastoreBrowserSearchResults, error) {
    defer trace.End(trace.Begin(dsPath))

    spec := types.HostDatastoreBrowserSearchSpec{
        MatchPattern: []string{"*"},
    }

    b, err := ds.Browser(d.ctx)
    if err != nil {
        return nil, err
    }

    task, err := b.SearchDatastore(d.ctx, dsPath, &spec)
    if err != nil {
        return nil, err
    }

    info, err := task.WaitForResult(d.ctx, nil)
    if err != nil {
        return nil, err
    }

    res := info.Result.(types.HostDatastoreBrowserSearchResults)
    return &res, nil
}
开发者ID:vmware,项目名称:vic,代码行数:25,代码来源:store_files.go

示例4: createVM

func (cmd *create) createVM(ctx context.Context) (*object.Task, error) {
    var devices object.VirtualDeviceList
    var err error

    spec := &types.VirtualMachineConfigSpec{
        Name:     cmd.name,
        GuestId:  cmd.guestID,
        NumCPUs:  int32(cmd.cpus),
        MemoryMB: int64(cmd.memory),
    }

    devices, err = cmd.addStorage(nil)
    if err != nil {
        return nil, err
    }

    devices, err = cmd.addNetwork(devices)
    if err != nil {
        return nil, err
    }

    deviceChange, err := devices.ConfigSpec(types.VirtualDeviceConfigSpecOperationAdd)
    if err != nil {
        return nil, err
    }

    spec.DeviceChange = deviceChange

    var datastore *object.Datastore

    // If storage pod is specified, collect placement recommendations
    if cmd.StoragePod != nil {
        datastore, err = cmd.recommendDatastore(ctx, spec)
        if err != nil {
            return nil, err
        }
    } else {
        datastore = cmd.Datastore
    }

    if !cmd.force {
        vmxPath := fmt.Sprintf("%s/%s.vmx", cmd.name, cmd.name)

        _, err := datastore.Stat(ctx, vmxPath)
        if err == nil {
            dsPath := cmd.Datastore.Path(vmxPath)
            return nil, fmt.Errorf("File %s already exists", dsPath)
        }
    }

    folder := cmd.Folder

    spec.Files = &types.VirtualMachineFileInfo{
        VmPathName: fmt.Sprintf("[%s]", datastore.Name()),
    }

    return folder.CreateVM(ctx, *spec, cmd.ResourcePool, cmd.HostSystem)
}
开发者ID:hmahmood,项目名称:govmomi,代码行数:58,代码来源:create.go

示例5: buildVMRelocateSpec

// buildVMRelocateSpec builds VirtualMachineRelocateSpec to set a place for a new VirtualMachine.
func buildVMRelocateSpec(finder *find.Finder, rp *object.ResourcePool, ds *object.Datastore, vm *object.VirtualMachine, linked bool) (types.VirtualMachineRelocateSpec, error) {
    var key int
    var parent *types.VirtualDiskFlatVer2BackingInfo

    devices, err := vm.Device(context.TODO())
    if err != nil {
        return types.VirtualMachineRelocateSpec{}, err
    }

    for _, d := range devices {
        if devices.Type(d) == "disk" {
            vd := d.GetVirtualDevice()
            parent = vd.Backing.(*types.VirtualDiskFlatVer2BackingInfo)
            key = vd.Key
        }
    }

    rpr := rp.Reference()
    relocateSpec := types.VirtualMachineRelocateSpec{}
    // Treat linked clones a bit differently.
    if linked {
        parentDs := strings.SplitN(parent.FileName[1:], "]", 2)
        parentDsObj, err := finder.Datastore(context.TODO(), parentDs[0])
        if err != nil {
            return types.VirtualMachineRelocateSpec{}, err
        }

        parentDbObjRef := parentDsObj.Reference()
        relocateSpec = types.VirtualMachineRelocateSpec{
            Datastore:    &parentDbObjRef,
            Pool:         &rpr,
            DiskMoveType: "createNewChildDiskBacking",
        }
    } else {
        dsr := ds.Reference()

        relocateSpec = types.VirtualMachineRelocateSpec{
            Datastore: &dsr,
            Pool:      &rpr,
            Disk: []types.VirtualMachineRelocateSpecDiskLocator{
                types.VirtualMachineRelocateSpecDiskLocator{
                    Datastore: dsr,
                    DiskId:    key,
                    DiskBackingInfo: &types.VirtualDiskFlatVer2BackingInfo{
                        DiskMode:        "persistent",
                        ThinProvisioned: types.NewBool(false),
                        EagerlyScrub:    types.NewBool(true),
                    },
                },
            },
        }
    }

    return relocateSpec, nil
}
开发者ID:NetworkBytes,项目名称:terraform,代码行数:56,代码来源:resource_vsphere_virtual_machine.go

示例6: addHardDisk

// addHardDisk adds a new Hard Disk to the VirtualMachine.
func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, datastore *object.Datastore, diskPath string, controller_type string) error {
    devices, err := vm.Device(context.TODO())
    if err != nil {
        return err
    }
    log.Printf("[DEBUG] vm devices: %#v\n", devices)

    controller, err := devices.FindDiskController(controller_type)
    if err != nil {
        return err
    }
    log.Printf("[DEBUG] disk controller: %#v\n", controller)

    // TODO Check if diskPath & datastore exist
    // If diskPath is not specified, pass empty string to CreateDisk()
    if diskPath == "" {
        return fmt.Errorf("[ERROR] addHardDisk - No path proided")
    } else {
        // TODO Check if diskPath & datastore exist
        diskPath = fmt.Sprintf("[%v] %v", datastore.Name(), diskPath)
    }
    log.Printf("[DEBUG] addHardDisk - diskPath: %v", diskPath)
    disk := devices.CreateDisk(controller, datastore.Reference(), diskPath)

    existing := devices.SelectByBackingInfo(disk.Backing)
    log.Printf("[DEBUG] disk: %#v\n", disk)

    if len(existing) == 0 {
        disk.CapacityInKB = int64(size * 1024 * 1024)
        if iops != 0 {
            disk.StorageIOAllocation = &types.StorageIOAllocationInfo{
                Limit: iops,
            }
        }
        backing := disk.Backing.(*types.VirtualDiskFlatVer2BackingInfo)

        if diskType == "eager_zeroed" {
            // eager zeroed thick virtual disk
            backing.ThinProvisioned = types.NewBool(false)
            backing.EagerlyScrub = types.NewBool(true)
        } else if diskType == "thin" {
            // thin provisioned virtual disk
            backing.ThinProvisioned = types.NewBool(true)
        }

        log.Printf("[DEBUG] addHardDisk: %#v\n", disk)
        log.Printf("[DEBUG] addHardDisk capacity: %#v\n", disk.CapacityInKB)

        return vm.AddDevice(context.TODO(), disk)
    } else {
        log.Printf("[DEBUG] addHardDisk: Disk already present.\n")

        return nil
    }
}
开发者ID:srikalyan,项目名称:terraform,代码行数:56,代码来源:resource_vsphere_virtual_machine.go

示例7: vmCleanup

func vmCleanup(dc *object.Datacenter, ds *object.Datastore, vmName string) error {
    client := testAccProvider.Meta().(*govmomi.Client)
    fileManager := object.NewFileManager(client.Client)
    task, err := fileManager.DeleteDatastoreFile(context.TODO(), ds.Path(vmName), dc)
    if err != nil {
        log.Printf("[ERROR] checkForDisk - Couldn't delete vm folder '%v': %v", vmName, err)
        return err
    }

    _, err = task.WaitForResult(context.TODO(), nil)
    if err != nil {
        log.Printf("[ERROR] checForDisk - Failed while deleting vm folder '%v': %v", vmName, err)
        return err
    }
    return nil
}
开发者ID:paultyng,项目名称:terraform,代码行数:16,代码来源:resource_vsphere_virtual_machine_test.go

示例8: addHardDisk

// addHardDisk adds a new Hard Disk to the VirtualMachine.
func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, datastore *object.Datastore, diskPath string) error {
    devices, err := vm.Device(context.TODO())
    if err != nil {
        return err
    }
    log.Printf("[DEBUG] vm devices: %#v\n", devices)

    controller, err := devices.FindDiskController("scsi")
    if err != nil {
        return err
    }
    log.Printf("[DEBUG] disk controller: %#v\n", controller)

    disk := devices.CreateDisk(controller, datastore.Reference(), diskPath)
    existing := devices.SelectByBackingInfo(disk.Backing)
    log.Printf("[DEBUG] disk: %#v\n", disk)

    if len(existing) == 0 {
        disk.CapacityInKB = int64(size * 1024 * 1024)
        if iops != 0 {
            disk.StorageIOAllocation = &types.StorageIOAllocationInfo{
                Limit: iops,
            }
        }
        backing := disk.Backing.(*types.VirtualDiskFlatVer2BackingInfo)

        if diskType == "eager_zeroed" {
            // eager zeroed thick virtual disk
            backing.ThinProvisioned = types.NewBool(false)
            backing.EagerlyScrub = types.NewBool(true)
        } else if diskType == "thin" {
            // thin provisioned virtual disk
            backing.ThinProvisioned = types.NewBool(true)
        }

        log.Printf("[DEBUG] addHardDisk: %#v\n", disk)
        log.Printf("[DEBUG] addHardDisk: %#v\n", disk.CapacityInKB)

        return vm.AddDevice(context.TODO(), disk)
    } else {
        log.Printf("[DEBUG] addHardDisk: Disk already present.\n")

        return nil
    }
}
开发者ID:ack,项目名称:terraform,代码行数:46,代码来源:resource_vsphere_virtual_machine.go

示例9: AddDisk

func (c *configSpec) AddDisk(ds *object.Datastore, path string) {
    var devices object.VirtualDeviceList

    controller, err := devices.CreateSCSIController("")
    if err != nil {
        panic(err)
    }
    devices = append(devices, controller)

    disk := devices.CreateDisk(controller.(types.BaseVirtualController), ds.Reference(), ds.Path(path))
    devices = append(devices, disk)

    spec, err := devices.ConfigSpec(types.VirtualDeviceConfigSpecOperationAdd)
    if err != nil {
        panic(err)
    }

    c.DeviceChange = append(c.DeviceChange, spec...)
}
开发者ID:vmware,项目名称:vic,代码行数:19,代码来源:vmdk.go

示例10: createDatastoreFiles

func createDatastoreFiles(d *Dispatcher, ds *object.Datastore, t *testing.T) error {
    tmpfile, err := ioutil.TempFile("", "tempDatastoreFile.vmdk")
    if err != nil {
        t.Errorf("Failed to create file: %s", err)
        return err
    }

    defer os.Remove(tmpfile.Name()) // clean up

    if err = ds.UploadFile(d.ctx, tmpfile.Name(), "Test/folder/data/temp.vmdk", nil); err != nil {
        t.Errorf("Failed to upload file %q: %s", "Test/folder/data/temp.vmdk", err)
        return err
    }
    if err = ds.UploadFile(d.ctx, tmpfile.Name(), "Test/folder/tempMetadata", nil); err != nil {
        t.Errorf("Failed to upload file %q: %s", "Test/folder/tempMetadata", err)
        return err
    }
    return nil
}
开发者ID:vmware,项目名称:vic,代码行数:19,代码来源:delete_test.go

示例11: AddDisk

func (c *configSpec) AddDisk(ds *object.Datastore, path string) {
    controller := &types.VirtualLsiLogicController{
        VirtualSCSIController: types.VirtualSCSIController{
            SharedBus: types.VirtualSCSISharingNoSharing,
            VirtualController: types.VirtualController{
                BusNumber: 0,
                VirtualDevice: types.VirtualDevice{
                    Key: -1,
                },
            },
        },
    }

    controllerSpec := &types.VirtualDeviceConfigSpec{
        Device:    controller,
        Operation: types.VirtualDeviceConfigSpecOperationAdd,
    }

    c.AddChange(controllerSpec)

    disk := &types.VirtualDisk{
        VirtualDevice: types.VirtualDevice{
            Key:           -1,
            ControllerKey: -1,
            UnitNumber:    -1,
            Backing: &types.VirtualDiskFlatVer2BackingInfo{
                VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
                    FileName: ds.Path(path),
                },
                DiskMode:        string(types.VirtualDiskModePersistent),
                ThinProvisioned: types.NewBool(true),
            },
        },
    }

    diskSpec := &types.VirtualDeviceConfigSpec{
        Device:    disk,
        Operation: types.VirtualDeviceConfigSpecOperationAdd,
    }

    c.AddChange(diskSpec)
}
开发者ID:fdawg4l,项目名称:govmomi,代码行数:42,代码来源:vmdk.go

示例12: deleteDatastoreFiles

func (d *Dispatcher) deleteDatastoreFiles(ds *object.Datastore, path string, force bool) (bool, error) {
    defer trace.End(trace.Begin(fmt.Sprintf("path %q, force %t", path, force)))

    // refuse to delete everything on the datstore, ignore force
    if path == "" {
        dsn, _ := ds.ObjectName(d.ctx)
        msg := fmt.Sprintf("refusing to remove datastore files for path \"\" on datastore %q", dsn)
        return false, errors.New(msg)
    }

    var empty bool
    dsPath := ds.Path(path)

    res, err := d.lsFolder(ds, dsPath)
    if err != nil {
        if !types.IsFileNotFound(err) {
            err = errors.Errorf("Failed to browse folder %q: %s", dsPath, err)
            return empty, err
        }
        log.Debugf("Folder %q is not found", dsPath)
        empty = true
        return empty, nil
    }
    if len(res.File) > 0 && !force {
        log.Debugf("Folder %q is not empty, leave it there", dsPath)
        return empty, nil
    }

    m := object.NewFileManager(ds.Client())
    if err = d.deleteFilesIteratively(m, ds, dsPath); err != nil {
        return empty, err
    }
    return true, nil
}
开发者ID:vmware,项目名称:vic,代码行数:34,代码来源:store_files.go

示例13: buildVMRelocateSpec

// buildVMRelocateSpec builds VirtualMachineRelocateSpec to set a place for a new VirtualMachine.
func buildVMRelocateSpec(rp *object.ResourcePool, ds *object.Datastore, vm *object.VirtualMachine, linkedClone bool, initType string) (types.VirtualMachineRelocateSpec, error) {
    var key int
    var moveType string
    if linkedClone {
        moveType = "createNewChildDiskBacking"
    } else {
        moveType = "moveAllDiskBackingsAndDisallowSharing"
    }
    log.Printf("[DEBUG] relocate type: [%s]", moveType)

    devices, err := vm.Device(context.TODO())
    if err != nil {
        return types.VirtualMachineRelocateSpec{}, err
    }
    for _, d := range devices {
        if devices.Type(d) == "disk" {
            key = d.GetVirtualDevice().Key
        }
    }

    isThin := initType == "thin"
    rpr := rp.Reference()
    dsr := ds.Reference()
    return types.VirtualMachineRelocateSpec{
        Datastore:    &dsr,
        Pool:         &rpr,
        DiskMoveType: moveType,
        Disk: []types.VirtualMachineRelocateSpecDiskLocator{
            types.VirtualMachineRelocateSpecDiskLocator{
                Datastore: dsr,
                DiskBackingInfo: &types.VirtualDiskFlatVer2BackingInfo{
                    DiskMode:        "persistent",
                    ThinProvisioned: types.NewBool(isThin),
                    EagerlyScrub:    types.NewBool(!isThin),
                },
                DiskId: key,
            },
        },
    }, nil
}
开发者ID:mafrosis,项目名称:terraform,代码行数:41,代码来源:resource_vsphere_virtual_machine.go

示例14: cloneVm

// cloneVm creates the virtual machine using a template.
func (vm *VirtualMachine) cloneVm(f *object.Folder, p *object.ResourcePool, ds *object.Datastore, h *object.HostSystem) error {
    Logf("%s cloning virtual machine from %s\n", vm.ID(), vm.TemplateConfig.Use)

    obj, err := vm.finder.VirtualMachine(vm.ctx, vm.TemplateConfig.Use)
    if err != nil {
        return err
    }

    folderRef := f.Reference()
    datastoreRef := ds.Reference()
    poolRef := p.Reference()

    var hostRef *types.ManagedObjectReference
    if h != nil {
        ref := h.Reference()
        hostRef = &ref
    }

    spec := types.VirtualMachineCloneSpec{
        Location: types.VirtualMachineRelocateSpec{
            Folder:    &folderRef,
            Datastore: &datastoreRef,
            Pool:      &poolRef,
            Host:      hostRef,
        },
        Template: vm.TemplateConfig.MarkAsTemplate,
        PowerOn:  vm.TemplateConfig.PowerOn,
    }

    task, err := obj.Clone(vm.ctx, f, vm.Name, spec)
    if err != nil {
        return err
    }

    return task.Wait(vm.ctx)
}
开发者ID:dnaeon,项目名称:gru,代码行数:37,代码来源:vsphere_vm.go

示例15: deleteUpgradeImages

func (d *Dispatcher) deleteUpgradeImages(ds *object.Datastore, settings *data.InstallerData) {
    defer trace.End(trace.Begin(""))

    log.Infof("Deleting upgrade images")

    // do clean up aggressively, even the previous operation failed with context deadline excceeded.
    d.ctx = context.Background()

    m := object.NewFileManager(ds.Client())

    file := ds.Path(path.Join(d.vmPathName, settings.ApplianceISO))
    if err := d.deleteVMFSFiles(m, ds, file); err != nil {
        log.Warnf("Image file %q is not removed for %s. Use the vSphere UI to delete content", file, err)
    }

    file = ds.Path(path.Join(d.vmPathName, settings.BootstrapISO))
    if err := d.deleteVMFSFiles(m, ds, file); err != nil {
        log.Warnf("Image file %q is not removed for %s. Use the vSphere UI to delete content", file, err)
    }
}
开发者ID:vmware,项目名称:vic,代码行数:20,代码来源:upgrade.go


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