github.com/vmware/govmomi@v0.51.0/object/vm_compatability_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 // VmCompatibilityChecker models the CompatibilityChecker, a singleton managed 16 // object that can answer questions about compatibility of a virtual machine 17 // with a host. 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.CompatibilityChecker.html 21 type VmCompatibilityChecker struct { 22 Common 23 } 24 25 func NewVmCompatibilityChecker(c *vim25.Client) *VmCompatibilityChecker { 26 return &VmCompatibilityChecker{ 27 Common: NewCommon(c, *c.ServiceContent.VmCompatibilityChecker), 28 } 29 } 30 31 func (c VmCompatibilityChecker) CheckCompatibility( 32 ctx context.Context, 33 vm types.ManagedObjectReference, 34 host *types.ManagedObjectReference, 35 pool *types.ManagedObjectReference, 36 testTypes ...types.CheckTestType) ([]types.CheckResult, error) { 37 38 req := types.CheckCompatibility_Task{ 39 This: c.Reference(), 40 Vm: vm, 41 Host: host, 42 Pool: pool, 43 TestType: checkTestTypesToStrings(testTypes), 44 } 45 46 res, err := methods.CheckCompatibility_Task(ctx, c.c, &req) 47 if err != nil { 48 return nil, err 49 } 50 51 ti, err := NewTask(c.c, res.Returnval).WaitForResult(ctx) 52 if err != nil { 53 return nil, err 54 } 55 56 return ti.Result.(types.ArrayOfCheckResult).CheckResult, nil 57 } 58 59 func (c VmCompatibilityChecker) CheckVmConfig( 60 ctx context.Context, 61 spec types.VirtualMachineConfigSpec, 62 vm *types.ManagedObjectReference, 63 host *types.ManagedObjectReference, 64 pool *types.ManagedObjectReference, 65 testTypes ...types.CheckTestType) ([]types.CheckResult, error) { 66 67 req := types.CheckVmConfig_Task{ 68 This: c.Reference(), 69 Spec: spec, 70 Vm: vm, 71 Host: host, 72 Pool: pool, 73 TestType: checkTestTypesToStrings(testTypes), 74 } 75 76 res, err := methods.CheckVmConfig_Task(ctx, c.c, &req) 77 if err != nil { 78 return nil, err 79 } 80 81 ti, err := NewTask(c.c, res.Returnval).WaitForResult(ctx) 82 if err != nil { 83 return nil, err 84 } 85 86 return ti.Result.(types.ArrayOfCheckResult).CheckResult, nil 87 } 88 89 func checkTestTypesToStrings(testTypes []types.CheckTestType) []string { 90 if len(testTypes) == 0 { 91 return nil 92 } 93 94 s := make([]string, len(testTypes)) 95 for i := range testTypes { 96 s[i] = string(testTypes[i]) 97 } 98 return s 99 }