Skip to content

Commit a69723c

Browse files
committed
add comments to clarify structures and services in Utho API
1 parent d24c282 commit a69723c

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

cluster-autoscaler/cloudprovider/utho/utho-go/cloud_instances.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ import (
2121
"errors"
2222
)
2323

24+
// CloudInstancesService provides methods for managing cloud instances via the Utho API.
2425
type CloudInstancesService service
2526

27+
// CloudInstances represents a list of cloud instances returned by the API.
2628
type CloudInstances struct {
2729
CloudInstance []CloudInstance `json:"cloud"`
2830
Meta Meta `json:"meta"`
2931
Status string `json:"status,omitempty" faker:"oneof:success,error"`
3032
Message string `json:"message,omitempty" faker:"sentence"`
3133
}
34+
35+
// CloudInstance represents a single cloud instance.
3236
type CloudInstance struct {
3337
ID string `json:"cloudid" faker:"oneof: 00000,11111,22222,33333"`
3438
Hostname string `json:"hostname"`
@@ -84,23 +88,33 @@ type CloudInstance struct {
8488
Gpus []any `json:"gpus,omitempty"`
8589
Rescue int `json:"rescue"`
8690
}
91+
92+
// Features represents the features available for a cloud instance.
8793
type Features struct {
8894
Backups string `json:"backups" faker:"oneof:0,1"`
8995
}
96+
97+
// Image represents an image available for a cloud instance.
9098
type Image struct {
9199
Name string `json:"name"`
92100
Distribution string `json:"distribution"`
93101
Version string `json:"version" faker:"semver"`
94102
Image string `json:"image"`
95103
Cost string `json:"cost"`
96104
}
105+
106+
// Networks represents the network configuration for a cloud instance.
97107
type Networks struct {
98108
Public Public `json:"public"`
99109
Private Private `json:"private"`
100110
}
111+
112+
// Public represents the public network configuration for a cloud instance.
101113
type Public struct {
102114
V4 V4PublicArray `json:"v4"`
103115
}
116+
117+
// V4Public represents a public IPv4 address for a cloud instance.
104118
type V4Public struct {
105119
IPAddress string `json:"ip_address,omitempty" faker:"ipv4"`
106120
Netmask string `json:"netmask,omitempty" faker:"ipv4_netmask"`
@@ -112,9 +126,12 @@ type V4Public struct {
112126
Mac string `json:"mac,omitempty"`
113127
}
114128

129+
// Private represents the private network configuration for a cloud instance.
115130
type Private struct {
116131
V4 []V4Private `json:"v4"`
117132
}
133+
134+
// V4Private represents a private IPv4 address for a cloud instance.
118135
type V4Private struct {
119136
Noip int `json:"noip"`
120137
IPAddress string `json:"ip_address,omitempty" faker:"ipv4"`
@@ -128,6 +145,8 @@ type V4Private struct {
128145
Mac string `json:"mac,omitempty"`
129146
Primary string `json:"primary,omitempty" faker:"oneof:1,0"`
130147
}
148+
149+
// Storages represents a collection of storage devices attached to a cloud instance.
131150
type Storages struct {
132151
ID string `json:"id" faker:"oneof: 00000,11111,22222,33333"`
133152
Size int `json:"size"`
@@ -138,6 +157,8 @@ type Storages struct {
138157
Bus string `json:"bus" faker:"oneof:virtio,sata"`
139158
Type string `json:"type" faker:"oneof:ssd,hdd"`
140159
}
160+
161+
// Storage represents a single storage device attached to a cloud instance.
141162
type Storage struct {
142163
ID string `json:"id" faker:"oneof: 00000,11111,22222,33333"`
143164
Size int `json:"size"`
@@ -148,41 +169,54 @@ type Storage struct {
148169
Bus string `json:"bus" faker:"oneof:virtio,sata"`
149170
Type string `json:"type" faker:"oneof:ssd,hdd"`
150171
}
172+
173+
// Snapshot represents a snapshot of a cloud instance's storage.
151174
type Snapshot struct {
152175
ID string `json:"id" faker:"oneof: 00000,11111,22222,33333"`
153176
Size string `json:"size" faker:"oneof:1GB,50GB,100GB"`
154177
CreatedAt string `json:"created_at" faker:"date"`
155178
Note string `json:"note" faker:"sentence"`
156179
Name string `json:"name"`
157180
}
181+
182+
// CloudInstanceFirewall represents a firewall attached to a cloud instance.
158183
type CloudInstanceFirewall struct {
159184
ID string `json:"id" faker:"oneof: 00000,11111,22222,33333"`
160185
Name string `json:"name"`
161186
CreatedAt string `json:"created_at" faker:"date"`
162187
}
188+
189+
// Meta contains metadata about a list of resources.
163190
type Meta struct {
164191
Total int `json:"total"`
165192
Totalpages int `json:"totalpages"`
166193
Currentpage int `json:"currentpage"`
167194
}
195+
196+
// Snapshots represents a collection of snapshots for a cloud instance.
168197
type Snapshots struct {
169198
ID string `json:"id" faker:"oneof: 00000,11111,22222,33333"`
170199
Size string `json:"size" faker:"oneof:1GB,50GB,100GB"`
171200
CreatedAt string `json:"created_at" faker:"date"`
172201
Note string `json:"note" faker:"sentence"`
173202
Name string `json:"name"`
174203
}
204+
205+
// CloudInstanceFirewalls represents a collection of firewalls attached to a cloud instance.
175206
type CloudInstanceFirewalls struct {
176207
ID string `json:"id" faker:"oneof: 00000,11111,22222,33333"`
177208
Name string `json:"name"`
178209
CreatedAt string `json:"created_at" faker:"date"`
179210
}
180211

212+
// OsImages represents a list of OS images available for cloud instances.
181213
type OsImages struct {
182214
OsImages []OsImage `json:"images"`
183215
Status string `json:"status,omitempty" faker:"oneof:success,error"`
184216
Message string `json:"message,omitempty" faker:"sentence"`
185217
}
218+
219+
// OsImage represents a single OS image available for cloud instances.
186220
type OsImage struct {
187221
Distro string `json:"distro,omitempty"`
188222
Distribution string `json:"distribution"`
@@ -191,11 +225,14 @@ type OsImage struct {
191225
Cost float64 `json:"cost"`
192226
}
193227

228+
// Plans represents a list of available plans for cloud instances.
194229
type Plans struct {
195230
Plans []Plan `json:"plans"`
196231
Status string `json:"status,omitempty" faker:"oneof:success,error"`
197232
Message string `json:"message,omitempty" faker:"sentence"`
198233
}
234+
235+
// Plan represents a single plan for a cloud instance.
199236
type Plan struct {
200237
ID string `json:"id" faker:"oneof: 00000,11111,22222,33333"`
201238
Type string `json:"type" faker:"oneof:ramcpu,disk"`
@@ -209,6 +246,7 @@ type Plan struct {
209246
Plantype string `json:"plantype" faker:"oneof:cloud,dedicated"`
210247
}
211248

249+
// CreateCloudInstanceParams contains parameters for creating a cloud instance.
212250
type CreateCloudInstanceParams struct {
213251
Dcslug string `json:"dcslug"`
214252
Image string `json:"image"`
@@ -230,10 +268,12 @@ type CreateCloudInstanceParams struct {
230268
Cloud []CloudHostname `json:"cloud"`
231269
}
232270

271+
// CloudHostname represents the hostname for a cloud instance.
233272
type CloudHostname struct {
234273
Hostname string `json:"hostname"`
235274
}
236275

276+
// CreateCloudInstanceResponse represents the response after creating a cloud instance.
237277
type CreateCloudInstanceResponse struct {
238278
ID string `json:"cloudid" faker:"oneof: 00000,11111,22222,33333"`
239279
Password string `json:"password" faker:"password"`
@@ -293,6 +333,7 @@ func (s *CloudInstancesService) List() ([]CloudInstance, error) {
293333
return cloudInstances.CloudInstance, nil
294334
}
295335

336+
// DeleteCloudInstanceParams contains parameters for deleting a cloud instance.
296337
type DeleteCloudInstanceParams struct {
297338
// Please provide confirm string as follow: "I am aware this action will delete data and server permanently"
298339
Confirm string `json:"confirm"`
@@ -346,6 +387,7 @@ func (s *CloudInstancesService) ListResizePlans(instanceId string) ([]Plan, erro
346387
return plans.Plans, nil
347388
}
348389

390+
// CreateSnapshotParams contains parameters for creating a snapshot.
349391
type CreateSnapshotParams struct {
350392
Name string `json:"name"`
351393
}
@@ -413,6 +455,7 @@ func (s *CloudInstancesService) DisableBackup(instanceId string) (*BasicResponse
413455
return &basicResponse, nil
414456
}
415457

458+
// UpdateBillingCycleParams contains parameters for updating the billing cycle of a cloud instance.
416459
type UpdateBillingCycleParams struct {
417460
Billingcycle string `json:"billingcycle"`
418461
}
@@ -497,6 +540,7 @@ func (s *CloudInstancesService) PowerOn(instanceId string) (*BasicResponse, erro
497540
return &basicResponse, nil
498541
}
499542

543+
// RebuildCloudInstanceParams contains parameters for rebuilding a cloud instance.
500544
type RebuildCloudInstanceParams struct {
501545
Image string `json:"image"`
502546
// Please provide confirm string as follow: "I am aware this action will delete data permanently and build a fresh server"
@@ -519,6 +563,7 @@ func (s *CloudInstancesService) Rebuild(instanceId string, rebuildCloudInstanceP
519563
return &basicResponse, nil
520564
}
521565

566+
// ResetPasswordResponse represents the response after resetting a cloud instance password.
522567
type ResetPasswordResponse struct {
523568
Password string `json:"password" faker:"password"`
524569
Status string `json:"status,omitempty" faker:"oneof:success,error"`
@@ -541,6 +586,7 @@ func (s *CloudInstancesService) ResetPassword(instanceId string) (*ResetPassword
541586
return &resetPasswordResponse, nil
542587
}
543588

589+
// ResizeCloudInstanceParams contains parameters for resizing a cloud instance.
544590
type ResizeCloudInstanceParams struct {
545591
Type string `json:"type"`
546592
Plan string `json:"plan"`
@@ -578,6 +624,7 @@ func (s *CloudInstancesService) RestoreSnapshot(instanceId, snapshotId string) (
578624
return &basicResponse, nil
579625
}
580626

627+
// UpdateStorageParams contains parameters for updating a storage device attached to a cloud instance.
581628
type UpdateStorageParams struct {
582629
Bus string `json:"bus"`
583630
Type string `json:"type"`
@@ -615,6 +662,7 @@ func (s *CloudInstancesService) AssignPublicIP(cloudid string) (*BasicResponse,
615662
return &basicResponse, nil
616663
}
617664

665+
// UpdateRDNSParams contains parameters for updating the RDNS of a cloud instance.
618666
type UpdateRDNSParams struct {
619667
Rdns string `json:"rdns"`
620668
}
@@ -667,6 +715,7 @@ func (s *CloudInstancesService) DisableRescue(cloudid string) (*BasicResponse, e
667715
return &basicResponse, nil
668716
}
669717

718+
// MountISOParams contains parameters for mounting an ISO to a cloud instance.
670719
type MountISOParams struct {
671720
Iso string `json:"iso"`
672721
}
@@ -704,6 +753,7 @@ func (s *CloudInstancesService) UnmountISO(cloudid string) (*BasicResponse, erro
704753
}
705754

706755
// Custom type to handle unmarshaling of V4Public
756+
// V4PublicArray is a custom type to handle unmarshaling of V4Public.
707757
type V4PublicArray []V4Public
708758

709759
func (v *V4PublicArray) UnmarshalJSON(data []byte) error {

cluster-autoscaler/cloudprovider/utho/utho-go/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import (
2121
"net/http"
2222
)
2323

24+
// ErrorResponse represents an error response from the Utho API.
2425
type ErrorResponse struct {
2526
Response *http.Response
2627
Errors []Error `json:"errors"`
2728
}
2829

30+
// Error represents a single error returned by the Utho API.
2931
type Error struct {
3032
Message string `json:"message"`
3133
LongMessage string `json:"long_message"`

cluster-autoscaler/cloudprovider/utho/utho-go/kubernetes.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ import (
2222
"fmt"
2323
)
2424

25+
// KubernetesService provides methods for interacting with Kubernetes resources via the Utho API.
2526
type KubernetesService service
2627

27-
// List
28+
// KubernetesList represents a list of Kubernetes clusters returned by the API.
2829
type KubernetesList struct {
2930
K8s []K8s `json:"k8s,omitempty"`
3031
Rcode string `json:"rcode,omitempty"`
3132
Status string `json:"status" faker:"oneof: success, failure"`
3233
Message string `json:"message" faker:"sentence"`
3334
}
35+
// K8s represents a single Kubernetes cluster.
3436
type K8s struct {
3537
ID int `json:"id,string"`
3638
CreatedAt string `json:"created_at" faker:"timestamp"`

cluster-autoscaler/cloudprovider/utho/utho-go/struct.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,40 @@ limitations under the License.
1616

1717
package utho
1818

19+
// BasicResponse represents a basic API response with status and message.
1920
type BasicResponse struct {
2021
Status string `json:"status,omitempty"`
2122
Message string `json:"message,omitempty"`
2223
}
2324

25+
// CreateResponse represents the response returned after creating a resource.
2426
type CreateResponse struct {
2527
ID string `json:"id"`
2628
AppStatus string `json:"app_status,omitempty"`
2729
Status string `json:"status"`
2830
Message string `json:"message"`
2931
}
3032

33+
// CreateBasicResponse represents a basic response for create operations.
3134
type CreateBasicResponse struct {
3235
Status string `json:"status"`
3336
Message string `json:"message"`
3437
}
3538

39+
// UpdateResponse represents the response returned after updating a resource.
3640
type UpdateResponse struct {
3741
ID string `json:"id"`
3842
Status string `json:"status"`
3943
Message string `json:"message"`
4044
}
4145

46+
// DeleteResponse represents the response returned after deleting a resource.
4247
type DeleteResponse struct {
4348
Status string `json:"status,omitempty"`
4449
Message string `json:"message,omitempty"`
4550
}
4651

52+
// Dclocation represents a datacenter location.
4753
type Dclocation struct {
4854
Location string `json:"location"`
4955
Country string `json:"country"`

cluster-autoscaler/cloudprovider/utho/utho-go/utho.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@ import (
2727
"time"
2828
)
2929

30+
// BaseUrl is the base endpoint for the Utho API.
3031
const BaseUrl = "https://api.utho.com/v2/"
3132

3233
var defaultHTTPClient = &http.Client{Timeout: time.Second * 300}
3334

35+
// Client is the interface for interacting with the Utho API client.
3436
type Client interface {
37+
// NewRequest creates a new API request.
3538
NewRequest(method, url string, body ...interface{}) (*http.Request, error)
39+
// Do sends an API request and decodes the response.
3640
Do(req *http.Request, v interface{}) (*http.Response, error)
3741

42+
// Kubernetes returns the KubernetesService for Kubernetes-related API calls.
3843
Kubernetes() *KubernetesService
3944
}
4045

0 commit comments

Comments
 (0)