github.com/vmware/govmomi@v0.51.0/vapi/esx/settings/depots/depots.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 depots
     6  
     7  import (
     8  	"context"
     9  	"fmt"
    10  	"net/http"
    11  
    12  	"github.com/vmware/govmomi/vapi/rest"
    13  )
    14  
    15  const (
    16  	basePath = "/api/esx/settings"
    17  	// DepotsOfflinePath The endpoint for the offline depots API
    18  	DepotsOfflinePath = basePath + "/depots/offline"
    19  	// DepotsOfflineContentPath The endpoint for retrieving the components in a depot
    20  	DepotsOfflineContentPath = DepotsOfflinePath + "/%s/content"
    21  	// BaseImagesPath The endpoint for retrieving the list of base ESXi images
    22  	BaseImagesPath = basePath + "/depot-content/base-images"
    23  )
    24  
    25  // Manager extends rest.Client, adding vLCM related methods.
    26  type Manager struct {
    27  	*rest.Client
    28  }
    29  
    30  // NewManager creates a new Manager instance with the given client.
    31  func NewManager(client *rest.Client) *Manager {
    32  	return &Manager{
    33  		Client: client,
    34  	}
    35  }
    36  
    37  type SourceType string
    38  
    39  const (
    40  	SourceTypePush = SourceType("PUSH")
    41  	SourceTypePull = SourceType("PULL")
    42  )
    43  
    44  // SettingsDepotsOfflineSummary is a type mapping for
    45  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/data-structures/Settings/Depots/Offline/Summary/
    46  type SettingsDepotsOfflineSummary struct {
    47  	Description string `json:"description"`
    48  	SourceType  string `json:"source_type"`
    49  	FileId      string `json:"file_id,omitempty"`
    50  	Location    string `json:"location,omitempty"`
    51  	Owner       string `json:"owner,omitempty"`
    52  	OwnerData   string `json:"owner_data,omitempty"`
    53  }
    54  
    55  // SettingsDepotsOfflineInfo is a type mapping for
    56  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/data-structures/Settings/Depots/Offline/Info/
    57  type SettingsDepotsOfflineInfo struct {
    58  	CreateTime  string `json:"create_time"`
    59  	Description string `json:"description"`
    60  	SourceType  string `json:"source_type"`
    61  	FileId      string `json:"file_id,omitempty"`
    62  	Location    string `json:"location,omitempty"`
    63  	Owner       string `json:"owner,omitempty"`
    64  	OwnerData   string `json:"owner_data,omitempty"`
    65  }
    66  
    67  // SettingsDepotsOfflineCreateSpec is a type mapping for
    68  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/data-structures/Settings/Depots/Offline/CreateSpec/
    69  type SettingsDepotsOfflineCreateSpec struct {
    70  	Description string `json:"description,omitempty"`
    71  	SourceType  string `json:"source_type"`
    72  	FileId      string `json:"file_id,omitempty"`
    73  	Location    string `json:"location,omitempty"`
    74  	OwnerData   string `json:"owner_data,omitempty"`
    75  }
    76  
    77  // SettingsDepotsComponentSummary is a type mapping for
    78  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/data-structures/Settings/Depots/ComponentSummary/
    79  type SettingsDepotsComponentSummary struct {
    80  	DisplayName string             `json:"display_name"`
    81  	Versions    []ComponentVersion `json:"versions"`
    82  }
    83  
    84  // ComponentVersion is a type mapping for
    85  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/data-structures/Settings/Depots/ComponentVersion/
    86  type ComponentVersion struct {
    87  	DisplayVersion string `json:"display_version"`
    88  	Version        string `json:"version"`
    89  }
    90  
    91  // SettingsDepotsMetadataInfo is a partial type mapping for
    92  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/data-structures/Settings/Depots/MetadataInfo/
    93  type SettingsDepotsMetadataInfo struct {
    94  	Addons                map[string]any                            `json:"addons,omitempty"`
    95  	BaseImages            []any                                     `json:"base_images,omitempty"`
    96  	FileName              string                                    `json:"file_name"`
    97  	HardwareSupport       map[string]any                            `json:"hardware_support,omitempty"`
    98  	IndependentComponents map[string]SettingsDepotsComponentSummary `json:"independent_components,omitempty"`
    99  	Solutions             map[string]any                            `json:"solutions,omitempty"`
   100  	Updates               map[string]any                            `json:"updates,omitempty"`
   101  }
   102  
   103  // SettingsDepotsOfflineContentInfo is a type mapping for
   104  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/data-structures/Settings/Depots/Offline/Content/Info/
   105  type SettingsDepotsOfflineContentInfo struct {
   106  	MetadataBundles map[string][]SettingsDepotsMetadataInfo `json:"metadata_bundles"`
   107  }
   108  
   109  // BaseImagesSummary is a type mapping for
   110  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/data-structures/Settings/DepotContent/BaseImages/Summary/
   111  type BaseImagesSummary struct {
   112  	DisplayName    string `json:"display_name"`
   113  	DisplayVersion string `json:"display_version"`
   114  	Kb             string `json:"kb"`
   115  	ReleaseDate    string `json:"release_date"`
   116  	Summary        string `json:"summary"`
   117  	Version        string `json:"version"`
   118  }
   119  
   120  // GetOfflineDepot retrieves an offline depot by its identifier
   121  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/api/esx/settings/depots/offline/depot/get/
   122  func (c *Manager) GetOfflineDepot(depotId string) (SettingsDepotsOfflineSummary, error) {
   123  	path := c.Resource(DepotsOfflinePath).WithSubpath(depotId)
   124  	req := path.Request(http.MethodGet)
   125  	var res SettingsDepotsOfflineSummary
   126  	return res, c.Do(context.Background(), req, &res)
   127  }
   128  
   129  // GetOfflineDepots retrieves all offline depots
   130  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/api/esx/settings/depots/offline/get/
   131  func (c *Manager) GetOfflineDepots() (map[string]SettingsDepotsOfflineInfo, error) {
   132  	path := c.Resource(DepotsOfflinePath)
   133  	req := path.Request(http.MethodGet)
   134  	var res map[string]SettingsDepotsOfflineInfo
   135  	return res, c.Do(context.Background(), req, &res)
   136  }
   137  
   138  // DeleteOfflineDepot triggers a task to delete an offline depot by its identifier
   139  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/api/esx/settings/depots/offline/depotvmw-tasktrue/delete/
   140  func (c *Manager) DeleteOfflineDepot(depotId string) (string, error) {
   141  	path := c.Resource(DepotsOfflinePath).WithSubpath(depotId).WithParam("vmw-task", "true")
   142  	req := path.Request(http.MethodDelete)
   143  	var res string
   144  	return res, c.Do(context.Background(), req, &res)
   145  }
   146  
   147  // CreateOfflineDepot triggers a task to create an offline depot
   148  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/api/esx/settings/depots/offlinevmw-tasktrue/post/
   149  func (c *Manager) CreateOfflineDepot(spec SettingsDepotsOfflineCreateSpec) (string, error) {
   150  	path := c.Resource(DepotsOfflinePath).WithParam("vmw-task", "true")
   151  	req := path.Request(http.MethodPost, spec)
   152  	var res string
   153  	return res, c.Do(context.Background(), req, &res)
   154  }
   155  
   156  // GetOfflineDepotContent retrieves the contents of a depot
   157  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/api/esx/settings/depots/offline/depot/content/get/
   158  func (c *Manager) GetOfflineDepotContent(depotId string) (SettingsDepotsOfflineContentInfo, error) {
   159  	path := c.Resource(fmt.Sprintf(DepotsOfflineContentPath, depotId))
   160  	req := path.Request(http.MethodGet)
   161  	var res SettingsDepotsOfflineContentInfo
   162  	return res, c.Do(context.Background(), req, &res)
   163  }
   164  
   165  // ListBaseImages retrieves the available ESXi versions
   166  // https://developer.vmware.com/apis/vsphere-automation/latest/esx/api/esx/settings/depot-content/base-images/get/
   167  func (c *Manager) ListBaseImages() ([]BaseImagesSummary, error) {
   168  	path := c.Resource(BaseImagesPath)
   169  	req := path.Request(http.MethodGet)
   170  	var res []BaseImagesSummary
   171  	return res, c.Do(context.Background(), req, &res)
   172  }