github.com/vmware/govmomi@v0.51.0/object/vm_provisioning_checker.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package object
     6  
     7  import (
     8  	"context"
     9  
    10  	"github.com/vmware/govmomi/vim25"
    11  	"github.com/vmware/govmomi/vim25/methods"
    12  	"github.com/vmware/govmomi/vim25/types"
    13  )
    14  
    15  // VmProvisioningChecker models the ProvisioningChecker, a singleton managed
    16  // object that can answer questions about the feasibility of certain
    17  // provisioning operations.
    18  //
    19  // For more information, see:
    20  // https://dp-downloads.broadcom.com/api-content/apis/API_VWSA_001/8.0U3/html/ReferenceGuides/vim.vm.check.ProvisioningChecker.html
    21  type VmProvisioningChecker struct {
    22  	Common
    23  }
    24  
    25  func NewVmProvisioningChecker(c *vim25.Client) *VmProvisioningChecker {
    26  	return &VmProvisioningChecker{
    27  		Common: NewCommon(c, *c.ServiceContent.VmProvisioningChecker),
    28  	}
    29  }
    30  
    31  func (c VmProvisioningChecker) CheckRelocate(
    32  	ctx context.Context,
    33  	vm types.ManagedObjectReference,
    34  	spec types.VirtualMachineRelocateSpec,
    35  	testTypes ...types.CheckTestType) ([]types.CheckResult, error) {
    36  
    37  	req := types.CheckRelocate_Task{
    38  		This:     c.Reference(),
    39  		Vm:       vm,
    40  		Spec:     spec,
    41  		TestType: checkTestTypesToStrings(testTypes),
    42  	}
    43  
    44  	res, err := methods.CheckRelocate_Task(ctx, c.c, &req)
    45  	if err != nil {
    46  		return nil, err
    47  	}
    48  
    49  	ti, err := NewTask(c.c, res.Returnval).WaitForResult(ctx)
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	return ti.Result.(types.ArrayOfCheckResult).CheckResult, nil
    55  }