github.com/vmware/govmomi@v0.51.0/vapi/library/library_item_downloadsession_file.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package library 6 7 import ( 8 "context" 9 "net/http" 10 11 "github.com/vmware/govmomi/vapi/internal" 12 "github.com/vmware/govmomi/vapi/rest" 13 ) 14 15 // DownloadFile is the specification for the downloadsession 16 // operations file:add, file:get, and file:list. 17 type DownloadFile struct { 18 BytesTransferred int64 `json:"bytes_transferred"` 19 Checksum *Checksum `json:"checksum_info,omitempty"` 20 DownloadEndpoint *TransferEndpoint `json:"download_endpoint,omitempty"` 21 ErrorMessage *rest.LocalizableMessage `json:"error_message,omitempty"` 22 Name string `json:"name"` 23 Size int64 `json:"size,omitempty"` 24 Status string `json:"status"` 25 } 26 27 // GetLibraryItemDownloadSessionFile retrieves information about a specific file that is a part of an download session. 28 func (c *Manager) GetLibraryItemDownloadSessionFile(ctx context.Context, sessionID string, name string) (*DownloadFile, error) { 29 url := c.Resource(internal.LibraryItemDownloadSessionFile).WithID(sessionID).WithAction("get") 30 spec := struct { 31 Name string `json:"file_name"` 32 }{name} 33 var res DownloadFile 34 err := c.Do(ctx, url.Request(http.MethodPost, spec), &res) 35 if err != nil { 36 return nil, err 37 } 38 if res.Status == "ERROR" { 39 return nil, res.ErrorMessage 40 } 41 return &res, nil 42 } 43 44 // ListLibraryItemDownloadSessionFile retrieves information about a specific file that is a part of an download session. 45 func (c *Manager) ListLibraryItemDownloadSessionFile(ctx context.Context, sessionID string) ([]DownloadFile, error) { 46 url := c.Resource(internal.LibraryItemDownloadSessionFile).WithParam("download_session_id", sessionID) 47 var res []DownloadFile 48 return res, c.Do(ctx, url.Request(http.MethodGet), &res) 49 } 50 51 // PrepareLibraryItemDownloadSessionFile retrieves information about a specific file that is a part of an download session. 52 func (c *Manager) PrepareLibraryItemDownloadSessionFile(ctx context.Context, sessionID string, name string) (*DownloadFile, error) { 53 url := c.Resource(internal.LibraryItemDownloadSessionFile).WithID(sessionID).WithAction("prepare") 54 spec := struct { 55 Name string `json:"file_name"` 56 }{name} 57 var res DownloadFile 58 return &res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) 59 }