python sdk查询scaleway api。
scaleway-sdk的Python项目详细描述
安装
该包在pip上可用。要将其安装到虚拟机中:
$ virtualenv my_virtualenv
$ source my_virtualenv/bin/activate
$ pip install scaleway-sdk
一般原则
如果您希望针对我们的api发送一个GEThttp请求,例如:
GET <api_url>/foo/bar
您只需要调用以下pythonic代码:
>>>fromscaleway.apisimportDummyAPI>>>DummyAPI().query().foo.bar.get()
这里的魔力在于scaleway.apis.*API实例,它们都有 query方法返回一个slumber.API对象。后者处理所有 请求中令人痛苦的细节。
文档
即使这个sdk的设计是对开发人员友好的,并且目标是自助服务 发现后,仍建议阅读官方API documentation。
因为大多数提供的帮助程序都采用了预先配置的形式 Slumber对象,很好地阅读了Slumber 同时也鼓励记录。
每个api的可用资源列表[在scaleway api存储库中](https://github.com/scaleway/api.scaleway.com/blob/master/README.md#apis)
示例
- 列出您的组织:
>>>fromscaleway.apisimportAccountAPI>>>api=AccountAPI(auth_token='')# Set your token here!>>>printapi.query().organizations.get(){u'organizations':[...]}
- 列出你的组织,但要得到一个flask.response而不是 dict:
>>>fromscaleway.apisimportAccountAPI>>>api=AccountAPI(auth_token='')# Set your token here!>>>resp=api.query(serialize=False).organizations.get()>>>printtype(resp)<Response[200]>>>>printresp.headers{...}# Response HTTP headers.>>>printresp.links{...}# Parsed "Link" HTTP header, for pagination.>>>printresp.json(){u'organizations':[...]}
- 列出您的服务器:
>>>fromscaleway.apisimportComputeAPI>>>api=ComputeAPI(auth_token='')# Set your token here!>>>printapi.query().servers.get(){u'servers':[...]}# Or choose your region, as in apis/api_compute.py>>>api=ComputeAPI(region='ams1',auth_token='')# Set your token here!>>>printapi.query().servers.get(){u'servers':[...]}
- 获取服务器的详细信息:
>>>fromscaleway.apisimportComputeAPI>>>api=ComputeAPI(auth_token='')# Set your token here!>>>server_id=''# Set a server ID here!>>>printapi.query().servers(server_id).get(){u'server':{...}}
- 检查您的令牌是否具有该服务的权限servers:read。 compute用于组织9a096d36-6bf9-470f-91df-2398aa7361f7:
>>>fromscaleway.apisimportAccountAPI>>>api=AccountAPI(auth_token='')# Set your token here!>>>printapi.has_perm(service='compute',name='servers:read',...resource='9a096d36-6bf9-470f-91df-2398aa7361f7')False
测试
要提交修补程序,您需要根据python2.7和 Python3.4。运行测试:
$ pip install nose coverage pycodestyle pylint $ python setup.py nosetests --with-coverage (...) $ pycodestyle scaleway (...) $ pylint scaleway (...)
- 覆盖率得分决不能低于您的修补程序之前。
- PEP8不应返回错误。
- Pylint得分永远不能低于您的补丁之前。
或者,要在python2.7和python3.4上运行鼻测试,可以运行 毒性。
替代库/客户端
许可证
此软件的许可证为BSD 2-Clause License。