github.com/vmware/govmomi@v0.51.0/vapi/namespace/supervisorsvc.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 namespace
     6  
     7  import (
     8  	"context"
     9  	"net/http"
    10  	"path"
    11  
    12  	"github.com/vmware/govmomi/vapi/namespace/internal"
    13  )
    14  
    15  // SupervisorServiceSummary for a supervisor service existent in vSphere.
    16  type SupervisorServiceSummary struct {
    17  	ID    string `json:"supervisor_service"`
    18  	Name  string `json:"display_name"`
    19  	State string `json:"state"`
    20  }
    21  
    22  // SupervisorServiceInfo for a supervisor service existent in vSphere.
    23  type SupervisorServiceInfo struct {
    24  	Name                         string `json:"display_name"`
    25  	State                        string `json:"state"`
    26  	Description                  string `json:"description"`
    27  	MustBeInstalled              bool   `json:"must_be_installed"`
    28  	HasDefaultVersionsRegistered bool   `json:"has_default_versions_registered"`
    29  }
    30  
    31  // SupervisorServiceVersionSummary describes a vSphere Supervisor Service version.
    32  type SupervisorServiceVersionSummary struct {
    33  	SupervisorServiceInfo
    34  	Version string `json:"version"`
    35  }
    36  
    37  // SupervisorServiceVersionInfo details a vSphere Supervisor Service version.
    38  type SupervisorServiceVersionInfo struct {
    39  	SupervisorServiceInfo
    40  	Eula                string `json:"EULA"`
    41  	Content             string `json:"content"`
    42  	ContentType         string `json:"content_type"`
    43  	TrustVerified       bool   `json:"trust_verified"`
    44  	RegisteredByDefault bool   `json:"registered_by_default"`
    45  }
    46  
    47  // SupervisorService defines a new SupervisorService specification
    48  type SupervisorService struct {
    49  	// The specification required to create a Supervisor Service with a version from inline content that is based on the vSphere application service format.
    50  	VsphereService *SupervisorServicesVSphereSpec `json:"vsphere_spec,omitempty"`
    51  	// The specification required to create a Supervisor Service with a version from inline content that is based on the Carvel application package format.
    52  	CarvelService *SupervisorServicesCarvelSpec `json:"carvel_spec,omitempty"`
    53  }
    54  
    55  // SupervisorServiceVersion defines a new SupervisorService version specification
    56  type SupervisorServiceVersion struct {
    57  	// The specification required to create a Supervisor Service with a version from inline content that is based on the vSphere application service format.
    58  	VsphereService *SupervisorServicesVSphereVersionCreateSpec `json:"vsphere_spec,omitempty"`
    59  	// The specification required to create a Supervisor Service with a version from inline content that is based on the Carvel application package format.
    60  	CarvelService *CarvelVersionCreateSpec `json:"carvel_spec,omitempty"`
    61  }
    62  
    63  // SupervisorServicesVSphereSpec defines a new SupervisorService specification of vSphere type
    64  type SupervisorServicesVSphereSpec struct {
    65  	VersionSpec SupervisorServicesVSphereVersionCreateSpec `json:"version_spec"`
    66  }
    67  
    68  // SupervisorServicesVSphereVersionCreateSpec defines a new SupervisorService specification for vSphere
    69  type SupervisorServicesVSphereVersionCreateSpec struct {
    70  	Content         string `json:"content"`
    71  	TrustedProvider bool   `json:"trusted_provider,omitempty"`
    72  	AcceptEula      bool   `json:"accept_EULA,omitempty"`
    73  }
    74  
    75  // The “SupervisorServicesCarvelSpec“ class provides a specification required to create a Supervisor Service with a version from Carvel application package format (Package and PackageMetadata resources should be declared).
    76  type SupervisorServicesCarvelSpec struct {
    77  	// Supervisor service version specification that provides the service definitions for one Supervisor Service version.
    78  	VersionSpec CarvelVersionCreateSpec `json:"version_spec"`
    79  }
    80  
    81  // The “CarvelVersionCreateSpec“ class provides a specification required to create a Supervisor Service version from Carvel application package format (Package and PackageMetadata resources should be declared).
    82  type CarvelVersionCreateSpec struct {
    83  	// Inline content that contains all service definition of the version in Carvel application package format, which shall be base64 encoded.
    84  	Content string `json:"content"`
    85  }
    86  
    87  // CreateSupervisorService creates a new Supervisor Service on vCenter.
    88  func (c *Manager) CreateSupervisorService(ctx context.Context, service *SupervisorService) error {
    89  	url := c.Resource(internal.SupervisorServicesPath)
    90  	return c.Do(ctx, url.Request(http.MethodPost, service), nil)
    91  }
    92  
    93  // ListSupervisorServices returns a summary of registered Supervisor Services.
    94  func (c *Manager) ListSupervisorServices(ctx context.Context) ([]SupervisorServiceSummary, error) {
    95  	var res []SupervisorServiceSummary
    96  	url := c.Resource(internal.SupervisorServicesPath)
    97  	return res, c.Do(ctx, url.Request(http.MethodGet), &res)
    98  }
    99  
   100  // GetSupervisorService gets the information of a specific Supervisor Service.
   101  func (c *Manager) GetSupervisorService(ctx context.Context, id string) (SupervisorServiceInfo, error) {
   102  	var res SupervisorServiceInfo
   103  	url := c.Resource(path.Join(internal.SupervisorServicesPath, id))
   104  	return res, c.Do(ctx, url.Request(http.MethodGet, nil), &res)
   105  }
   106  
   107  // ActivateSupervisorServices activates a previously registered Supervisor Service.
   108  func (c *Manager) ActivateSupervisorServices(ctx context.Context, id string) error {
   109  	url := c.Resource(path.Join(internal.SupervisorServicesPath, id)).WithParam("action", "activate")
   110  	return c.Do(ctx, url.Request(http.MethodPatch, nil), nil)
   111  }
   112  
   113  // DeactivateSupervisorServices deactivates a previously registered Supervisor Service.
   114  func (c *Manager) DeactivateSupervisorServices(ctx context.Context, id string) error {
   115  	url := c.Resource(path.Join(internal.SupervisorServicesPath, id)).WithParam("action", "deactivate")
   116  	return c.Do(ctx, url.Request(http.MethodPatch, nil), nil)
   117  }
   118  
   119  // RemoveSupervisorService removes a previously deactivated Supervisor Service.
   120  func (c *Manager) RemoveSupervisorService(ctx context.Context, id string) error {
   121  	url := c.Resource(path.Join(internal.SupervisorServicesPath, id))
   122  	err := c.Do(ctx, url.Request(http.MethodDelete, nil), nil)
   123  	return err
   124  }
   125  
   126  // ListSupervisorServiceVersions lists all versions of the given Supervisor Service.
   127  // https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/get/
   128  func (c *Manager) ListSupervisorServiceVersions(ctx context.Context, id string) ([]SupervisorServiceVersionSummary, error) {
   129  	var res []SupervisorServiceVersionSummary
   130  	url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath))
   131  	return res, c.Do(ctx, url.Request(http.MethodGet), &res)
   132  }
   133  
   134  // RemoveSupervisorServiceVersion removes a previously deactivated Supervisor Service version.
   135  // https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/version/delete/
   136  func (c *Manager) RemoveSupervisorServiceVersion(ctx context.Context, id string, version string) error {
   137  	url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath, version))
   138  	err := c.Do(ctx, url.Request(http.MethodDelete, nil), nil)
   139  	return err
   140  }
   141  
   142  // CreateSupervisorServiceVersion creates a new version for an existing Supervisor Service.
   143  // https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/post/
   144  func (c *Manager) CreateSupervisorServiceVersion(ctx context.Context, id string, service *SupervisorServiceVersion) error {
   145  	url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath))
   146  	return c.Do(ctx, url.Request(http.MethodPost, service), nil)
   147  }
   148  
   149  // DeactivateSupervisorServiceVersion deactivates a version of an existing Supervisor Service.
   150  // https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/versionactiondeactivate/patch/
   151  func (c *Manager) DeactivateSupervisorServiceVersion(ctx context.Context, id string, version string) error {
   152  	url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath, version)).WithParam("action", "deactivate")
   153  	return c.Do(ctx, url.Request(http.MethodPatch, nil), nil)
   154  }
   155  
   156  // ActivateSupervisorServiceVersion activates a version of an existing Supervisor Service.
   157  // https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/versionactiondeactivate/patch/
   158  func (c *Manager) ActivateSupervisorServiceVersion(ctx context.Context, id string, version string) error {
   159  	url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath, version)).WithParam("action", "activate")
   160  	return c.Do(ctx, url.Request(http.MethodPatch, nil), nil)
   161  }
   162  
   163  // GetSupervisorServiceVersion gets the information of a specific Supervisor Service version.
   164  // https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/version/get/
   165  func (c *Manager) GetSupervisorServiceVersion(ctx context.Context, id string, version string) (SupervisorServiceVersionInfo, error) {
   166  	var res SupervisorServiceVersionInfo
   167  	url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath, version))
   168  	return res, c.Do(ctx, url.Request(http.MethodGet, nil), &res)
   169  }