Skip to content

Commit 74eea10

Browse files
committed
api: add bindings for esx/settings/cluster/enablement/configuration/transition
Signed-off-by: Stoyan Zhelyazkov <[email protected]>
1 parent 7d04264 commit 74eea10

File tree

4 files changed

+118
-6
lines changed

4 files changed

+118
-6
lines changed

vapi/esx/settings/clusters/clusters.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ import (
1010
"net/http"
1111
"strings"
1212

13+
"github.com/vmware/govmomi/vapi/esx/settings"
1314
"github.com/vmware/govmomi/vapi/rest"
1415
)
1516

1617
const (
17-
basePath = "/api/esx/settings"
18+
// BasePath The base endpoint for the clusters API
19+
BasePath = settings.BasePath + "/clusters"
1820
// SoftwareDraftsPath The endpoint for the software drafts API
19-
SoftwareDraftsPath = basePath + "/clusters/%s/software/drafts"
21+
SoftwareDraftsPath = BasePath + "/%s/software/drafts"
2022
// SoftwareComponentsPath The endpoint for retrieving the custom components in a software draft
2123
SoftwareComponentsPath = SoftwareDraftsPath + "/%s/software/components"
2224
// BaseImagePath The endpoint for retrieving the base image of a software draft
2325
BaseImagePath = SoftwareDraftsPath + "/%s/software/base-image"
2426
// SoftwareEnablementPath The endpoint for retrieving the vLCM status (enabled/disabled) of a cluster
25-
SoftwareEnablementPath = basePath + "/clusters/%s/enablement/software"
27+
SoftwareEnablementPath = BasePath + "/%s/enablement/software"
2628
)
2729

2830
// Manager extends rest.Client, adding Software Drafts related methods.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 enablement
6+
7+
import (
8+
"context"
9+
"fmt"
10+
"net/http"
11+
12+
"github.com/vmware/govmomi/vapi/esx/settings"
13+
"github.com/vmware/govmomi/vapi/rest"
14+
)
15+
16+
const (
17+
// BasePath The base endpoint for the clusters configuration enablement API
18+
BasePath = settings.BasePath + "/%s/enablement"
19+
Configuration = BasePath + "/configuration"
20+
Transition = Configuration + "/transition"
21+
)
22+
23+
type FileSpec struct {
24+
Config string `json:"config"`
25+
Filename string `json:"filename"`
26+
}
27+
28+
// Manager extends rest.Client, adding cluster configuration enablement related methods.
29+
type Manager struct {
30+
*rest.Client
31+
}
32+
33+
// NewManager creates a new Manager instance with the given client.
34+
func NewManager(client *rest.Client) *Manager {
35+
return &Manager{
36+
Client: client,
37+
}
38+
}
39+
40+
// EnableClusterConfiguration enables cluster configuration profiles
41+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
42+
func (c *Manager) EnableClusterConfiguration(clusterId string) (string, error) {
43+
path := c.getBaseTransitionUrl(clusterId, "enable")
44+
req := path.Request(http.MethodPost, nil)
45+
var res string
46+
return res, c.Do(context.Background(), req, &res)
47+
}
48+
49+
// ImportFromReferenceHost imports the configuration of an existing ESXi host
50+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
51+
func (c *Manager) ImportFromReferenceHost(clusterId, hostId string) (string, error) {
52+
path := c.getBaseTransitionUrl(clusterId, "importFromHost")
53+
req := path.Request(http.MethodPost, hostId)
54+
var res string
55+
return res, c.Do(context.Background(), req, &res)
56+
}
57+
58+
// ImportFromFile imports the configuration in the provided json string
59+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
60+
func (c *Manager) ImportFromFile(clusterId string, spec FileSpec) (string, error) {
61+
path := c.getBaseTransitionUrl(clusterId, "importFromFile")
62+
req := path.Request(http.MethodPost, spec)
63+
var res string
64+
return res, c.Do(context.Background(), req, &res)
65+
}
66+
67+
// ValidateConfiguration performs server-side validation of the pending cluster configuration
68+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
69+
func (c *Manager) ValidateConfiguration(clusterId string) (string, error) {
70+
path := c.getBaseTransitionUrl(clusterId, "validateConfig")
71+
req := path.Request(http.MethodPost, nil)
72+
var res string
73+
return res, c.Do(context.Background(), req, &res)
74+
}
75+
76+
// RunPrecheck performs server-side pre-checks of the pending cluster configuration
77+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
78+
func (c *Manager) RunPrecheck(clusterId string) (string, error) {
79+
path := c.getBaseTransitionUrl(clusterId, "precheck")
80+
req := path.Request(http.MethodPost, nil)
81+
var res string
82+
return res, c.Do(context.Background(), req, &res)
83+
}
84+
85+
// Cancel deletes the pending cluster configuration
86+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
87+
func (c *Manager) Cancel(clusterId string) (string, error) {
88+
path := c.Resource(fmt.Sprintf(Transition, clusterId)).WithParam("action", "cancel")
89+
req := path.Request(http.MethodPost, nil)
90+
var res string
91+
return res, c.Do(context.Background(), req, &res)
92+
}
93+
94+
// GetClusterConfigurationStatus returns the status of the current pending cluster configuration
95+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
96+
func (c *Manager) GetClusterConfigurationStatus(clusterId string) (string, error) {
97+
path := c.Resource(fmt.Sprintf(Transition, clusterId))
98+
req := path.Request(http.MethodGet)
99+
var res string
100+
return res, c.Do(context.Background(), req, &res)
101+
}
102+
103+
func (c *Manager) getBaseTransitionUrl(clusterId, action string) *rest.Resource {
104+
return c.Resource(fmt.Sprintf(Transition, clusterId)).WithParam("action", action).WithParam("vmw-task", "true")
105+
}

vapi/esx/settings/depots/depots.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import (
99
"fmt"
1010
"net/http"
1111

12+
"github.com/vmware/govmomi/vapi/esx/settings"
1213
"github.com/vmware/govmomi/vapi/rest"
1314
)
1415

1516
const (
16-
basePath = "/api/esx/settings"
1717
// DepotsOfflinePath The endpoint for the offline depots API
18-
DepotsOfflinePath = basePath + "/depots/offline"
18+
DepotsOfflinePath = settings.BasePath + "/depots/offline"
1919
// DepotsOfflineContentPath The endpoint for retrieving the components in a depot
2020
DepotsOfflineContentPath = DepotsOfflinePath + "/%s/content"
2121
// BaseImagesPath The endpoint for retrieving the list of base ESXi images
22-
BaseImagesPath = basePath + "/depot-content/base-images"
22+
BaseImagesPath = settings.BasePath + "/depot-content/base-images"
2323
)
2424

2525
// Manager extends rest.Client, adding vLCM related methods.

vapi/esx/settings/settings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package settings
2+
3+
const (
4+
BasePath = "/api/esx/settings"
5+
)

0 commit comments

Comments
 (0)