资源池相关
更新时间:2025-11-26
查询资源池列表
使用以下代码可以查询资源池列表。
Python
1import logging
2import os
3
4import dotenv
5
6from baidubce.bce_client_configuration import BceClientConfiguration
7from baidubce.auth.bce_credentials import BceCredentials
8from baidubce.services.aihc.aihc_client import AihcClient
9from baidubce.exception import BceHttpClientError, BceServerError
10
11# 加载环境变量(可选,推荐使用)
12dotenv.load_dotenv()
13
14logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', force=True)
15logging.getLogger().setLevel(logging.INFO)
16logging.getLogger("baidubce").setLevel(logging.INFO)
17__logger = logging.getLogger(__name__)
18__logger.setLevel(logging.INFO)
19
20# 配置认证信息和服务端点
21HOST = os.getenv('HOST') or 'https://aihc.bj.baidubce.com' # 百舸AIHC服务地址
22AK = os.getenv('AK') or 'your-access-key-id' # 您的Access Key ID
23SK = os.getenv('SK') or 'your-secret-access-key' # 您的Secret Access Key
24
25# 创建BCE客户端配置
26config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
27
28# 创建 aihc client
29aihc_client = AihcClient(config)
30
31# 查询资源池列表
32try:
33 __logger.info('--------------------------------DescribeResourcePools start--------------------------------')
34 # resourcePoolType: 资源池类型:1、通用资源池:common,2、托管资源池:dedicatedV2
35 response = aihc_client.resource_pool.DescribeResourcePools(resourcePoolType='common')
36 print(response)
37except BceHttpClientError as e:
38 if isinstance(e.last_error, BceServerError):
39 __logger.error('send request failed. Response %s, code: %s, msg: %s'
40 % (e.last_error.status_code, e.last_error.code, str(e.last_error)))
41 else:
42 __logger.error('send request failed. Unknown exception: %s' % e)
注意: 根据接口文档去填写具体的访问参数,接口链接为查询资源池列表
查询资源池详情
使用以下代码可以查询资源池详情。
Python
1import logging
2import os
3
4import dotenv
5
6from baidubce.bce_client_configuration import BceClientConfiguration
7from baidubce.auth.bce_credentials import BceCredentials
8from baidubce.services.aihc.aihc_client import AihcClient
9from baidubce.exception import BceHttpClientError, BceServerError
10
11# 加载环境变量
12dotenv.load_dotenv()
13
14logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', force=True)
15logging.getLogger().setLevel(logging.INFO)
16logging.getLogger("baidubce").setLevel(logging.INFO)
17__logger = logging.getLogger(__name__)
18__logger.setLevel(logging.INFO)
19
20# 配置认证信息
21HOST = os.getenv('HOST') or 'https://aihc.bj.baidubce.com'
22AK = os.getenv('AK') or 'your-access-key-id'
23SK = os.getenv('SK') or 'your-secret-access-key'
24
25config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
26aihc_client = AihcClient(config)
27
28# 查询资源池详情
29try:
30 __logger.info('-------------------------DescribeResourcePool start--------------------------------')
31 resource_pool_id = "cce-xxx" # 替换为实际的资源池ID
32 response = aihc_client.resource_pool.DescribeResourcePool(resourcePoolId=resource_pool_id)
33 print(response)
34except BceHttpClientError as e:
35 if isinstance(e.last_error, BceServerError):
36 __logger.error('send request failed. Response %s, code: %s, msg: %s'
37 % (e.last_error.status_code, e.last_error.code, str(e.last_error)))
38 else:
39 __logger.error('send request failed. Unknown exception: %s' % e)
注意: 根据接口文档去填写具体的访问参数,接口链接为查询资源池详情
查询资源池概览
使用以下代码可以查询资源池概览。
Python
1import logging
2import os
3
4import dotenv
5
6from baidubce.bce_client_configuration import BceClientConfiguration
7from baidubce.auth.bce_credentials import BceCredentials
8from baidubce.services.aihc.aihc_client import AihcClient
9from baidubce.exception import BceHttpClientError, BceServerError
10
11# 加载环境变量
12dotenv.load_dotenv()
13
14logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', force=True)
15logging.getLogger().setLevel(logging.INFO)
16logging.getLogger("baidubce").setLevel(logging.INFO)
17__logger = logging.getLogger(__name__)
18__logger.setLevel(logging.INFO)
19
20# 配置认证信息
21HOST = os.getenv('HOST') or 'https://aihc.bj.baidubce.com'
22AK = os.getenv('AK') or 'your-access-key-id'
23SK = os.getenv('SK') or 'your-secret-access-key'
24
25config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
26aihc_client = AihcClient(config)
27
28# 查询资源池概览
29try:
30 __logger.info('--------------------------------DescribeResourcePoolOverview start--------------------------------')
31 response = aihc_client.resource_pool.DescribeResourcePoolOverview()
32 print(response)
33except BceHttpClientError as e:
34 if isinstance(e.last_error, BceServerError):
35 __logger.error('send request failed. Response %s, code: %s, msg: %s'
36 % (e.last_error.status_code, e.last_error.code, str(e.last_error)))
37 else:
38 __logger.error('send request failed. Unknown exception: %s' % e)
注意: 根据接口文档去填写具体的访问参数,接口链接为查询资源池概览
查询资源池配置
使用以下代码可以查询资源池配置。
Python
1import logging
2import os
3
4import dotenv
5
6from baidubce.bce_client_configuration import BceClientConfiguration
7from baidubce.auth.bce_credentials import BceCredentials
8from baidubce.services.aihc.aihc_client import AihcClient
9from baidubce.exception import BceHttpClientError, BceServerError
10
11# 加载环境变量
12dotenv.load_dotenv()
13
14logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', force=True)
15logging.getLogger().setLevel(logging.INFO)
16logging.getLogger("baidubce").setLevel(logging.INFO)
17__logger = logging.getLogger(__name__)
18__logger.setLevel(logging.INFO)
19
20# 配置认证信息
21HOST = os.getenv('HOST') or 'https://aihc.bj.baidubce.com'
22AK = os.getenv('AK') or 'your-access-key-id'
23SK = os.getenv('SK') or 'your-secret-access-key'
24
25config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
26aihc_client = AihcClient(config)
27
28# 查询资源池配置
29try:
30 __logger.info('-----------------DescribeResourcePoolConfiguration start--------------------------------')
31 resource_pool_id = "cce-xxx" # 替换为实际的资源池ID
32 response = aihc_client.resource_pool.DescribeResourcePoolConfiguration(resourcePoolId=resource_pool_id)
33 print(response)
34except BceHttpClientError as e:
35 if isinstance(e.last_error, BceServerError):
36 __logger.error('send request failed. Response %s, code: %s, msg: %s'
37 % (e.last_error.status_code, e.last_error.code, str(e.last_error)))
38 else:
39 __logger.error('send request failed. Unknown exception: %s' % e)
注意: 根据接口文档去填写具体的访问参数,接口链接为查询资源池配置
查询队列列表
使用以下代码可以查询队列列表。
Python
1import logging
2import os
3
4import dotenv
5
6from baidubce.bce_client_configuration import BceClientConfiguration
7from baidubce.auth.bce_credentials import BceCredentials
8from baidubce.services.aihc.aihc_client import AihcClient
9from baidubce.exception import BceHttpClientError, BceServerError
10
11# 加载环境变量
12dotenv.load_dotenv()
13
14logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', force=True)
15logging.getLogger().setLevel(logging.INFO)
16logging.getLogger("baidubce").setLevel(logging.INFO)
17__logger = logging.getLogger(__name__)
18__logger.setLevel(logging.INFO)
19
20# 配置认证信息
21HOST = os.getenv('HOST') or 'https://aihc.bj.baidubce.com'
22AK = os.getenv('AK') or 'your-access-key-id'
23SK = os.getenv('SK') or 'your-secret-access-key'
24
25config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
26aihc_client = AihcClient(config)
27
28# 查询队列列表
29try:
30 __logger.info('--------------------------------DescribeQueues start--------------------------------')
31 resource_pool_id = "cce-xxx" # 替换为实际的资源池ID
32 response = aihc_client.resource_pool.DescribeQueues(resourcePoolId=resource_pool_id)
33 print(response)
34except BceHttpClientError as e:
35 if isinstance(e.last_error, BceServerError):
36 __logger.error('send request failed. Response %s, code: %s, msg: %s'
37 % (e.last_error.status_code, e.last_error.code, str(e.last_error)))
38 else:
39 __logger.error('send request failed. Unknown exception: %s' % e)
注意: 根据接口文档去填写具体的访问参数,接口链接为查询队列列表
查询队列详情
使用以下代码可以查询队列详情。
Python
1import logging
2import os
3
4import dotenv
5
6from baidubce.bce_client_configuration import BceClientConfiguration
7from baidubce.auth.bce_credentials import BceCredentials
8from baidubce.services.aihc.aihc_client import AihcClient
9from baidubce.exception import BceHttpClientError, BceServerError
10
11# 加载环境变量
12dotenv.load_dotenv()
13
14logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', force=True)
15logging.getLogger().setLevel(logging.INFO)
16logging.getLogger("baidubce").setLevel(logging.INFO)
17__logger = logging.getLogger(__name__)
18__logger.setLevel(logging.INFO)
19
20# 配置认证信息
21HOST = os.getenv('HOST') or 'https://aihc.bj.baidubce.com'
22AK = os.getenv('AK') or 'your-access-key-id'
23SK = os.getenv('SK') or 'your-secret-access-key'
24
25config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
26aihc_client = AihcClient(config)
27
28# 查询队列详情
29try:
30 __logger.info('--------------------------------DescribeQueue start--------------------------------')
31 queue_id = "queue-xxx" # 替换为实际的队列ID
32 response = aihc_client.resource_pool.DescribeQueue(queueId=queue_id)
33 print(response)
34except BceHttpClientError as e:
35 if isinstance(e.last_error, BceServerError):
36 __logger.error('send request failed. Response %s, code: %s, msg: %s'
37 % (e.last_error.status_code, e.last_error.code, str(e.last_error)))
38 else:
39 __logger.error('send request failed. Unknown exception: %s' % e)
注意: 根据接口文档去填写具体的访问参数,接口链接为查询队列详情
