|
| 1 | +### 1. 获取请求和响应类型 |
| 2 | +在方法调用前,通过 param 和 return 获取请求和响应对应的结构体 |
| 3 | +以 ecs.run_instances 为例 |
| 4 | +```python |
| 5 | +def run_instances(self, body, **kwargs): # noqa: E501 |
| 6 | + """run_instances |
| 7 | + :param RunInstancesRequest body: (required) |
| 8 | + :return: RunInstancesResponse |
| 9 | + """ |
| 10 | +``` |
| 11 | + |
| 12 | + |
| 13 | +### 2. 获取请求和响应的参数类型 |
| 14 | +在 Request 或者 Response 请求体中,通过 swagger_types 查看具体的请求参数和类型 |
| 15 | +以 volcenginesdkecs.RunInstancesRequest 为例,其参数名称和定义如下所示 |
| 16 | +```python |
| 17 | +swagger_types = { |
| 18 | + 'auto_renew': 'bool', |
| 19 | + 'auto_renew_period': 'int', |
| 20 | + 'client_token': 'str', |
| 21 | + 'count': 'int', |
| 22 | + 'network_interfaces': 'list[NetworkInterfaceForRunInstancesInput]', |
| 23 | + 'security_enhancement_strategy': 'str', |
| 24 | + 'volumes': 'list[VolumeForRunInstancesInput]', |
| 25 | + ...... |
| 26 | +} |
| 27 | +``` |
| 28 | +对应的请求体为 |
| 29 | +```python |
| 30 | +volcenginesdkecs.RunInstancesRequest( |
| 31 | + instance_name="insname", |
| 32 | + network_interfaces=[volcenginesdkecs.NetworkInterfaceForRunInstancesInput( |
| 33 | + subnet_id="subnet-2d68bh73d858ozfekrm8fj", |
| 34 | + security_group_ids=["sg-2b3dq7v0ha0w2dx0eg0nhljv"], |
| 35 | + )], |
| 36 | + image_id="image-ybvz29l3da4ox5h0m9", |
| 37 | + volumes=[volcenginesdkecs.VolumeForRunInstancesInput( |
| 38 | + volume_type="ESSD", |
| 39 | + size=40, |
| 40 | + )], |
| 41 | + key_pair_name="vtable", |
| 42 | + instance_charge_type="PostPaid" |
| 43 | +) |
| 44 | +``` |
| 45 | +### 3. 出现内存溢出 |
| 46 | +检查 Configuration._default 是否被初始化 |
| 47 | +如果没有初始化,每一次创建 Configuration 的时候,会创建新的 logger handler 并加入到全局的 logger 中 |
| 48 | +建议通过 Configuration.set_default 方法对 Configuration 进行赋值 |
| 49 | +```python |
| 50 | +configuration = volcenginesdkcore.Configuration() |
| 51 | +configuration.client_side_validation = False |
| 52 | +configuration.schema = "http" # https or http |
| 53 | +configuration.debug = False # 是否开启调试 |
| 54 | + |
| 55 | +volcenginesdkcore.Configuration.set_default(configuration) |
| 56 | +``` |
0 commit comments