Skip to content

Commit 37dd0c8

Browse files
committed
api: bindings for esx/settings/clusters/cluster/configuration/drafts
Signed-off-by: Stoyan Zhelyazkov <[email protected]>
1 parent 55501e2 commit 37dd0c8

File tree

4 files changed

+167
-7
lines changed

4 files changed

+167
-7
lines changed

vapi/esx/settings/clusters/configuration/configuraton.go

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

12-
"github.com/vmware/govmomi/vapi/esx/settings"
12+
"github.com/vmware/govmomi/vapi/esx/settings/clusters"
1313
"github.com/vmware/govmomi/vapi/rest"
1414
)
1515

1616
const (
1717
// BasePath The base endpoint for the clusters configuration API
18-
BasePath = settings.BasePath + "/%s/configuration"
18+
BasePath = clusters.BasePath + "/%s/configuration"
1919
RecentTasksPath = BasePath + "/reports/recent-tasks"
2020
SchemaPath = BasePath + "/schema"
2121
)
2222

23-
// Manager extends rest.Client, adding cluster configuration enablement related methods.
23+
// Manager extends rest.Client, adding cluster configuration related methods.
2424
type Manager struct {
2525
*rest.Client
2626
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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 drafts
6+
7+
import (
8+
"context"
9+
"fmt"
10+
"net/http"
11+
12+
"github.com/vmware/govmomi/vapi/esx/settings/clusters/configuration"
13+
"github.com/vmware/govmomi/vapi/rest"
14+
)
15+
16+
const (
17+
// BasePath The base endpoint for the clusters configuration API
18+
BasePath = configuration.BasePath + "/drafts"
19+
DraftPath = BasePath + "/%s"
20+
)
21+
22+
// Manager extends rest.Client, adding cluster configuration drafts related methods.
23+
type Manager struct {
24+
*rest.Client
25+
}
26+
27+
// NewManager creates a new Manager instance with the given client.
28+
func NewManager(client *rest.Client) *Manager {
29+
return &Manager{
30+
Client: client,
31+
}
32+
}
33+
34+
type Draft struct {
35+
ID string `json:"id"`
36+
State string `json:"state"`
37+
}
38+
39+
type CreateSpec struct {
40+
Config string `json:"config"`
41+
ReferenceHost string `json:"reference_host"`
42+
}
43+
44+
type ApplySpec struct {
45+
PolicySpec ApplyPolicySpec `json:"apply_policy_spec"`
46+
}
47+
48+
type ApplyPolicySpec struct {
49+
FailureAction *FailureAction `json:"failure_action"`
50+
PreRemediationPowerAction *string `json:"pre_remediation_power_action"`
51+
EnableQuickBoot *bool `json:"enable_quick_boot"`
52+
DisableDpm *bool `json:"disable_dpm"`
53+
DisableHac *bool `json:"disable_hac"`
54+
EvacuateOfflineVms *bool `json:"evacuate_offline_vms"`
55+
EnforceHclValidation *bool `json:"enforce_hcl_validation"`
56+
EnforceQuickPatch *bool `json:"enforce_quick_patch"`
57+
ParallelRemediationAction *ParallelRemediationAction `json:"parallel_remediation_action"`
58+
ConfigManagerPolicySpec *ConfigManagerPolicySpec `json:"config_manager_policy_spec"`
59+
}
60+
61+
type FailureAction struct {
62+
Action string `json:"action"`
63+
RetryDelay int `json:"retry_delay"`
64+
RetryCount int `json:"retry_count"`
65+
}
66+
67+
type ParallelRemediationAction struct {
68+
Enabled bool `json:"enabled"`
69+
MaxHosts int `json:"max_hosts"`
70+
}
71+
72+
type ConfigManagerPolicySpec struct {
73+
SerialRemediation bool `json:"serial_remediation"`
74+
}
75+
76+
type UpdateSpec struct {
77+
Config string `json:"config"`
78+
}
79+
80+
type ImportSpec struct {
81+
Host string `json:"host"`
82+
}
83+
84+
// ListDrafts returns all active drafts
85+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration/drafts
86+
func (c *Manager) ListDrafts(clusterId string) (map[string]Draft, error) {
87+
path := c.Resource(fmt.Sprintf(BasePath, clusterId))
88+
req := path.Request(http.MethodGet)
89+
var res map[string]Draft
90+
return res, c.Do(context.Background(), req, &res)
91+
}
92+
93+
// GetDraft returns a draft by its ID
94+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration/drafts
95+
func (c *Manager) GetDraft(clusterId, draftId string) (Draft, error) {
96+
path := c.Resource(fmt.Sprintf(DraftPath, clusterId, draftId))
97+
req := path.Request(http.MethodGet)
98+
var res Draft
99+
return res, c.Do(context.Background(), req, &res)
100+
}
101+
102+
// DeleteDraft deletes a draft
103+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration/drafts
104+
func (c *Manager) DeleteDraft(clusterId, draftId string) (Draft, error) {
105+
path := c.Resource(fmt.Sprintf(DraftPath, clusterId, draftId))
106+
req := path.Request(http.MethodDelete)
107+
var res Draft
108+
return res, c.Do(context.Background(), req, &res)
109+
}
110+
111+
// CreateDraft creates a draft with the provided configuration
112+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration/drafts
113+
func (c *Manager) CreateDraft(clusterId string, spec CreateSpec) error {
114+
path := c.Resource(fmt.Sprintf(BasePath, clusterId))
115+
req := path.Request(http.MethodPost, spec)
116+
return c.Do(context.Background(), req, nil)
117+
}
118+
119+
// ApplyDraft commits the draft with the specified ID
120+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration/drafts
121+
func (c *Manager) ApplyDraft(clusterId, draftId string) error {
122+
path := c.Resource(fmt.Sprintf(DraftPath, clusterId, draftId)).WithAction("apply")
123+
req := path.Request(http.MethodPost)
124+
return c.Do(context.Background(), req, nil)
125+
}
126+
127+
// UpdateDraft updates the configuration of the draft with the specified ID
128+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration/drafts
129+
func (c *Manager) UpdateDraft(clusterId, draftId string, spec UpdateSpec) error {
130+
path := c.Resource(fmt.Sprintf(DraftPath, clusterId, draftId)).WithAction("update")
131+
req := path.Request(http.MethodPost, spec)
132+
return c.Do(context.Background(), req, nil)
133+
}
134+
135+
// ImportFromHost sets a reference host to use as the source for the draft configuration
136+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration/drafts
137+
func (c *Manager) ImportFromHost(clusterId, draftId string, spec ImportSpec) (string, error) {
138+
path := c.Resource(fmt.Sprintf(DraftPath, clusterId, draftId)).WithAction("importFromHost").WithParam("vmw-task", "true")
139+
req := path.Request(http.MethodPost, spec)
140+
var res string
141+
return res, c.Do(context.Background(), req, &res)
142+
}
143+
144+
// Precheck runs pre-checks for the provided draft on the specified cluster
145+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration/drafts
146+
func (c *Manager) Precheck(clusterId, draftId string) (string, error) {
147+
path := c.Resource(fmt.Sprintf(DraftPath, clusterId, draftId)).WithAction("precheck").WithParam("vmw-task", "true")
148+
req := path.Request(http.MethodPost)
149+
var res string
150+
return res, c.Do(context.Background(), req, &res)
151+
}

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

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

12-
"github.com/vmware/govmomi/vapi/esx/settings"
12+
"github.com/vmware/govmomi/vapi/esx/settings/clusters"
1313
"github.com/vmware/govmomi/vapi/rest"
1414
)
1515

