github.com/vmware/govmomi@v0.37.2/vapi/esx/settings/depots/depots.go (about)

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