github.com/vmware/govmomi@v0.43.0/event/history_collector.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 event 18 19 import ( 20 "context" 21 22 "github.com/vmware/govmomi/history" 23 "github.com/vmware/govmomi/vim25" 24 "github.com/vmware/govmomi/vim25/methods" 25 "github.com/vmware/govmomi/vim25/mo" 26 "github.com/vmware/govmomi/vim25/types" 27 ) 28 29 type HistoryCollector struct { 30 *history.Collector 31 } 32 33 func newHistoryCollector(c *vim25.Client, ref types.ManagedObjectReference) *HistoryCollector { 34 return &HistoryCollector{ 35 Collector: history.NewCollector(c, ref), 36 } 37 } 38 39 func (h HistoryCollector) LatestPage(ctx context.Context) ([]types.BaseEvent, error) { 40 var o mo.EventHistoryCollector 41 42 err := h.Properties(ctx, h.Reference(), []string{"latestPage"}, &o) 43 if err != nil { 44 return nil, err 45 } 46 47 return o.LatestPage, nil 48 } 49 50 func (h HistoryCollector) ReadNextEvents(ctx context.Context, maxCount int32) ([]types.BaseEvent, error) { 51 req := types.ReadNextEvents{ 52 This: h.Reference(), 53 MaxCount: maxCount, 54 } 55 56 res, err := methods.ReadNextEvents(ctx, h.Client(), &req) 57 if err != nil { 58 return nil, err 59 } 60 61 return res.Returnval, nil 62 } 63 64 func (h HistoryCollector) ReadPreviousEvents(ctx context.Context, maxCount int32) ([]types.BaseEvent, error) { 65 req := types.ReadPreviousEvents{ 66 This: h.Reference(), 67 MaxCount: maxCount, 68 } 69 70 res, err := methods.ReadPreviousEvents(ctx, h.Client(), &req) 71 if err != nil { 72 return nil, err 73 } 74 75 return res.Returnval, nil 76 }