本文整理汇总了Golang中github.com/vmware/govmomi/object.Folder类的典型用法代码示例。如果您正苦于以下问题:Golang Folder类的具体用法?Golang Folder怎么用?Golang Folder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Folder类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: registerVM
func (vm *VirtualMachine) registerVM(ctx context.Context, path, name string,
vapp, pool, host *types.ManagedObjectReference, vmfolder *object.Folder) (*object.Task, error) {
log.Debugf("Register VM %s", name)
if vapp == nil {
var hostObject *object.HostSystem
if host != nil {
hostObject = object.NewHostSystem(vm.Vim25(), *host)
}
poolObject := object.NewResourcePool(vm.Vim25(), *pool)
return vmfolder.RegisterVM(ctx, path, name, false, poolObject, hostObject)
}
req := types.RegisterChildVM_Task{
This: vapp.Reference(),
Path: path,
Host: host,
}
if name != "" {
req.Name = name
}
res, err := methods.RegisterChildVM_Task(ctx, vm.Vim25(), &req)
if err != nil {
return nil, err
}
return object.NewTask(vm.Vim25(), res.Returnval), nil
}
开发者ID:vmware,项目名称:vic,代码行数:30,代码来源:vm.go
示例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)
}
开发者ID:dnaeon,项目名称:gru,代码行数:29,代码来源:vsphere_vm.go
示例3: deleteFolder
func deleteFolder(client *govmomi.Client, f *folder) error {
dc, err := getDatacenter(client, f.datacenter)
if err != nil {
return err
}
var folder *object.Folder
currentPath := f.path
finder := find.NewFinder(client.Client, true)
finder = finder.SetDatacenter(dc)
si := object.NewSearchIndex(client.Client)
folderRef, err := si.FindByInventoryPath(
context.TODO(), fmt.Sprintf("%v/vm/%v", f.datacenter, f.path))
if err != nil {
return fmt.Errorf("[ERROR] Could not locate folder %s: %v", f.path, err)
} else {
folder = folderRef.(*object.Folder)
}
log.Printf("[INFO] Deleting empty sub-folders of existing path: %s", f.existingPath)
for currentPath != f.existingPath {
log.Printf("[INFO] Deleting folder: %s", currentPath)
children, err := folder.Children(context.TODO())
if err != nil {
return err
}
if len(children) > 0 {
return fmt.Errorf("Folder %s is non-empty and will not be deleted", currentPath)
} else {
log.Printf("[DEBUG] current folder: %#v", folder)
currentPath = path.Dir(currentPath)
if currentPath == "." {
currentPath = ""
}
log.Printf("[INFO] parent path of %s is calculated as %s", f.path, currentPath)
task, err := folder.Destroy(context.TODO())
if err != nil {
return err
}
err = task.Wait(context.TODO())
if err != nil {
return err
}
folderRef, err = si.FindByInventoryPath(
context.TODO(), fmt.Sprintf("%v/vm/%v", f.datacenter, currentPath))
if err != nil {
return err
} else if folderRef != nil {
folder = folderRef.(*object.Folder)
}
}
}
return nil
}
开发者ID:devendraPSL,项目名称:terraform-api,代码行数:58,代码来源:resource_vsphere_folder.go
示例4: Run
func (cmd *create) Run(f *flag.FlagSet) error {
ctx := context.TODO()
var parent *object.Folder
if f.NArg() != 1 {
return flag.ErrHelp
}
name := f.Arg(0)
if cmd.parent == "" {
dc, err := cmd.Datacenter()
if err != nil {
return err
}
folders, err := dc.Folders(ctx)
if err != nil {
return err
}
parent = folders.NetworkFolder
} else {
finder, err := cmd.Finder()
if err != nil {
return err
}
parent, err = finder.Folder(ctx, cmd.parent)
if err != nil {
return err
}
}
cmd.configSpec.Name = name
task, err := parent.CreateDVS(ctx, cmd.DVSCreateSpec)
if err != nil {
return err
}
logger := cmd.ProgressLogger(fmt.Sprintf("adding %s to folder %s... ", name, parent.InventoryPath))
defer logger.Wait()
_, err = task.WaitForResult(ctx, logger)
return err
}
开发者ID:kristinn,项目名称:govmomi,代码行数:47,代码来源:create.go
示例5: findSwitchesInFolder
func (f *Finder) findSwitchesInFolder(ctx context.Context, folder *object.Folder) []object.DistributedVirtualSwitch {
var switches []object.DistributedVirtualSwitch
if children, err := folder.Children(ctx); err == nil {
for _, j := range children {
if j.Reference().Type == "VmwareDistributedVirtualSwitch" {
switches = append(switches, *object.NewDistributedVirtualSwitch(f.client, j.Reference()))
}
if j.Reference().Type == "Folder" {
switches2 := f.findSwitchesInFolder(ctx, object.NewFolder(f.client, j.Reference()))
for _, k := range switches2 {
switches = append(switches, k)
}
}
}
} else {
fmt.Printf("Error getting switches! %v\n", err)
}
return switches
}
开发者ID:gonkulator,项目名称:govmomi,代码行数:19,代码来源:finder.go
示例6: 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
示例7: Add
func (cmd *add) Add(ctx context.Context, parent *object.Folder) error {
spec := cmd.Spec(parent.Client())
req := types.AddStandaloneHost_Task{
This: parent.Reference(),
Spec: spec,
AddConnected: cmd.connect,
}
res, err := methods.AddStandaloneHost_Task(ctx, parent.Client(), &req)
if err != nil {
return err
}
logger := cmd.ProgressLogger(fmt.Sprintf("adding %s to folder %s... ", spec.HostName, parent.InventoryPath))
defer logger.Wait()
task := object.NewTask(parent.Client(), res.Returnval)
_, err = task.WaitForResult(ctx, logger)
return err
}
开发者ID:vmware,项目名称:vic,代码行数:21,代码来源:add.go
示例8: addStandaloneHost
func addStandaloneHost(folder *object.Folder, spec types.HostConnectSpec) (*object.Task, error) {
// TODO: add govmomi wrapper
req := types.AddStandaloneHost_Task{
This: folder.Reference(),
Spec: spec,
AddConnected: true,
}
res, err := methods.AddStandaloneHost_Task(context.TODO(), folder.Client(), &req)
if err != nil {
return nil, err
}
task := object.NewTask(folder.Client(), res.Returnval)
return task, nil
}
开发者ID:jak-atx,项目名称:vic,代码行数:16,代码来源:folder_test.go
示例9: Run
func (cmd *add) Run(f *flag.FlagSet) error {
var ctx = context.Background()
var parent *object.Folder
client, err := cmd.Client()
if err != nil {
return err
}
if cmd.parent == "" {
dc, err := cmd.Datacenter()
if err != nil {
return err
}
folders, err := dc.Folders(ctx)
if err != nil {
return err
}
parent = folders.HostFolder
} else {
finder, err := cmd.Finder()
if err != nil {
return err
}
mo, err := finder.ManagedObjectList(ctx, cmd.parent)
if err != nil {
return err
}
if len(mo) == 0 {
return errors.New("parent does not resolve to object")
}
if len(mo) > 1 {
return errors.New("parent resolves to more than one object")
}
ref := mo[0].Object.Reference()
if ref.Type != "Folder" {
return errors.New("parent does not resolve to folder")
}
parent = object.NewFolder(client, ref)
}
req := types.AddStandaloneHost_Task{
This: parent.Reference(),
Spec: types.HostConnectSpec{
HostName: cmd.host,
UserName: cmd.username,
Password: cmd.password,
SslThumbprint: cmd.fingerprint,
},
AddConnected: cmd.connect,
}
res, err := methods.AddStandaloneHost_Task(ctx, client, &req)
if err != nil {
return err
}
task := object.NewTask(client, res.Returnval)
_, err = task.WaitForResult(ctx, nil)
if err != nil {
f, ok := err.(types.HasFault)
if !ok {
return err
}
switch fault := f.Fault().(type) {
case *types.SSLVerifyFault:
// Add fingerprint to error message
return fmt.Errorf("%s Fingerprint is %s.", err.Error(), fault.Thumbprint)
default:
return err
}
}
return nil
}
开发者ID:MerlinDMC,项目名称:machine,代码行数:83,代码来源:add.go
注:本文中的github.com/vmware/govmomi/object.Folder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论