forked from scaleway/scaleway-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
1674 lines (1442 loc) · 55.5 KB
/
api.py
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
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from typing import List, Optional
from scaleway_core.api import API
from scaleway_core.bridge import (
Region as ScwRegion,
)
from scaleway_core.utils import (
validate_path_param,
fetch_all_pages,
)
from .types import (
AlertState,
DataSourceOrigin,
DataSourceType,
GrafanaUserRole,
ListDataSourcesRequestOrderBy,
ListGrafanaUsersRequestOrderBy,
ListPlansRequestOrderBy,
ListTokensRequestOrderBy,
PlanName,
TokenScope,
AlertManager,
ContactPoint,
ContactPointEmail,
DataSource,
DisableAlertRulesResponse,
EnableAlertRulesResponse,
GetConfigResponse,
GlobalApiCreateGrafanaUserRequest,
GlobalApiResetGrafanaUserPasswordRequest,
GlobalApiSelectPlanRequest,
GlobalApiSyncGrafanaDataSourcesRequest,
Grafana,
GrafanaProductDashboard,
GrafanaUser,
ListAlertsResponse,
ListContactPointsResponse,
ListDataSourcesResponse,
ListGrafanaProductDashboardsResponse,
ListGrafanaUsersResponse,
ListPlansResponse,
ListTokensResponse,
Plan,
RegionalApiCreateContactPointRequest,
RegionalApiCreateDataSourceRequest,
RegionalApiCreateTokenRequest,
RegionalApiDeleteContactPointRequest,
RegionalApiDisableAlertManagerRequest,
RegionalApiDisableAlertRulesRequest,
RegionalApiDisableManagedAlertsRequest,
RegionalApiEnableAlertManagerRequest,
RegionalApiEnableAlertRulesRequest,
RegionalApiEnableManagedAlertsRequest,
RegionalApiTriggerTestAlertRequest,
RegionalApiUpdateContactPointRequest,
RegionalApiUpdateDataSourceRequest,
Token,
UsageOverview,
)
from .marshalling import (
unmarshal_ContactPoint,
unmarshal_DataSource,
unmarshal_GrafanaProductDashboard,
unmarshal_GrafanaUser,
unmarshal_Plan,
unmarshal_Token,
unmarshal_AlertManager,
unmarshal_DisableAlertRulesResponse,
unmarshal_EnableAlertRulesResponse,
unmarshal_GetConfigResponse,
unmarshal_Grafana,
unmarshal_ListAlertsResponse,
unmarshal_ListContactPointsResponse,
unmarshal_ListDataSourcesResponse,
unmarshal_ListGrafanaProductDashboardsResponse,
unmarshal_ListGrafanaUsersResponse,
unmarshal_ListPlansResponse,
unmarshal_ListTokensResponse,
unmarshal_UsageOverview,
marshal_GlobalApiCreateGrafanaUserRequest,
marshal_GlobalApiResetGrafanaUserPasswordRequest,
marshal_GlobalApiSelectPlanRequest,
marshal_GlobalApiSyncGrafanaDataSourcesRequest,
marshal_RegionalApiCreateContactPointRequest,
marshal_RegionalApiCreateDataSourceRequest,
marshal_RegionalApiCreateTokenRequest,
marshal_RegionalApiDeleteContactPointRequest,
marshal_RegionalApiDisableAlertManagerRequest,
marshal_RegionalApiDisableAlertRulesRequest,
marshal_RegionalApiDisableManagedAlertsRequest,
marshal_RegionalApiEnableAlertManagerRequest,
marshal_RegionalApiEnableAlertRulesRequest,
marshal_RegionalApiEnableManagedAlertsRequest,
marshal_RegionalApiTriggerTestAlertRequest,
marshal_RegionalApiUpdateContactPointRequest,
marshal_RegionalApiUpdateDataSourceRequest,
)
class CockpitV1GlobalAPI(API):
"""
The Cockpit Global API allows you to manage your Cockpit's Grafana.
"""
def get_grafana(
self,
*,
project_id: Optional[str] = None,
) -> Grafana:
"""
Get your Cockpit's Grafana.
Retrieve information on your Cockpit's Grafana, specified by the ID of the Project the Cockpit belongs to.
The output returned displays the URL to access your Cockpit's Grafana.
:param project_id: ID of the Project.
:return: :class:`Grafana <Grafana>`
Usage:
::
result = api.get_grafana()
"""
res = self._request(
"GET",
"/cockpit/v1/grafana",
params={
"project_id": project_id or self.client.default_project_id,
},
)
self._throw_on_error(res)
return unmarshal_Grafana(res.json())
def sync_grafana_data_sources(
self,
*,
project_id: Optional[str] = None,
) -> None:
"""
Synchronize Grafana data sources.
Trigger the synchronization of all your data sources and the alert manager in the relevant regions. The alert manager will only be synchronized if you have enabled it.
:param project_id: ID of the Project to target.
Usage:
::
result = api.sync_grafana_data_sources()
"""
res = self._request(
"POST",
"/cockpit/v1/grafana/sync-data-sources",
body=marshal_GlobalApiSyncGrafanaDataSourcesRequest(
GlobalApiSyncGrafanaDataSourcesRequest(
project_id=project_id,
),
self.client,
),
)
self._throw_on_error(res)
def create_grafana_user(
self,
*,
login: str,
project_id: Optional[str] = None,
role: Optional[GrafanaUserRole] = None,
) -> GrafanaUser:
"""
Create a Grafana user.
Create a Grafana user to connect to your Cockpit's Grafana. Upon creation, your user password displays only once, so make sure that you save it.
Each Grafana user is associated with a role: viewer or editor. A viewer can only view dashboards, whereas an editor can create and edit dashboards. Note that the `admin` username is not available for creation.
:param login: Username of the Grafana user. Note that the `admin` username is not available for creation.
:param project_id: ID of the Project in which to create the Grafana user.
:param role: Role assigned to the Grafana user.
:return: :class:`GrafanaUser <GrafanaUser>`
Usage:
::
result = api.create_grafana_user(
login="example",
)
"""
res = self._request(
"POST",
"/cockpit/v1/grafana/users",
body=marshal_GlobalApiCreateGrafanaUserRequest(
GlobalApiCreateGrafanaUserRequest(
login=login,
project_id=project_id,
role=role,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_GrafanaUser(res.json())
def list_grafana_users(
self,
*,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListGrafanaUsersRequestOrderBy] = None,
project_id: Optional[str] = None,
) -> ListGrafanaUsersResponse:
"""
List Grafana users.
List all Grafana users created in your Cockpit's Grafana. By default, the Grafana users returned in the list are ordered in ascending order.
:param page: Page number.
:param page_size: Page size.
:param order_by: Order of the Grafana users.
:param project_id: ID of the Project to target.
:return: :class:`ListGrafanaUsersResponse <ListGrafanaUsersResponse>`
Usage:
::
result = api.list_grafana_users()
"""
res = self._request(
"GET",
"/cockpit/v1/grafana/users",
params={
"order_by": order_by,
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
},
)
self._throw_on_error(res)
return unmarshal_ListGrafanaUsersResponse(res.json())
def list_grafana_users_all(
self,
*,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListGrafanaUsersRequestOrderBy] = None,
project_id: Optional[str] = None,
) -> List[GrafanaUser]:
"""
List Grafana users.
List all Grafana users created in your Cockpit's Grafana. By default, the Grafana users returned in the list are ordered in ascending order.
:param page: Page number.
:param page_size: Page size.
:param order_by: Order of the Grafana users.
:param project_id: ID of the Project to target.
:return: :class:`List[GrafanaUser] <List[GrafanaUser]>`
Usage:
::
result = api.list_grafana_users_all()
"""
return fetch_all_pages(
type=ListGrafanaUsersResponse,
key="grafana_users",
fetcher=self.list_grafana_users,
args={
"page": page,
"page_size": page_size,
"order_by": order_by,
"project_id": project_id,
},
)
def delete_grafana_user(
self,
*,
project_id: Optional[str] = None,
grafana_user_id: int,
) -> None:
"""
Delete a Grafana user.
Delete a Grafana user from your Cockpit's Grafana, specified by the ID of the Project the Cockpit belongs to, and the ID of the Grafana user.
:param project_id: ID of the Project to target.
:param grafana_user_id: ID of the Grafana user.
Usage:
::
result = api.delete_grafana_user(
grafana_user_id=1,
)
"""
param_grafana_user_id = validate_path_param("grafana_user_id", grafana_user_id)
res = self._request(
"DELETE",
f"/cockpit/v1/grafana/users/{param_grafana_user_id}",
params={
"project_id": project_id or self.client.default_project_id,
},
)
self._throw_on_error(res)
def reset_grafana_user_password(
self,
*,
project_id: Optional[str] = None,
grafana_user_id: int,
) -> GrafanaUser:
"""
Reset a Grafana user password.
Reset the password of a Grafana user, specified by the ID of the Project the Cockpit belongs to, and the ID of the Grafana user.
A new password regenerates and only displays once. Make sure that you save it.
:param project_id: ID of the Project to target.
:param grafana_user_id: ID of the Grafana user.
:return: :class:`GrafanaUser <GrafanaUser>`
Usage:
::
result = api.reset_grafana_user_password(
grafana_user_id=1,
)
"""
param_grafana_user_id = validate_path_param("grafana_user_id", grafana_user_id)
res = self._request(
"POST",
f"/cockpit/v1/grafana/users/{param_grafana_user_id}/reset-password",
body=marshal_GlobalApiResetGrafanaUserPasswordRequest(
GlobalApiResetGrafanaUserPasswordRequest(
project_id=project_id,
grafana_user_id=grafana_user_id,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_GrafanaUser(res.json())
def list_grafana_product_dashboards(
self,
*,
project_id: Optional[str] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
tags: Optional[List[str]] = None,
) -> ListGrafanaProductDashboardsResponse:
"""
List Scaleway resources dashboards.
Retrieve a list of available dashboards in Grafana, for all Scaleway resources which are integrated with Cockpit.
:param project_id: ID of the Project to target.
:param page: Page number.
:param page_size: Page size.
:param tags: Tags to filter for.
:return: :class:`ListGrafanaProductDashboardsResponse <ListGrafanaProductDashboardsResponse>`
Usage:
::
result = api.list_grafana_product_dashboards()
"""
res = self._request(
"GET",
"/cockpit/v1/grafana/product-dashboards",
params={
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
"tags": tags,
},
)
self._throw_on_error(res)
return unmarshal_ListGrafanaProductDashboardsResponse(res.json())
def list_grafana_product_dashboards_all(
self,
*,
project_id: Optional[str] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
tags: Optional[List[str]] = None,
) -> List[GrafanaProductDashboard]:
"""
List Scaleway resources dashboards.
Retrieve a list of available dashboards in Grafana, for all Scaleway resources which are integrated with Cockpit.
:param project_id: ID of the Project to target.
:param page: Page number.
:param page_size: Page size.
:param tags: Tags to filter for.
:return: :class:`List[GrafanaProductDashboard] <List[GrafanaProductDashboard]>`
Usage:
::
result = api.list_grafana_product_dashboards_all()
"""
return fetch_all_pages(
type=ListGrafanaProductDashboardsResponse,
key="dashboards",
fetcher=self.list_grafana_product_dashboards,
args={
"project_id": project_id,
"page": page,
"page_size": page_size,
"tags": tags,
},
)
def get_grafana_product_dashboard(
self,
*,
project_id: Optional[str] = None,
dashboard_name: str,
) -> GrafanaProductDashboard:
"""
Get Scaleway resource dashboard.
Retrieve information about the dashboard of a Scaleway resource in Grafana, specified by the ID of the Project the Cockpit belongs to, and the name of the dashboard.
:param project_id: ID of the Project the dashboard belongs to.
:param dashboard_name: Name of the dashboard.
:return: :class:`GrafanaProductDashboard <GrafanaProductDashboard>`
Usage:
::
result = api.get_grafana_product_dashboard(
dashboard_name="example",
)
"""
param_dashboard_name = validate_path_param("dashboard_name", dashboard_name)
res = self._request(
"GET",
f"/cockpit/v1/grafana/product-dashboards/{param_dashboard_name}",
params={
"project_id": project_id or self.client.default_project_id,
},
)
self._throw_on_error(res)
return unmarshal_GrafanaProductDashboard(res.json())
def list_plans(
self,
*,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListPlansRequestOrderBy] = None,
) -> ListPlansResponse:
"""
List plan types.
Retrieve a list of available pricing plan types.
Deprecated: retention is now managed at the data source level.
:param page: Page number.
:param page_size: Page size.
:param order_by:
:return: :class:`ListPlansResponse <ListPlansResponse>`
:deprecated
Usage:
::
result = api.list_plans()
"""
res = self._request(
"GET",
"/cockpit/v1/plans",
params={
"order_by": order_by,
"page": page,
"page_size": page_size or self.client.default_page_size,
},
)
self._throw_on_error(res)
return unmarshal_ListPlansResponse(res.json())
def list_plans_all(
self,
*,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListPlansRequestOrderBy] = None,
) -> List[Plan]:
"""
List plan types.
Retrieve a list of available pricing plan types.
Deprecated: retention is now managed at the data source level.
:param page: Page number.
:param page_size: Page size.
:param order_by:
:return: :class:`List[Plan] <List[Plan]>`
:deprecated
Usage:
::
result = api.list_plans_all()
"""
return fetch_all_pages(
type=ListPlansResponse,
key="plans",
fetcher=self.list_plans,
args={
"page": page,
"page_size": page_size,
"order_by": order_by,
},
)
def select_plan(
self,
*,
project_id: Optional[str] = None,
plan_name: Optional[PlanName] = None,
) -> Plan:
"""
Apply a pricing plan.
Apply a pricing plan on a given Project. You must specify the ID of the pricing plan type. Note that you will be billed for the plan you apply.
Deprecated: retention is now managed at the data source level.
:param project_id: ID of the Project.
:param plan_name: Name of the pricing plan.
:return: :class:`Plan <Plan>`
:deprecated
Usage:
::
result = api.select_plan()
"""
res = self._request(
"PATCH",
"/cockpit/v1/plans",
body=marshal_GlobalApiSelectPlanRequest(
GlobalApiSelectPlanRequest(
project_id=project_id,
plan_name=plan_name,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Plan(res.json())
def get_current_plan(
self,
*,
project_id: Optional[str] = None,
) -> Plan:
"""
Get current plan.
Retrieve a pricing plan for the given Project, specified by the ID of the Project.
Deprecated: retention is now managed at the data source level.
:param project_id: ID of the Project.
:return: :class:`Plan <Plan>`
:deprecated
Usage:
::
result = api.get_current_plan()
"""
res = self._request(
"GET",
"/cockpit/v1/current-plan",
params={
"project_id": project_id or self.client.default_project_id,
},
)
self._throw_on_error(res)
return unmarshal_Plan(res.json())
class CockpitV1RegionalAPI(API):
"""
The Cockpit Regional API allows you to create data sources and tokens to store and query data types such as metrics, logs, and traces. You can also push your data into Cockpit, and send alerts to your contact points when your resources may require your attention, using the regional Alert manager.
"""
def get_config(
self,
*,
region: Optional[ScwRegion] = None,
) -> GetConfigResponse:
"""
Get the Cockpit configuration.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`GetConfigResponse <GetConfigResponse>`
Usage:
::
result = api.get_config()
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"GET",
f"/cockpit/v1/regions/{param_region}/config",
)
self._throw_on_error(res)
return unmarshal_GetConfigResponse(res.json())
def create_data_source(
self,
*,
name: str,
region: Optional[ScwRegion] = None,
project_id: Optional[str] = None,
type_: Optional[DataSourceType] = None,
retention_days: Optional[int] = None,
) -> DataSource:
"""
Create a data source.
You must specify the data source type upon creation. Available data source types include:
- metrics
- logs
- traces
The name of the data source will then be used as reference to name the associated Grafana data source.
:param name: Data source name.
:param region: Region to target. If none is passed will use default region from the config.
:param project_id: ID of the Project the data source belongs to.
:param type_: Data source type.
:param retention_days: Default values are 30 days for metrics, 7 days for logs and traces.
:return: :class:`DataSource <DataSource>`
Usage:
::
result = api.create_data_source(
name="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"POST",
f"/cockpit/v1/regions/{param_region}/data-sources",
body=marshal_RegionalApiCreateDataSourceRequest(
RegionalApiCreateDataSourceRequest(
name=name,
region=region,
project_id=project_id,
type_=type_,
retention_days=retention_days,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_DataSource(res.json())
def get_data_source(
self,
*,
data_source_id: str,
region: Optional[ScwRegion] = None,
) -> DataSource:
"""
Get a data source.
Retrieve information about a given data source, specified by the data source ID. The data source's information such as its name, type, URL, origin, and retention period, is returned.
:param data_source_id: ID of the relevant data source.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`DataSource <DataSource>`
Usage:
::
result = api.get_data_source(
data_source_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_data_source_id = validate_path_param("data_source_id", data_source_id)
res = self._request(
"GET",
f"/cockpit/v1/regions/{param_region}/data-sources/{param_data_source_id}",
)
self._throw_on_error(res)
return unmarshal_DataSource(res.json())
def delete_data_source(
self,
*,
data_source_id: str,
region: Optional[ScwRegion] = None,
) -> None:
"""
Delete a data source.
Delete a given data source, specified by the data source ID. Note that deleting a data source is irreversible, and cannot be undone.
:param data_source_id: ID of the data source to delete.
:param region: Region to target. If none is passed will use default region from the config.
Usage:
::
result = api.delete_data_source(
data_source_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_data_source_id = validate_path_param("data_source_id", data_source_id)
res = self._request(
"DELETE",
f"/cockpit/v1/regions/{param_region}/data-sources/{param_data_source_id}",
)
self._throw_on_error(res)
def list_data_sources(
self,
*,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListDataSourcesRequestOrderBy] = None,
project_id: Optional[str] = None,
origin: Optional[DataSourceOrigin] = None,
types: Optional[List[DataSourceType]] = None,
) -> ListDataSourcesResponse:
"""
List data sources.
Retrieve the list of data sources available in the specified region. By default, the data sources returned in the list are ordered by creation date, in ascending order.
You can list data sources by Project, type and origin.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number to return, from the paginated results.
:param page_size: Number of data sources to return per page.
:param order_by: Sort order for data sources in the response.
:param project_id: Project ID to filter for, only data sources from this Project will be returned.
:param origin: Origin to filter for, only data sources with matching origin will be returned.
:param types: Types to filter for, only data sources with matching types will be returned.
:return: :class:`ListDataSourcesResponse <ListDataSourcesResponse>`
Usage:
::
result = api.list_data_sources()
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"GET",
f"/cockpit/v1/regions/{param_region}/data-sources",
params={
"order_by": order_by,
"origin": origin,
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
"types": types,
},
)
self._throw_on_error(res)
return unmarshal_ListDataSourcesResponse(res.json())
def list_data_sources_all(
self,
*,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListDataSourcesRequestOrderBy] = None,
project_id: Optional[str] = None,
origin: Optional[DataSourceOrigin] = None,
types: Optional[List[DataSourceType]] = None,
) -> List[DataSource]:
"""
List data sources.
Retrieve the list of data sources available in the specified region. By default, the data sources returned in the list are ordered by creation date, in ascending order.
You can list data sources by Project, type and origin.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number to return, from the paginated results.
:param page_size: Number of data sources to return per page.
:param order_by: Sort order for data sources in the response.
:param project_id: Project ID to filter for, only data sources from this Project will be returned.
:param origin: Origin to filter for, only data sources with matching origin will be returned.
:param types: Types to filter for, only data sources with matching types will be returned.
:return: :class:`List[DataSource] <List[DataSource]>`
Usage:
::
result = api.list_data_sources_all()
"""
return fetch_all_pages(
type=ListDataSourcesResponse,
key="data_sources",
fetcher=self.list_data_sources,
args={
"region": region,
"page": page,
"page_size": page_size,
"order_by": order_by,
"project_id": project_id,
"origin": origin,
"types": types,
},
)
def update_data_source(
self,
*,
data_source_id: str,
region: Optional[ScwRegion] = None,
name: Optional[str] = None,
retention_days: Optional[int] = None,
) -> DataSource:
"""
Update a data source.
Update a given data source name, specified by the data source ID.
:param data_source_id: ID of the data source to update.
:param region: Region to target. If none is passed will use default region from the config.
:param name: Updated name of the data source.
:param retention_days: BETA - Duration for which the data will be retained in the data source.
:return: :class:`DataSource <DataSource>`
Usage:
::
result = api.update_data_source(
data_source_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_data_source_id = validate_path_param("data_source_id", data_source_id)
res = self._request(
"PATCH",
f"/cockpit/v1/regions/{param_region}/data-sources/{param_data_source_id}",
body=marshal_RegionalApiUpdateDataSourceRequest(
RegionalApiUpdateDataSourceRequest(
data_source_id=data_source_id,
region=region,
name=name,
retention_days=retention_days,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_DataSource(res.json())
def get_usage_overview(
self,
*,
region: Optional[ScwRegion] = None,
project_id: Optional[str] = None,
interval: Optional[str] = None,
) -> UsageOverview:
"""
Get data source usage overview.
Retrieve the data source usage overview per type for the specified Project.
:param region: Region to target. If none is passed will use default region from the config.
:param project_id:
:param interval:
:return: :class:`UsageOverview <UsageOverview>`
Usage:
::
result = api.get_usage_overview()
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"GET",
f"/cockpit/v1/regions/{param_region}/usage-overview",
params={
"interval": interval,
"project_id": project_id or self.client.default_project_id,
},
)
self._throw_on_error(res)
return unmarshal_UsageOverview(res.json())
def create_token(
self,
*,
name: str,
region: Optional[ScwRegion] = None,
project_id: Optional[str] = None,
token_scopes: Optional[List[TokenScope]] = None,
) -> Token:
"""
Create a token.
Give your token the relevant scopes to ensure it has the right permissions to interact with your data sources and the Alert manager. Make sure that you create your token in the same regions as the data sources you want to use it for.
Upon creation, your token's secret key display only once. Make sure that you save it.
:param name: Name of the token.
:param region: Region to target. If none is passed will use default region from the config.
:param project_id: ID of the Project the token belongs to.
:param token_scopes: Token permission scopes.
:return: :class:`Token <Token>`
Usage:
::
result = api.create_token(
name="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"POST",
f"/cockpit/v1/regions/{param_region}/tokens",
body=marshal_RegionalApiCreateTokenRequest(
RegionalApiCreateTokenRequest(
name=name,
region=region,
project_id=project_id,
token_scopes=token_scopes,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Token(res.json())
def list_tokens(
self,
*,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListTokensRequestOrderBy] = None,
project_id: Optional[str] = None,
token_scopes: Optional[List[TokenScope]] = None,
) -> ListTokensResponse:
"""
List tokens.
Retrieve a list of all tokens in the specified region. By default, tokens returned in the list are ordered by creation date, in ascending order.
You can filter tokens by Project ID and token scopes.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number to return, from the paginated results.
:param page_size: Number of tokens to return per page.
:param order_by: Order in which to return results.
:param project_id: ID of the Project the tokens belong to.
:param token_scopes: Token scopes to filter for.
:return: :class:`ListTokensResponse <ListTokensResponse>`
Usage:
::
result = api.list_tokens()
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)