使用Rancher API开发小型实用程序
lazo的Python项目详细描述
拉佐
与牧场主合作的小型公用事业。它已被开发用于ci环境中。
当前功能:
- 获取有关运行群集/项目/工作负载的信息
- 获取Docker图像信息
- 升级工作负载
- 在运行的容器中执行命令
安装
$ pip install lazo
或者使用pipsi
$ pipsi install lazo
帮助
$ lazo --help
Usage: lazo [OPTIONS] COMMAND [ARGS]...
Options:
--version Show the version and exit.
--env
-v, --verbosity verbosity level
-q, --quit no output
-d, --dry-run dry-run mode
--debug debug mode
-h, --help Show this message and exit.
Commands:
docker
rancher
环境变量
- 牧场主的URL为
--base-url
- 牧场主密钥为
--key
- 牧场主的秘密是
--secret
- 牧场主集群为
--cluster
- 牧场主项目
- 牧场主不安全
- Docker_存储库为
--repository
您可以使用以下命令检查默认配置:
$ lazo --defaults
Env Value Origin
repository https://hub.docker.com/v2
auth
base_url
cluster
insecure False
project
use_names False
或使用以下命令列出处理程序环境变量:
$ lazo --env
Env Value
DOCKER_REPOSITORY -- not set --
RANCHER_AUTH -- not set --
RANCHER_BASE_URL -- not set --
RANCHER_CLUSTER -- not set --
RANCHER_INSECURE -- not set --
RANCHER_PROJECT -- not set --
RANCHER_USE_NAMES -- not set --
示例
牧场主获取有关运行工作负载的信息
$ lazo rancher -i -n info -p cluster1:bitcaster -w bitcaster:bitcaster
Workload infos:
Image: bitcaster/bitcaster:0.3.0a15
Command: ['stack']
imagePullPolicy: Always
升级工作负载
$ export RANCHER_KEY=key
$ export RANCHER_SECRET=secret
$ lazo upgrade saxix/devpi:latest \
--base-url https://rancher.example.com/v3/
--cluster c-wwk6v
--project p-xd4dg
使用stdin读取凭据
$ cat .pass.txt | lazo --stdin \
upgrade bitcaster:bitcaster \
bitcaster/bitcaster:0.3.0a10 \
--insecure
在运行容器中执行命令
$ lazo shell bitcaster:db -- ls -al /var/log
total 432
drwxr-xr-x 1 root root 4096 Jan 1 01:39 .
drwxr-xr-x 1 root root 4096 Dec 26 00:00 ..
drwxr-xr-x 1 root root 4096 Jan 1 01:39 apt
-rw-r--r-- 1 root root 74886 Jan 1 01:39 dpkg.log
-rw-r--r-- 1 root root 32000 Jan 1 01:39 faillog
drwxr-xr-x 2 root root 4096 May 25 2017 sysstat
码头工人
列出可用的图像标签
$ lazo docker info saxix/devpi
latest
2.3
2.2
2.1
2.0
1.1
获取有关图像的信息
$ lazo docker info library/python --filter '3\.6.*alpine3.8' --size
3.6-alpine3.8 26.2MiB
3.6.8-alpine3.8 26.2MiB
3.6.7-alpine3.8 26.2MiB
3.6.6-alpine3.8 26.2MiB
$ lazo rancher -i -n info -p cluster1:bitcaster -w bitcaster:bitcaster
Workload infos:
Image: bitcaster/bitcaster:0.3.0a15
Command: ['stack']
imagePullPolicy: Always
$ export RANCHER_KEY=key
$ export RANCHER_SECRET=secret
$ lazo upgrade saxix/devpi:latest \
--base-url https://rancher.example.com/v3/
--cluster c-wwk6v
--project p-xd4dg
$ cat .pass.txt | lazo --stdin \
upgrade bitcaster:bitcaster \
bitcaster/bitcaster:0.3.0a10 \
--insecure
$ lazo shell bitcaster:db -- ls -al /var/log
total 432
drwxr-xr-x 1 root root 4096 Jan 1 01:39 .
drwxr-xr-x 1 root root 4096 Dec 26 00:00 ..
drwxr-xr-x 1 root root 4096 Jan 1 01:39 apt
-rw-r--r-- 1 root root 74886 Jan 1 01:39 dpkg.log
-rw-r--r-- 1 root root 32000 Jan 1 01:39 faillog
drwxr-xr-x 2 root root 4096 May 25 2017 sysstat
码头工人
列出可用的图像标签
$ lazo docker info saxix/devpi
latest
2.3
2.2
2.1
2.0
1.1
获取有关图像的信息
$ lazo docker info library/python --filter '3\.6.*alpine3.8' --size
3.6-alpine3.8 26.2MiB
3.6.8-alpine3.8 26.2MiB
3.6.7-alpine3.8 26.2MiB
3.6.6-alpine3.8 26.2MiB
$ lazo docker info saxix/devpi
latest
2.3
2.2
2.1
2.0
1.1
获取有关图像的信息
$ lazo docker info library/python --filter '3\.6.*alpine3.8' --size
3.6-alpine3.8 26.2MiB
3.6.8-alpine3.8 26.2MiB
3.6.7-alpine3.8 26.2MiB
3.6.6-alpine3.8 26.2MiB
$ lazo docker info library/python --filter '3\.6.*alpine3.8' --size
3.6-alpine3.8 26.2MiB
3.6.8-alpine3.8 26.2MiB
3.6.7-alpine3.8 26.2MiB
3.6.6-alpine3.8 26.2MiB