1616
const (
1717
// BasePath The base endpoint for the clusters enablement configuration API
18-
BasePath = settings.BasePath + "/%s/enablement"
18+
BasePath = clusters.BasePath + "/%s/enablement"
1919
ConfigurationPath = BasePath + "/configuration"
2020
TransitionPath = ConfigurationPath + "/transition"
2121
)
@@ -25,6 +25,11 @@ type FileSpec struct {
2525
Filename string `json:"filename"`
2626
}
2727

28+
type DraftImportResult struct {
29+
Status string `json:"status"`
30+
Draft string `json:"draft"`
31+
}
32+
2833
// Manager extends rest.Client, adding cluster configuration enablement related methods.
2934
type Manager struct {
3035
*rest.Client
@@ -60,10 +65,10 @@ func (c *Manager) ImportFromReferenceHost(clusterId, hostId string) (string, err
6065
// ImportFromFile imports the configuration in the provided json string
6166
// Returns a task identifier and an error
6267
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
63-
func (c *Manager) ImportFromFile(clusterId string, spec FileSpec) (string, error) {
68+
func (c *Manager) ImportFromFile(clusterId string, spec FileSpec) (DraftImportResult, error) {
6469
path := c.getUrlWithActionAndTask(clusterId, "importFromFile")
6570
req := path.Request(http.MethodPost, spec)
66-
var res string
71+
var res DraftImportResult
6772
return res, c.Do(context.Background(), req, &res)
6873
}
6974

vapi/esx/settings/settings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
package settings
26

37
const (

0 commit comments

Comments
 (0)