github.com/vmware/govmomi@v0.43.0/view/list_view.go (about)

     1  /*
     2  Copyright (c) 2015-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 view
    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 ListView struct {
    28  	ManagedObjectView
    29  }
    30  
    31  func NewListView(c *vim25.Client, ref types.ManagedObjectReference) *ListView {
    32  	return &ListView{
    33  		ManagedObjectView: *NewManagedObjectView(c, ref),
    34  	}
    35  }
    36  
    37  func (v ListView) Add(ctx context.Context, refs []types.ManagedObjectReference) ([]types.ManagedObjectReference, error) {
    38  	req := types.ModifyListView{
    39  		This: v.Reference(),
    40  		Add:  refs,
    41  	}
    42  	res, err := methods.ModifyListView(ctx, v.Client(), &req)
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  
    47  	return res.Returnval, nil
    48  }
    49  
    50  func (v ListView) Remove(ctx context.Context, refs []types.ManagedObjectReference) ([]types.ManagedObjectReference, error) {
    51  	req := types.ModifyListView{
    52  		This:   v.Reference(),
    53  		Remove: refs,
    54  	}
    55  	res, err := methods.ModifyListView(ctx, v.Client(), &req)
    56  	if err != nil {
    57  		return nil, err
    58  	}
    59  
    60  	return res.Returnval, nil
    61  }
    62  
    63  func (v ListView) Reset(ctx context.Context, refs []types.ManagedObjectReference) ([]types.ManagedObjectReference, error) {
    64  	req := types.ResetListView{
    65  		This: v.Reference(),
    66  		Obj:  refs,
    67  	}
    68  	res, err := methods.ResetListView(ctx, v.Client(), &req)
    69  	if err != nil {
    70  		return nil, err
    71  	}
    72  
    73  	return res.Returnval, nil
    74  }