本文整理汇总了Golang中github.com/vmware/vic/pkg/vsphere/session.Session.Folders方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Folders方法的具体用法?Golang Session.Folders怎么用?Golang Session.Folders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/vic/pkg/vsphere/session.Session
的用法示例。
在下文中一共展示了Session.Folders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createNodes
func createNodes(ctx context.Context, sess *session.Session, pool *object.ResourcePool, node *Node, base string) error {
log.Debugf("create node %+v", node)
if node == nil {
return nil
}
spec := simulator.NewResourceConfigSpec()
node.Name = fmt.Sprintf("%s-%s", base, node.Name)
switch node.Kind {
case rpNode:
child, err := pool.Create(ctx, node.Name, spec)
if err != nil {
return err
}
for _, childNode := range node.Children {
return createNodes(ctx, sess, child, childNode, base)
}
case vappNode:
confSpec := types.VAppConfigSpec{
VmConfigSpec: types.VmConfigSpec{},
}
vapp, err := pool.CreateVApp(ctx, node.Name, spec, confSpec, nil)
if err != nil {
return err
}
config := types.VirtualMachineConfigSpec{
Name: node.Name,
GuestId: string(types.VirtualMachineGuestOsIdentifierOtherGuest),
Files: &types.VirtualMachineFileInfo{
VmPathName: fmt.Sprintf("[LocalDS_0] %s", node.Name),
},
}
if _, err = tasks.WaitForResult(ctx, func(ctx context.Context) (tasks.Task, error) {
return vapp.CreateChildVM_Task(ctx, config, nil)
}); err != nil {
return err
}
case vmNode:
config := types.VirtualMachineConfigSpec{
Name: node.Name,
GuestId: string(types.VirtualMachineGuestOsIdentifierOtherGuest),
Files: &types.VirtualMachineFileInfo{
VmPathName: fmt.Sprintf("[LocalDS_0] %s", node.Name),
},
}
folder := sess.Folders(ctx).VmFolder
if _, err := tasks.WaitForResult(ctx, func(ctx context.Context) (tasks.Task, error) {
return folder.CreateVM(ctx, config, pool, nil)
}); err != nil {
return err
}
default:
return nil
}
return nil
}