用于atc的rest api
django-atc-api的Python项目详细描述
#atc api
atc api是一个django应用程序,允许将rest api连接到atcd的节俭api。
裂谷](../atc-atc-thrift)
`安装` django atc-api `最简单的安装方法是直接从[pip(https://pypi.pypypypypython.org/pypi)上安装` django atc-api
/>`` ` ` `
` ` ` ` ` ` ` ` ` ` ` `>
`` bash
$cd path/to/django-atc-api
pip安装。
```
编辑django项目的"settings.py",将"atc_api"和"rest_framework"添加到"已安装的应用程序"中:
``python
installed_apps=(
…
'atc_api',
'rest_framework',
)
```
2。在Django项目URL中包含"atc_api"urlconf。py如下:
``python
url(r'^api/v1/',include('atc_api.url'),
````
>3。启动开发服务器
``bash
python manage.py runserver 0.0.0:8000
```
>4。访问http://127.0.0.1:8000/api/v1/shape/设置/取消设置形状。
有些设置,如"ATCD主机"和"ATCD端口"可以在Django项目的设置中更改。py:
``python
`atC API={
"ATCD主机":"本地主机",
"ATCD端口":9090,
}
`
`请参见[atc api settings](atc_api/settings.py)了解更多详细信息。
核心api是有限的,允许:
*通过获取`/api/v1/shape/`
*通过发布到`/api/v1/shape/`
*通过发送删除请求到`/api/v1/shape/`
shaping status
s形,可以得到`/api/v1/shape/[ip/]`
TTP代码404):
``sh
$curl-h'接受:application/json;indent=2'h ttp://127.0.0.1:8080/api/v1/shape/
{
"detail":"此IP(10.0.2.2)未成形"
}
```
*检查我是否成形(正在成形的设备,http代码200):
``sh
$curl-h"'accept:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/
{
"down":{
"rate":400,
"loss":{
"percentage":5.0,
"correlation":0.0
},
"delay":{
"delay":15,
"jitter":0,
"correlation":0.0
},
"腐败":{
"百分比":0.0,
"相关性":0.0
},
"重新排序":{
"百分比":0.0,
"相关性":0.0,
"间隙":0
}
},
"向上":{
"比率":200,
"损失":{
"百分比":1。0,
"相关":0.0
},
"延迟":{
"延迟":10,
"抖动":0,
"相关":0.0
},
"损坏":{
"百分比":0.0,
"相关":0.0
},
"重新排序":{
"百分比":0.0,
"correlation":0.0,
"gap":0
}
}
}
}
`````
*检查1.1.1是否正在成形(设备未成形,http代码404):
```sh
$curl-h'接受:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/1.1.1/
"detail":"此IP"(1.1.1.1)未被整形"
}
```
10毫秒中的y,数据包丢失率为1%,减少了400 KB,增加了15毫秒的延迟和5%的数据包丢失率
这将始终在成功时重新运行http代码201。如果设备已经成形,则将应用新设置,删除唯一的设置。
注意(ctrl-d)
``sh
$curl-x post-d@-'-i-h'内容类型:application/json'-h'接受:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/
{
"down":{
"rate":400,
"loss":{
"percentage":5.0,
"correlation":0.0
},
"delay":{
"delay":15,
"jitter":0,
"correlation":0.0
},
"corruptio"n":{
"百分比":0.0,
"相关性":0.0
},
"重新排序":{
"百分比":0.0,
"相关性":0.0,
"间隔":0
}
},
"向上":{
"比率":200,
"损失":{
"百分比":1.0,
"相关性":0.0
},
"延迟":{
"延迟":10,
"抖动":0,
"相关性":0.0
},
"损坏":{
"百分比":0.0,
"co相关性:0.0
},
"重新排序":{
"百分比":0.0,
"相关性":0.0,
"间隔":0
}
}
}
}
ctrl-d
http/1.1 201创建
服务器:gunicorn/19.2.1
日期:2015年2月27日星期五20:02:05 GMT
连接n:关闭
传输编码:分块
变化:接受,cookie
内容类型:application/json;indent=2
允许:获取,发布,删除,head,选项
{
"向下":{
"速率":400,
"损失":{
"百分比":5.0,
"相关性":0.0
},
"delay":{
"延迟":15,
"抖动":0,
"相关性":0.0
},
"损坏":{
"百分比":0.0,
"相关性":0.0
},
"重新排序":{
"百分比":0.0,
"相关性":0.0,
"间隙":0
}
},
"up":{
"rate":200,
"loss":{
"percentage":1.0,
"correlation":0.0
},
"delay":{
"delay":10,
"jitter":0,
"correlation":0.0
},
"corruption":{
"percentage":0.0,
"c"相关度:0.0
},
"重新排序":{
"百分比":0.0,
"相关度":0.0,
"间隙":0
}
}
}
}
`````
或……更简单的说:
``sh
$curl-h'接受:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/
{
"down":{
"rate":400,
"loss":{
"percentage":5.0
},
"delay":{
"delay":15
},
"损坏":{},
"重新排序":{}
},
"向上":{
"速率":200,
"损失":{
"百分比":1.0
},
"延迟":{
"延迟":10
},
"损坏":{},
"重新排序"{}
}
}
}
ctrl-d
…相同的响应…
```
可能,可以使用url http://127.0.0.1:8080/api/v1/shape/1.1.1.1/来塑造设备1.1.1.1。
self(正在成形的设备,http代码204)
``sh
$curl-x delete-i-h'接受:应用程序/json;indent=2'http://127.0.0.1:8080/api/v1/shape/
http/1.1 204无内容
服务器:gunicorn/19.2.1
日期:2015年2月27日星期五19:46:58 gmt
连接:关闭
更改:接受,cookie
内容长度:0
允许:get、post、delete,head,options
```
*自己取消形状(设备未成形,http代码400):
```sh
$curl-x delete-i-h'接受:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/
http/1.1400错误请求
服务器:gunicorn/19.2.1
日期:201年2月27日星期五5 19:43:36 GMT
连接:关闭
传输编码:分块
变化:接受,cookie
内容类型:应用程序/json;缩进=2
允许:获取,发布,删除,标题,选项
{
"详细信息":"{消息":"未找到IP 10.0.2.2的会话","结果":12}
}
``````
*unshape 1.1.1.1(设备未成形,http代码400):
``sh
$curl-x delete-i-h'接受:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/1.1.1/
http/1.1400错误请求
服务器:gunicorn/19.2.1
日期:2015年2月27日星期五19:47:57 GMT
连接:关闭
传输编码:分块
变化:接受,cookie
内容类型:application/json;indent=2
允许:get、post、delete、head、options
{
"detail":"{'message':"找不到IP 1.1.1.1的会话","result':12}
}
`````
身份验证和授权
atc采用基于令牌的身份验证系统,允许设备安全地塑造其他设备。
要使用此系统,受控设备必须向atc请求令牌。一旦获得令牌,
令牌。
出于安全原因,这是设置客户端IP的唯一方法。请参阅下面的[代理设置](代理安全性)。
``sh
$curl-i-h'接受:应用程序/json;indent=2'http://127.0.0.1:8080/api/v1/token/
http/1.1200确定
服务器:gunicorn/19.3.0
日期:2015年3月16日星期一19:16:42 GMT
连接:关闭
传输编码:分块
更改:accept,cookie
内容类型:application/json;indent=2
允许:get,head,options
{
"有效截止日期":1426533420,
"令牌":186032,
"间隔":60,
"地址":"10.0.2.2"
}
`````
e使用`/api/v1/auth/addr`端点:
变化:接受
允许:获取、发布、发送、发送、选项
{
"控制IP":"127.0.0.0.1",
"控制IP":"10.0.2.2"
` `
:接受
接受:允许:获取、发送、发送、发送、发送、发送、选项
http://nginx.org/),请确保将其配置为设置
`http_x_real_ip`头,否则将无法生成令牌。
SS。例如,`curl-h'x戋real戋ip:1.2.3.4'`.
为了防止这种情况,atc限制允许哪些客户端设置"http戋x戋real戋ip"请求头。
这是通过使用django设置文件中"atc戋api"dict的"proxy戋ips"字段完成的:
"proxy"_ips':['1.2.3.4','2.3.4.5'],
}
atc api是一个django应用程序,允许将rest api连接到atcd的节俭api。
裂谷](../atc-atc-thrift)
`安装` django atc-api `最简单的安装方法是直接从[pip(https://pypi.pypypypypython.org/pypi)上安装` django atc-api
/>`` ` ` `
` ` ` ` ` ` ` ` ` ` ` `>
`` bash
$cd path/to/django-atc-api
pip安装。
```
编辑django项目的"settings.py",将"atc_api"和"rest_framework"添加到"已安装的应用程序"中:
``python
installed_apps=(
…
'atc_api',
'rest_framework',
)
```
2。在Django项目URL中包含"atc_api"urlconf。py如下:
``python
url(r'^api/v1/',include('atc_api.url'),
````
>3。启动开发服务器
``bash
python manage.py runserver 0.0.0:8000
```
>4。访问http://127.0.0.1:8000/api/v1/shape/设置/取消设置形状。
有些设置,如"ATCD主机"和"ATCD端口"可以在Django项目的设置中更改。py:
``python
`atC API={
"ATCD主机":"本地主机",
"ATCD端口":9090,
}
`
`请参见[atc api settings](atc_api/settings.py)了解更多详细信息。
核心api是有限的,允许:
*通过获取`/api/v1/shape/`
*通过发布到`/api/v1/shape/`
*通过发送删除请求到`/api/v1/shape/`
shaping status
s形,可以得到`/api/v1/shape/[ip/]`
TTP代码404):
``sh
$curl-h'接受:application/json;indent=2'h ttp://127.0.0.1:8080/api/v1/shape/
{
"detail":"此IP(10.0.2.2)未成形"
}
```
*检查我是否成形(正在成形的设备,http代码200):
``sh
$curl-h"'accept:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/
{
"down":{
"rate":400,
"loss":{
"percentage":5.0,
"correlation":0.0
},
"delay":{
"delay":15,
"jitter":0,
"correlation":0.0
},
"腐败":{
"百分比":0.0,
"相关性":0.0
},
"重新排序":{
"百分比":0.0,
"相关性":0.0,
"间隙":0
}
},
"向上":{
"比率":200,
"损失":{
"百分比":1。0,
"相关":0.0
},
"延迟":{
"延迟":10,
"抖动":0,
"相关":0.0
},
"损坏":{
"百分比":0.0,
"相关":0.0
},
"重新排序":{
"百分比":0.0,
"correlation":0.0,
"gap":0
}
}
}
}
`````
*检查1.1.1是否正在成形(设备未成形,http代码404):
```sh
$curl-h'接受:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/1.1.1/
"detail":"此IP"(1.1.1.1)未被整形"
}
```
10毫秒中的y,数据包丢失率为1%,减少了400 KB,增加了15毫秒的延迟和5%的数据包丢失率
这将始终在成功时重新运行http代码201。如果设备已经成形,则将应用新设置,删除唯一的设置。
注意(ctrl-d)
``sh
$curl-x post-d@-'-i-h'内容类型:application/json'-h'接受:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/
{
"down":{
"rate":400,
"loss":{
"percentage":5.0,
"correlation":0.0
},
"delay":{
"delay":15,
"jitter":0,
"correlation":0.0
},
"corruptio"n":{
"百分比":0.0,
"相关性":0.0
},
"重新排序":{
"百分比":0.0,
"相关性":0.0,
"间隔":0
}
},
"向上":{
"比率":200,
"损失":{
"百分比":1.0,
"相关性":0.0
},
"延迟":{
"延迟":10,
"抖动":0,
"相关性":0.0
},
"损坏":{
"百分比":0.0,
"co相关性:0.0
},
"重新排序":{
"百分比":0.0,
"相关性":0.0,
"间隔":0
}
}
}
}
ctrl-d
http/1.1 201创建
服务器:gunicorn/19.2.1
日期:2015年2月27日星期五20:02:05 GMT
连接n:关闭
传输编码:分块
变化:接受,cookie
内容类型:application/json;indent=2
允许:获取,发布,删除,head,选项
{
"向下":{
"速率":400,
"损失":{
"百分比":5.0,
"相关性":0.0
},
"delay":{
"延迟":15,
"抖动":0,
"相关性":0.0
},
"损坏":{
"百分比":0.0,
"相关性":0.0
},
"重新排序":{
"百分比":0.0,
"相关性":0.0,
"间隙":0
}
},
"up":{
"rate":200,
"loss":{
"percentage":1.0,
"correlation":0.0
},
"delay":{
"delay":10,
"jitter":0,
"correlation":0.0
},
"corruption":{
"percentage":0.0,
"c"相关度:0.0
},
"重新排序":{
"百分比":0.0,
"相关度":0.0,
"间隙":0
}
}
}
}
`````
或……更简单的说:
``sh
$curl-h'接受:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/
{
"down":{
"rate":400,
"loss":{
"percentage":5.0
},
"delay":{
"delay":15
},
"损坏":{},
"重新排序":{}
},
"向上":{
"速率":200,
"损失":{
"百分比":1.0
},
"延迟":{
"延迟":10
},
"损坏":{},
"重新排序"{}
}
}
}
ctrl-d
…相同的响应…
```
可能,可以使用url http://127.0.0.1:8080/api/v1/shape/1.1.1.1/来塑造设备1.1.1.1。
self(正在成形的设备,http代码204)
``sh
$curl-x delete-i-h'接受:应用程序/json;indent=2'http://127.0.0.1:8080/api/v1/shape/
http/1.1 204无内容
服务器:gunicorn/19.2.1
日期:2015年2月27日星期五19:46:58 gmt
连接:关闭
更改:接受,cookie
内容长度:0
允许:get、post、delete,head,options
```
*自己取消形状(设备未成形,http代码400):
```sh
$curl-x delete-i-h'接受:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/
http/1.1400错误请求
服务器:gunicorn/19.2.1
日期:201年2月27日星期五5 19:43:36 GMT
连接:关闭
传输编码:分块
变化:接受,cookie
内容类型:应用程序/json;缩进=2
允许:获取,发布,删除,标题,选项
{
"详细信息":"{消息":"未找到IP 10.0.2.2的会话","结果":12}
}
``````
*unshape 1.1.1.1(设备未成形,http代码400):
``sh
$curl-x delete-i-h'接受:application/json;indent=2'http://127.0.0.1:8080/api/v1/shape/1.1.1/
http/1.1400错误请求
服务器:gunicorn/19.2.1
日期:2015年2月27日星期五19:47:57 GMT
连接:关闭
传输编码:分块
变化:接受,cookie
内容类型:application/json;indent=2
允许:get、post、delete、head、options
{
"detail":"{'message':"找不到IP 1.1.1.1的会话","result':12}
}
`````
身份验证和授权
atc采用基于令牌的身份验证系统,允许设备安全地塑造其他设备。
要使用此系统,受控设备必须向atc请求令牌。一旦获得令牌,
令牌。
出于安全原因,这是设置客户端IP的唯一方法。请参阅下面的[代理设置](代理安全性)。
``sh
$curl-i-h'接受:应用程序/json;indent=2'http://127.0.0.1:8080/api/v1/token/
http/1.1200确定
服务器:gunicorn/19.3.0
日期:2015年3月16日星期一19:16:42 GMT
连接:关闭
传输编码:分块
更改:accept,cookie
内容类型:application/json;indent=2
允许:get,head,options
{
"有效截止日期":1426533420,
"令牌":186032,
"间隔":60,
"地址":"10.0.2.2"
}
`````
e使用`/api/v1/auth/addr`端点:
变化:接受
允许:获取、发布、发送、发送、选项
{
"控制IP":"127.0.0.0.1",
"控制IP":"10.0.2.2"
` `
:接受
接受:允许:获取、发送、发送、发送、发送、发送、选项
http://nginx.org/),请确保将其配置为设置
`http_x_real_ip`头,否则将无法生成令牌。
SS。例如,`curl-h'x戋real戋ip:1.2.3.4'`.
为了防止这种情况,atc限制允许哪些客户端设置"http戋x戋real戋ip"请求头。
这是通过使用django设置文件中"atc戋api"dict的"proxy戋ips"字段完成的:
}