There are times when I need to create a number of OpenVZ containers in Proxmox at once, which would take way too long via the user interface. There are a number of ways to accomplish this programmatically, but the most straightforward (assuming you have root access) is via pvectl .
Below is an example script which creates identical containers. Adjust the container IDs to ones that are available, as well as any other parameters you need. If you need more advanced options, the man page can be found at https://pve.proxmox.com/wiki/Pvectl_manual .
1 2 3 4 5 6 7 8 9 10 11 12 13 |
TEMPLATE_PATH="/var/lib/vz/template/cache/ubuntu-14.04-x86_64-minimal.tar.gz" IP_PREFIX="192.168.4." HOSTNAME_SUFFIX=`hostname -f` MEMORY_SIZE=2048 SWAP_SIZE=2048 DISK_SIZE=40 CPU_COUNT=2 for CTID in 100 101 102; do CMD="pvectl create ${CTID} ${TEMPLATE_PATH} -ip_address=${IP_PREFIX}${CTID} -onboot 1 \ -hostname v${CTID}-${HOSTNAME_SUFFIX} -cpus ${CPU_COUNT} -memory=${MEMORY_SIZE} -swap=${SWAP_SIZE} -disk=${DISK_SIZE}" echo "Running '${CMD}'..." $CMD done |
Your output will be something like:
1 2 3 4 5 |
Running 'pvectl create 100 /var/lib/vz/template/cache/ubuntu-14.04-x86_64-minimal.tar.gz -ip_address=192.168.4.106 -onboot 1 -hostname v100.my-proxmox-host.com -memory=2048 -swap=2048 -disk=40'... Creating container private area (/var/lib/vz/template/cache/ubuntu-14.04-x86_64-minimal.tar.gz) Performing postcreate actions CT configuration saved to /etc/pve/openvz/100.conf Container private area was created |
Leave a Reply