rightscale api的python包装器
python-rightscale的Python项目详细描述
python rightscale
=====
rightscale api的python包装器。这支持1.5api和rightscale的oauth令牌身份验证。
用法示例
----
**设置身份验证令牌**
``python
``import rightscale
api=rightscale.rightscale/>-` refreshToken是在启用API访问时颁发给您的刷新令牌。
-`api_endpoint`是来自同一页的"令牌终结点(API 1.5)"的FQDN。
格式见示例文件。当使用`~/.rightscale rc`时,您可以不指定凭据而实例化'rightscale'对象,它将使用rc文件中的凭据:
``python
import rightscale
api=rightscale.rightscale()
```
**方便命令**
在此库中为其实现了函数的一些常见高级操作中:
-列出"ec2 us-east-1"中的所有实例:
``` python
来自rightscale import list\u instances
use1\u instances=list\u instances(cloud\u name='ec2 us-east-1')
```
成功后,"use1戡u instances"将包含一个dict对象列表,表示rightscale api返回的每个实例的小视图。
-在特定服务器上运行rightscript:
``python
from rightscale import run戡script戡on戡server
inputs={
'apache_vhost':'我的照片库',
}
在服务器上运行脚本'u('enable apache vhost','my web server',inputs=inputs)
````
参考[官方的rightscale api指南](http://support.rightscale.com/12 guides/rightscale_api_1.5)。
此库的用户应参考[api参考](http://reference.rightscale.com/api1.5/index.html)以获取特定于上下文的参数,如过滤器、视图、get和post参数ters.
**根api对象**
方便命令都希望您在`~/.rightscalerc'中拥有工作凭据。它们还使用隐式创建的API对象(即"rightscale.rightscale"的单实例)并为您执行所有API调用。
但是,如果您需要指定与存储在`~/.rightscalerc'中的凭据不同的凭据,或者如果您需要对rightscale API的完全访问,则您应该通过实例化"rightscale.rightscale"来创建自己的api对象。例如,
`` python
从rightscale导入rightscale
api=rightscale()
现在检查rightscale的运行状况!
api.health\u check()
```
**资源和操作**
`rightscale.rightscale'类具有api引用中记录的顶级资源的属性。每个"rightscale"属性上的方法都映射到文档中列出的操作。调用action方法就像发出http请求一样。操作方法返回的对象总是具有"response"属性,该属性包含来自[请求库](http://python requests.org)的http"response"对象。例如,[用户资源](http://reference.rightscale.com/api1.5/resources/resourceaccounts.html)有一个"index"操作,列出该帐户可用的所有用户。此列表的http请求是:
使用此库检索列表:
``python
users=api.users.index()
检查其他r http响应头(注意:人为的示例;实际上不会这样做,因为库已经为您检查了状态)
assert'200 ok'==users.response.headers['status']
````
` id`值。例如,要获取帐户详细信息,API文档将[帐户资源](http://reference.rightscale.com/api1.5/resources/resource accounts.html)描述为具有"show"操作,该操作要求URL路径的最后一部分是"id"。如果帐户"id"是"12345",则关联的http请求将是:
get/api/accounts/12345
若要为操作方法指定资源标识符,请为"res-id"关键字参数分配一个值,如下所示:
``python
account=api.accounts.show(res-id=12345')
```
不管资源的实际名称是什么(例如"accounts"、"users"、"servers"等等),特殊的关键字参数总是被称为"res_id"。
**过滤器**
p://python requests.org)。这意味着方法接受get参数和post数据作为关键字参数。例如,要按名称查找服务器,api引用指示我们对[servers resource](http://reference.rightscale.com/api1.5/resources/resourceservers.html index)使用带筛选器的"index"方法。如果服务器的名称是"server_foo",那么http请求将是:
,rightscale将返回一个匹配列表。使用这个库进行相同的搜索如下:
``python
params={
'filter[]:['name==server_foo',
}
found=api.server s.index(params=params)
````
**标记**
ython
params={
'标记[]':['rs_backup:lineage=prod_db'],
'资源类型':'卷快照',
}
snapshots=api.tags.by_标记(params=params)
```
=====
rightscale api的python包装器。这支持1.5api和rightscale的oauth令牌身份验证。
用法示例
----
**设置身份验证令牌**
``python
``import rightscale
api=rightscale.rightscale/>-` refreshToken是在启用API访问时颁发给您的刷新令牌。
-`api_endpoint`是来自同一页的"令牌终结点(API 1.5)"的FQDN。
格式见示例文件。当使用`~/.rightscale rc`时,您可以不指定凭据而实例化'rightscale'对象,它将使用rc文件中的凭据:
``python
import rightscale
api=rightscale.rightscale()
```
**方便命令**
在此库中为其实现了函数的一些常见高级操作中:
-列出"ec2 us-east-1"中的所有实例:
``` python
来自rightscale import list\u instances
use1\u instances=list\u instances(cloud\u name='ec2 us-east-1')
```
成功后,"use1戡u instances"将包含一个dict对象列表,表示rightscale api返回的每个实例的小视图。
-在特定服务器上运行rightscript:
``python
from rightscale import run戡script戡on戡server
inputs={
'apache_vhost':'我的照片库',
}
在服务器上运行脚本'u('enable apache vhost','my web server',inputs=inputs)
````
参考[官方的rightscale api指南](http://support.rightscale.com/12 guides/rightscale_api_1.5)。
此库的用户应参考[api参考](http://reference.rightscale.com/api1.5/index.html)以获取特定于上下文的参数,如过滤器、视图、get和post参数ters.
**根api对象**
方便命令都希望您在`~/.rightscalerc'中拥有工作凭据。它们还使用隐式创建的API对象(即"rightscale.rightscale"的单实例)并为您执行所有API调用。
但是,如果您需要指定与存储在`~/.rightscalerc'中的凭据不同的凭据,或者如果您需要对rightscale API的完全访问,则您应该通过实例化"rightscale.rightscale"来创建自己的api对象。例如,
`` python
从rightscale导入rightscale
api=rightscale()
现在检查rightscale的运行状况!
api.health\u check()
```
**资源和操作**
`rightscale.rightscale'类具有api引用中记录的顶级资源的属性。每个"rightscale"属性上的方法都映射到文档中列出的操作。调用action方法就像发出http请求一样。操作方法返回的对象总是具有"response"属性,该属性包含来自[请求库](http://python requests.org)的http"response"对象。例如,[用户资源](http://reference.rightscale.com/api1.5/resources/resourceaccounts.html)有一个"index"操作,列出该帐户可用的所有用户。此列表的http请求是:
使用此库检索列表:
``python
users=api.users.index()
检查其他r http响应头(注意:人为的示例;实际上不会这样做,因为库已经为您检查了状态)
assert'200 ok'==users.response.headers['status']
````
` id`值。例如,要获取帐户详细信息,API文档将[帐户资源](http://reference.rightscale.com/api1.5/resources/resource accounts.html)描述为具有"show"操作,该操作要求URL路径的最后一部分是"id"。如果帐户"id"是"12345",则关联的http请求将是:
get/api/accounts/12345
若要为操作方法指定资源标识符,请为"res-id"关键字参数分配一个值,如下所示:
``python
account=api.accounts.show(res-id=12345')
```
不管资源的实际名称是什么(例如"accounts"、"users"、"servers"等等),特殊的关键字参数总是被称为"res_id"。
**过滤器**
p://python requests.org)。这意味着方法接受get参数和post数据作为关键字参数。例如,要按名称查找服务器,api引用指示我们对[servers resource](http://reference.rightscale.com/api1.5/resources/resourceservers.html index)使用带筛选器的"index"方法。如果服务器的名称是"server_foo",那么http请求将是:
,rightscale将返回一个匹配列表。使用这个库进行相同的搜索如下:
``python
params={
'filter[]:['name==server_foo',
}
found=api.server s.index(params=params)
````
**标记**
ython
params={
'标记[]':['rs_backup:lineage=prod_db'],
'资源类型':'卷快照',
}
snapshots=api.tags.by_标记(params=params)
```