github.com/vmware/govmomi@v0.37.1/object/diagnostic_manager.go (about) 1 /* 2 Copyright (c) 2015 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 22 "github.com/vmware/govmomi/vim25" 23 "github.com/vmware/govmomi/vim25/methods" 24 "github.com/vmware/govmomi/vim25/types" 25 ) 26 27 type DiagnosticManager struct { 28 Common 29 } 30 31 func NewDiagnosticManager(c *vim25.Client) *DiagnosticManager { 32 m := DiagnosticManager{ 33 Common: NewCommon(c, *c.ServiceContent.DiagnosticManager), 34 } 35 36 return &m 37 } 38 39 func (m DiagnosticManager) Log(ctx context.Context, host *HostSystem, key string) *DiagnosticLog { 40 return &DiagnosticLog{ 41 m: m, 42 Key: key, 43 Host: host, 44 } 45 } 46 47 func (m DiagnosticManager) BrowseLog(ctx context.Context, host *HostSystem, key string, start, lines int32) (*types.DiagnosticManagerLogHeader, error) { 48 req := types.BrowseDiagnosticLog{ 49 This: m.Reference(), 50 Key: key, 51 Start: start, 52 Lines: lines, 53 } 54 55 if host != nil { 56 ref := host.Reference() 57 req.Host = &ref 58 } 59 60 res, err := methods.BrowseDiagnosticLog(ctx, m.Client(), &req) 61 if err != nil { 62 return nil, err 63 } 64 65 return &res.Returnval, nil 66 } 67 68 func (m DiagnosticManager) GenerateLogBundles(ctx context.Context, includeDefault bool, host []*HostSystem) (*Task, error) { 69 req := types.GenerateLogBundles_Task{ 70 This: m.Reference(), 71 IncludeDefault: includeDefault, 72 } 73 74 for _, h := range host { 75 req.Host = append(req.Host, h.Reference()) 76 } 77 78 res, err := methods.GenerateLogBundles_Task(ctx, m.c, &req) 79 if err != nil { 80 return nil, err 81 } 82 83 return NewTask(m.c, res.Returnval), nil 84 } 85 86 func (m DiagnosticManager) QueryDescriptions(ctx context.Context, host *HostSystem) ([]types.DiagnosticManagerLogDescriptor, error) { 87 req := types.QueryDescriptions{ 88 This: m.Reference(), 89 } 90 91 if host != nil { 92 ref := host.Reference() 93 req.Host = &ref 94 } 95 96 res, err := methods.QueryDescriptions(ctx, m.Client(), &req) 97 if err != nil { 98 return nil, err 99 } 100 101 return res.Returnval, nil 102 }