0
# Cloud Computing
1
2
Application and service stack management for cloud computing resources including containers, access points, and volume management. The compute platform provides comprehensive infrastructure management capabilities.
3
4
## Capabilities
5
6
### Account and Application Management
7
8
Account-level operations and application lifecycle management through the `AccountClient` class.
9
10
```python { .api }
11
class AccountClient:
12
def __init__(self, auth: Auth, host: str = None):
13
"""
14
Initialize account client.
15
16
Args:
17
auth: Auth instance for authentication
18
host: Custom host URL (optional)
19
"""
20
21
def get_account_info(self) -> tuple:
22
"""
23
Get account information.
24
25
Returns:
26
(dict, ResponseInfo): Account info and response info
27
"""
28
29
def list_regions(self) -> tuple:
30
"""
31
List available regions.
32
33
Returns:
34
(dict, ResponseInfo): Region list and response info
35
"""
36
37
def list_apps(self) -> tuple:
38
"""
39
List applications.
40
41
Returns:
42
(dict, ResponseInfo): Application list and response info
43
"""
44
45
def create_app(self, args: dict) -> tuple:
46
"""
47
Create new application.
48
49
Args:
50
args: Application configuration dictionary
51
52
Returns:
53
(dict, ResponseInfo): Creation result and response info
54
"""
55
56
def delete_app(self, app_uri: str) -> tuple:
57
"""
58
Delete application.
59
60
Args:
61
app_uri: Application URI identifier
62
63
Returns:
64
(dict, ResponseInfo): Deletion result and response info
65
"""
66
67
def get_app_keys(self, app_uri: str) -> tuple:
68
"""
69
Get application keys.
70
71
Args:
72
app_uri: Application URI identifier
73
74
Returns:
75
(dict, ResponseInfo): Application keys and response info
76
"""
77
78
def get_valid_app_auth(self, app_uri: str) -> tuple:
79
"""
80
Get valid application authentication.
81
82
Args:
83
app_uri: Application URI identifier
84
85
Returns:
86
(dict, ResponseInfo): Authentication info and response info
87
"""
88
89
def get_app_region_products(self, app_uri: str) -> tuple:
90
"""
91
Get application region products.
92
93
Args:
94
app_uri: Application URI identifier
95
96
Returns:
97
(dict, ResponseInfo): Region products and response info
98
"""
99
100
def get_region_products(self, region: str) -> tuple:
101
"""
102
Get products available in region.
103
104
Args:
105
region: Region identifier
106
107
Returns:
108
(dict, ResponseInfo): Region products and response info
109
"""
110
111
def get_qcos_client(self, app_uri: str):
112
"""
113
Get cached resource client for application.
114
115
Args:
116
app_uri: Application URI identifier
117
118
Returns:
119
QcosClient: Resource management client
120
"""
121
122
def create_qcos_client(self, app_uri: str):
123
"""
124
Create new resource client for application.
125
126
Args:
127
app_uri: Application URI identifier
128
129
Returns:
130
QcosClient: Resource management client
131
"""
132
```
133
134
### Resource Management
135
136
Comprehensive resource management including stacks, services, containers, and access points through the `QcosClient` class.
137
138
```python { .api }
139
class QcosClient:
140
def __init__(self, auth: Auth, host: str = None):
141
"""
142
Initialize resource management client.
143
144
Args:
145
auth: Auth instance for authentication
146
host: Custom host URL (optional)
147
"""
148
149
# Stack Operations
150
def list_stacks(self) -> tuple:
151
"""
152
List service stacks.
153
154
Returns:
155
(dict, ResponseInfo): Stack list and response info
156
"""
157
158
def create_stack(self, args: dict) -> tuple:
159
"""
160
Create service stack.
161
162
Args:
163
args: Stack configuration dictionary
164
165
Returns:
166
(dict, ResponseInfo): Creation result and response info
167
"""
168
169
def delete_stack(self, stack: str) -> tuple:
170
"""
171
Delete service stack.
172
173
Args:
174
stack: Stack identifier
175
176
Returns:
177
(dict, ResponseInfo): Deletion result and response info
178
"""
179
180
def get_stack(self, stack: str) -> tuple:
181
"""
182
Get stack information.
183
184
Args:
185
stack: Stack identifier
186
187
Returns:
188
(dict, ResponseInfo): Stack info and response info
189
"""
190
191
def start_stack(self, stack: str) -> tuple:
192
"""
193
Start service stack.
194
195
Args:
196
stack: Stack identifier
197
198
Returns:
199
(dict, ResponseInfo): Operation result and response info
200
"""
201
202
def stop_stack(self, stack: str) -> tuple:
203
"""
204
Stop service stack.
205
206
Args:
207
stack: Stack identifier
208
209
Returns:
210
(dict, ResponseInfo): Operation result and response info
211
"""
212
213
# Service Operations
214
def list_services(self, stack: str) -> tuple:
215
"""
216
List services in stack.
217
218
Args:
219
stack: Stack identifier
220
221
Returns:
222
(dict, ResponseInfo): Service list and response info
223
"""
224
225
def create_service(self, stack: str, args: dict) -> tuple:
226
"""
227
Create service in stack.
228
229
Args:
230
stack: Stack identifier
231
args: Service configuration dictionary
232
233
Returns:
234
(dict, ResponseInfo): Creation result and response info
235
"""
236
237
def delete_service(self, stack: str, service: str) -> tuple:
238
"""
239
Delete service from stack.
240
241
Args:
242
stack: Stack identifier
243
service: Service identifier
244
245
Returns:
246
(dict, ResponseInfo): Deletion result and response info
247
"""
248
249
def get_service_inspect(self, stack: str, service: str) -> tuple:
250
"""
251
Get detailed service information.
252
253
Args:
254
stack: Stack identifier
255
service: Service identifier
256
257
Returns:
258
(dict, ResponseInfo): Service details and response info
259
"""
260
261
def start_service(self, stack: str, service: str) -> tuple:
262
"""
263
Start service.
264
265
Args:
266
stack: Stack identifier
267
service: Service identifier
268
269
Returns:
270
(dict, ResponseInfo): Operation result and response info
271
"""
272
273
def stop_service(self, stack: str, service: str) -> tuple:
274
"""
275
Stop service.
276
277
Args:
278
stack: Stack identifier
279
service: Service identifier
280
281
Returns:
282
(dict, ResponseInfo): Operation result and response info
283
"""
284
285
def update_service(self, stack: str, service: str, args: dict) -> tuple:
286
"""
287
Update service configuration.
288
289
Args:
290
stack: Stack identifier
291
service: Service identifier
292
args: Updated configuration dictionary
293
294
Returns:
295
(dict, ResponseInfo): Update result and response info
296
"""
297
298
def scale_service(self, stack: str, service: str, args: dict) -> tuple:
299
"""
300
Scale service replicas.
301
302
Args:
303
stack: Stack identifier
304
service: Service identifier
305
args: Scaling configuration dictionary
306
307
Returns:
308
(dict, ResponseInfo): Scaling result and response info
309
"""
310
311
# Volume Operations
312
def create_service_volume(self, stack: str, service: str, args: dict) -> tuple:
313
"""
314
Create volume for service.
315
316
Args:
317
stack: Stack identifier
318
service: Service identifier
319
args: Volume configuration dictionary
320
321
Returns:
322
(dict, ResponseInfo): Creation result and response info
323
"""
324
325
def extend_service_volume(self, stack: str, service: str, volume: str, args: dict) -> tuple:
326
"""
327
Extend service volume capacity.
328
329
Args:
330
stack: Stack identifier
331
service: Service identifier
332
volume: Volume identifier
333
args: Extension configuration dictionary
334
335
Returns:
336
(dict, ResponseInfo): Extension result and response info
337
"""
338
339
def delete_service_volume(self, stack: str, service: str, volume: str) -> tuple:
340
"""
341
Delete service volume.
342
343
Args:
344
stack: Stack identifier
345
service: Service identifier
346
volume: Volume identifier
347
348
Returns:
349
(dict, ResponseInfo): Deletion result and response info
350
"""
351
352
# Container Operations
353
def list_containers(self, stack: str = None, service: str = None) -> tuple:
354
"""
355
List containers.
356
357
Args:
358
stack: Stack identifier (optional filter)
359
service: Service identifier (optional filter)
360
361
Returns:
362
(dict, ResponseInfo): Container list and response info
363
"""
364
365
def get_container_inspect(self, ip: str) -> tuple:
366
"""
367
Get detailed container information.
368
369
Args:
370
ip: Container IP address
371
372
Returns:
373
(dict, ResponseInfo): Container details and response info
374
"""
375
376
def start_container(self, ip: str) -> tuple:
377
"""
378
Start container.
379
380
Args:
381
ip: Container IP address
382
383
Returns:
384
(dict, ResponseInfo): Operation result and response info
385
"""
386
387
def stop_container(self, ip: str) -> tuple:
388
"""
389
Stop container.
390
391
Args:
392
ip: Container IP address
393
394
Returns:
395
(dict, ResponseInfo): Operation result and response info
396
"""
397
398
def restart_container(self, ip: str) -> tuple:
399
"""
400
Restart container.
401
402
Args:
403
ip: Container IP address
404
405
Returns:
406
(dict, ResponseInfo): Operation result and response info
407
"""
408
409
# Access Point Operations
410
def list_aps(self) -> tuple:
411
"""
412
List access points.
413
414
Returns:
415
(dict, ResponseInfo): Access point list and response info
416
"""
417
418
def create_ap(self, args: dict) -> tuple:
419
"""
420
Create access point.
421
422
Args:
423
args: Access point configuration dictionary
424
425
Returns:
426
(dict, ResponseInfo): Creation result and response info
427
"""
428
429
def search_ap(self, mode: str, query: str) -> tuple:
430
"""
431
Search access points.
432
433
Args:
434
mode: Search mode
435
query: Search query string
436
437
Returns:
438
(dict, ResponseInfo): Search results and response info
439
"""
440
441
def get_ap(self, apid: str) -> tuple:
442
"""
443
Get access point information.
444
445
Args:
446
apid: Access point ID
447
448
Returns:
449
(dict, ResponseInfo): Access point info and response info
450
"""
451
452
def update_ap(self, apid: str, args: dict) -> tuple:
453
"""
454
Update access point configuration.
455
456
Args:
457
apid: Access point ID
458
args: Updated configuration dictionary
459
460
Returns:
461
(dict, ResponseInfo): Update result and response info
462
"""
463
464
def delete_ap(self, apid: str) -> tuple:
465
"""
466
Delete access point.
467
468
Args:
469
apid: Access point ID
470
471
Returns:
472
(dict, ResponseInfo): Deletion result and response info
473
"""
474
475
def set_ap_port(self, apid: str, port: int, args: dict) -> tuple:
476
"""
477
Set access point port configuration.
478
479
Args:
480
apid: Access point ID
481
port: Port number
482
args: Port configuration dictionary
483
484
Returns:
485
(dict, ResponseInfo): Configuration result and response info
486
"""
487
488
def publish_ap(self, apid: str, args: dict) -> tuple:
489
"""
490
Bind custom domain to access point.
491
492
Args:
493
apid: Access point ID
494
args: Domain binding configuration
495
496
Returns:
497
(dict, ResponseInfo): Binding result and response info
498
"""
499
500
def unpublish_ap(self, apid: str, args: dict) -> tuple:
501
"""
502
Unbind custom domain from access point.
503
504
Args:
505
apid: Access point ID
506
args: Domain unbinding configuration
507
508
Returns:
509
(dict, ResponseInfo): Unbinding result and response info
510
"""
511
512
def get_ap_port_healthcheck(self, apid: str, port: int) -> tuple:
513
"""
514
Get access point port health check configuration.
515
516
Args:
517
apid: Access point ID
518
port: Port number
519
520
Returns:
521
(dict, ResponseInfo): Health check config and response info
522
"""
523
524
def set_ap_port_container(self, apid: str, port: int, args: dict) -> tuple:
525
"""
526
Set backend container for access point port.
527
528
Args:
529
apid: Access point ID
530
port: Port number
531
args: Container configuration dictionary
532
533
Returns:
534
(dict, ResponseInfo): Configuration result and response info
535
"""
536
537
def disable_ap_port(self, apid: str, port: int) -> tuple:
538
"""
539
Disable access point port.
540
541
Args:
542
apid: Access point ID
543
port: Port number
544
545
Returns:
546
(dict, ResponseInfo): Operation result and response info
547
"""
548
549
def enable_ap_port(self, apid: str, port: int) -> tuple:
550
"""
551
Enable access point port.
552
553
Args:
554
apid: Access point ID
555
port: Port number
556
557
Returns:
558
(dict, ResponseInfo): Operation result and response info
559
"""
560
561
def get_ap_providers(self) -> tuple:
562
"""
563
List access point providers.
564
565
Returns:
566
(dict, ResponseInfo): Provider list and response info
567
"""
568
569
def get_web_proxy(self, backend: str) -> tuple:
570
"""
571
Get web proxy configuration.
572
573
Args:
574
backend: Backend identifier
575
576
Returns:
577
(dict, ResponseInfo): Proxy config and response info
578
"""
579
```
580
581
## Usage Examples
582
583
### Application Management
584
585
```python
586
from qiniu import Auth, AccountClient
587
588
auth = Auth(access_key, secret_key)
589
account_client = AccountClient(auth)
590
591
# Get account information
592
ret, info = account_client.get_account_info()
593
if info.ok():
594
print(f"Account ID: {ret['id']}")
595
print(f"Account name: {ret['name']}")
596
597
# List available regions
598
ret, info = account_client.list_regions()
599
if info.ok():
600
for region in ret['items']:
601
print(f"Region: {region['id']} - {region['name']}")
602
603
# Create new application
604
app_config = {
605
'name': 'my-web-app',
606
'region': 'cn-east-1',
607
'description': 'Web application deployment'
608
}
609
610
ret, info = account_client.create_app(app_config)
611
if info.ok():
612
app_uri = ret['uri']
613
print(f"Application created: {app_uri}")
614
615
# Get application keys
616
ret, info = account_client.get_app_keys(app_uri)
617
if info.ok():
618
print(f"App access key: {ret['accessKey']}")
619
620
# List all applications
621
ret, info = account_client.list_apps()
622
if info.ok():
623
for app in ret['items']:
624
print(f"App: {app['name']} ({app['uri']})")
625
```
626
627
### Stack and Service Management
628
629
```python
630
from qiniu import Auth, AccountClient
631
632
auth = Auth(access_key, secret_key)
633
account_client = AccountClient(auth)
634
635
# Get resource client for application
636
app_uri = 'qcos://my-web-app'
637
qcos_client = account_client.get_qcos_client(app_uri)
638
639
# Create service stack
640
stack_config = {
641
'name': 'web-stack',
642
'description': 'Web service stack',
643
'region': 'cn-east-1'
644
}
645
646
ret, info = qcos_client.create_stack(stack_config)
647
if info.ok():
648
stack_id = ret['name']
649
print(f"Stack created: {stack_id}")
650
651
# Create web service
652
service_config = {
653
'name': 'web-server',
654
'image': 'nginx:alpine',
655
'replicas': 2,
656
'resources': {
657
'cpu': '500m',
658
'memory': '512Mi'
659
},
660
'ports': [
661
{
662
'containerPort': 80,
663
'protocol': 'TCP'
664
}
665
],
666
'env': [
667
{
668
'name': 'ENV',
669
'value': 'production'
670
}
671
]
672
}
673
674
ret, info = qcos_client.create_service(stack_id, service_config)
675
if info.ok():
676
service_id = ret['name']
677
print(f"Service created: {service_id}")
678
679
# Get service details
680
ret, info = qcos_client.get_service_inspect(stack_id, service_id)
681
if info.ok():
682
print(f"Service status: {ret['status']}")
683
print(f"Replicas: {ret['replicas']}")
684
685
# List all stacks
686
ret, info = qcos_client.list_stacks()
687
if info.ok():
688
for stack in ret['items']:
689
print(f"Stack: {stack['name']} - Status: {stack['status']}")
690
691
# List services in stack
692
ret, info = qcos_client.list_services(stack['name'])
693
if info.ok():
694
for service in ret['items']:
695
print(f" Service: {service['name']} - {service['status']}")
696
```
697
698
### Container Management
699
700
```python
701
from qiniu import Auth, AccountClient
702
703
auth = Auth(access_key, secret_key)
704
account_client = AccountClient(auth)
705
qcos_client = account_client.get_qcos_client('qcos://my-web-app')
706
707
# List all containers
708
ret, info = qcos_client.list_containers()
709
if info.ok():
710
for container in ret['items']:
711
container_ip = container['ip']
712
print(f"Container: {container['name']} - IP: {container_ip}")
713
print(f"Status: {container['status']}")
714
715
# Get detailed container information
716
ret, info = qcos_client.get_container_inspect(container_ip)
717
if info.ok():
718
container_details = ret
719
print(f"Image: {container_details['image']}")
720
print(f"CPU Usage: {container_details.get('cpuUsage', 'N/A')}")
721
print(f"Memory Usage: {container_details.get('memoryUsage', 'N/A')}")
722
723
# Container lifecycle operations
724
container_ip = '10.0.1.100'
725
726
# Stop container
727
ret, info = qcos_client.stop_container(container_ip)
728
if info.ok():
729
print("Container stopped successfully")
730
731
# Start container
732
ret, info = qcos_client.start_container(container_ip)
733
if info.ok():
734
print("Container started successfully")
735
736
# Restart container
737
ret, info = qcos_client.restart_container(container_ip)
738
if info.ok():
739
print("Container restarted successfully")
740
```
741
742
### Service Scaling and Updates
743
744
```python
745
from qiniu import Auth, AccountClient
746
747
auth = Auth(access_key, secret_key)
748
account_client = AccountClient(auth)
749
qcos_client = account_client.get_qcos_client('qcos://my-web-app')
750
751
stack_id = 'web-stack'
752
service_id = 'web-server'
753
754
# Scale service replicas
755
scale_config = {
756
'replicas': 5
757
}
758
759
ret, info = qcos_client.scale_service(stack_id, service_id, scale_config)
760
if info.ok():
761
print("Service scaled successfully")
762
763
# Update service configuration
764
update_config = {
765
'image': 'nginx:1.21-alpine',
766
'resources': {
767
'cpu': '1000m',
768
'memory': '1Gi'
769
},
770
'env': [
771
{
772
'name': 'ENV',
773
'value': 'production'
774
},
775
{
776
'name': 'LOG_LEVEL',
777
'value': 'info'
778
}
779
]
780
}
781
782
ret, info = qcos_client.update_service(stack_id, service_id, update_config)
783
if info.ok():
784
print("Service updated successfully")
785
```
786
787
### Volume Management
788
789
```python
790
from qiniu import Auth, AccountClient
791
792
auth = Auth(access_key, secret_key)
793
account_client = AccountClient(auth)
794
qcos_client = account_client.get_qcos_client('qcos://my-web-app')
795
796
stack_id = 'web-stack'
797
service_id = 'web-server'
798
799
# Create volume for service
800
volume_config = {
801
'name': 'web-data',
802
'size': '10Gi',
803
'mountPath': '/var/www/html',
804
'storageClass': 'ssd'
805
}
806
807
ret, info = qcos_client.create_service_volume(stack_id, service_id, volume_config)
808
if info.ok():
809
volume_id = ret['name']
810
print(f"Volume created: {volume_id}")
811
812
# Extend volume capacity
813
extend_config = {
814
'size': '20Gi'
815
}
816
817
ret, info = qcos_client.extend_service_volume(stack_id, service_id, volume_id, extend_config)
818
if info.ok():
819
print("Volume extended successfully")
820
```
821
822
### Access Point Configuration
823
824
```python
825
from qiniu import Auth, AccountClient
826
827
auth = Auth(access_key, secret_key)
828
account_client = AccountClient(auth)
829
qcos_client = account_client.get_qcos_client('qcos://my-web-app')
830
831
# Create access point
832
ap_config = {
833
'name': 'web-access-point',
834
'type': 'public',
835
'region': 'cn-east-1'
836
}
837
838
ret, info = qcos_client.create_ap(ap_config)
839
if info.ok():
840
ap_id = ret['id']
841
print(f"Access point created: {ap_id}")
842
843
# Configure port routing
844
port_config = {
845
'targetPort': 80,
846
'protocol': 'HTTP',
847
'healthCheck': {
848
'path': '/health',
849
'intervalSeconds': 30
850
}
851
}
852
853
ret, info = qcos_client.set_ap_port(ap_id, 80, port_config)
854
if info.ok():
855
print("Port configuration set")
856
857
# Bind custom domain
858
domain_config = {
859
'domain': 'api.example.com',
860
'sslEnabled': True
861
}
862
863
ret, info = qcos_client.publish_ap(ap_id, domain_config)
864
if info.ok():
865
print("Custom domain bound successfully")
866
867
# List all access points
868
ret, info = qcos_client.list_aps()
869
if info.ok():
870
for ap in ret['items']:
871
print(f"Access Point: {ap['name']} - Status: {ap['status']}")
872
print(f"Public URL: {ap.get('publicUrl', 'N/A')}")
873
```
874
875
### Infrastructure Monitoring
876
877
```python
878
from qiniu import Auth, AccountClient
879
import time
880
881
auth = Auth(access_key, secret_key)
882
account_client = AccountClient(auth)
883
qcos_client = account_client.get_qcos_client('qcos://my-web-app')
884
885
def monitor_infrastructure():
886
"""Monitor infrastructure health"""
887
while True:
888
print("\n=== Infrastructure Status ===")
889
890
# Check stacks
891
ret, info = qcos_client.list_stacks()
892
if info.ok():
893
for stack in ret['items']:
894
print(f"Stack: {stack['name']} - {stack['status']}")
895
896
# Check services in stack
897
ret, info = qcos_client.list_services(stack['name'])
898
if info.ok():
899
for service in ret['items']:
900
print(f" Service: {service['name']} - {service['status']}")
901
print(f" Replicas: {service.get('replicas', 0)}")
902
903
# Check containers
904
ret, info = qcos_client.list_containers()
905
if info.ok():
906
healthy_containers = sum(1 for c in ret['items'] if c['status'] == 'running')
907
total_containers = len(ret['items'])
908
print(f"Containers: {healthy_containers}/{total_containers} healthy")
909
910
# Check access points
911
ret, info = qcos_client.list_aps()
912
if info.ok():
913
active_aps = sum(1 for ap in ret['items'] if ap['status'] == 'active')
914
total_aps = len(ret['items'])
915
print(f"Access Points: {active_aps}/{total_aps} active")
916
917
time.sleep(60) # Check every minute
918
919
# Start monitoring (run in background)
920
import threading
921
monitor_thread = threading.Thread(target=monitor_infrastructure)
922
monitor_thread.daemon = True
923
monitor_thread.start()
924
```