Repository: QcloudApi/qcloudapi-sdk-python Branch: master Commit: 9b097e4f4089 Files: 72 Total size: 68.5 KB Directory structure: gitextract_w0ip0a__/ ├── .gitignore ├── .travis.yml ├── CHANGELOG.rst ├── LICENSE ├── MANIFEST.in ├── QcloudApi/ │ ├── __init__.py │ ├── common/ │ │ ├── __init__.py │ │ ├── api_exception.py │ │ ├── request.py │ │ └── sign.py │ ├── modules/ │ │ ├── __init__.py │ │ ├── account.py │ │ ├── apigateway.py │ │ ├── athena.py │ │ ├── base.py │ │ ├── batch.py │ │ ├── bgpip.py │ │ ├── bill.py │ │ ├── bm.py │ │ ├── bmeip.py │ │ ├── bmlb.py │ │ ├── bmvpc.py │ │ ├── cbs.py │ │ ├── ccr.py │ │ ├── ccs.py │ │ ├── cdb.py │ │ ├── cdn.py │ │ ├── cloudaudit.py │ │ ├── cmem.py │ │ ├── cns.py │ │ ├── cvm.py │ │ ├── dc.py │ │ ├── dfw.py │ │ ├── eip.py │ │ ├── emr.py │ │ ├── feecenter.py │ │ ├── image.py │ │ ├── lb.py │ │ ├── live.py │ │ ├── market.py │ │ ├── monitor.py │ │ ├── partners.py │ │ ├── redis.py │ │ ├── scaling.py │ │ ├── scf.py │ │ ├── sec.py │ │ ├── snapshot.py │ │ ├── sts.py │ │ ├── tbaas.py │ │ ├── tdsql.py │ │ ├── tmt.py │ │ ├── trade.py │ │ ├── vod.py │ │ ├── vpc.py │ │ ├── wenzhi.py │ │ └── yunsou.py │ └── qcloudapi.py ├── README.md ├── README.rst ├── setup.cfg ├── setup.py ├── tests/ │ ├── __init__.py │ ├── demo.py │ ├── functional/ │ │ ├── __init__.py │ │ └── test_cvm.py │ ├── integration/ │ │ ├── ckafka/ │ │ │ └── test_list_instance.py │ │ └── cvm/ │ │ └── test_describe_instances.py │ └── unit/ │ ├── __init__.py │ ├── common/ │ │ └── test_sign.py │ └── modules/ │ ├── __init__.py │ └── test_basic.py └── tox.ini ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ *.pyc # twine dist/ # tox .tox/ qcloudapi_sdk_python.egg-info/ # pytest, pytest-cov .cache/ .coverage ================================================ FILE: .travis.yml ================================================ sudo: false matrix: include: - language: python python: "2.7" env: TOXENV=py27 - language: python python: "3.5" env: TOXENV=py35 - language: python python: "3.6" env: TOXENV=py36 install: - pip install --upgrade tox script: tox -r after_success: - tox -r -ecoveralls ================================================ FILE: CHANGELOG.rst ================================================ ========= CHANGELOG ========= latest (now) ============ 2.0.15 (2018-06-15) =================== * dynamic module support: Now user can call any product's API which runs on \*.api.qcloud.com even its module is not listed in SDK. 2.0.14 (2018-04-20) =================== * add dc module 2.0.13 (2018-04-16) =================== * add ccr module 2.0.12 (2018-03-02) =================== * add sts module * add emr module * add athena module * add tbaas module * add partners module 2.0.11 ====== * add tmt module * add apigateway, batch, cloudaudit, scf module 2.0.10 ====== 2017-11-27 * fix bmlb, cns, feecenter module import error 2.0.9 ===== 2017-10-30 * add bgpip module history ======= * [2017/9/11] 增加Bmeip和Bmvpc模块 * [2017/8/28] 业务接口的数组参数或者Object参数,支持以Json方式传入,可参考demo.py * [2017/8/21] 兼容python2和python3版本;支持pip安装使用 * [2017/8/8] 增加Cns模块 * [2017/8/7] 增加Feecenter模块 * [2017/7/31] 增加Bmlb模块 * [2017/7/12] 回滚:不默认传Version参数 * [2017/5/24] 增加Ccs模块 * [2017/5/19]设置接口默认Version: Cvm模块新版本API已经上线,通过是否传Version区分新旧版本。SDK默认调用新接口,因此需要增加Version的默认设置。 CvmAPI接口介绍见:https://www.qcloud.com/document/api/213/569 * [2017/3/1] 增加对HmacSHA1和HmacSHA256签名算法兼容的支持 * [2016/7/15] 增加Tdsql模块 * [2016/7/6] 添加Cmem模块 * [2016/5/24] 添加Cbs、Snapshot和Scaling模块 ================================================ FILE: LICENSE ================================================ Copyright 1999-2017 Tencent Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: MANIFEST.in ================================================ include README.rst include LICENSE recursive-include QcloudApi * ================================================ FILE: QcloudApi/__init__.py ================================================ __version__ = '2.0.15' ================================================ FILE: QcloudApi/common/__init__.py ================================================ ================================================ FILE: QcloudApi/common/api_exception.py ================================================ # -*- coding: utf-8 -*- class ApiExceptionBase(Exception): """ @type message: string @param message: error describe """ def __init__(self, message): self.message = message def get_info(self): return 'Error Message: %s\n' % (self.message) def __str__(self): return "ApiExceptionBase %s" % (self.get_info()) class ApiClientParamException(ApiExceptionBase): def __init__(self, message): ApiExceptionBase.__init__(self, message) def __str__(self): return "ApiClientException %s" % (self.get_info()) class ApiClientNetworkException(ApiExceptionBase): """ @note: client network exception """ def __init__(self, message): ApiExceptionBase.__init__(self, message) def __str__(self): return "ApiClientNetworkException %s" % (self.get_info()) class ApiServerNetworkException(ApiExceptionBase): """ @note: api server exception """ def __init__(self, status=200, header=None, data=""): if header is None: header = {} self.status = status self.header = header self.data = data def __str__(self): headers = "\n".join("%s: %s" % (k, v) for k, v in self.header.items()) return ("ApiServerNetworkException Status: %s\nHeader: %s\nData: %s\n" % (self.status, headers, self.data)) ================================================ FILE: QcloudApi/common/request.py ================================================ #!/usr/bin/python # -*- coding: utf-8 -*- import os import socket try: from http.client import HTTPConnection, BadStatusLine, HTTPSConnection from urllib.parse import urlparse except ImportError: from httplib import HTTPConnection, BadStatusLine, HTTPSConnection from urlparse import urlparse from .api_exception import ApiClientNetworkException, ApiClientParamException class MyHTTPSConnection(HTTPSConnection): def __init__(self, host, port=None): self.has_proxy = False self.request_host = host https_proxy = (os.environ.get('https_proxy') or os.environ.get('HTTPS_PROXY')) if https_proxy: url = urlparse(https_proxy) if not url.hostname: url = urlparse('https://' + https_proxy) host = url.hostname port = url.port self.has_proxy = True HTTPSConnection.__init__(self, host, port) self.request_length = 0 def send(self, astr): HTTPSConnection.send(self, astr) self.request_length += len(astr) def request(self, method, url, body=None, headers={}): self.request_length = 0 if self.has_proxy: self.set_tunnel(self.request_host, 443) HTTPSConnection.request(self, method, url, body, headers) class ApiRequest(object): def __init__(self, host, req_timeout=90, debug=False): self.conn = MyHTTPSConnection(host) self.req_timeout = req_timeout self.keep_alive = False self.debug = debug self.request_size = 0 self.response_size = 0 def set_req_timeout(self, req_timeout): self.req_timeout = req_timeout def is_keep_alive(self): return self.keep_alive def set_debug(self, debug): self.debug = debug def send_request(self, req_inter): try: if self.debug: print("SendRequest %s" % req_inter) if req_inter.method == 'GET': req_inter_url = '%s?%s' % (req_inter.uri, req_inter.data) self.conn.request(req_inter.method, req_inter_url, None, req_inter.header) elif req_inter.method == 'POST': self.conn.request(req_inter.method, req_inter.uri, req_inter.data, req_inter.header) else: raise ApiClientParamException( 'Method only support (GET, POST)') self.conn.sock.settimeout(self.req_timeout) self.conn.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) try: http_resp = self.conn.getresponse() except BadStatusLine: # open another connection when keep-alive timeout # httplib will not handle keep-alive timeout, # so we must handle it ourself if self.debug: print("keep-alive timeout, reopen connection") self.conn.close() self.conn.request(req_inter.method, req_inter.uri, req_inter.data, req_inter.header) self.conn.sock.settimeout(self.req_timeout) self.conn.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) http_resp = self.conn.getresponse() headers = dict(http_resp.getheaders()) resp_inter = ResponseInternal(status=http_resp.status, header=headers, data=http_resp.read()) self.request_size = self.conn.request_length self.response_size = len(resp_inter.data) if not self.is_keep_alive(): self.conn.close() if self.debug: print(("GetResponse %s" % resp_inter)) return resp_inter except Exception as e: self.conn.close() raise ApiClientNetworkException(str(e)) class RequestInternal(object): def __init__(self, host="", method="", uri="", header=None, data=""): if header is None: header = {} self.host = host self.method = method self.uri = uri self.header = header self.data = data def __str__(self): headers = "\n".join("%s: %s" % (k, v) for k, v in self.header.items()) return ("Host: %s\nMethod: %s\nUri: %s\nHeader: %s\nData: %s\n" % (self.host, self.method, self.uri, headers, self.data)) class ResponseInternal(object): def __init__(self, status=0, header=None, data=""): if header is None: header = {} self.status = status self.header = header self.data = data def __str__(self): headers = "\n".join("%s: %s" % (k, v) for k, v in self.header.items()) return ("Status: %s\nHeader: %s\nData: %s\n" % (self.status, headers, self.data)) ================================================ FILE: QcloudApi/common/sign.py ================================================ # -*- coding: utf-8 -*- import binascii import hashlib import hmac import sys class Sign(object): def __init__(self, secretId, secretKey): self.secretId = secretId self.secretKey = secretKey if sys.version_info[0] > 2: self.Py2 = False self.secretKey = bytes(self.secretKey, 'utf-8') else: self.Py2 = True def make(self, requestHost, requestUri, params, method='POST', sign_method='HmacSHA1'): p = {} for k in params: if method == 'POST' and str(params[k])[0:1] == '@': continue p[k.replace('_', '.')] = params[k] ps = '&'.join('%s=%s' % (k, p[k]) for k in sorted(p)) msg = '%s%s%s?%s' % (method.upper(), requestHost, requestUri, ps) if not self.Py2: msg = bytes(msg, 'utf-8') if sign_method == 'HmacSHA256': digestmod = hashlib.sha256 else: digestmod = hashlib.sha1 hashed = hmac.new(self.secretKey, msg, digestmod) base64 = binascii.b2a_base64(hashed.digest())[:-1] if not self.Py2: base64 = base64.decode() return base64 ================================================ FILE: QcloudApi/modules/__init__.py ================================================ ================================================ FILE: QcloudApi/modules/account.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Account(base.Base): requestHost = 'account.api.qcloud.com' ================================================ FILE: QcloudApi/modules/apigateway.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class APIGateway(base.Base): requestHost = 'apigateway.api.qcloud.com' ================================================ FILE: QcloudApi/modules/athena.py ================================================ # Copyright 1999-2018 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Athena(base.Base): """Financial Intelligent Customer Service. document: https://cloud.tencent.com/document/product/671 """ requestHost = 'athena.api.qcloud.com' ================================================ FILE: QcloudApi/modules/base.py ================================================ # -*- coding: utf-8 -*- # # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import copy import time import random import sys import os import warnings try: from urllib.parse import urlencode except ImportError: from urllib import urlencode import QcloudApi from QcloudApi.common.api_exception import ApiClientParamException from QcloudApi.common.api_exception import ApiServerNetworkException from QcloudApi.common.request import ApiRequest from QcloudApi.common.request import RequestInternal from QcloudApi.common.sign import Sign warnings.filterwarnings("ignore") class Base(object): requestHost = '' requestUri = '/v2/index.php' _params = {} version = 'SDK_PYTHON_%s' % QcloudApi.__version__ def __init__(self, config): self.secretId = config['secretId'] self.secretKey = config['secretKey'] self.defaultRegion = config.get('Region', '') self.Version = config.get('Version', '') self.method = config.get('method', 'GET').upper() self.sign_method = config.get('SignatureMethod', 'HmacSHA1') self.requestHost = self.requestHost or config.get("endpoint") self.apiRequest = ApiRequest(self.requestHost) self.Token = config.get('Token', '') def set_req_timeout(self, req_timeout): self.apiRequest.set_req_timeout(req_timeout) def open_debug(self): self.apiRequest.set_debug(True) def close_debug(self): self.apiRequest.set_debug(False) def _build_header(self, req): if self.apiRequest.is_keep_alive(): req.header["Connection"] = "Keep-Alive" if req.method == 'POST': req.header["Content-Type"] = "application/x-www-form-urlencoded" def _fix_params(self, params): if not isinstance(params, (dict,)): return params return self._format_params(None, params) def _format_params(self, prefix, params): d = {} if params is None: return d if not isinstance(params, (tuple, list, dict)): d[prefix] = params return d if isinstance(params, (list, tuple)): for idx, item in enumerate(params): if prefix: key = "{0}.{1}".format(prefix, idx) else: key = "{0}".format(idx) d.update(self._format_params(key, item)) return d if isinstance(params, dict): for k, v in params.items(): if prefix: key = '{0}.{1}'.format(prefix, k) else: key = '{0}'.format(k) d.update(self._format_params(key, v)) return d raise ApiClientParamException('some params type error') def _build_req_inter(self, action, params, req_inter): _params = copy.deepcopy(self._fix_params(params)) _params['Action'] = action[0].upper() + action[1:] _params['RequestClient'] = self.version if ('Region' not in _params and self.defaultRegion != ''): _params['Region'] = self.defaultRegion if ('Version' not in _params and self.Version != ''): _params['Version'] = self.Version if ('Token' not in _params and self.Token != ''): _params['Token'] = self.Token if ('SecretId' not in _params): _params['SecretId'] = self.secretId if ('Nonce' not in _params): _params['Nonce'] = random.randint(1, sys.maxsize) if ('Timestamp' not in _params): _params['Timestamp'] = int(time.time()) if ('SignatureMethod' in _params): self.sign_method = _params['SignatureMethod'] else: _params['SignatureMethod'] = self.sign_method sign = Sign(self.secretId, self.secretKey) _params['Signature'] = sign.make( req_inter.host, req_inter.uri, _params, req_inter.method, self.sign_method) req_inter.data = urlencode(_params) self._build_header(req_inter) def _check_status(self, resp_inter): if resp_inter.status != 200: raise ApiServerNetworkException( resp_inter.status, resp_inter.header, resp_inter.data) def generateUrl(self, action, params): req_inter = RequestInternal( self.requestHost, self.method, self.requestUri) self._build_req_inter(action, params, req_inter) url = 'https://%s%s' % (req_inter.host, req_inter.uri) if (req_inter.method == 'GET'): url += '?' + req_inter.data return url def call(self, action, params, files={}): req_inter = RequestInternal( self.requestHost, self.method, self.requestUri) self._build_req_inter(action, params, req_inter) resp_inter = self.apiRequest.send_request(req_inter) self._check_status(resp_inter) return resp_inter.data ================================================ FILE: QcloudApi/modules/batch.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Batch(base.Base): requestHost = 'batch.api.qcloud.com' ================================================ FILE: QcloudApi/modules/bgpip.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Bgpip(base.Base): requestHost = 'bgpip.api.qcloud.com' ================================================ FILE: QcloudApi/modules/bill.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Bill(base.Base): requestHost = 'bill.api.qcloud.com' ================================================ FILE: QcloudApi/modules/bm.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Bm(base.Base): requestHost = 'bm.api.qcloud.com' ================================================ FILE: QcloudApi/modules/bmeip.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Bmeip(base.Base): requestHost = 'bmeip.api.qcloud.com' ================================================ FILE: QcloudApi/modules/bmlb.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Bmlb(base.Base): requestHost = 'bmlb.api.qcloud.com' ================================================ FILE: QcloudApi/modules/bmvpc.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Bmvpc(base.Base): requestHost = 'bmvpc.api.qcloud.com' ================================================ FILE: QcloudApi/modules/cbs.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Cbs(base.Base): requestHost = 'cbs.api.qcloud.com' ================================================ FILE: QcloudApi/modules/ccr.py ================================================ # Copyright (c) 2018 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Ccr(base.Base): """Cloud Container Repository document: https://cloud.tencent.com/document/product/457/9427 """ requestHost = 'ccr.api.qcloud.com' ================================================ FILE: QcloudApi/modules/ccs.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Ccs(base.Base): requestHost = 'ccs.api.qcloud.com' ================================================ FILE: QcloudApi/modules/cdb.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Cdb(base.Base): requestHost = 'cdb.api.qcloud.com' ================================================ FILE: QcloudApi/modules/cdn.py ================================================ # -*- coding: utf-8 -*- # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import hashlib import os from QcloudApi.modules import base class Cdn(base.Base): requestHost = 'cdn.api.qcloud.com' def UploadCdnEntity(self, params): action = 'UploadCdnEntity' if params.get('entityFile') is None: raise ValueError('entityFile can not be empty.') if os.path.isfile(params['entityFile']) is False: raise ValueError('entityFile is not exist.') file = params.pop('entityFile') if 'entityFileMd5' not in params: content = open(file, 'rb').read() params['entityFileMd5'] = hashlib.md5(content).hexdigest() files = { 'entityFile': open(file, 'rb') } return self.call(action, params, files) ================================================ FILE: QcloudApi/modules/cloudaudit.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class CloudAudit(base.Base): requestHost = 'cloudaudit.api.qcloud.com' ================================================ FILE: QcloudApi/modules/cmem.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Cmem(base.Base): requestHost = 'cmem.api.qcloud.com' ================================================ FILE: QcloudApi/modules/cns.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Cns(base.Base): requestHost = 'cns.api.qcloud.com' ================================================ FILE: QcloudApi/modules/cvm.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Cvm(base.Base): requestHost = 'cvm.api.qcloud.com' ================================================ FILE: QcloudApi/modules/dc.py ================================================ # -*- coding: utf-8 -*- # Copyright (c) 2018 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Dc(base.Base): """Tencent Cloud Direct Connect document: https://cloud.tencent.com/document/product/216/1711 """ requestHost = 'dc.api.qcloud.com' ================================================ FILE: QcloudApi/modules/dfw.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Dfw(base.Base): requestHost = 'dfw.api.qcloud.com' ================================================ FILE: QcloudApi/modules/eip.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Eip(base.Base): requestHost = 'eip.api.qcloud.com' ================================================ FILE: QcloudApi/modules/emr.py ================================================ # Copyright 1999-2018 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Emr(base.Base): """Elastic Map Reduce. document: https://cloud.tencent.com/document/product/589 """ requestHost = 'emr.api.qcloud.com' ================================================ FILE: QcloudApi/modules/feecenter.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Feecenter(base.Base): requestHost = 'feecenter.api.qcloud.com' ================================================ FILE: QcloudApi/modules/image.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Image(base.Base): requestHost = 'image.api.qcloud.com' ================================================ FILE: QcloudApi/modules/lb.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Lb(base.Base): requestHost = 'lb.api.qcloud.com' ================================================ FILE: QcloudApi/modules/live.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Live(base.Base): requestHost = 'live.api.qcloud.com' ================================================ FILE: QcloudApi/modules/market.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Market(base.Base): requestHost = 'market.api.qcloud.com' ================================================ FILE: QcloudApi/modules/monitor.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Monitor(base.Base): requestHost = 'monitor.api.qcloud.com' ================================================ FILE: QcloudApi/modules/partners.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Partners(base.Base): requestHost = 'partners.api.qcloud.com' ================================================ FILE: QcloudApi/modules/redis.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Redis(base.Base): requestHost = 'redis.api.qcloud.com' ================================================ FILE: QcloudApi/modules/scaling.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Scaling(base.Base): requestHost = 'scaling.api.qcloud.com' ================================================ FILE: QcloudApi/modules/scf.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Scf(base.Base): """Serverless Cloud Function.""" requestHost = 'scf.api.qcloud.com' ================================================ FILE: QcloudApi/modules/sec.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Sec(base.Base): requestHost = 'csec.api.qcloud.com' ================================================ FILE: QcloudApi/modules/snapshot.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Snapshot(base.Base): requestHost = 'snapshot.api.qcloud.com' ================================================ FILE: QcloudApi/modules/sts.py ================================================ # Copyright 1999-2018 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Sts(base.Base): """Security Token Service. document: https://cloud.tencent.com/document/product/598 """ requestHost = 'sts.api.qcloud.com' ================================================ FILE: QcloudApi/modules/tbaas.py ================================================ # Copyright 1999-2018 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Tbaas(base.Base): """Tencent Blockchain as a Service. document: https://cloud.tencent.com/document/product/663 """ requestHost = 'tbaas.api.qcloud.com' ================================================ FILE: QcloudApi/modules/tdsql.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Tdsql(base.Base): requestHost = 'tdsql.api.qcloud.com' ================================================ FILE: QcloudApi/modules/tmt.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Tmt(base.Base): """Tencent Machine Translation. document: https://cloud.tencent.com/document/product/551 """ requestHost = 'tmt.api.qcloud.com' ================================================ FILE: QcloudApi/modules/trade.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Trade(base.Base): requestHost = 'trade.api.qcloud.com' ================================================ FILE: QcloudApi/modules/vod.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Vod(base.Base): requestHost = 'vod.api.qcloud.com' ================================================ FILE: QcloudApi/modules/vpc.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Vpc(base.Base): requestHost = 'vpc.api.qcloud.com' ================================================ FILE: QcloudApi/modules/wenzhi.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Wenzhi(base.Base): requestHost = 'wenzhi.api.qcloud.com' ================================================ FILE: QcloudApi/modules/yunsou.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.modules import base class Yunsou(base.Base): requestHost = 'yunsou.api.qcloud.com' ================================================ FILE: QcloudApi/qcloudapi.py ================================================ #! /usr/bin/env python # -*- coding: utf-8 -*- from QcloudApi.modules import base class QcloudApi(object): def __init__(self, module, config): self.module = module self.config = config def _factory(self, module, config): if (module == 'cdb'): from .modules.cdb import Cdb service = Cdb(config) elif (module == 'account'): from .modules.account import Account service = Account(config) elif (module == 'cvm'): from .modules.cvm import Cvm service = Cvm(config) elif (module == 'image'): from .modules.image import Image service = Image(config) elif (module == 'lb'): from .modules.lb import Lb service = Lb(config) elif (module == 'sec'): from .modules.sec import Sec service = Sec(config) elif (module == 'trade'): from .modules.trade import Trade service = Trade(config) elif (module == 'bill'): from .modules.bill import Bill service = Bill(config) elif (module == 'monitor'): from .modules.monitor import Monitor service = Monitor(config) elif (module == 'cdn'): from .modules.cdn import Cdn service = Cdn(config) elif (module == 'vpc'): from .modules.vpc import Vpc service = Vpc(config) elif (module == 'vod'): from .modules.vod import Vod service = Vod(config) elif (module == 'yunsou'): from .modules.yunsou import Yunsou service = Yunsou(config) elif (module == 'wenzhi'): from .modules.wenzhi import Wenzhi service = Wenzhi(config) elif (module == 'market'): from .modules.market import Market service = Market(config) elif (module == 'live'): from .modules.live import Live service = Live(config) elif (module == 'eip'): from .modules.eip import Eip service = Eip(config) elif (module == 'cbs'): from .modules.cbs import Cbs service = Cbs(config) elif (module == 'snapshot'): from .modules.snapshot import Snapshot service = Snapshot(config) elif (module == 'scaling'): from .modules.scaling import Scaling service = Scaling(config) elif (module == 'cmem'): from .modules.cmem import Cmem service = Cmem(config) elif (module == 'tdsql'): from .modules.tdsql import Tdsql service = Tdsql(config) elif (module == 'bm'): from .modules.bm import Bm service = Bm(config) elif (module == 'bmlb'): from .modules.bmlb import Bmlb service = Bmlb(config) elif (module == 'redis'): from .modules.redis import Redis service = Redis(config) elif (module == 'dfw'): from .modules.dfw import Dfw service = Dfw(config) elif (module == 'ccs'): from .modules.ccs import Ccs service = Ccs(config) elif (module == 'feecenter'): from .modules.feecenter import Feecenter service = Feecenter(config) elif (module == 'cns'): from .modules.cns import Cns service = Cns(config) elif (module == 'bmeip'): from .modules.bmeip import Bmeip service = Bmeip(config) elif (module == 'bmvpc'): from .modules.bmvpc import Bmvpc service = Bmvpc(config) elif module == 'bgpip': from .modules.bgpip import Bgpip service = Bgpip(config) elif module == 'scf': from .modules.scf import Scf service = Scf(config) elif module == 'apigateway': from .modules.apigateway import APIGateway service = APIGateway(config) elif module == 'batch': from .modules.batch import Batch service = Batch(config) elif module == 'cloudaudit': from .modules.cloudaudit import CloudAudit service = CloudAudit(config) elif module == 'tmt': from .modules.tmt import Tmt service = Tmt(config) elif module == 'partners': from .modules.partners import Partners service = Partners(config) elif module == 'tbaas': from .modules.tbaas import Tbaas service = Tbaas(config) elif module == 'athena': from .modules.athena import Athena service = Athena(config) elif module == 'emr': from .modules.emr import Emr service = Emr(config) elif module == 'sts': from .modules.sts import Sts service = Sts(config) elif module == 'ccr': from .modules.ccr import Ccr service = Ccr(config) elif module == 'dc': from .modules.dc import Dc service = Dc(config) else: config.setdefault("endpoint", module + '.api.qcloud.com') service = base.Base(config) return service def setSecretId(self, secretId): self.config['secretId'] = secretId def setSecretKey(self, secretKey): self.config['secretKey'] = secretKey def setRequestMethod(self, method): self.config['method'] = method def setRegion(self, region): self.config['Region'] = region def setSignatureMethod(self, SignatureMethod): self.config['SignatureMethod'] = SignatureMethod def generateUrl(self, action, params): service = self._factory(self.module, self.config) return service.generateUrl(action, params) def call(self, action, params, req_timeout=None, debug=False): """ @type action: string @param action: action interface @type params: dict @param params: interface parameters @type req_timeout: int @param req_timeout: request timeout(seconds) @type debug: bool @param debug: debug switch """ service = self._factory(self.module, self.config) if req_timeout is not None: service.set_req_timeout(req_timeout) if debug: service.open_debug() methods = dir(service) for method in methods: if (method == action): func = getattr(service, action) return func(params) return service.call(action, params) ================================================ FILE: README.md ================================================ [![pypi version](https://img.shields.io/pypi/v/qcloudapi-sdk-python.svg)](https://pypi.python.org/pypi/qcloudapi-sdk-python) [![Build Status](https://travis-ci.org/QcloudApi/qcloudapi-sdk-python.svg?branch=master)](https://travis-ci.org/QcloudApi/qcloudapi-sdk-python) [![Coverage Status](https://coveralls.io/repos/github/QcloudApi/qcloudapi-sdk-python/badge.svg?branch=master)](https://coveralls.io/github/QcloudApi/qcloudapi-sdk-python) # qcloudapi-sdk-python qcloudapi-sdk-python是为了让Python开发者能够在自己的代码里更快捷方便的使用腾讯云的API而开发的SDK工具包。 ## 资源 * [公共参数](https://www.qcloud.com/document/api/213/6976) * [API列表](https://www.qcloud.com/document/api) * [错误码](https://www.qcloud.com/document/api/213/10146) ## 入门 1. 申请[安全凭证](https://console.qcloud.com/capi)。 在第一次使用云API之前,用户首先需要在腾讯云网站上申请安全凭证,安全凭证包括 SecretId 和 SecretKey, SecretId 是用于标识 API 调用者的身份,SecretKey是用于加密签名字符串和服务器端验证签名字符串的密钥。SecretKey 必须严格保管,避免泄露。 ## 安装 $ pip install qcloudapi-sdk-python 或者下载源码安装 $ git clone https://github.com/QcloudApi/qcloudapi-sdk-python $ cd qcloudapi-sdk-python $ python setup.py install ## 示例 ```python # -*- coding: utf8 -*- from QcloudApi.qcloudapi import QcloudApi # 设置需要加载的模块 module = 'cvm' # 对应接口的接口名,请参考wiki文档上对应接口的接口名 action = 'DescribeInstances' # 云API的公共参数 config = { 'Region': 'ap-guangzhou', 'secretId': '您的secretId', 'secretKey': '您的secretKey', 'method': 'GET', 'SignatureMethod': 'HmacSHA1', # 只有cvm需要填写version,其他产品不需要 'Version': '2017-03-12' } # 接口参数,根据实际情况填写,支持json # 例如数组可以 "ArrayExample": ["1","2","3"] # 例如字典可以 "DictExample": {"key1": "value1", "key2": "values2"} action_params = { 'Limit':1, } try: service = QcloudApi(module, config) # 请求前可以通过下面几个方法重新设置请求的secretId/secretKey/Region/method/SignatureMethod参数 # 重新设置请求的Region #service.setRegion('ap-shanghai') # 打印生成的请求URL,不发起请求 print(service.generateUrl(action, action_params)) # 调用接口,发起请求,并打印返回结果 print(service.call(action, action_params)) except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc()) ``` ## 模块对照表 每个产品都有自己的独立域名,例如云服务器对应的域名为 cvm.api.qcloud.com ,一般域名的第一段对应产品名的缩写(特殊情况会另行说明),此例中为 cvm 。在 SDK 中,产品名缩写对应为模块名,放置于 QcloudApi/modules 目录下(base.py 例外,它是基类),对于没有在 modules 目录列出的产品,依然可以使用。例如在 tests/integration/ckafka 目录下的测试文件 test\_list\_instance.py ,表明了调用未显式注册的产品也可以被正常使用,前提是使用产品名和域名首段一致,如果不一致,则以域名首段为准,在使用cmq的产品时将会发生这种情况。 以下列出目前已经显式支持或者可以动态支持的产品列表,顺序依照官网 API 文档的权重。有些产品已经支持或者部分支持 API 3.0 ,在表格中有注明,建议用户使用 API 3.0 对应的 [SDK](https://github.com/TencentCloud/tencentcloud-sdk-python)。 请注意,并非所有腾讯云上的产品都支持腾讯云 API ,有部分产品例如对象存储服务( COS )有自己独立的 API 和 SDK ,详情请咨询对应产品的技术支持人员。 部分产品根据自身业务特点,拆分成多个服务,其调用域名根据功能而不同,此种情况下模块名会有多个,请配合官网文档进行使用,本文档不另作说明了。 以下信息更新于2018-09-25 | 产品中文名 | 模块名 | 显式支持 | 支持 API 3.0 | 备注 |-|-|-|-|-| | 云服务器 | cvm、image、dfw、eip | 是 | 是 | | | 云硬盘 | cbs、snapshot | 是 | 是 | | | 黑石物理服务器 | bm、bmlb、bmeip、bmvpc | 是 | 部分 | | | 容器服务 | ccs、ccr | 是 | 否 | | | 弹性伸缩 | scaling | 是 | 是 | | | 负载均衡 | lb | 是 | 否 | | | 无服务器云函数 | scf | 是 | 部分 | | | 私有网络 | vpc | 是 | 是 | | | 批量计算 | batch | 是 | 是 | | | API网关 | apigateway | 是 | 否 | | | 专线接入 | dc | 是 | 是 | | | 动态加速网络 | dsa | 否 | 否 | | | 消息队列 CKafka | ckafka | 否 | 否 | | | 消息队列 IoT MQ | mqiot | 否 | 否 | | | 消息队列 CMQ | cmq-queue-{REGION} | 否 | 否 | 产品域名不固定,和区域有关 | | 数据库 MySQL | cdb | 是 | 是 | | | 数据库 MariaDB(TDSQL)| tdsql | 是 | 是 | | | 数据库 SQL Server | sqlserver | 否 | 是 | | | 内容分发网络 | cdn | 是 | 否 | | | 弹性缓存 Redis | redis | 是 | 部分 | | | 弹性缓存 Memcached | cmem | 是 | 否 | | | 文档数据库 MongoDB | mongodb | 否 | 否 | | | 云监控 | monitor | 是 | 否 | | | TBaaS | tbaas | 是 | 是 | | | 访问管理 | cam、sts | 部分 | 否 | | | 大禹网络安全 | bgpip、shield | 部分 | 否 | | | 天御业务安全防护 | sec | 是 | 否 | 产品域名为 csec | 云审计 | cloudaudit | 是 | 否 | | | 云解析 | cns | 是 | 否 | | | SSL 证书 | wss | 否 | 否 | | | 云搜 | yunsou | 是 | 否 | | | 文智自然语言处理 | wenzhi | 是 | 否 | | | 点播 | vod | 是 | 否 | | | 云市场 | market | 是 | 是 | | | 直播 | live | 是 | 部分 | | | 腾讯机器翻译 | tmt | 是 | 是 | | | 物联网通信 | iotcloud | 否 | 否 | | | 弹性 Mapreduce | emr | 是 | 否 | | | 账号相关 | trade、tag、account、feecenter | 部分 | 否 | | | 渠道合作伙伴 | partners | 是 | 是 | | | 金融智能客服 | athena | 是 | 否 | | ================================================ FILE: README.rst ================================================ =============================== The Qcloud API SDK for Python =============================== Qcloud Python SDK is the official software development kit, which allows Python developers to write software that makes use of qcloud services like CVM and CBS. The SDK works on Python versions: * 2.7 and greater, including 3.x.x Quick Start ----------- First, install the library: .. code-block:: sh $ pip install qcloudapi-sdk-python or download source code from github and install: .. code-block:: sh $ git clone https://github.com/QcloudApi/qcloudapi-sdk-python.git $ cd qcloudapi-sdk-python $ python setup.py install Then, from a Python interpreter or script: .. code-block:: python >>> from QcloudApi.qcloudapi import QcloudApi >>> module = 'cvm' >>> action = 'DescribeInstances' >>> config = {'Region':'ap-guangzhou', 'secretId':'xxxx', 'secretKey':'xxxx', 'Version':'2017-03-20'} >>> params = {'Limit':1} >>> service = QcloudApi(module, config) >>> service.call(action, params) ================================================ FILE: setup.cfg ================================================ [bdist_wheel] universal=1 ================================================ FILE: setup.py ================================================ #!/usr/bin/env python """ distutils/setuptools install script. """ import os from setuptools import setup, find_packages import QcloudApi ROOT = os.path.dirname(__file__) setup( name='qcloudapi-sdk-python', version=QcloudApi.__version__, description='The Qcloud Api SDK for Python', long_description=open('README.rst').read(), author='Qcloud', url='https://github.com/QcloudApi/qcloudapi-sdk-python.git', maintainer_email="QcloudApi@tencent.com", scripts=[], packages=find_packages(exclude=["tests*"]), license="Apache License 2.0", platforms='any', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.1', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', ], ) ================================================ FILE: tests/__init__.py ================================================ ================================================ FILE: tests/demo.py ================================================ #!/usr/bin/python # -*- coding: utf-8 -*- # 引入云API入口模块 from QcloudApi.qcloudapi import QcloudApi ''' module: 设置需要加载的模块 已有的模块列表: cvm 对应 cvm.api.qcloud.com cdb 对应 cdb.api.qcloud.com lb 对应 lb.api.qcloud.com trade 对应 trade.api.qcloud.com sec 对应 csec.api.qcloud.com image 对应 image.api.qcloud.com monitor 对应 monitor.api.qcloud.com cdn 对应 cdn.api.qcloud.com ''' module = 'cvm' ''' action: 对应接口的接口名,请参考wiki文档上对应接口的接口名 ''' action = 'DescribeInstances' ''' config: 云API的公共参数 ''' config = { 'Region': 'ap-guangzhou', 'secretId': '您的secretId', 'secretKey': '您的secretKey', } # 接口参数 action_params = { 'Version': '2017-03-12', 'Filters': [{ 'Name': 'zone', 'Values': ['ap-guangzhou-1', 'ap-guangzhou-2'] }], 'limit': 1, } try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) print(service.call(action, action_params)) except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc()) ================================================ FILE: tests/functional/__init__.py ================================================ ================================================ FILE: tests/functional/test_cvm.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Test cvm basic functionalities.""" from QcloudApi.common import request from QcloudApi import qcloudapi def test_describe_instances(monkeypatch): def mock(*args, **kwargs): return request.ResponseInternal(status=200) monkeypatch.setattr(request.ApiRequest, 'send_request', mock) config = { 'Region': 'gz', 'secretId': '123', 'secretKey': '456', } service = qcloudapi.QcloudApi('cvm', config) service.call('DescribInstances', {}) ================================================ FILE: tests/integration/ckafka/test_list_instance.py ================================================ # Copyright (c) 1999-2018 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import json import os from QcloudApi import qcloudapi def test_describe_instances(): config = { "Region": "ap-guangzhou", "secretId": os.environ.get("TENCENTCLOUD_SECRET_ID"), "secretKey": os.environ.get("TENCENTCLOUD_SECRET_KEY"), } service = qcloudapi.QcloudApi("ckafka", config) result = service.call("ListInstance", {}, req_timeout=10, debug=True).decode("utf-8") assert json.loads(result)["code"] == 0 ================================================ FILE: tests/integration/cvm/test_describe_instances.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import json import os from QcloudApi import qcloudapi def test_describe_instances(): config = { "Region": "ap-guangzhou", "secretId": os.environ.get("TENCENTCLOUD_SECRET_ID"), "secretKey": os.environ.get("TENCENTCLOUD_SECRET_KEY"), } service = qcloudapi.QcloudApi("cvm", config) params = { "Version": "2017-03-12", "Limit": 1, } result = service.call("DescribeInstances", params, req_timeout=10, debug=True).decode("utf-8") assert len(json.loads(result)["Response"].get("InstanceSet", [])) == 1 ================================================ FILE: tests/unit/__init__.py ================================================ ================================================ FILE: tests/unit/common/test_sign.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from QcloudApi.common import sign def test_sign(): s = sign.Sign('secretIdFoo', 'secretKeyBar') params = { 'SecretId': 'secretIdFoo', 'Region': 'ap-guangzhou', 'SignatureMethod': 'HmacSHA1', 'Nonce': '1290303896666895346', 'Timestamp': '1512393162', 'Action': 'DescribeInstances', 'Version': '2017-03-12', } ss = s.make('cvm.api.qcloud.com', '/v2/index.php', params, method='POST') assert ss == 'p3n+pxBqF5JGZtDSxoVn5tGngf0=' def test_sign_post_lowercase(): s = sign.Sign('secretIdFoo', 'secretKeyBar') params = { 'SecretId': 'secretIdFoo', 'Region': 'ap-guangzhou', 'SignatureMethod': 'HmacSHA1', 'Nonce': '1290303896666895346', 'Timestamp': '1512393162', 'Action': 'DescribeInstances', 'Version': '2017-03-12', } ss = s.make('cvm.api.qcloud.com', '/v2/index.php', params, method='post') assert ss == 'p3n+pxBqF5JGZtDSxoVn5tGngf0=' def test_sign_hmacsha256(): s = sign.Sign('secretIdFoo', 'secretKeyBar') params = { 'SecretId': 'secretIdFoo', 'Region': 'ap-guangzhou', 'SignatureMethod': 'HmacSHA256', 'Nonce': '1290303896666895346', 'Timestamp': '1512393162', 'Action': 'DescribeInstances', 'Version': '2017-03-12', } ss = s.make('cvm.api.qcloud.com', '/v2/index.php', params, method='POST', sign_method='HmacSHA256') assert ss == 'B2T37FRSP6Fk0/q/cdfrTE0p3zX5ooB/2BPWZUFpsj4=' def test_sign_get(): s = sign.Sign('secretIdFoo', 'secretKeyBar') params = { 'SecretId': 'secretIdFoo', 'Region': 'ap-guangzhou', 'SignatureMethod': 'HmacSHA1', 'Nonce': '1290303896666895346', 'Timestamp': '1512393162', 'Action': 'DescribeInstances', 'Version': '2017-03-12', } ss = s.make('cvm.api.qcloud.com', '/v2/index.php', params, method='GET') assert ss == '5HAq1BOKNLEE2/uauWnp6Zv9Z3c=' ================================================ FILE: tests/unit/modules/__init__.py ================================================ ================================================ FILE: tests/unit/modules/test_basic.py ================================================ # Copyright 1999-2017 Tencent Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Basic test for modules, simply check if import succeed.""" from QcloudApi.modules import apigateway from QcloudApi.modules import account from QcloudApi.modules import athena from QcloudApi.modules import batch from QcloudApi.modules import bgpip from QcloudApi.modules import bill from QcloudApi.modules import bm from QcloudApi.modules import bmeip from QcloudApi.modules import bmlb from QcloudApi.modules import bmvpc from QcloudApi.modules import cbs from QcloudApi.modules import ccr from QcloudApi.modules import ccs from QcloudApi.modules import cdb from QcloudApi.modules import cdn from QcloudApi.modules import cloudaudit from QcloudApi.modules import cmem from QcloudApi.modules import cns from QcloudApi.modules import cvm from QcloudApi.modules import dc from QcloudApi.modules import dfw from QcloudApi.modules import eip from QcloudApi.modules import emr from QcloudApi.modules import feecenter from QcloudApi.modules import image from QcloudApi.modules import lb from QcloudApi.modules import live from QcloudApi.modules import market from QcloudApi.modules import monitor from QcloudApi.modules import partners from QcloudApi.modules import redis from QcloudApi.modules import scaling from QcloudApi.modules import scf from QcloudApi.modules import sec from QcloudApi.modules import snapshot from QcloudApi.modules import sts from QcloudApi.modules import tbaas from QcloudApi.modules import tdsql from QcloudApi.modules import tmt from QcloudApi.modules import trade from QcloudApi.modules import vod from QcloudApi.modules import vpc from QcloudApi.modules import wenzhi from QcloudApi.modules import yunsou def test_import(): """test to ensure pr #22 will never happen again.""" pass ================================================ FILE: tox.ini ================================================ [tox] minversion = 1.8 skipsdist = True envlist = py{27,35,36},pep8 [testenv] deps = pytest pytest-cov usedevelop = True commands = py.test {toxinidir}/tests passenv = TENCENTCLOUD_SECRET_ID TENCENTCLOUD_SECRET_KEY HTTPS_PROXY [testenv:coveralls] passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH COVERALLS_REPO_TOKEN deps = {[testenv]deps} coveralls commands = py.test --cov {toxinidir}/QcloudApi {toxinidir}/tests coveralls [testenv:pep8] deps = pycodestyle commands = pycodestyle [pycodestyle] ignore = exclude=.tox/,doc/ show-source = True