github.com/vmware/govmomi@v0.37.1/vapi/namespace/supervisorsvc.go (about) 1 /* 2 Copyright (c) 2021 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 namespace 18 19 import ( 20 "context" 21 "net/http" 22 "path" 23 24 "github.com/vmware/govmomi/vapi/namespace/internal" 25 ) 26 27 // SupervisorServiceSummary for a supervisor service existent in vSphere. 28 type SupervisorServiceSummary struct { 29 ID string `json:"supervisor_service"` 30 Name string `json:"display_name"` 31 State string `json:"state"` 32 } 33 34 // SupervisorServiceInfo for a supervisor service existent in vSphere. 35 type SupervisorServiceInfo struct { 36 Name string `json:"display_name"` 37 State string `json:"state"` 38 Description string `json:"description"` 39 } 40 41 // SupervisorService defines a new SupervisorService specification 42 type SupervisorService struct { 43 VsphereService SupervisorServicesVSphereSpec `json:"vsphere_spec,omitempty"` 44 } 45 46 // SupervisorServicesVSphereSpec defines a new SupervisorService specification of vSphere type 47 type SupervisorServicesVSphereSpec struct { 48 VersionSpec SupervisorServicesVSphereVersionCreateSpec `json:"version_spec"` 49 } 50 51 // SupervisorServicesVSphereVersionCreateSpec defines a new SupervisorService specification for vSphere 52 type SupervisorServicesVSphereVersionCreateSpec struct { 53 Content string `json:"content"` 54 TrustedProvider bool `json:"trusted_provider,omitempty"` 55 AcceptEula bool `json:"accept_EULA,omitempty"` 56 } 57 58 // CreateSupervisorService creates a new Supervisor Service on vSphere Namespaces endpoint. 59 func (c *Manager) CreateSupervisorService(ctx context.Context, service *SupervisorService) error { 60 url := c.Resource(internal.SupervisorServicesPath) 61 return c.Do(ctx, url.Request(http.MethodPost, service), nil) 62 } 63 64 // ListSupervisorServices returns a summary of all clusters with vSphere Namespaces enabled. 65 func (c *Manager) ListSupervisorServices(ctx context.Context) ([]SupervisorServiceSummary, error) { 66 var res []SupervisorServiceSummary 67 url := c.Resource(internal.SupervisorServicesPath) 68 return res, c.Do(ctx, url.Request(http.MethodGet), &res) 69 } 70 71 // GetSupervisorService gets the information of a specific supervisor service. 72 func (c *Manager) GetSupervisorService(ctx context.Context, id string) (SupervisorServiceInfo, error) { 73 var res SupervisorServiceInfo 74 url := c.Resource(path.Join(internal.SupervisorServicesPath, id)) 75 return res, c.Do(ctx, url.Request(http.MethodGet, nil), &res) 76 } 77 78 // ActivateSupervisorServices activates a previously registered Supervisor Service. 79 func (c *Manager) ActivateSupervisorServices(ctx context.Context, id string) error { 80 url := c.Resource(path.Join(internal.SupervisorServicesPath, id)).WithParam("action", "activate") 81 err := c.Do(ctx, url.Request(http.MethodPatch, nil), nil) 82 return err 83 } 84 85 // DeactivateSupervisorServices deactivates a previously registered Supervisor Service. 86 func (c *Manager) DeactivateSupervisorServices(ctx context.Context, id string) error { 87 url := c.Resource(path.Join(internal.SupervisorServicesPath, id)).WithParam("action", "deactivate") 88 err := c.Do(ctx, url.Request(http.MethodPatch, nil), nil) 89 return err 90 } 91 92 // RemoveSupervisorService removes a previously deactivated supervisor service. 93 func (c *Manager) RemoveSupervisorService(ctx context.Context, id string) error { 94 url := c.Resource(path.Join(internal.SupervisorServicesPath, id)) 95 err := c.Do(ctx, url.Request(http.MethodDelete, nil), nil) 96 return err 97 }