本文整理汇总了Golang中github.com/vmware/govmomi/object.Datastore.Path方法的典型用法代码示例。如果您正苦于以下问题:Golang Datastore.Path方法的具体用法?Golang Datastore.Path怎么用?Golang Datastore.Path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/govmomi/object.Datastore
的用法示例。
在下文中一共展示了Datastore.Path方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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)
}
示例3: 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
}
示例4: 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)
}
示例5: 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)
}
}
示例6: 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...)
}