Skip to content

Commit 3230765

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

File tree

2 files changed

+167
-1
lines changed

2 files changed

+167
-1
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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 configuration
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 API
18+
BasePath = settings.BasePath + "/%s/configuration"
19+
)
20+
21+
// Manager extends rest.Client, adding cluster configuration enablement related methods.
22+
type Manager struct {
23+
*rest.Client
24+
}
25+
26+
// NewManager creates a new Manager instance with the given client.
27+
func NewManager(client *rest.Client) *Manager {
28+
return &Manager{
29+
Client: client,
30+
}
31+
}
32+
33+
type Info struct {
34+
Config string `json:"config"`
35+
Metadata Metadata `json:"metadata"`
36+
}
37+
38+
type Metadata struct {
39+
Id string `json:"id"`
40+
}
41+
42+
type ExportResult struct {
43+
Config string `json:"config"`
44+
}
45+
46+
type ImportSpec struct {
47+
Config string `json:"config"`
48+
Description *string `json:"description"`
49+
}
50+
51+
type ApplySpec struct {
52+
Hosts *[]string `json:"hosts"`
53+
ApplyPolicySpec *ApplyPolicySpec `json:"apply_policy_spec"`
54+
}
55+
56+
type ApplyPolicySpec struct {
57+
FailureAction *FailureAction `json:"failure_action"`
58+
PreRemediationPowerAction *string `json:"pre_remediation_power_action"`
59+
EnableQuickBoot *bool `json:"enable_quick_boot"`
60+
DisableDpm *bool `json:"disable_dpm"`
61+
DisableHac *bool `json:"disable_hac"`
62+
EvacuateOfflineVms *bool `json:"evacuate_offline_vms"`
63+
EnforceHclValidation *bool `json:"enforce_hcl_validation"`
64+
EnforceQuickPatch *bool `json:"enforce_quick_patch"`
65+
ParallelRemediationAction *ParallelRemediationAction `json:"parallel_remediation_action"`
66+
ConfigManagerPolicySpec *ConfigManagerPolicySpec `json:"config_manager_policy_spec"`
67+
}
68+
69+
type FailureAction struct {
70+
Action string `json:"action"`
71+
RetryDelay int `json:"retry_delay"`
72+
RetryCount int `json:"retry_count"`
73+
}
74+
75+
type ParallelRemediationAction struct {
76+
Enabled bool `json:"enabled"`
77+
MaxHosts int `json:"max_hosts"`
78+
}
79+
80+
type ConfigManagerPolicySpec struct {
81+
SerialRemediation bool `json:"serial_remediation"`
82+
}
83+
84+
// GetConfiguration returns the cluster configuration
85+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
86+
func (c *Manager) GetConfiguration(clusterId string) (Info, error) {
87+
path := c.Resource(fmt.Sprintf(BasePath, clusterId))
88+
req := path.Request(http.MethodGet)
89+
var res Info
90+
return res, c.Do(context.Background(), req, &res)
91+
}
92+
93+
// ExportConfiguration returns the cluster configuration
94+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
95+
func (c *Manager) ExportConfiguration(clusterId string) (ExportResult, error) {
96+
path := c.Resource(fmt.Sprintf(BasePath, clusterId)).WithAction("exportConfig")
97+
req := path.Request(http.MethodPost)
98+
var res ExportResult
99+
return res, c.Do(context.Background(), req, &res)
100+
}
101+
102+
// ApplyConfiguration applies the current configuration to the provided hosts in the cluster
103+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
104+
func (c *Manager) ApplyConfiguration(clusterId string, spec ApplySpec) (string, error) {
105+
path := c.getBaseTransitionUrl(clusterId, "apply")
106+
req := path.Request(http.MethodPost, spec)
107+
var res string
108+
return res, c.Do(context.Background(), req, &res)
109+
}
110+
111+
// CheckCompliance initiates a compliance check on the cluster
112+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
113+
func (c *Manager) CheckCompliance(clusterId string) (string, error) {
114+
path := c.getBaseTransitionUrl(clusterId, "checkCompliance")
115+
req := path.Request(http.MethodPost)
116+
var res string
117+
return res, c.Do(context.Background(), req, &res)
118+
}
119+
120+
// Validate initiates a validation check on the pending cluster configuration
121+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
122+
func (c *Manager) Validate(clusterId string) (string, error) {
123+
path := c.getBaseTransitionUrl(clusterId, "validate")
124+
req := path.Request(http.MethodPost)
125+
var res string
126+
return res, c.Do(context.Background(), req, &res)
127+
}
128+
129+
// Precheck initiates a precheck on the pending cluster configuration
130+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
131+
func (c *Manager) Precheck(clusterId string) (string, error) {
132+
path := c.getBaseTransitionUrl(clusterId, "precheck")
133+
req := path.Request(http.MethodPost)
134+
var res string
135+
return res, c.Do(context.Background(), req, &res)
136+
}
137+
138+
// Import imports the provided configuration
139+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
140+
func (c *Manager) Import(clusterId string, spec ImportSpec) (string, error) {
141+
path := c.getBaseTransitionUrl(clusterId, "importConfig")
142+
req := path.Request(http.MethodPost, spec)
143+
var res string
144+
return res, c.Do(context.Background(), req, &res)
145+
}
146+
147+
func (c *Manager) getBaseTransitionUrl(clusterId, action string) *rest.Resource {
148+
return c.Resource(fmt.Sprintf(BasePath, clusterId)).WithParam("action", action).WithParam("vmw-task", "true")
149+
}

