github.com/vmware/govmomi@v0.51.0/vapi/vcenter/consumptiondomains/zones/zones.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 zones
     6  
     7  import (
     8  	"context"
     9  	"net/http"
    10  
    11  	"github.com/vmware/govmomi/vapi/rest"
    12  )
    13  
    14  const (
    15  	basePath = "/api/vcenter/consumption-domains/zones"
    16  )
    17  
    18  // Manager extends rest.Client, adding vSphere Zone related methods.
    19  type Manager struct {
    20  	*rest.Client
    21  }
    22  
    23  // NewManager creates a new Manager instance with the given client.
    24  func NewManager(client *rest.Client) *Manager {
    25  	return &Manager{
    26  		Client: client,
    27  	}
    28  }
    29  
    30  // CreateSpec
    31  // https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/data-structures/ConsumptionDomains_Zones_CreateSpec
    32  type CreateSpec struct {
    33  	Zone        string `json:"zone"`
    34  	Description string `json:"description"`
    35  }
    36  
    37  // ZoneInfo
    38  // https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/data-structures/ConsumptionDomains_Zones_Info
    39  type ZoneInfo struct {
    40  	Description string `json:"description"`
    41  }
    42  
    43  // ListItem
    44  // https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/data-structures/ConsumptionDomains_Zones_ListItem
    45  type ListItem struct {
    46  	Zone string   `json:"zone"`
    47  	Info ZoneInfo `json:"info"`
    48  }
    49  
    50  // ListResult
    51  // https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/data-structures/ConsumptionDomains_Zones_ListResult
    52  type ListResult struct {
    53  	Items []ListItem `json:"items"`
    54  }
    55  
    56  // CreateZone creates a vSphere Zone. Returns the identifier of the new zone and an error if the operation fails
    57  // https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/consumption-domains/zones/post
    58  func (c *Manager) CreateZone(spec CreateSpec) (string, error) {
    59  	path := c.Resource(basePath)
    60  	req := path.Request(http.MethodPost, spec)
    61  	var res string
    62  	return res, c.Do(context.Background(), req, &res)
    63  }
    64  
    65  // DeleteZone deletes a vSphere Zone
    66  // https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/consumption-domains/zones/zone/delete
    67  func (c *Manager) DeleteZone(zone string) error {
    68  	path := c.Resource(basePath).WithSubpath(zone)
    69  	req := path.Request(http.MethodDelete)
    70  	return c.Do(context.Background(), req, nil)
    71  }
    72  
    73  // GetZone returns the details of a vSphere Zone
    74  // https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/consumption-domains/zones/zone/get
    75  func (c *Manager) GetZone(zone string) (ZoneInfo, error) {
    76  	path := c.Resource(basePath).WithSubpath(zone)
    77  	req := path.Request(http.MethodGet)
    78  	var res ZoneInfo
    79  	return res, c.Do(context.Background(), req, &res)
    80  }
    81  
    82  // ListZones returns the details of all vSphere Zones
    83  // https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/consumption-domains/zones/get
    84  func (c *Manager) ListZones() ([]ListItem, error) {
    85  	path := c.Resource(basePath)
    86  	req := path.Request(http.MethodGet)
    87  	var res ListResult
    88  
    89  	if err := c.Do(context.Background(), req, &res); err != nil {
    90  		return nil, err
    91  	}
    92  
    93  	return res.Items, nil
    94  }