# ecloud-sdk-python
**Repository Path**: chinamobile_ecloud/ecloud-sdk-python
## Basic Information
- **Project Name**: ecloud-sdk-python
- **Description**: 移动云OpenAPI平台的Python SDK,可以让Python开发者无需关心API请求细节即可快速使用弹性云服务器、虚拟私有云等多个移动云服务。
- **Primary Language**: Python
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2023-11-02
- **Last Updated**: 2025-02-13
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
移动云开发者 Python 软件开发工具包(Python SDK)
欢迎使用移动云Python SDK 。
移动云 Python SDK 让您无需关心请求细节即可快速使用弹性云主机等多个移动云服务。
这里将向您介绍如何获取并使用移动云Python SDK 。
## 使用前提
- 要使用移动云 Python SDK ,您需要拥有移动云账号以及该账号对应的 Access Key(AK)和 Secret Key(SK)。请在移动云控制台 “我的凭证-访问密钥” 页面上创建和查看您的 AK&SK
。更多信息请查看 [访问密钥](https://ecloud.10086.cn/op-help-center/doc/article/48917) 。
- 移动云 Python SDK 支持 **Python 3.3** 及其以上版本。
## SDK 获取和安装
移动云支持通过 pip 安装依赖的方式使用移动云 Python SDK。
首先,您需要设置移动云镜像源:
```python
pip config set global.index-url https://ecloud.10086.cn/api/query/developer/nexus/repository/python-sdk/simple
```
其次,您可以根据需要独立引入SDK依赖包 。以使用云服务器ECS SDK 为例,您需要安装 `ecloudsdkecs` :
``` python
pip install ecloudsdkecs
```
## 代码示例
- 使用如下代码查询云主机列表,首先指定地域(资源池编号)。
- 调用前请根据实际情况替换如下变量: ``、``、`poolId` 。
``` python
# coding: utf-8
"""
Description: python client
Generated by: ecloud-sdk
"""
import sys
from typing import List
from ecloudsdkcore.config.config import Config
from ecloudsdkecs.v1.model import *
from ecloudsdkecs.v1.client import Client
class VmLstServerPortsDetailSample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key: str,
access_secret: str,
pool_id: str
) -> Client:
"""
使用AK&SK初始化账号Client
@param access_key:
@param access_secret:
@param pool_id:
@return: Client
@throws Exception
"""
config = Config(
access_key=access_key,
access_secret=access_secret,
pool_id=pool_id
)
return Client(config)
@staticmethod
def main(
args: List[str]
) -> None:
client = VmLstServerPortsDetailSample.create_client("",
"",
"poolId")
request = VmLstServerPortsDetailRequest()
response = client.vm_lst_server_ports_detail(request)
print(response)
if __name__ == '__main__':
VmLstServerPortsDetailSample.main(sys.argv[1:])
```
## 在线调试
[API开放平台](https://ecloud.10086.cn/op-oneapi-static/#/overview)
提供API检索及平台调试,支持全量快速检索、可视化调试、帮助文档查看等能力。
## 用户手册
* [1. 客户端连接参数](#1-客户端连接参数-top)
* [1.1 默认配置](#11-默认配置-top)
* [1.2 超时配置](#12-超时配置-top)
* [2. 客户端认证信息](#2-客户端认证信息-top)
[2.1 使用AK/SK](#2.1-使用AK/SK-top)
* [3. 客户端初始化](#3-客户端初始化-top)
* [4. 发送请求并查看响应](#4-发送请求并查看响应-top)
* [4.1 异常处理](#41-异常处理-top)
* [5. 故障处理](#5-故障处理-top)
* [5.1 访问日志](#51-访问日志-top)
### 1. 客户端连接参数
#### 1.1 默认配置
``` python
# 使用默认配置
config = Config(access_key="",
access_secret="",
pool_id="poolId")
client = Client(config)
```
#### 1.2 超时配置
``` python
config = Config(access_key="",
access_secret="",
pool_id="poolId",
read_timeout="10", # 默认响应超时时间为120秒,可根据需要调整
connect_timeout="60" # 默认连接超时时间为3秒,可根据需要调整
)
```
### 2. 客户端认证信息
**认证参数说明**:
- `ak` - 移动云账号 Access Key
- `sk` - 移动云账号 Secret Key
- `poolId` - 服务部署区域(资源池编号)
#### 2.1 使用 AK 和 SK
``` python
config = Config(access_key="",
access_secret="",
pool_id="poolId")
```
### 3. 客户端初始化
``` python
@staticmethod
def create_client(
access_key: str,
access_secret: str,
pool_id: str
) -> Client:
"""
使用AK&SK初始化账号Client
@param access_key:
@param access_secret:
@param pool_id:
@return: Client
@throws Exception
"""
config = Config(
access_key=access_key,
access_secret=access_secret,
pool_id=pool_id
)
return Client(config)
```
### 4. 发送请求并查看响应
``` python
client = VmLstServerPortsDetailSample.create_client("", "", "poolId")
request = VmLstServerPortsDetailRequest()
response = client.vm_lst_server_ports_detail(request)
print(response)
```
### 5 故障处理
SDK 提供 Access 级别的访问日志。
#### 5.1 访问日志
日志默认级别为INFO级别,日志格式为:
```python
%(asctime)s %(levelname)s %(message)s
```