vapi/esx/settings/clusters/enablement/enablement.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
const (
17-
// BasePath The base endpoint for the clusters configuration enablement API
17+
// BasePath The base endpoint for the clusters enablement configuration API
1818
BasePath = settings.BasePath + "/%s/enablement"
1919
Configuration = BasePath + "/configuration"
2020
Transition = Configuration + "/transition"
@@ -38,6 +38,7 @@ func NewManager(client *rest.Client) *Manager {
3838
}
3939

4040
// EnableClusterConfiguration enables cluster configuration profiles
41+
// Returns a task identifier and an error
4142
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
4243
func (c *Manager) EnableClusterConfiguration(clusterId string) (string, error) {
4344
path := c.getBaseTransitionUrl(clusterId, "enable")
@@ -47,6 +48,7 @@ func (c *Manager) EnableClusterConfiguration(clusterId string) (string, error) {
4748
}
4849

4950
// ImportFromReferenceHost imports the configuration of an existing ESXi host
51+
// Returns a task identifier and an error
5052
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
5153
func (c *Manager) ImportFromReferenceHost(clusterId, hostId string) (string, error) {
5254
path := c.getBaseTransitionUrl(clusterId, "importFromHost")
@@ -56,6 +58,7 @@ func (c *Manager) ImportFromReferenceHost(clusterId, hostId string) (string, err
5658
}
5759

5860
// ImportFromFile imports the configuration in the provided json string
61+
// Returns a task identifier and an error
5962
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
6063
func (c *Manager) ImportFromFile(clusterId string, spec FileSpec) (string, error) {
6164
path := c.getBaseTransitionUrl(clusterId, "importFromFile")
@@ -65,6 +68,7 @@ func (c *Manager) ImportFromFile(clusterId string, spec FileSpec) (string, error
6568
}
6669

6770
// ValidateConfiguration performs server-side validation of the pending cluster configuration
71+
// Returns a task identifier and an error
6872
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
6973
func (c *Manager) ValidateConfiguration(clusterId string) (string, error) {
7074
path := c.getBaseTransitionUrl(clusterId, "validateConfig")
@@ -73,7 +77,18 @@ func (c *Manager) ValidateConfiguration(clusterId string) (string, error) {
7377
return res, c.Do(context.Background(), req, &res)
7478
}
7579

80+
// CheckEligibility performs server-side validation of whether the cluster is eligible for configuration management via profiles
81+
// Returns a task identifier and an error
82+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
83+
func (c *Manager) CheckEligibility(clusterId string) (string, error) {
84+
path := c.getBaseTransitionUrl(clusterId, "checkEligibility")
85+
req := path.Request(http.MethodPost, nil)
86+
var res string
87+
return res, c.Do(context.Background(), req, &res)
88+
}
89+
7690
// RunPrecheck performs server-side pre-checks of the pending cluster configuration
91+
// Returns a task identifier and an error
7792
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
7893
func (c *Manager) RunPrecheck(clusterId string) (string, error) {
7994
path := c.getBaseTransitionUrl(clusterId, "precheck")
@@ -83,6 +98,7 @@ func (c *Manager) RunPrecheck(clusterId string) (string, error) {
8398
}
8499

85100
// Cancel deletes the pending cluster configuration
101+
// Returns a task identifier and an error
86102
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
87103
func (c *Manager) Cancel(clusterId string) (string, error) {
88104
path := c.Resource(fmt.Sprintf(Transition, clusterId)).WithParam("action", "cancel")
@@ -92,6 +108,7 @@ func (c *Manager) Cancel(clusterId string) (string, error) {
92108
}
93109

94110
// GetClusterConfigurationStatus returns the status of the current pending cluster configuration
111+
// Returns the config status and an error
95112
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
96113
func (c *Manager) GetClusterConfigurationStatus(clusterId string) (string, error) {
97114
path := c.Resource(fmt.Sprintf(Transition, clusterId))

0 commit comments

Comments
 (0)