Skip to content

Commit 55501e2

Browse files
committed
api: add bindings for recent tasks and schema
Signed-off-by: Stoyan Zhelyazkov <[email protected]>
1 parent 3230765 commit 55501e2

File tree

2 files changed

+52
-20
lines changed

2 files changed

+52
-20
lines changed

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import (
1515

1616
const (
1717
// BasePath The base endpoint for the clusters configuration API
18-
BasePath = settings.BasePath + "/%s/configuration"
18+
BasePath = settings.BasePath + "/%s/configuration"
19+
RecentTasksPath = BasePath + "/reports/recent-tasks"
20+
SchemaPath = BasePath + "/schema"
1921
)
2022

2123
// Manager extends rest.Client, adding cluster configuration enablement related methods.
@@ -81,6 +83,18 @@ type ConfigManagerPolicySpec struct {
8183
SerialRemediation bool `json:"serial_remediation"`
8284
}
8385

86+
type RecentTasksInfo struct {
87+
CheckCompliance string `json:"check_compliance"`
88+
Precheck string `json:"precheck"`
89+
Apply string `json:"apply"`
90+
DraftTasks []any `json:"draft_tasks"`
91+
}
92+
93+
type SchemaInfo struct {
94+
Source string `json:"source"`
95+
Schema string `json:"schema"`
96+
}
97+
8498
// GetConfiguration returns the cluster configuration
8599
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
86100
func (c *Manager) GetConfiguration(clusterId string) (Info, error) {
@@ -102,7 +116,7 @@ func (c *Manager) ExportConfiguration(clusterId string) (ExportResult, error) {
102116
// ApplyConfiguration applies the current configuration to the provided hosts in the cluster
103117
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
104118
func (c *Manager) ApplyConfiguration(clusterId string, spec ApplySpec) (string, error) {
105-
path := c.getBaseTransitionUrl(clusterId, "apply")
119+
path := c.getUrlWithActionAndTask(clusterId, "apply")
106120
req := path.Request(http.MethodPost, spec)
107121
var res string
108122
return res, c.Do(context.Background(), req, &res)
@@ -111,7 +125,7 @@ func (c *Manager) ApplyConfiguration(clusterId string, spec ApplySpec) (string,
111125
// CheckCompliance initiates a compliance check on the cluster
112126
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
113127
func (c *Manager) CheckCompliance(clusterId string) (string, error) {
114-
path := c.getBaseTransitionUrl(clusterId, "checkCompliance")
128+
path := c.getUrlWithActionAndTask(clusterId, "checkCompliance")
115129
req := path.Request(http.MethodPost)
116130
var res string
117131
return res, c.Do(context.Background(), req, &res)
@@ -120,7 +134,7 @@ func (c *Manager) CheckCompliance(clusterId string) (string, error) {
120134
// Validate initiates a validation check on the pending cluster configuration
121135
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
122136
func (c *Manager) Validate(clusterId string) (string, error) {
123-
path := c.getBaseTransitionUrl(clusterId, "validate")
137+
path := c.getUrlWithActionAndTask(clusterId, "validate")
124138
req := path.Request(http.MethodPost)
125139
var res string
126140
return res, c.Do(context.Background(), req, &res)
@@ -129,7 +143,7 @@ func (c *Manager) Validate(clusterId string) (string, error) {
129143
// Precheck initiates a precheck on the pending cluster configuration
130144
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
131145
func (c *Manager) Precheck(clusterId string) (string, error) {
132-
path := c.getBaseTransitionUrl(clusterId, "precheck")
146+
path := c.getUrlWithActionAndTask(clusterId, "precheck")
133147
req := path.Request(http.MethodPost)
134148
var res string
135149
return res, c.Do(context.Background(), req, &res)
@@ -138,12 +152,30 @@ func (c *Manager) Precheck(clusterId string) (string, error) {
138152
// Import imports the provided configuration
139153
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration
140154
func (c *Manager) Import(clusterId string, spec ImportSpec) (string, error) {
141-
path := c.getBaseTransitionUrl(clusterId, "importConfig")
155+
path := c.getUrlWithActionAndTask(clusterId, "importConfig")
142156
req := path.Request(http.MethodPost, spec)
143157
var res string
144158
return res, c.Do(context.Background(), req, &res)
145159
}
146160

147-
func (c *Manager) getBaseTransitionUrl(clusterId, action string) *rest.Resource {
161+
// GetRecentTasks returns the task identifiers for the latest configuration operations of each type
162+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration/reports/recent-tasks
163+
func (c *Manager) GetRecentTasks(clusterId string) (RecentTasksInfo, error) {
164+
path := c.Resource(fmt.Sprintf(RecentTasksPath, clusterId))
165+
req := path.Request(http.MethodGet)
166+
var res RecentTasksInfo
167+
return res, c.Do(context.Background(), req, &res)
168+
}
169+
170+
// GetSchema returns the configuration schema for the cluster
171+
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/configuration/schema
172+
func (c *Manager) GetSchema(clusterId string) (SchemaInfo, error) {
173+
path := c.Resource(fmt.Sprintf(SchemaPath, clusterId))
174+
req := path.Request(http.MethodGet)
175+
var res SchemaInfo
176+
return res, c.Do(context.Background(), req, &res)
177+
}
178+
179+
func (c *Manager) getUrlWithActionAndTask(clusterId, action string) *rest.Resource {
148180
return c.Resource(fmt.Sprintf(BasePath, clusterId)).WithParam("action", action).WithParam("vmw-task", "true")
149181
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import (
1515

1616
const (
1717
// BasePath The base endpoint for the clusters enablement configuration API
18-
BasePath = settings.BasePath + "/%s/enablement"
19-
Configuration = BasePath + "/configuration"
20-
Transition = Configuration + "/transition"
18+
BasePath = settings.BasePath + "/%s/enablement"
19+
ConfigurationPath = BasePath + "/configuration"
20+
TransitionPath = ConfigurationPath + "/transition"
2121
)
2222

2323
type FileSpec struct {
@@ -41,7 +41,7 @@ func NewManager(client *rest.Client) *Manager {
4141
// Returns a task identifier and an error
4242
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
4343
func (c *Manager) EnableClusterConfiguration(clusterId string) (string, error) {
44-
path := c.getBaseTransitionUrl(clusterId, "enable")
44+
path := c.getUrlWithActionAndTask(clusterId, "enable")
4545
req := path.Request(http.MethodPost, nil)
4646
var res string
4747
return res, c.Do(context.Background(), req, &res)
@@ -51,7 +51,7 @@ func (c *Manager) EnableClusterConfiguration(clusterId string) (string, error) {
5151
// Returns a task identifier and an error
5252
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
5353
func (c *Manager) ImportFromReferenceHost(clusterId, hostId string) (string, error) {
54-
path := c.getBaseTransitionUrl(clusterId, "importFromHost")
54+
path := c.getUrlWithActionAndTask(clusterId, "importFromHost")
5555
req := path.Request(http.MethodPost, hostId)
5656
var res string
5757
return res, c.Do(context.Background(), req, &res)
@@ -61,7 +61,7 @@ func (c *Manager) ImportFromReferenceHost(clusterId, hostId string) (string, err
6161
// Returns a task identifier and an error
6262
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
6363
func (c *Manager) ImportFromFile(clusterId string, spec FileSpec) (string, error) {
64-
path := c.getBaseTransitionUrl(clusterId, "importFromFile")
64+
path := c.getUrlWithActionAndTask(clusterId, "importFromFile")
6565
req := path.Request(http.MethodPost, spec)
6666
var res string
6767
return res, c.Do(context.Background(), req, &res)
@@ -71,7 +71,7 @@ func (c *Manager) ImportFromFile(clusterId string, spec FileSpec) (string, error
7171
// Returns a task identifier and an error
7272
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
7373
func (c *Manager) ValidateConfiguration(clusterId string) (string, error) {
74-
path := c.getBaseTransitionUrl(clusterId, "validateConfig")
74+
path := c.getUrlWithActionAndTask(clusterId, "validateConfig")
7575
req := path.Request(http.MethodPost, nil)
7676
var res string
7777
return res, c.Do(context.Background(), req, &res)
@@ -81,7 +81,7 @@ func (c *Manager) ValidateConfiguration(clusterId string) (string, error) {
8181
// Returns a task identifier and an error
8282
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
8383
func (c *Manager) CheckEligibility(clusterId string) (string, error) {
84-
path := c.getBaseTransitionUrl(clusterId, "checkEligibility")
84+
path := c.getUrlWithActionAndTask(clusterId, "checkEligibility")
8585
req := path.Request(http.MethodPost, nil)
8686
var res string
8787
return res, c.Do(context.Background(), req, &res)
@@ -91,7 +91,7 @@ func (c *Manager) CheckEligibility(clusterId string) (string, error) {
9191
// Returns a task identifier and an error
9292
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
9393
func (c *Manager) RunPrecheck(clusterId string) (string, error) {
94-
path := c.getBaseTransitionUrl(clusterId, "precheck")
94+
path := c.getUrlWithActionAndTask(clusterId, "precheck")
9595
req := path.Request(http.MethodPost, nil)
9696
var res string
9797
return res, c.Do(context.Background(), req, &res)
@@ -101,7 +101,7 @@ func (c *Manager) RunPrecheck(clusterId string) (string, error) {
101101
// Returns a task identifier and an error
102102
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
103103
func (c *Manager) Cancel(clusterId string) (string, error) {
104-
path := c.Resource(fmt.Sprintf(Transition, clusterId)).WithParam("action", "cancel")
104+
path := c.Resource(fmt.Sprintf(TransitionPath, clusterId)).WithParam("action", "cancel")
105105
req := path.Request(http.MethodPost, nil)
106106
var res string
107107
return res, c.Do(context.Background(), req, &res)
@@ -111,12 +111,12 @@ func (c *Manager) Cancel(clusterId string) (string, error) {
111111
// Returns the config status and an error
112112
// https://developer.broadcom.com/xapis/vsphere-automation-api/latest/api/esx/settings/clusters/cluster/enablement/configuration/transition
113113
func (c *Manager) GetClusterConfigurationStatus(clusterId string) (string, error) {
114-
path := c.Resource(fmt.Sprintf(Transition, clusterId))
114+
path := c.Resource(fmt.Sprintf(TransitionPath, clusterId))
115115
req := path.Request(http.MethodGet)
116116
var res string
117117
return res, c.Do(context.Background(), req, &res)
118118
}
119119

120-
func (c *Manager) getBaseTransitionUrl(clusterId, action string) *rest.Resource {
121-
return c.Resource(fmt.Sprintf(Transition, clusterId)).WithParam("action", action).WithParam("vmw-task", "true")
120+
func (c *Manager) getUrlWithActionAndTask(clusterId, action string) *rest.Resource {
121+
return c.Resource(fmt.Sprintf(TransitionPath, clusterId)).WithParam("action", action).WithParam("vmw-task", "true")
122122
}

0 commit comments

Comments
 (0)