prox是一个命令行接口,用于使用proxmox rest api从远程主机在proxmox上快速部署lxc容器。

proxmox-tools的Python项目详细描述


前置器

prox是一个命令行接口,用于从远程主机在proxmox上快速部署lxc容器 使用proxmox rest api。

Prox支持许多子命令和命令行选项:

> prox --help
usage: prox  [-h] [--debug]
             {assist,gui,ssh,connect,list,ls,show,start,run,stop,shutdown,destroy,delete,modify,mod,snap,snapshot,rollback,rb,new,create}
             ...

a tool for deploying resources from proxmox (LXC containers or VMs)

positional arguments:
  {assist,gui,ssh,connect,list,ls,show,start,run,stop,shutdown,destroy,delete,modify,mod,snap,snapshot,rollback,rb,new,create}
                        sub-command help
    assist (gui)        navigate application via GUI (experimental)
    ssh (connect)       connect to first host via ssh
    list (ls, show)     list hosts(s) with status, size and contact (optional)
    start (run)         start the host(s)
    stop (shutdown)     stop the host(s)
    destroy (delete)    delete the hosts(s) from disk
    modify (mod)        modify the config of one or more hosts
    snap (snapshot)     take a snapshot of the host
    rollback (rb)       roll back a snapshot
    new (create)        create one or more new hosts

optional arguments:
  -h, --help            show this help message and exit
  --debug, -g           verbose output for all commands

其中一个最常见的子命令是“prox new”,用于创建新机器:

> prox new --help
usage: prox new [-h] [--runlist RUNLIST] [--mem MEM] [--disk DISK]
                [--cores CORES] [--store-net] [--bootstrap] [--no-bootstrap]
                [hosts [hosts ...]]

positional arguments:
  hosts                 hostname(s) of VM/containers (separated by space),
                        example: prox new host1 host2 host3

optional arguments:
  -h, --help            show this help message and exit
  --runlist RUNLIST, -r RUNLIST
                        a local shell script file or a command to execute
                        after install
  --mem MEM, -m MEM     Memory allocation for the machine, e.g. 4G or 512
                        Default: 512
  --disk DISK, -d DISK  disk storage allocated to the machine. Default: 4
  --cores CORES, -c CORES
                        Number of cores to be allocated for the machine.
                        Default: 2
  --store-net, -s       use networked storage with backup (nfs, ceph) instead
                        of local storage
  --bootstrap, -b       auto-configure the system using Chef.
  --no-bootstrap, -n    do not auto-configure the system using Chef.

要安装prox,只需使用pip3。但在你需要一些操作系统包之前。在ubuntu上/ Debian您可以运行:

sudo apt-get install -y python3-pip python3-dev libffi-dev libssl-dev

在centos/redhat上运行:

yum -y install epel-release python34-devel libffi-devel openssl-devel

之后,您可以运行pip3:

pip3 install --upgrade pip
pip3 install --upgrade proxmox-tools

之后,您只需配置prox,就可以通过取消注释开始的行来完成此操作。 直接在/usr/local/bin/prox文件中使用“export”,或者将export语句粘贴到文件中 ~/.proxrc,位于运行prox的用户的主目录中。

> cat ~/.proxrc
export PPROXHOST='proxmox.domain.org'
export PREALM='pam'
export PLXCTEMPLATE='proxnfs:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz'
export PSTORLOC='proxazfs'
export PSTORNET='proxnfs'

现在假设您想部署一个新的Docker主机,名为香肠:

> prox new --mem 1024 --disk 8 sausage
Password for 'user':

creating host sausage with ID 121 in pool SciComp
    ...UPID:proxa3:00001F6C:00F2DBDE:57EE629A:vzcreate:121:user@DOMAIN.ORG:
Starting host 121 ..
    ...UPID:proxa3:00001FB3:00F2E185:57EE62A8:vzstart:121:user@DOMAIN.ORG:
Machine 121 : running, cpu: 0%

