github.com/vmware/govmomi@v0.43.0/view/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 view 18 19 import ( 20 "context" 21 22 "github.com/vmware/govmomi/object" 23 "github.com/vmware/govmomi/vim25" 24 "github.com/vmware/govmomi/vim25/methods" 25 "github.com/vmware/govmomi/vim25/types" 26 ) 27 28 type Manager struct { 29 object.Common 30 } 31 32 func NewManager(c *vim25.Client) *Manager { 33 m := Manager{ 34 object.NewCommon(c, *c.ServiceContent.ViewManager), 35 } 36 37 return &m 38 } 39 40 func (m Manager) CreateListView(ctx context.Context, objects []types.ManagedObjectReference) (*ListView, error) { 41 req := types.CreateListView{ 42 This: m.Common.Reference(), 43 Obj: objects, 44 } 45 46 res, err := methods.CreateListView(ctx, m.Client(), &req) 47 if err != nil { 48 return nil, err 49 } 50 51 return NewListView(m.Client(), res.Returnval), nil 52 } 53 54 func (m Manager) CreateContainerView(ctx context.Context, container types.ManagedObjectReference, managedObjectTypes []string, recursive bool) (*ContainerView, error) { 55 56 req := types.CreateContainerView{ 57 This: m.Common.Reference(), 58 Container: container, 59 Recursive: recursive, 60 Type: managedObjectTypes, 61 } 62 63 res, err := methods.CreateContainerView(ctx, m.Client(), &req) 64 if err != nil { 65 return nil, err 66 } 67 68 return NewContainerView(m.Client(), res.Returnval), nil 69 }