使用Rancher API呈现模板的文件生成器
rancher-gen的Python项目详细描述
```
888888 b.888.d8888b.
888 y88b 888 d88p y88b
888 888 888 888 888
888 D888P 888B.88888 B..D888B 88888 B..D888B.888D888 D888 888.D888B.
888888 P""888 B 888"888 D888 P"888"888 D8B D8P Y8B 888P"888 D8P Y8B 8888 D8P Y8B 888"888 B
888 T888B.D88888 888 888 888 888 888 888 888 888 888 888888888888888888888 888
888 t88b 888 888 888 y88b.888 888 y8b.888 y88b.888 y88b d88p y8b.888 888
888 t88b"y88888 888 888"y8888p 888"y88888 888 888"y88888"y88888 888 p88"y888
````
使用Rancher API呈现模板的文件生成器。灵感来自
[docker gen](https://github.com/jwilder/docker gen)。
此程序侦听牧场主服务的更改并呈现
[jinja2]模板(http://jinja.pocoo.org/docs/dev/)。它还具有
在模板呈现后不运行通知命令的功能。这对于生成nginx等服务的配置文件很有用。
[--secret key secret_key][--project id project_id][-h]
[--log level{debug,info,warning,critical,error}
[--stack stack][--service service][--ssl]
[--notify notify]
template dest
从Rancher元数据
位置参数:
要生成的模板的模板路径
生成文件的目标输出路径
命名参数:
--主机Rancher主机(默认为本地主机)
--端口Rancher端口(如果指定了ssl,则默认为80或443)
--访问密钥访问密钥
牧场主访问密钥
--密钥密钥密钥
牧场主密钥
--项目ID项目ID
rancher的项目id
错误}
设置日志级别。
--堆栈堆栈Rancher堆栈的名称
--服务服务Rancher服务的名称
--SSL用户安全连接(https和wss)
--通知在模板之后运行的命令生成(例如
重新启动某些服务)
```
要运行rancher gen,必须至少指定以下参数:
*主机:rancher服务器的IP/DNS名称。
*端口:rancher服务器的端口。SSL的默认值为80或443。
*访问密钥:访问Rancher服务器的访问密钥。
*密钥:访问Rancher服务器的密钥。
*项目ID:来自Rancher的项目ID(环境)。
实例在呈现时传递给模板。因此,
您可以这样做:
{%对于containers%}
{{container['primarypaddress']}
{%endfor%}
{container['primarypaddress']}
{%endfor%}
"links":{
"self":"../v1/projects/1a5/containers/1i258"、
"account":"../v1/projects/1a5/containers/1i258/account"、
"credentials":"../v1/projects/1a5/containers/1i258/credentials"、
"healthcheckinstan"cehostmaps"../v1/projects/1a5/containers/1i258/healthcheckinstancehostmaps",
"hosts":"../v1/projects/1a5/containers/1i258/hosts",
"instancelabels":"../v1/projects/1a5/containers/1i258/instancelabels",
"instancelinks":"../v1/projects/1a5/containers/1i258/instancelinks",
"instances":"../v1/projects/1a5/containers/1i258/instances",
"mounts":"../v1/projects/1a5/containers/1i258/mounts",
"ports":"../v1/projects/1a5/containers/1i258/ports",
"服务事件":"../v1/projects/1a5/containers/1i258/serviceevents"、
"serviceExposeMaps":"../v1/projects/1a5/containers/1i258/serviceExposeMaps"、
"服务":"../v1/projects/1a5/containers/1i258/services",
"targetInstanceLinks":"../v1/projects/1a5/containers/1i258/targetInstanceLinks",
"volumes":"../v1/projects/1a5/containers/1i258/volumes",
"stats":"../v1/projects/1a5/containers/1i258/stats",
"containerstats":"../v1/projects/1a5/containers/1i258/containerstats",
},
"actions":{
"update":"../v1/projects/1a5/containers/1i258/?操作=更新",
"停止":"../v1/projects/1a5/containers/1i258/?action=stop",
"restart":"../v1/projects/1a5/containers/1i258/?操作=重新启动",
"迁移":"../v1/projects/1a5/containers/1i258/?操作=迁移",
"日志":"../v1/projects/1a5/containers/1i258/?action=logs",
"setlabels":"../v1/projects/1a5/containers/1i258/?action=setlabels",
"执行":"../v1/projects/1a5/containers/1i258/?操作=执行",
"代理":"../v1/projects/1a5/containers/1i258/?action=proxy",
},
"name":"foo-nginx2-1",
"state":"running",
"accountid":"1a5",
"blkiodeviceoptions":空,
"build":空,
"capadd":空,
"capdrop":空,
"command":空,
"cpuset":空,
"cpushares":空,
"createindex":1,
"创建":"2016-09-07t01:37:19z",
"创建DTS":1473212239000,
"数据卷管理":{},
"数据卷":[
"/tmp/nginxconf:/nginxconf",
],
"数据卷来源":空,
"部署单元uuid":"e4af719b-39ad-4576-8402-8a29a6ec97d6",
"description":空,
"devices":空,
"dns":[
"169.254.169.250",
],
"dnssearch":[
"foo.rancher.internal",
"nginx2.foo.rancher.internal",
"rancher.internal",
"domainname":空,
"entrypoint":空,
"environment":{
"nginx-run-u-type":"rancher-gen",
"rancher-gen-access-key":"37af1f5cd18843df00cc",
"rancher-gen-u-host":"192.168.0.15",
"rancher-gen-u-options":--"端口8080——stack foo——服务hello",
"rancher-gen u-project-id":"1a5",
"牧场主密钥":"7D7bio7bck1vgbj5jngvcnaezfrnmzxpjaez8fs2",
},
"公开":空,
"外部":"f61757f4ed26d6bb2dc31aa8b17dd4227a3bbca12225ddab66e77d76971d",
"外部主机":空,
"首次运行":"2016-09-07t01:37:20z",
"firstrunningts":1473212240000,
"healthcheck":空,
"healthstate":空,
"hostid":"1h2",
"hostname":空,
"imageuuid":"docker:pitro/nginx:dev",
"kind":"container",
"labels":{
"io.rancher.project.name":"foo",
"io.rancher.service.deployment.unit":"e4af719b-39ad-4576-8402-8a29a6ec97d6"、
"io.rancher.service.launch.config":"io.rancher.service.primary.launch.config"、
"io.rancher.project\u service.name":"foo/nginx2"、
"io.rancher.stack.name":"foo",
"io.rancher.stack_service.name":"foo/nginx2"、
"io.rancher.service.hash":"ddf05372f057253876d50b81c26eb1a350438d49"、
"io.rancher.container.uuid":"90028a61-6fd5-460a-a8b7-f90bcaf664f2"、
"io.rancher.container.name":"foo_nginx2_1"、
"io.rancher.container.ip":"10.42.172.71/16",
},
"logconfig":{},
"lxcconf":空,
"memory":空,
"memoryswap":空,
"nativecontainer":false,
"networkcontainerID":空,
"networkmode":"managed",
"pidmode":空,
"ports":[
"80:80/tcp",
],
"primarypaddress":"10.42.172.71",
"privileged":假,
"publishallports":假,
"readonly":假,
"registrycredentialid":null,
"removed":null,
"requestedhostid":null,
"restartpolicy":null,
"securityopt":null,
"startcount":1,
"startoncreate":true,
"stdinopen":false,
"systemcontainer":null,
"transitioning":"no",
"传输消息":空,
"传输进度":空,
"tty":假,
"用户":空,
"uuid":"90028a61-6fd5-460a-a8b7-f90bcaf664f2",
"版本":"0",
"VolumedDrive":空,
"WorkingDir":空,
}
````
###在堆栈级别侦听更改
rancher gen--host rancher.mycompany.com--port 8080--access key 1234567890--secret key 123abc456def789ghi--project id 1a5--stack mystack--template/tmp/template.j2:/tmp/output.txt
level
rancher gen--host rancher.mycompany.com--port 8080--access key 1234567890--secret key 123abc456def789ghi--project id 1a5--stack mystack--service myservice--template/tmp/template.j2:/tmp/output.txt
stack
rancher gen--host rancher.mycompany.com--port 8080--access key 1234567890--secret key 123abc456def789ghi--project id 1a5--stack mystack--service myservice1--service myservice2--template/tmp/template.j2:/tmp/output.txt
rancher gen--host rancher.mycompany.com--access key 1234567890--secret key 123abc456def789ghi--project id 1a5--stack mystack--service myservice--ssl--template/tmp/template.j2:/tmp/output.txt
rancher.mycompany.com--port 8080--access key 1234567890--secret key 123abc456def789ghi--project id 1a5--stack mystack--service myservice--ssl--notify"service nginx reload"--template/tmp/template.j2:/tmp/output.txt
rancher.mycompany.com--端口8080--访问密钥1234567890--密钥123abc456def789ghi--项目ID 1a5--模板/tmp/template1.j2:/tmp/output1.txt--模板/tmp/template2.j2:/tmp/output2.txt
888888 b.888.d8888b.
888 y88b 888 d88p y88b
888 888 888 888 888
888 D888P 888B.88888 B..D888B 88888 B..D888B.888D888 D888 888.D888B.
888888 P""888 B 888"888 D888 P"888"888 D8B D8P Y8B 888P"888 D8P Y8B 8888 D8P Y8B 888"888 B
888 T888B.D88888 888 888 888 888 888 888 888 888 888 888888888888888888888 888
888 t88b 888 888 888 y88b.888 888 y8b.888 y88b.888 y88b d88p y8b.888 888
888 t88b"y88888 888 888"y8888p 888"y88888 888 888"y88888"y88888 888 p88"y888
````
使用Rancher API呈现模板的文件生成器。灵感来自
[docker gen](https://github.com/jwilder/docker gen)。
此程序侦听牧场主服务的更改并呈现
[jinja2]模板(http://jinja.pocoo.org/docs/dev/)。它还具有
在模板呈现后不运行通知命令的功能。这对于生成nginx等服务的配置文件很有用。
[--secret key secret_key][--project id project_id][-h]
[--log level{debug,info,warning,critical,error}
[--stack stack][--service service][--ssl]
[--notify notify]
template dest
从Rancher元数据
位置参数:
要生成的模板的模板路径
生成文件的目标输出路径
命名参数:
--主机Rancher主机(默认为本地主机)
--端口Rancher端口(如果指定了ssl,则默认为80或443)
--访问密钥访问密钥
牧场主访问密钥
--密钥密钥密钥
牧场主密钥
--项目ID项目ID
rancher的项目id
错误}
设置日志级别。
--堆栈堆栈Rancher堆栈的名称
--服务服务Rancher服务的名称
--SSL用户安全连接(https和wss)
--通知在模板之后运行的命令生成(例如
重新启动某些服务)
```
要运行rancher gen,必须至少指定以下参数:
*主机:rancher服务器的IP/DNS名称。
*端口:rancher服务器的端口。SSL的默认值为80或443。
*访问密钥:访问Rancher服务器的访问密钥。
*密钥:访问Rancher服务器的密钥。
*项目ID:来自Rancher的项目ID(环境)。
实例在呈现时传递给模板。因此,
您可以这样做:
{%对于containers%}
{{container['primarypaddress']}
{%endfor%}
{container['primarypaddress']}
{%endfor%}
"links":{
"self":"../v1/projects/1a5/containers/1i258"、
"account":"../v1/projects/1a5/containers/1i258/account"、
"credentials":"../v1/projects/1a5/containers/1i258/credentials"、
"healthcheckinstan"cehostmaps"../v1/projects/1a5/containers/1i258/healthcheckinstancehostmaps",
"hosts":"../v1/projects/1a5/containers/1i258/hosts",
"instancelabels":"../v1/projects/1a5/containers/1i258/instancelabels",
"instancelinks":"../v1/projects/1a5/containers/1i258/instancelinks",
"instances":"../v1/projects/1a5/containers/1i258/instances",
"mounts":"../v1/projects/1a5/containers/1i258/mounts",
"ports":"../v1/projects/1a5/containers/1i258/ports",
"服务事件":"../v1/projects/1a5/containers/1i258/serviceevents"、
"serviceExposeMaps":"../v1/projects/1a5/containers/1i258/serviceExposeMaps"、
"服务":"../v1/projects/1a5/containers/1i258/services",
"targetInstanceLinks":"../v1/projects/1a5/containers/1i258/targetInstanceLinks",
"volumes":"../v1/projects/1a5/containers/1i258/volumes",
"stats":"../v1/projects/1a5/containers/1i258/stats",
"containerstats":"../v1/projects/1a5/containers/1i258/containerstats",
},
"actions":{
"update":"../v1/projects/1a5/containers/1i258/?操作=更新",
"停止":"../v1/projects/1a5/containers/1i258/?action=stop",
"restart":"../v1/projects/1a5/containers/1i258/?操作=重新启动",
"迁移":"../v1/projects/1a5/containers/1i258/?操作=迁移",
"日志":"../v1/projects/1a5/containers/1i258/?action=logs",
"setlabels":"../v1/projects/1a5/containers/1i258/?action=setlabels",
"执行":"../v1/projects/1a5/containers/1i258/?操作=执行",
"代理":"../v1/projects/1a5/containers/1i258/?action=proxy",
},
"name":"foo-nginx2-1",
"state":"running",
"accountid":"1a5",
"blkiodeviceoptions":空,
"build":空,
"capadd":空,
"capdrop":空,
"command":空,
"cpuset":空,
"cpushares":空,
"createindex":1,
"创建":"2016-09-07t01:37:19z",
"创建DTS":1473212239000,
"数据卷管理":{},
"数据卷":[
"/tmp/nginxconf:/nginxconf",
],
"数据卷来源":空,
"部署单元uuid":"e4af719b-39ad-4576-8402-8a29a6ec97d6",
"description":空,
"devices":空,
"dns":[
"169.254.169.250",
],
"dnssearch":[
"foo.rancher.internal",
"nginx2.foo.rancher.internal",
"rancher.internal",
"domainname":空,
"entrypoint":空,
"environment":{
"nginx-run-u-type":"rancher-gen",
"rancher-gen-access-key":"37af1f5cd18843df00cc",
"rancher-gen-u-host":"192.168.0.15",
"rancher-gen-u-options":--"端口8080——stack foo——服务hello",
"rancher-gen u-project-id":"1a5",
"牧场主密钥":"7D7bio7bck1vgbj5jngvcnaezfrnmzxpjaez8fs2",
},
"公开":空,
"外部":"f61757f4ed26d6bb2dc31aa8b17dd4227a3bbca12225ddab66e77d76971d",
"外部主机":空,
"首次运行":"2016-09-07t01:37:20z",
"firstrunningts":1473212240000,
"healthcheck":空,
"healthstate":空,
"hostid":"1h2",
"hostname":空,
"imageuuid":"docker:pitro/nginx:dev",
"kind":"container",
"labels":{
"io.rancher.project.name":"foo",
"io.rancher.service.deployment.unit":"e4af719b-39ad-4576-8402-8a29a6ec97d6"、
"io.rancher.service.launch.config":"io.rancher.service.primary.launch.config"、
"io.rancher.project\u service.name":"foo/nginx2"、
"io.rancher.stack.name":"foo",
"io.rancher.stack_service.name":"foo/nginx2"、
"io.rancher.service.hash":"ddf05372f057253876d50b81c26eb1a350438d49"、
"io.rancher.container.uuid":"90028a61-6fd5-460a-a8b7-f90bcaf664f2"、
"io.rancher.container.name":"foo_nginx2_1"、
"io.rancher.container.ip":"10.42.172.71/16",
},
"logconfig":{},
"lxcconf":空,
"memory":空,
"memoryswap":空,
"nativecontainer":false,
"networkcontainerID":空,
"networkmode":"managed",
"pidmode":空,
"ports":[
"80:80/tcp",
],
"primarypaddress":"10.42.172.71",
"privileged":假,
"publishallports":假,
"readonly":假,
"registrycredentialid":null,
"removed":null,
"requestedhostid":null,
"restartpolicy":null,
"securityopt":null,
"startcount":1,
"startoncreate":true,
"stdinopen":false,
"systemcontainer":null,
"transitioning":"no",
"传输消息":空,
"传输进度":空,
"tty":假,
"用户":空,
"uuid":"90028a61-6fd5-460a-a8b7-f90bcaf664f2",
"版本":"0",
"VolumedDrive":空,
"WorkingDir":空,
}
````
###在堆栈级别侦听更改
rancher gen--host rancher.mycompany.com--port 8080--access key 1234567890--secret key 123abc456def789ghi--project id 1a5--stack mystack--template/tmp/template.j2:/tmp/output.txt
level
rancher gen--host rancher.mycompany.com--port 8080--access key 1234567890--secret key 123abc456def789ghi--project id 1a5--stack mystack--service myservice--template/tmp/template.j2:/tmp/output.txt
stack
rancher gen--host rancher.mycompany.com--port 8080--access key 1234567890--secret key 123abc456def789ghi--project id 1a5--stack mystack--service myservice1--service myservice2--template/tmp/template.j2:/tmp/output.txt
rancher gen--host rancher.mycompany.com--access key 1234567890--secret key 123abc456def789ghi--project id 1a5--stack mystack--service myservice--ssl--template/tmp/template.j2:/tmp/output.txt
rancher.mycompany.com--port 8080--access key 1234567890--secret key 123abc456def789ghi--project id 1a5--stack mystack--service myservice--ssl--notify"service nginx reload"--template/tmp/template.j2:/tmp/output.txt
rancher.mycompany.com--端口8080--访问密钥1234567890--密钥123abc456def789ghi--项目ID 1a5--模板/tmp/template1.j2:/tmp/output1.txt--模板/tmp/template2.j2:/tmp/output2.txt