github.com/vmware/govmomi@v0.51.0/object/host_vsan_internal_system.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 "encoding/json" 10 11 "github.com/vmware/govmomi/vim25" 12 "github.com/vmware/govmomi/vim25/methods" 13 "github.com/vmware/govmomi/vim25/types" 14 ) 15 16 type HostVsanInternalSystem struct { 17 Common 18 } 19 20 func NewHostVsanInternalSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostVsanInternalSystem { 21 m := HostVsanInternalSystem{ 22 Common: NewCommon(c, ref), 23 } 24 25 return &m 26 } 27 28 // QueryVsanObjectUuidsByFilter returns vSAN DOM object uuids by filter. 29 func (m HostVsanInternalSystem) QueryVsanObjectUuidsByFilter(ctx context.Context, uuids []string, limit int32, version int32) ([]string, error) { 30 req := types.QueryVsanObjectUuidsByFilter{ 31 This: m.Reference(), 32 Uuids: uuids, 33 Limit: &limit, 34 Version: version, 35 } 36 37 res, err := methods.QueryVsanObjectUuidsByFilter(ctx, m.Client(), &req) 38 if err != nil { 39 return nil, err 40 } 41 42 return res.Returnval, nil 43 } 44 45 type VsanObjExtAttrs struct { 46 Type string `json:"Object type"` 47 Class string `json:"Object class"` 48 Size string `json:"Object size"` 49 Path string `json:"Object path"` 50 Name string `json:"User friendly name"` 51 } 52 53 func (a *VsanObjExtAttrs) DatastorePath(dir string) string { 54 l := len(dir) 55 path := a.Path 56 57 if len(path) >= l { 58 path = a.Path[l:] 59 } 60 61 if path != "" { 62 return path 63 } 64 65 return a.Name // vmnamespace 66 } 67 68 // GetVsanObjExtAttrs is internal and intended for troubleshooting/debugging situations in the field. 69 // WARNING: This API can be slow because we do IOs (reads) to all the objects. 70 func (m HostVsanInternalSystem) GetVsanObjExtAttrs(ctx context.Context, uuids []string) (map[string]VsanObjExtAttrs, error) { 71 req := types.GetVsanObjExtAttrs{ 72 This: m.Reference(), 73 Uuids: uuids, 74 } 75 76 res, err := methods.GetVsanObjExtAttrs(ctx, m.Client(), &req) 77 if err != nil { 78 return nil, err 79 } 80 81 var attrs map[string]VsanObjExtAttrs 82 83 err = json.Unmarshal([]byte(res.Returnval), &attrs) 84 85 return attrs, err 86 } 87 88 // DeleteVsanObjects is internal and intended for troubleshooting/debugging only. 89 // WARNING: This API can be slow because we do IOs to all the objects. 90 // DOM won't allow access to objects which have lost quorum. Such objects can be deleted with the optional "force" flag. 91 // These objects may however re-appear with quorum if the absent components come back (network partition gets resolved, etc.) 92 func (m HostVsanInternalSystem) DeleteVsanObjects(ctx context.Context, uuids []string, force *bool) ([]types.HostVsanInternalSystemDeleteVsanObjectsResult, error) { 93 req := types.DeleteVsanObjects{ 94 This: m.Reference(), 95 Uuids: uuids, 96 Force: force, 97 } 98 99 res, err := methods.DeleteVsanObjects(ctx, m.Client(), &req) 100 if err != nil { 101 return nil, err 102 } 103 104 return res.Returnval, nil 105 }