github.com/vmware/govmomi@v0.43.0/object/host_vsan_internal_system.go (about) 1 /* 2 Copyright (c) 2017 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package object 18 19 import ( 20 "context" 21 "encoding/json" 22 23 "github.com/vmware/govmomi/vim25" 24 "github.com/vmware/govmomi/vim25/methods" 25 "github.com/vmware/govmomi/vim25/types" 26 ) 27 28 type HostVsanInternalSystem struct { 29 Common 30 } 31 32 func NewHostVsanInternalSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostVsanInternalSystem { 33 m := HostVsanInternalSystem{ 34 Common: NewCommon(c, ref), 35 } 36 37 return &m 38 } 39 40 // QueryVsanObjectUuidsByFilter returns vSAN DOM object uuids by filter. 41 func (m HostVsanInternalSystem) QueryVsanObjectUuidsByFilter(ctx context.Context, uuids []string, limit int32, version int32) ([]string, error) { 42 req := types.QueryVsanObjectUuidsByFilter{ 43 This: m.Reference(), 44 Uuids: uuids, 45 Limit: &limit, 46 Version: version, 47 } 48 49 res, err := methods.QueryVsanObjectUuidsByFilter(ctx, m.Client(), &req) 50 if err != nil { 51 return nil, err 52 } 53 54 return res.Returnval, nil 55 } 56 57 type VsanObjExtAttrs struct { 58 Type string `json:"Object type"` 59 Class string `json:"Object class"` 60 Size string `json:"Object size"` 61 Path string `json:"Object path"` 62 Name string `json:"User friendly name"` 63 } 64 65 func (a *VsanObjExtAttrs) DatastorePath(dir string) string { 66 l := len(dir) 67 path := a.Path 68 69 if len(path) >= l { 70 path = a.Path[l:] 71 } 72 73 if path != "" { 74 return path 75 } 76 77 return a.Name // vmnamespace 78 } 79 80 // GetVsanObjExtAttrs is internal and intended for troubleshooting/debugging situations in the field. 81 // WARNING: This API can be slow because we do IOs (reads) to all the objects. 82 func (m HostVsanInternalSystem) GetVsanObjExtAttrs(ctx context.Context, uuids []string) (map[string]VsanObjExtAttrs, error) { 83 req := types.GetVsanObjExtAttrs{ 84 This: m.Reference(), 85 Uuids: uuids, 86 } 87 88 res, err := methods.GetVsanObjExtAttrs(ctx, m.Client(), &req) 89 if err != nil { 90 return nil, err 91 } 92 93 var attrs map[string]VsanObjExtAttrs 94 95 err = json.Unmarshal([]byte(res.Returnval), &attrs) 96 97 return attrs, err 98 } 99 100 // DeleteVsanObjects is internal and intended for troubleshooting/debugging only. 101 // WARNING: This API can be slow because we do IOs to all the objects. 102 // DOM won't allow access to objects which have lost quorum. Such objects can be deleted with the optional "force" flag. 103 // These objects may however re-appear with quorum if the absent components come back (network partition gets resolved, etc.) 104 func (m HostVsanInternalSystem) DeleteVsanObjects(ctx context.Context, uuids []string, force *bool) ([]types.HostVsanInternalSystemDeleteVsanObjectsResult, error) { 105 req := types.DeleteVsanObjects{ 106 This: m.Reference(), 107 Uuids: uuids, 108 Force: force, 109 } 110 111 res, err := methods.DeleteVsanObjects(ctx, m.Client(), &req) 112 if err != nil { 113 return nil, err 114 } 115 116 return res.Returnval, nil 117 }