當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Folder.Reference方法代碼示例

本文整理匯總了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
}
開發者ID:jak-atx,項目名稱:vic,代碼行數:16,代碼來源:folder_test.go

示例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
}
開發者ID:kristinn,項目名稱:govmomi,代碼行數:21,代碼來源:add.go

示例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)
}
開發者ID:dnaeon,項目名稱:gru,代碼行數:37,代碼來源:vsphere_vm.go

示例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
}
開發者ID:MerlinDMC,項目名稱:machine,代碼行數:83,代碼來源:add.go


注:本文中的github.com/vmware/govmomi/object.Folder.Reference方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。