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