github.com/vmware/govmomi@v0.37.2/object/host_datastore_browser.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 HostDatastoreBrowser struct {
    28  	Common
    29  }
    30  
    31  func NewHostDatastoreBrowser(c *vim25.Client, ref types.ManagedObjectReference) *HostDatastoreBrowser {
    32  	return &HostDatastoreBrowser{
    33  		Common: NewCommon(c, ref),
    34  	}
    35  }
    36  
    37  func (b HostDatastoreBrowser) SearchDatastore(ctx context.Context, datastorePath string, searchSpec *types.HostDatastoreBrowserSearchSpec) (*Task, error) {
    38  	req := types.SearchDatastore_Task{
    39  		This:          b.Reference(),
    40  		DatastorePath: datastorePath,
    41  		SearchSpec:    searchSpec,
    42  	}
    43  
    44  	res, err := methods.SearchDatastore_Task(ctx, b.c, &req)
    45  	if err != nil {
    46  		return nil, err
    47  	}
    48  
    49  	return NewTask(b.c, res.Returnval), nil
    50  }
    51  
    52  func (b HostDatastoreBrowser) SearchDatastoreSubFolders(ctx context.Context, datastorePath string, searchSpec *types.HostDatastoreBrowserSearchSpec) (*Task, error) {
    53  	req := types.SearchDatastoreSubFolders_Task{
    54  		This:          b.Reference(),
    55  		DatastorePath: datastorePath,
    56  		SearchSpec:    searchSpec,
    57  	}
    58  
    59  	res, err := methods.SearchDatastoreSubFolders_Task(ctx, b.c, &req)
    60  	if err != nil {
    61  		return nil, err
    62  	}
    63  
    64  	return NewTask(b.c, res.Returnval), nil
    65  }