2
0

README.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. SDK 使用文档
  2. ========
  3. A low-level interface to a growing number of KSC Web Services.
  4. ----------------
  5. Install 安装
  6. ----------------
  7. + github 安装
  8. + 通过 `GitHub <https://github.com/KscSDK/ksc-sdk-python>`__ 下载
  9. + 通过命令 python setup.py install 安装
  10. ----------------
  11. Config 配置
  12. ----------------
  13. + 申请安全凭证:
  14. 在第一次使用云API之前,用户首先需要在金山云控制台申请安全凭证,安全凭证包括access_key_id和secret_access_key,access_key_id 是用于标识API调用者的身份,secret_access_key是用于加密签名字符串和服务器端验证签名字符串的密钥。secret_access_key 必须严格保管,避免泄露。
  15. + 获取安全凭证方法:
  16. 参见金山云文档: https://docs.ksyun.com/documents/40311
  17. + 通过文件配置及管理密钥,参考examples内示例:
  18. + 所在位置: '/etc/kscore.cfg' 或 './.kscore.cfg' 或 'C:\\kscore.cfg'
  19. + 注意: 使用相对路径时,需与运行目录保持一致。
  20. ::
  21. [Credentials]
  22. ks_access_key_id=your ak
  23. ks_secret_access_key=your sk
  24. + 或在程序运行时配置:
  25. ::
  26. from kscore.session import get_session
  27. # 密钥
  28. ACCESS_KEY_ID = "your ak"
  29. SECRET_ACCESS_KEY = "your sk"
  30. s = get_session()
  31. client = s.create_client("iam", ks_access_key_id=ACCESS_KEY_ID, ks_secret_access_key=SECRET_ACCESS_KEY)
  32. ----------------
  33. 接口输出自定义 SDK版本 >=1.3.46
  34. ----------------
  35. + 通过自定义映射yaml文件,文件名称必须为customer.yaml
  36. + customer.yaml必须放置在 您的路径/service名称/官网服务版本号 的路径下
  37. + 以EIP为例 需要放在 您的路径/eip/2016-03-04/customer.yaml
  38. + customer.yaml示例
  39. ::
  40. DescribeAddresses:
  41. PublicIp: address
  42. AllocationId: uuid
  43. AddressesSet: ips
  44. + 使用示例
  45. ::
  46. eipClient = s.create_client("eip", region, use_ssl=True,customer_path='your path')
  47. ----------------
  48. 金山云-私有云域名配置 SDK版本 >1.3.32
  49. ----------------
  50. + 通过文件配置及管理密钥,参考examples内示例:
  51. + 所在位置: '/etc/kscore.cfg' 或 './.kscore.cfg' 或 'C:\\kscore.cfg'
  52. + 注意: 使用相对路径时,需与运行目录保持一致。
  53. + 注意 域名不要带引号 示例 ks_domain = api.ksyun.com
  54. ::
  55. [Domain]
  56. ks_domain = your domain
  57. + 或在程序运行时配置:
  58. ::
  59. from kscore.session import get_session
  60. # 密钥
  61. ks_domain = "your domain"
  62. s = get_session()
  63. s.set_domain(ks_domain)
  64. ----------------
  65. 日志级别配置方法
  66. ----------------
  67. from kscore.utils import set_logger_level
  68. import logging
  69. set_logger_level(logging.WARNING)
  70. ----------------
  71. Service 服务
  72. ----------------
  73. + 已支持大区 region_name
  74. +---------------------+--------------+
  75. | region_name | 大区 |
  76. +=====================+==============+
  77. | cn-beijing-6 | 北京6区 |
  78. +---------------------+--------------+
  79. | cn-shanghai-2 | 上海2区 |
  80. +---------------------+--------------+
  81. | cn-guangzhou-1 | 广州1区 |
  82. +---------------------+--------------+
  83. | cn-hongkong-2 | 香港2区 |
  84. +---------------------+--------------+
  85. | cn-taipei-1 | 台北1区 |
  86. +---------------------+--------------+
  87. | ap-singapore-1 | 新加坡1区 |
  88. +---------------------+--------------+
  89. | eu-east-1 | 俄罗斯1区 |
  90. +---------------------+--------------+
  91. | cn-beijing-fin | 北京金融 |
  92. +---------------------+--------------+
  93. | cn-shanghai-fin | 上海金融 |
  94. +---------------------+--------------+
  95. + 已支持服务列表 service_name,具体方法与API的Action对应,如kec服务RunInstances对应为run_instances方法。 `详情参考API手册 <http://docs.ksyun.com>`__
  96. +-------------------+----------------+
  97. | service | 服务名 |
  98. +===================+================+
  99. | iam | 身份与访问控制 |
  100. +-------------------+----------------+
  101. | eip | 弹性IP |
  102. +-------------------+----------------+
  103. | bws | 共享带宽 |
  104. +-------------------+----------------+
  105. | slb | 负载均衡 |
  106. +-------------------+----------------+
  107. | kec | 云服务器 |
  108. +-------------------+----------------+
  109. | epc | 云物理机 |
  110. +-------------------+----------------+
  111. | kce | 容服 |
  112. +-------------------+----------------+
  113. | tag | 标签服务 |
  114. +-------------------+----------------+
  115. | slb | 负载均衡 |
  116. +-------------------+----------------+
  117. | kcs | REDIS |
  118. +-------------------+----------------+
  119. | vpc | 虚拟私有网络 |
  120. +-------------------+----------------+
  121. | cdn | 内容分发网络 |
  122. +-------------------+----------------+
  123. | monitor | 云监控 |
  124. +-------------------+----------------+
  125. | offline | 视频转码 |
  126. +-------------------+----------------+
  127. ----------------
  128. Method 方法
  129. ----------------
  130. + 常用方法
  131. + get_session
  132. +---------------------------+---------------------------------------+
  133. | 参数 | 说明 |
  134. +===========================+=======================================+
  135. | env_vars | 环境变量 |
  136. +---------------------------+---------------------------------------+
  137. + create_client
  138. +---------------------------+---------------------------------------+
  139. | 参数 | 说明 |
  140. +===========================+=======================================+
  141. | service_name | 服务,必须参数,例:iam |
  142. +---------------------------+---------------------------------------+
  143. | region_name=None | 大区,必须参数,全局服务可以为None |
  144. +---------------------------+---------------------------------------+
  145. | api_version=None | API 版本,默认使用最近版本 |
  146. +---------------------------+---------------------------------------+
  147. | use_ssl=True | 是否使用HTTPS,优先使用 |
  148. +---------------------------+---------------------------------------+
  149. | verify=None | 是否验证SSL证书 |
  150. +---------------------------+---------------------------------------+
  151. | endpoint_url=None | |
  152. +---------------------------+---------------------------------------+
  153. | ks_access_key_id=None | |
  154. +---------------------------+---------------------------------------+
  155. | ks_secret_access_key=None | |
  156. +---------------------------+---------------------------------------+
  157. | ks_session_token=None | |
  158. +---------------------------+---------------------------------------+
  159. ----------------
  160. Examples 示例
  161. ----------------
  162. + IAM
  163. ::
  164. from kscore.session import get_session
  165. if __name__ == "__main__":
  166. s = get_session()
  167. client = s.create_client("iam", use_ssl=False)
  168. users = client.list_users()
  169. + KEC
  170. ::
  171. from kscore.session import get_session
  172. if __name__ == "__main__":
  173. s = get_session()
  174. client = s.create_client("kec", "cn-beijing-6", use_ssl=False)
  175. client.[your method]()
  176. + MONITOR
  177. ::
  178. from kscore.session import get_session
  179. if __name__ == "__main__":
  180. s = get_session()
  181. client = s.create_client("monitor", "cn-beijing-5", use_ssl=True)
  182. m=client.get_metric_statistics(InstanceID="6f582c78-5d49-438e-bf2d-db4345daf503",Namespace="eip",MetricName="qos.bps_in",StartTime="2016-08-16T17:09:00Z",EndTime="2016-08-16T23:56:00Z",Period="600",Aggregate="Average")
  183. print json.dumps(m,sort_keys=True,indent=4)
  184. + OFFLINE
  185. ::
  186. from kscore.session import get_session
  187. import json
  188. if __name__=="__main__":
  189. #初始化
  190. s = get_session()
  191. client = s.create_client("offline", "cn-beijing-6", use_ssl=False)
  192. #创建模板接口调用示例 : preset
  193. presetname = 'testpreset'
  194. description = 'just a demo'
  195. presetType = 'avop'
  196. param = {
  197. "preset": presetname,
  198. "description": description,
  199. "presettype": presetType,
  200. "param": {
  201. "f": "mp4",
  202. "AUDIO": {
  203. "acodec": "aac",
  204. "ar":"44100",
  205. "ab":"64k"
  206. },
  207. "VIDEO": {
  208. "vr": 25,
  209. "vb": "500k",
  210. "vcodec": "h264",
  211. "width": 640,
  212. "height": 360
  213. }
  214. }
  215. }
  216. res = client.preset(**param)
  217. print json.dumps(res)
  218. #获取模板信息接口调用示例 : get_preset_detail
  219. res = client.get_preset_detail(preset = presetname)
  220. print json.dumps(res)
  221. + CDN
  222. ::
  223. from kscore.session import get_session
  224. if __name__ == "__main__":
  225. # CDN API调用 详细示例位于 ./examples/cdn.py
  226. s = get_session()
  227. client = s.create_client("cdn", use_ssl=False)
  228. res = client.get_cdn_domains(PageSize=20,PageNumber=0,DomainStatus='online',CdnType='download')
  229. print res
  230. + 更多
  231. --------------------
  232. BUG FIXED 问题修正
  233. --------------------
  234. + CERTIFICATE_VERIFY_FAILED
  235. ::
  236. requests.exceptions.SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
  237. + 参考 `InsecurePlatformWarning <https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings>`__ 解决方法如下
  238. ::
  239. pip install requests[security]
  240. + 如 `build/temp.linux-x86_64-2.7/_openssl.c:433:30: fatal error: openssl/opensslv.h: No such file or directory` 解决方法如下
  241. ::
  242. yum install openssl-devel
  243. + 如 `build/temp.linux-x86_64-2.7/_openssl.c:12:24: fatal error: pyconfig.h: No such file or directory`解决方法如下
  244. ::
  245. yum install python-devel