本文整理汇总了Golang中github.com/vmware/govmomi/object.NewVirtualDiskManager函数的典型用法代码示例。如果您正苦于以下问题:Golang NewVirtualDiskManager函数的具体用法?Golang NewVirtualDiskManager怎么用?Golang NewVirtualDiskManager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewVirtualDiskManager函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: createHardDisk
// createHardDisk creates a new Hard Disk.
func createHardDisk(client *govmomi.Client, size int, diskPath string, diskType string, adapterType string, dc string) error {
virtualDiskManager := object.NewVirtualDiskManager(client.Client)
spec := &types.FileBackedVirtualDiskSpec{
VirtualDiskSpec: types.VirtualDiskSpec{
AdapterType: adapterType,
DiskType: diskType,
},
CapacityKb: int64(1024 * 1024 * size),
}
datacenter, err := getDatacenter(client, dc)
if err != nil {
return err
}
log.Printf("[DEBUG] Disk spec: %v", spec)
task, err := virtualDiskManager.CreateVirtualDisk(context.TODO(), diskPath, datacenter, spec)
if err != nil {
return err
}
_, err = task.WaitForResult(context.TODO(), nil)
if err != nil {
log.Printf("[INFO] Failed to create disk: %v", err)
return err
}
log.Printf("[INFO] Created disk.")
return nil
}
开发者ID:Zordrak,项目名称:terraform,代码行数:30,代码来源:resource_vsphere_virtual_disk.go
示例2: DeleteVolume
// DeleteVolume deletes a volume given volume name.
func (vs *VSphere) DeleteVolume(vmDiskPath string) error {
// Create context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Create vSphere client
c, err := vsphereLogin(vs.cfg, ctx)
if err != nil {
return err
}
defer c.Logout(ctx)
// Create a new finder
f := find.NewFinder(c.Client, true)
// Fetch and set data center
dc, err := f.Datacenter(ctx, vs.cfg.Global.Datacenter)
f.SetDatacenter(dc)
// Create a virtual disk manager
virtualDiskManager := object.NewVirtualDiskManager(c.Client)
// Delete virtual disk
task, err := virtualDiskManager.DeleteVirtualDisk(ctx, vmDiskPath, dc)
if err != nil {
return err
}
return task.Wait(ctx)
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:31,代码来源:vsphere.go
示例3: Create
// Create creates a disk without a parent (and doesn't attach it).
func (m *Manager) Create(ctx context.Context, newDiskURI string,
capacityKB int64) (*VirtualDisk, error) {
defer trace.End(trace.Begin(newDiskURI))
vdm := object.NewVirtualDiskManager(m.vm.Client())
d, err := NewVirtualDisk(newDiskURI)
if err != nil {
return nil, errors.Trace(err)
}
spec := &types.FileBackedVirtualDiskSpec{
VirtualDiskSpec: types.VirtualDiskSpec{
DiskType: string(types.VirtualDiskTypeThin),
AdapterType: string(types.VirtualDiskAdapterTypeLsiLogic),
},
CapacityKb: capacityKB,
}
log.Infof("Creating vmdk for layer or volume %s", d.DatastoreURI)
err = tasks.Wait(ctx, func(ctx context.Context) (tasks.Waiter, error) {
return vdm.CreateVirtualDisk(ctx, d.DatastoreURI, nil, spec)
})
if err != nil {
return nil, errors.Trace(err)
}
return d, nil
}
开发者ID:jak-atx,项目名称:vic,代码行数:33,代码来源:disk_manager.go
示例4: resourceVSphereVirtualDiskDelete
func resourceVSphereVirtualDiskDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*govmomi.Client)
vDisk := virtualDisk{}
if v, ok := d.GetOk("vmdk_path"); ok {
vDisk.vmdkPath = v.(string)
}
if v, ok := d.GetOk("datastore"); ok {
vDisk.datastore = v.(string)
}
dc, err := getDatacenter(client, d.Get("datacenter").(string))
if err != nil {
return err
}
diskPath := fmt.Sprintf("[%v] %v", vDisk.datastore, vDisk.vmdkPath)
virtualDiskManager := object.NewVirtualDiskManager(client.Client)
task, err := virtualDiskManager.DeleteVirtualDisk(context.TODO(), diskPath, dc)
if err != nil {
return err
}
_, err = task.WaitForResult(context.TODO(), nil)
if err != nil {
log.Printf("[INFO] Failed to delete disk: %v", err)
return err
}
log.Printf("[INFO] Deleted disk: %v", diskPath)
d.SetId("")
return nil
}
开发者ID:Zordrak,项目名称:terraform,代码行数:35,代码来源:resource_vsphere_virtual_disk.go
示例5: DeleteVolume
// DeleteVolume deletes a volume given volume name.
func (vs *VSphere) DeleteVolume(vmDiskPath string) error {
// Create context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Ensure client is logged in and session is valid
err := vSphereLogin(vs, ctx)
if err != nil {
glog.Errorf("Failed to login into vCenter - %v", err)
return err
}
// Create a new finder
f := find.NewFinder(vs.client.Client, true)
// Fetch and set data center
dc, err := f.Datacenter(ctx, vs.cfg.Global.Datacenter)
f.SetDatacenter(dc)
// Create a virtual disk manager
virtualDiskManager := object.NewVirtualDiskManager(vs.client.Client)
// Delete virtual disk
task, err := virtualDiskManager.DeleteVirtualDisk(ctx, vmDiskPath, dc)
if err != nil {
return err
}
return task.Wait(ctx)
}
开发者ID:nak3,项目名称:kubernetes,代码行数:31,代码来源:vsphere.go
示例6: TestDeleteExceptDisk
func TestDeleteExceptDisk(t *testing.T) {
s := os.Getenv("DRONE")
if s != "" {
t.Skip("Skipping: test must be run in a VM")
}
ctx := context.Background()
session := test.Session(ctx, t)
defer session.Logout(ctx)
host := test.PickRandomHost(ctx, session, t)
uuid, err := sys.UUID()
if err != nil {
t.Fatalf("unable to get UUID for guest - used for VM name: %s", err)
}
name := fmt.Sprintf("%s-%d", uuid, rand.Intn(math.MaxInt32))
moref, err := CreateVM(ctx, session, host, name)
if err != nil {
t.Fatalf("ERROR: %s", err)
}
// Wrap the result with our version of VirtualMachine
vm := NewVirtualMachine(ctx, session, *moref)
folder, err := vm.FolderName(ctx)
if err != nil {
t.Fatalf("ERROR: %s", err)
}
// generate the disk name
diskName := fmt.Sprintf("%s/%s.vmdk", folder, folder)
// Delete the VM but not it's disk
_, err = tasks.WaitForResult(ctx, func(ctx context.Context) (tasks.ResultWaiter, error) {
return vm.DeleteExceptDisks(ctx)
})
if err != nil {
t.Fatalf("ERROR: %s", err)
}
// check that the disk still exists
session.Datastore.Stat(ctx, diskName)
if err != nil {
t.Fatalf("Disk does not exist")
}
// clean up
dm := object.NewVirtualDiskManager(session.Client.Client)
task, err := dm.DeleteVirtualDisk(context.TODO(), diskName, nil)
if err != nil {
t.Fatalf("Unable to locate orphan vmdk: %s", err)
}
if err = task.Wait(context.TODO()); err != nil {
t.Fatalf("Unable to remove orphan vmdk: %s", err)
}
}
开发者ID:kjplatz,项目名称:vic,代码行数:60,代码来源:vm_test.go
示例7: DeleteDisk
func (cmd *vmdk) DeleteDisk(path string) error {
vdm := object.NewVirtualDiskManager(cmd.Client)
task, err := vdm.DeleteVirtualDisk(context.TODO(), cmd.Datastore.Path(path), cmd.Datacenter)
if err != nil {
return err
}
return task.Wait(context.TODO())
}
开发者ID:fdawg4l,项目名称:govmomi,代码行数:9,代码来源:vmdk.go
示例8: MoveDisk
func (cmd *vmdk) MoveDisk(src, dst string) error {
dsSrc := cmd.Datastore.Path(src)
dsDst := cmd.Datastore.Path(dst)
vdm := object.NewVirtualDiskManager(cmd.Client)
task, err := vdm.MoveVirtualDisk(context.TODO(), dsSrc, cmd.Datacenter, dsDst, cmd.Datacenter, true)
if err != nil {
return err
}
return task.Wait(context.TODO())
}
开发者ID:fdawg4l,项目名称:govmomi,代码行数:11,代码来源:vmdk.go
示例9: CreateVolume
// CreateVolume creates a volume of given size (in KiB).
func (vs *VSphere) CreateVolume(name string, size int, tags *map[string]string) (volumePath string, err error) {
// Create context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Create vSphere client
c, err := vsphereLogin(vs.cfg, ctx)
if err != nil {
return "", err
}
defer c.Logout(ctx)
// Create a new finder
f := find.NewFinder(c.Client, true)
// Fetch and set data center
dc, err := f.Datacenter(ctx, vs.cfg.Global.Datacenter)
f.SetDatacenter(dc)
// Create a virtual disk manager
vmDiskPath := "[" + vs.cfg.Global.Datastore + "] " + name + ".vmdk"
virtualDiskManager := object.NewVirtualDiskManager(c.Client)
// Create specification for new virtual disk
vmDiskSpec := &types.FileBackedVirtualDiskSpec{
VirtualDiskSpec: types.VirtualDiskSpec{
AdapterType: (*tags)["adapterType"],
DiskType: (*tags)["diskType"],
},
CapacityKb: int64(size),
}
// Create virtual disk
task, err := virtualDiskManager.CreateVirtualDisk(ctx, vmDiskPath, dc, vmDiskSpec)
if err != nil {
return "", err
}
err = task.Wait(ctx)
if err != nil {
return "", err
}
return vmDiskPath, nil
}
开发者ID:thrasher-redhat,项目名称:origin,代码行数:45,代码来源:vsphere.go
示例10: getVirtualDiskUUIDByPath
// Gets virtual disk UUID by datastore (namespace) path
//
// volPath can be namespace path (e.g. "[vsanDatastore] volumes/test.vmdk") or
// uuid path (e.g. "[vsanDatastore] 59427457-6c5a-a917-7997-0200103eedbc/test.vmdk").
// `volumes` in this case would be a symlink to
// `59427457-6c5a-a917-7997-0200103eedbc`.
//
// We want users to use namespace path. It is good for attaching the disk,
// but for detaching the API requires uuid path. Hence, to detach the right
// device we have to convert the namespace path to uuid path.
func getVirtualDiskUUIDByPath(volPath string, dc *object.Datacenter, client *govmomi.Client) (string, error) {
if len(volPath) > 0 && filepath.Ext(volPath) != ".vmdk" {
volPath += ".vmdk"
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// VirtualDiskManager provides a way to manage and manipulate virtual disks on vmware datastores.
vdm := object.NewVirtualDiskManager(client.Client)
// Returns uuid of vmdk virtual disk
diskUUID, err := vdm.QueryVirtualDiskUuid(ctx, volPath, dc)
if err != nil {
return "", ErrNoDiskUUIDFound
}
diskUUID = formatVirtualDiskUUID(diskUUID)
return diskUUID, nil
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:31,代码来源:vsphere.go
示例11: CopyHostAgent
func (cmd *vmdk) CopyHostAgent(i importable, s progress.Sinker) error {
spec := &types.VirtualDiskSpec{
AdapterType: "lsiLogic",
DiskType: "thin",
}
dc := cmd.Datacenter
src := cmd.Datastore.Path(i.RemoteSrcVMDK())
dst := cmd.Datastore.Path(i.RemoteDstVMDK())
vdm := object.NewVirtualDiskManager(cmd.Client)
task, err := vdm.CopyVirtualDisk(context.TODO(), src, dc, dst, dc, spec, false)
if err != nil {
return err
}
ps := progress.Prefix(s, "copying disk")
_, err = task.WaitForResult(context.TODO(), ps)
if err != nil {
return err
}
return nil
}
开发者ID:fdawg4l,项目名称:govmomi,代码行数:23,代码来源:vmdk.go
示例12: CreateVolume
// CreateVolume creates a volume of given size (in KiB).
func (vs *VSphere) CreateVolume(volumeOptions *VolumeOptions) (volumePath string, err error) {
var diskFormat string
// Default diskformat as 'thin'
if volumeOptions.DiskFormat == "" {
volumeOptions.DiskFormat = ThinDiskType
}
if _, ok := diskFormatValidType[volumeOptions.DiskFormat]; !ok {
return "", fmt.Errorf("Cannot create disk. Error diskformat %+q."+
" Valid options are %s.", volumeOptions.DiskFormat, DiskformatValidOptions)
}
diskFormat = diskFormatValidType[volumeOptions.DiskFormat]
// Create context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Create vSphere client
c, err := vsphereLogin(vs.cfg, ctx)
if err != nil {
return "", err
}
defer c.Logout(ctx)
// Create a new finder
f := find.NewFinder(c.Client, true)
// Fetch and set data center
dc, err := f.Datacenter(ctx, vs.cfg.Global.Datacenter)
f.SetDatacenter(dc)
ds, err := f.Datastore(ctx, vs.cfg.Global.Datastore)
if err != nil {
glog.Errorf("Failed while searching for datastore %+q. err %s", vs.cfg.Global.Datastore, err)
return "", err
}
// vmdks will be created inside kubevols directory
kubeVolsPath := filepath.Clean(ds.Path(VolDir)) + "/"
err = makeDirectoryInDatastore(c, dc, kubeVolsPath, false)
if err != nil && err != ErrFileAlreadyExist {
glog.Errorf("Cannot create dir %#v. err %s", kubeVolsPath, err)
return "", err
}
glog.V(4).Infof("Created dir with path as %+q", kubeVolsPath)
vmDiskPath := kubeVolsPath + volumeOptions.Name + ".vmdk"
// Create a virtual disk manager
virtualDiskManager := object.NewVirtualDiskManager(c.Client)
// Create specification for new virtual disk
vmDiskSpec := &types.FileBackedVirtualDiskSpec{
VirtualDiskSpec: types.VirtualDiskSpec{
AdapterType: LSILogicControllerType,
DiskType: diskFormat,
},
CapacityKb: int64(volumeOptions.CapacityKB),
}
// Create virtual disk
task, err := virtualDiskManager.CreateVirtualDisk(ctx, vmDiskPath, dc, vmDiskSpec)
if err != nil {
return "", err
}
err = task.Wait(ctx)
if err != nil {
return "", err
}
return vmDiskPath, nil
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:75,代码来源:vsphere.go
示例13: CreateVolume
// CreateVolume creates a volume of given size (in KiB).
func (vs *VSphere) CreateVolume(name string, size int, tags *map[string]string) (volumePath string, err error) {
// Create context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Create vSphere client
c, err := vsphereLogin(vs.cfg, ctx)
if err != nil {
return "", err
}
defer c.Logout(ctx)
// Create a new finder
f := find.NewFinder(c.Client, true)
// Fetch and set data center
dc, err := f.Datacenter(ctx, vs.cfg.Global.Datacenter)
f.SetDatacenter(dc)
ds, err := f.Datastore(ctx, vs.cfg.Global.Datastore)
if err != nil {
glog.Errorf("Failed while searching for datastore %+q. err %s", vs.cfg.Global.Datastore, err)
return "", err
}
if (*tags)["adapterType"] == "" {
(*tags)["adapterType"] = LSILogicControllerType
}
if (*tags)["diskType"] == "" {
(*tags)["diskType"] = ThinDiskType
}
// vmdks will be created inside kubevols directory
kubeVolsPath := filepath.Clean(ds.Path(VolDir)) + "/"
err = makeDirectoryInDatastore(c, dc, kubeVolsPath, false)
if err != nil && err != ErrFileAlreadyExist {
glog.Errorf("Cannot create dir %#v. err %s", kubeVolsPath, err)
return "", err
}
vmDiskPath := kubeVolsPath + name + ".vmdk"
// Create a virtual disk manager
virtualDiskManager := object.NewVirtualDiskManager(c.Client)
// Create specification for new virtual disk
vmDiskSpec := &types.FileBackedVirtualDiskSpec{
VirtualDiskSpec: types.VirtualDiskSpec{
AdapterType: (*tags)["adapterType"],
DiskType: (*tags)["diskType"],
},
CapacityKb: int64(size),
}
// Create virtual disk
task, err := virtualDiskManager.CreateVirtualDisk(ctx, vmDiskPath, dc, vmDiskSpec)
if err != nil {
return "", err
}
err = task.Wait(ctx)
if err != nil {
return "", err
}
return vmDiskPath, nil
}
开发者ID:cheld,项目名称:kubernetes,代码行数:66,代码来源:vsphere.go
注:本文中的github.com/vmware/govmomi/object.NewVirtualDiskManager函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论