github.com/vmware/govmomi@v0.37.2/vapi/library/library_file.go (about)

     1  /*
     2  Copyright (c) 2018 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 library
    18  
    19  import (
    20  	"context"
    21  	"net/http"
    22  
    23  	"github.com/vmware/govmomi/vapi/internal"
    24  )
    25  
    26  // Checksum provides checksum information on library item files.
    27  type Checksum struct {
    28  	Algorithm string `json:"algorithm,omitempty"`
    29  	Checksum  string `json:"checksum"`
    30  }
    31  
    32  // File provides methods to get information on library item files.
    33  type File struct {
    34  	Cached           *bool     `json:"cached,omitempty"`
    35  	Checksum         *Checksum `json:"checksum_info,omitempty"`
    36  	Name             string    `json:"name,omitempty"`
    37  	Size             *int64    `json:"size,omitempty"`
    38  	Version          string    `json:"version,omitempty"`
    39  	DownloadEndpoint string    `json:"file_download_endpoint,omitempty"`
    40  }
    41  
    42  // ListLibraryItemFiles returns a list of all the files for a library item.
    43  func (c *Manager) ListLibraryItemFiles(ctx context.Context, id string) ([]File, error) {
    44  	url := c.Resource(internal.LibraryItemFilePath).WithParam("library_item_id", id)
    45  	var res []File
    46  	return res, c.Do(ctx, url.Request(http.MethodGet), &res)
    47  }
    48  
    49  // GetLibraryItemFile returns a file with the provided name for a library item.
    50  func (c *Manager) GetLibraryItemFile(ctx context.Context, id, fileName string) (*File, error) {
    51  	url := c.Resource(internal.LibraryItemFilePath).WithID(id).WithAction("get")
    52  	spec := struct {
    53  		Name string `json:"name"`
    54  	}{fileName}
    55  	var res File
    56  	return &res, c.Do(ctx, url.Request(http.MethodPost, spec), &res)
    57  }