-
Notifications
You must be signed in to change notification settings - Fork 7
/
usage.go
946 lines (790 loc) · 36.3 KB
/
usage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
package gsclient
import (
"context"
"errors"
"net/http"
"path"
"strconv"
)
// UsageOperator provides an interface for operations on usage.
type UsageOperator interface {
GetGeneralUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (GeneralUsage, error)
GetServersUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (ServersUsage, error)
GetDistributedStoragesUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (DistributedStoragesUsage, error)
GetRocketStoragesUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (RocketStoragesUsage, error)
GetStorageBackupsUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (StorageBackupsUsage, error)
etSnapshotsUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (SnapshotsUsage, error)
GetTemplatesUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (TemplatesUsage, error)
GetISOImagesUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (ISOImagesUsage, error)
GetIPsUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (IPsUsage, error)
GetLoadBalancersUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (LoadBalancersUsage, error)
GetPaaSServicesUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (PaaSServicesUsage, error)
}
// Usage represents usage of a product.
type Usage struct {
// Number of a product.
ProductNumber int `json:"product_number"`
// Total usage of a product.
Value int `json:"value"`
}
// UsagePerInterval represents usage of active product within a specific interval.
type UsagePerInterval struct {
// Start accumulation period.
IntervalStart GSTime `json:"interval_start"`
// interval_end
IntervalEnd GSTime `json:"interval_end"`
// Accumulation of product's usage in given period
AccumulatedUsage []Usage `json:"accumulated_usage"`
}
// ResourceUsageInfo represents usage of a specific resource (e.g. server, storage, etc.).
type ResourceUsageInfo struct {
CurrentUsagePerMinute []Usage `json:"current_usage_per_minute"`
UsagePerInterval []UsagePerInterval `json:"usage_per_interval"`
}
// GeneralUsage represents general usage.
type GeneralUsage struct {
ResourcesUsage GeneralUsageProperties `json:"products"`
}
// GeneralUsageProperties holds GeneralUsage's properties.
type GeneralUsageProperties struct {
Servers ResourceUsageInfo `json:"servers"`
RocketStorages ResourceUsageInfo `json:"rocket_storages"`
DistributedStorages ResourceUsageInfo `json:"distributed_storages"`
StorageBackups ResourceUsageInfo `json:"storage_backups"`
Snapshots ResourceUsageInfo `json:"snapshots"`
Templates ResourceUsageInfo `json:"templates"`
IsoImages ResourceUsageInfo `json:"iso_images"`
IPAddresses ResourceUsageInfo `json:"ip_addresses"`
LoadBalancers ResourceUsageInfo `json:"load_balancers"`
PaaSServices ResourceUsageInfo `json:"paas_services"`
}
// ServersUsage represents usage of servers.
type ServersUsage struct {
ResourcesUsage []ServerUsageProperties `json:"servers"`
}
// ServerUsageProperties holds properties of a server usage.
type ServerUsageProperties struct {
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// Indicates the amount of memory in GB.
Memory int `json:"memory"`
// Number of server cores.
Cores int `json:"cores"`
// The power status of the server.
Power bool `json:"power"`
// List of labels.
Labels []string `json:"labels"`
// True if the object is deleted.
Deleted bool `json:"deleted"`
// Status indicates the status of the object. it could be in-provisioning or active.
Status string `json:"status"`
// Current usage of active product.
CurrentUsagePerMinute []Usage `json:"current_usage_per_minute"`
// Usage of active product within a specific interval.
UsagePerInterval []UsagePerInterval `json:"usage_per_interval"`
}
// DistributedStoragesUsage represents usage of distributed storages.
type DistributedStoragesUsage struct {
ResourcesUsage []StorageUsageProperties `json:"distributed_storages"`
}
// RocketStoragesUsage represents usage of rocket storages.
type RocketStoragesUsage struct {
ResourcesUsage []StorageUsageProperties `json:"rocket_storages"`
}
// StorageUsageProperties holds the properties of a distributed/rocket storage usage.
type StorageUsageProperties struct {
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// The UUID of the Storage used to create this Snapshot.
ParentUUID string `json:"parent_uuid"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// List of labels.
Labels []string `json:"labels"`
// True if the object is deleted.
Deleted bool `json:"deleted"`
// Status indicates the status of the object. it could be in-provisioning or active.
Status string `json:"status"`
// Storage type.
// (one of storage, storage_high, storage_insane).
StorageType string `json:"storage_type"`
// Indicates the UUID of the last used template on this storage.
LastUsedTemplate string `json:"last_used_template"`
// The capacity of a storage/ISO image/template/snapshot in GB.
Capacity int `json:"capacity"`
// Current usage of active product.
CurrentUsagePerMinute []Usage `json:"current_usage_per_minute"`
// Usage of active product within a specific interval.
UsagePerInterval []UsagePerInterval `json:"usage_per_interval"`
}
// StorageBackupsUsage represents usage of storage backups.
type StorageBackupsUsage struct {
ResourcesUsage []StorageBackupUsageProperties `json:"storage_backups"`
}
// StorageBackupUsageProperties holds properties of a storage bakup usage.
type StorageBackupUsageProperties struct {
// The UUID of a backup is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// The name of the backup equals schedule name plus backup UUID.
Name string `json:"name"`
// Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
// Defines the date and time of the last object change.
ChangeTime GSTime `json:"change_time"`
// The size of a backup in GB.
Capacity int `json:"capacity"`
// Current usage of active product.
CurrentUsagePerMinute []Usage `json:"current_usage_per_minute"`
// Usage of active product within a specific interval.
UsagePerInterval []UsagePerInterval `json:"usage_per_interval"`
}
// SnapshotsUsage represents usage of snapshots.
type SnapshotsUsage struct {
ResourcesUsage []SnapshotUsageProperties `json:"snapshots"`
}
// SnapshotUsageProperties holds properties of a snapshot usage.
type SnapshotUsageProperties struct {
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// Uuid of the storage used to create this snapshot.
ParentUUID string `json:"parent_uuid"`
// Name of the storage used to create this snapshot.
ParentName string `json:"parent_name"`
// Uuid of the project used to create this snapshot.
ProjectUUID string `json:"project_uuid"`
// List of labels.
Labels []string `json:"labels"`
// Status indicates the status of the object.
Status string `json:"status"`
// Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
// Defines the date and time of the last object change.
ChangeTime GSTime `json:"change_time"`
// The capacity of a storage/ISO image/template/snapshot in GB.
Capacity int `json:"capacity"`
// True if the object is deleted.
Deleted bool `json:"deleted"`
// Current usage of active product.
CurrentUsagePerMinute []Usage `json:"current_usage_per_minute"`
// Usage of active product within a specific interval.
UsagePerInterval []UsagePerInterval `json:"usage_per_interval"`
}
// TemplatesUsage represents usage of templates.
type TemplatesUsage struct {
ResourcesUsage []TemplateUsageProperties `json:"templates"`
}
// TemplateUsageProperties holds properties of a template usage.
type TemplateUsageProperties struct {
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// Status indicates the status of the object.
Status string `json:"status"`
// Status indicates the status of the object.
Ostype string `json:"ostype"`
// A version string for this template.
Version string `json:"version"`
// Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
// Defines the date and time of the last change.
ChangeTime GSTime `json:"change_time"`
// Whether the object is private, the value will be true. Otherwise the value will be false.
Private bool `json:"private"`
// If a template has been used that requires a license key (e.g. Windows Servers)
// this shows the product_no of the license (see the /prices endpoint for more details).
LicenseProductNo int `json:"license_product_no"`
// The capacity of a storage/ISO image/template/snapshot in GiB.
Capacity int `json:"capacity"`
// The OS distribution of this template.
Distro string `json:"distro"`
// Description of the template.
Description string `json:"description"`
// List of labels.
Labels []string `json:"labels"`
// Uuid of the project used to create this template.
ProjectUUID string `json:"project_uuid"`
// True if the object is deleted.
Deleted bool `json:"deleted"`
// Current usage of active product.
CurrentUsagePerMinute []Usage `json:"current_usage_per_minute"`
// Usage of active product within a specific interval.
UsagePerInterval []UsagePerInterval `json:"usage_per_interval"`
}
// ISOImagesUsage represents usage of ISO images.
type ISOImagesUsage struct {
ResourcesUsage []ISOImageUsageProperties `json:"iso_images"`
}
// ISOImageUsageProperties holds properties of an ISO Image usage.
type ISOImageUsageProperties struct {
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// Description of the ISO image release.
Description string `json:"description"`
// Contains the source URL of the ISO image that it was originally fetched from.
SourceURL string `json:"source_url"`
// List of labels.
Labels []string `json:"labels"`
// Status indicates the status of the object.
Status string `json:"status"`
// Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
// Defines the date and time of the last object change.
ChangeTime GSTime `json:"change_time"`
// Upstream version of the ISO image release.
Version string `json:"version"`
// Whether the ISO image is private or not.
Private bool `json:"private"`
// The capacity of an ISO image in GB.
Capacity int `json:"capacity"`
// Uuid of the project used to create this ISO image.
ProjectUUID string `json:"project_uuid"`
// True if the object is deleted.
Deleted bool `json:"deleted"`
// Current usage of active product.
CurrentUsagePerMinute []Usage `json:"current_usage_per_minute"`
// Usage of active product within a specific interval.
UsagePerInterval []UsagePerInterval `json:"usage_per_interval"`
}
// IPsUsage represents usage of IP addresses.
type IPsUsage struct {
ResourcesUsage []IPUsageProperties `json:"ip_addresses"`
}
// IPUsageProperties holds properties of an IP address usage.
type IPUsageProperties struct {
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// Defines the IP Address (v4 or v6).
IP string `json:"ip"`
// Enum:4 6. The IP Address family (v4 or v6).
Family int `json:"family"`
// Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
// Defines the date and time of the last object change.
ChangeTime GSTime `json:"change_time"`
// Status indicates the status of the object.
Status string `json:"status"`
// The human-readable name of the location. It supports the full UTF-8 character set, with a maximum of 64 characters.
LocationCountry string `json:"location_country"`
// The human-readable name of the location. It supports the full UTF-8 character set, with a maximum of 64 characters.
LocationName string `json:"location_name"`
// Uses IATA airport code, which works as a location identifier.
LocationIata string `json:"location_iata"`
// Helps to identify which data center an object belongs to.
LocationUUID string `json:"location_uuid"`
// The IP prefix.
Prefix string `json:"prefix"`
// Defines if the object is administratively blocked. If true, it can not be deleted by the user.
DeleteBlock bool `json:"delete_block"`
// Sets failover mode for this IP. If true, then this IP is no longer available for DHCP and can no longer be related to any server.
Failover bool `json:"failover"`
// List of labels.
Labels []string `json:"labels"`
// Defines the reverse DNS entry for the IP Address (PTR Resource Record).
ReverseDNS string `json:"reverse_dns"`
// Uuid of the partner used to create this IP address.
PartnerUUID string `json:"partner_uuid"`
// Uuid of the project used to create this IP address.
ProjectUUID string `json:"project_uuid"`
// True if the object is deleted.
Deleted bool `json:"deleted"`
// Current usage of active product.
CurrentUsagePerMinute []Usage `json:"current_usage_per_minute"`
// Usage of active product within a specific interval.
UsagePerInterval []UsagePerInterval `json:"usage_per_interval"`
}
// LoadBalancersUsage represents usage of storage backups.
type LoadBalancersUsage struct {
ResourcesUsage []LoadBalancerUsageProperties `json:"load_balancers"`
}
// LoadBalancerUsageProperties holds properties of a loadbalancer usage.
type LoadBalancerUsageProperties struct {
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// Forwarding rules of a load balancer.
ForwardingRules []ForwardingRule `json:"forwarding_rules"`
// The servers that this Load balancer can communicate with.
BackendServers []BackendServer `json:"backend_servers"`
// Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
// Defines the date and time of the last object change.
ChangeTime GSTime `json:"change_time"`
// Status indicates the status of the object.
Status string `json:"status"`
// Whether the Load balancer is forced to redirect requests from HTTP to HTTPS.
RedirectHTTPToHTTPS bool `json:"redirect_http_to_https"`
// The algorithm used to process requests. Accepted values: roundrobin / leastconn.
Algorithm string `json:"algorithm"`
// The UUID of the IPv6 address the Load balancer will listen to for incoming requests.
ListenIPv6UUID string `json:"listen_ipv6_uuid"`
// The UUID of the IPv4 address the Load balancer will listen to for incoming requests.
ListenIPv4UUID string `json:"listen_ipv4_uuid"`
// Current usage of active product.
CurrentUsagePerMinute []Usage `json:"current_usage_per_minute"`
// Usage of active product within a specific interval.
UsagePerInterval []UsagePerInterval `json:"usage_per_interval"`
}
// PaaSServicesUsage represents usage of PaaS services.
type PaaSServicesUsage struct {
ResourcesUsage []PaaSServiceUsageProperties `json:"paas_services"`
}
// PaaSServiceUsageProperties holds properties of a PaaS service usage.
type PaaSServiceUsageProperties struct {
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// Status indicates the status of the object.
Status string `json:"status"`
// Contains the initial setup credentials for Service.
Credentials []Credential `json:"credentials"`
// Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
// Defines the date and time of the last object change.
ChangeTime GSTime `json:"change_time"`
// The template used to create the service, you can find an available list at the /service_templates endpoint.
ServiceTemplateUUID string `json:"service_template_uuid"`
// Contains the service parameters for the service.
Parameters map[string]interface{} `json:"parameters"`
// A list of service resource limits.
ResourceLimits []ResourceLimit `json:"resource_limits"`
// Uuid of the project used to create this PaaS.
ProjectUUID string `json:"project_uuid"`
// True if the object is deleted.
Deleted bool `json:"deleted"`
// Current usage of active product.
CurrentUsagePerMinute []Usage `json:"current_usage_per_minute"`
// Usage of active product within a specific interval.
UsagePerInterval []UsagePerInterval `json:"usage_per_interval"`
}
// All allowed interval variable's values
const (
HourIntervalVariable = "H"
DayIntervalVariable = "D"
WeekIntervalVariable = "W"
MonthIntervalVariable = "M"
)
type usageQueryLevel int
const (
// ProjectLevelUsage is used to query resources' usage in project level.
ProjectLevelUsage usageQueryLevel = iota
// ContractLevelUsage is used to query resources' usage in contract level.
ContractLevelUsage = iota
)
var invalidUsageQueryLevel = errors.New("invalid Usage query level. Valid values: `gslclient.ProjectLevelUsage`, and `gslclient.ContractLevelUsage`")
// GetGeneralUsage returns general usage of all resources in project/contract level.
// Args:
// - queryLevel (Required): resources' usage query level. Either ProjectLevelUsage or ContractLevelUsage.
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Required, true/false): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelUsageGet
func (c *Client) GetGeneralUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (GeneralUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return GeneralUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: uri,
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response GeneralUsage
err := r.execute(ctx, *c, &response)
return response, err
}
// GetServersUsage returns usage of all servers in project/contract level.
// Args:
// - queryLevel (Required): resources' usage query level. Either ProjectLevelUsage or ContractLevelUsage.
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Required, true/false): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelServerUsageGet
func (c *Client) GetServersUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (ServersUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return ServersUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: path.Join(uri, "servers"),
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response ServersUsage
err := r.execute(ctx, *c, &response)
return response, err
}
// GetDistributedStoragesUsage returns usage of all distributed storages in project/contract level.
// Args:
// - queryLevel (Required): resources' usage query level. Either ProjectLevelUsage or ContractLevelUsage.
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Required, true/false): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelDistributedStorageUsageGet
func (c *Client) GetDistributedStoragesUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (DistributedStoragesUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return DistributedStoragesUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: path.Join(uri, "distributed_storages"),
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response DistributedStoragesUsage
err := r.execute(ctx, *c, &response)
return response, err
}
// GetRocketStoragesUsage returns usage of all servers in project/contract level.
// Args:
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Optional, can be nil): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelRocketStorageUsageGet
func (c *Client) GetRocketStoragesUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (RocketStoragesUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return RocketStoragesUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: path.Join(uri, "rocket_storages"),
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response RocketStoragesUsage
err := r.execute(ctx, *c, &response)
return response, err
}
// GetStorageBackupsUsage returns usage of all storage backups in project/contract level.
// Args:
// - queryLevel (Required): resources' usage query level. Either ProjectLevelUsage or ContractLevelUsage.
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Required, true/false): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelStorageBackupUsageGet
func (c *Client) GetStorageBackupsUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (StorageBackupsUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return StorageBackupsUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: path.Join(uri, "storage_backups"),
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response StorageBackupsUsage
err := r.execute(ctx, *c, &response)
return response, err
}
// GetSnapshotsUsage returns usage of all snapshots in project/contract level.
// Args:
// - queryLevel (Required): resources' usage query level. Either ProjectLevelUsage or ContractLevelUsage.
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Required, true/false): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelSnapshotUsageGet
func (c *Client) GetSnapshotsUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (SnapshotsUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return SnapshotsUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: path.Join(uri, "snapshots"),
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response SnapshotsUsage
err := r.execute(ctx, *c, &response)
return response, err
}
// GetTemplatesUsage returns usage of all templates in project/contract level.
// Args:
// - queryLevel (Required): resources' usage query level. Either ProjectLevelUsage or ContractLevelUsage.
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Required, true/false): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelTemplateUsageGet
func (c *Client) GetTemplatesUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (TemplatesUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return TemplatesUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: path.Join(uri, "templates"),
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response TemplatesUsage
err := r.execute(ctx, *c, &response)
return response, err
}
// GetISOImagesUsage returns usage of all ISO images in project/contract level.
// Args:
// - queryLevel (Required): resources' usage query level. Either ProjectLevelUsage or ContractLevelUsage.
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Required, true/false): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelIsoimageUsageGet
func (c *Client) GetISOImagesUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (ISOImagesUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return ISOImagesUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: path.Join(uri, "iso_images"),
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response ISOImagesUsage
err := r.execute(ctx, *c, &response)
return response, err
}
// GetIPsUsage returns usage of all IP addresses' usage in project/contract level.
// Args:
// - queryLevel (Required): resources' usage query level. Either ProjectLevelUsage or ContractLevelUsage.
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Required, true/false): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelIpUsageGet
func (c *Client) GetIPsUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (IPsUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return IPsUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: path.Join(uri, "ip_addresses"),
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response IPsUsage
err := r.execute(ctx, *c, &response)
return response, err
}
// GetLoadBalancersUsage returns usage of all Load Balancers' usage in project/contract level.
// Args:
// - queryLevel (Required): resources' usage query level. Either ProjectLevelUsage or ContractLevelUsage.
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Required, true/false): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelLoadbalancerUsageGet
func (c *Client) GetLoadBalancersUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (LoadBalancersUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return LoadBalancersUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: path.Join(uri, "load_balancers"),
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response LoadBalancersUsage
err := r.execute(ctx, *c, &response)
return response, err
}
// GetPaaSServicesUsage returns usage of all PaaS services' usage in project/contract level.
// Args:
// - queryLevel (Required): resources' usage query level. Either ProjectLevelUsage or ContractLevelUsage.
// - fromTime (Required): Starting time when the usage should be calculated.
// - toTime (Optional, can be nil): End time when the usage should be calculated.
// - withoutDeleted (Required, true/false): To calculate the usage with or without deleted resources.
// - intervalVariable (Optional, can be empty ""): HourIntervalVariable, DayIntervalVariable, WeekIntervalVariable, MonthIntervalVariable, or "".
//
// See: https://gridscale.io/en/api-documentation/index.html#operation/ProjectLevelPaasServiceUsageGet
func (c *Client) GetPaaSServicesUsage(ctx context.Context, queryLevel usageQueryLevel, fromTime GSTime, toTime *GSTime, withoutDeleted bool, intervalVariable string) (PaaSServicesUsage, error) {
queryParam := map[string]string{
"from_time": fromTime.String(),
"without_deleted": strconv.FormatBool(withoutDeleted),
"interval_variable": intervalVariable,
}
if toTime != nil {
queryParam["to_time"] = toTime.String()
}
var uri string
switch queryLevel {
case ProjectLevelUsage:
uri = apiProjectLevelUsage
case ContractLevelUsage:
uri = apiContractLevelUsage
default:
return PaaSServicesUsage{}, invalidUsageQueryLevel
}
r := gsRequest{
uri: path.Join(uri, "paas_services"),
method: http.MethodGet,
skipCheckingRequest: true,
queryParameters: queryParam,
}
var response PaaSServicesUsage
err := r.execute(ctx, *c, &response)
return response, err
}