waiting for machine sausage to come up .. hit ctrl+c to stop ping

现在你可以手动安装Docker了。作为下一步,假设您希望在 多台机器。我们可以在一个简单的文本文件中创建一个运行列表,该列表中的每个命令都将 在每台机器上执行。在本例中,我们生成了一个安装Docker的运行列表:

> cat ~/runlist-docker
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" > /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get install -y docker-engine

现在,我们可以使用prox命令安装多台计算机:

> prox new --runlist ~/runlist-docker --disk 8 sausage1 sausage2 sausage3
Password for 'user':

creating host sausage1 with ID 116 in pool SciComp
    ...UPID:proxa3:000039A6:0111B96E:57EEB19E:vzcreate:116:user@DOMAIN.ORG:
creating host sausage2 with ID 118 in pool SciComp
    ...UPID:proxa3:000039B6:0111B980:57EEB19E:vzcreate:118:user@DOMAIN.ORG:
creating host sausage3 with ID 121 in pool SciComp
    ...UPID:proxa3:000039C4:0111B991:57EEB19E:vzcreate:121:user@DOMAIN.ORG:
Starting host 116 ..
starting host 116, re-try 0
    ...UPID:proxa3:00003A04:0111BCB7:57EEB1A6:vzstart:116:user@DOMAIN.ORG:
Machine 116 : running, cpu: 0%
Starting host 118 ..
    ...UPID:proxa3:00003AF7:0111BD3C:57EEB1A8:vzstart:118:user@DOMAIN.ORG:
Machine 118 : running, cpu: 0%
Starting host 121 ..
    ...UPID:proxa3:00003BE2:0111BDC2:57EEB1A9:vzstart:121:user@DOMAIN.ORG:
Machine 121 : running, cpu: -1%

完成工作后,您可以停止并销毁这些机器:

> prox stop sausage1 sausage2 sausage3
Password for 'user':

UPID:proxa2:000060FE:01121EA2:57EEB2A1:vzstop:116:user@DOMAIN.ORG:
UPID:proxa3:00006110:01121EB3:57EEB2A1:vzstop:118:user@DOMAIN.ORG:
UPID:proxa4:00006127:01121EC6:57EEB2A1:vzstop:121:user@DOMAIN.ORG:

> prox destroy sausage1 sausage2 sausage3
Password for 'user':

UPID:proxa2:000061C7:01122C18:57EEB2C4:vzdestroy:116:user@DOMAIN.ORG:
UPID:proxa3:000061CB:01122C2A:57EEB2C4:vzdestroy:118:user@DOMAIN.ORG:
UPID:proxa4:000061CF:01122C3B:57EEB2C4:vzdestroy:121:user@DOMAIN.ORG:

proxhostname.py

脚本在新部署的proxmox vm或容器中运行,查询promox api以获得正确的主机名 根据在本地系统上找到的MAC地址并设置新主机名

如果您有一个ipam设备(如infoblox),只需将linux上的主机名更改为 让动态dns给你一个新的ip地址。这允许您在几秒钟内部署许多主机

与ubuntu 14.04和ubuntu 16.04一起测试

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java在循环中使用if语句   Java onthefly字符串替换   安卓 java。util。拉链ZipInputStream在解压过程中部分为空   java检查安卓设备是否支持4K视频?   java如何显示ArrayList<Integer[]>lista=new ArrayList<>()   如何在Java8中将字符流转换为字符串   java序列化ArrayList<Objects>并返回,保留类   java通过复制到webapps手动部署Tomcat应用   java如何将JsonNode转换为映射   java从addOnSuccessListener获取结果   java在泛型类中生成随机数   列表中每个对象的java格式   最新GAE SDK版本(1.9.26)的java MemcacheService增量问题   RESTful服务的java url设计   java Maven可传递依赖公共集合版本3 vs 4   list Java:如何使用try/catch块和return   如何在Eclipse 202012中为Java 14启用预览功能?