Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with OpenID
Advertise on LowEndTalk.com

In this Discussion

BashProx.sh: alternative to the Proxmox VE webinterface

BashProx.sh: alternative to the Proxmox VE webinterface

RaymiiRaymii Member
edited July 2012 in General

So I've been writing a bash script to manage proxmox. It now can create, start, stop and delete openvz VM's. If you don't give a vm ID it will ask you. And it has a openVZ shell dropper.

Creating a CT


 ./proxbash.sh createct test1 passw0rd ubuntu12 512 5 192.168.0.91
Creating ovz CT #: 920 test1 on proxmox with password passw0rd, template: ubuntu12, IP: 192.168.0.91, HDD: 5 GB, RAM: 512 MB.
Are you sure? Please enter y(es) or n(o): y
Creating OpenVZ Container CT 920
Creating container private area (/var/lib/vz/template/cache/ubuntu-12.04-x86.tar.gz)
Performing postcreate actions
CT configuration saved to /etc/pve/openvz/920.conf
Container private area was created
200 OK
UPID:proxmox:0000453A:000BB323:5013B844:vzcreate:920:root@pam:Starting CT 920
Starting container ...
Container is mounted
Adding IP address(es): 192.168.0.91
Setting CPU units: 1000
Setting CPUs: 1
Container start in progress...
200 OK
UPID:proxmox:00004578:000BBE63:5013B861:vzstart:920:root@pam:
Command finished

List all the VM's (including KVM): (You will also see this if you do something without a vm id)


./proxbash.sh listcts
OpenVZ Containers
200 OK
      "name" : "freedombox.raymii.nl",
      "vmid" : "103"
      "name" : "test1.raymii.nl",
      "vmid" : "920"
      "name" : "chatserver.raymii.nl",
      "vmid" : "101"
      "name" : "share.raymii.nl",
      "vmid" : "102"

KVM Virtual Machines:
200 OK
      "name" : "win2k8-ad-dns1",
      "vmid" : "100"

Start/Stop:


./proxbash.sh stopct 920
Stopping CT 920
Stopping container ...
Container was stopped
Container is unmounted
200 OK
UPID:proxmox:00004A40:000C4ECD:5013B9D2:vzstop:920:root@pam
Command finished


./proxbash.sh startct 920   
Starting CT 920
Starting container ...
Container is mounted
Adding IP address(es): 192.168.0.91
Setting CPU units: 1000
Setting CPUs: 1
Container start in progress...
200 OK
UPID:proxmox:00004AA3:000C65EC:5013BA0E:vzstart:920:root@pam:
Command finished

Deleting a CT:


./proxbash.sh deletect 
OpenVZ Containers
200 OK
      "name" : "freedombox.raymii.nl",
      "vmid" : "103"
      "name" : "test1.raymii.nl",
      "vmid" : "920"
      "name" : "chatserver.raymii.nl",
      "vmid" : "101"
      "name" : "share.raymii.nl",
      "vmid" : "102"
Enter VM ID please: 920
Are you sure you want to REMOVE VM 920?
Please enter y(es) or n(o): y
Are you really sure you want to remove VM 920? it will be gone forever and forever is a long time... 
Please enter y(es) or n(o): y
Stopping CT 920
Stopping container ...
Container was stopped
Container is unmounted
200 OK
UPID:proxmox:00004D02:000C7AFF:5013BA44:vzstop:920:root@pam:Removing CT 920
Destroying container private area: /var/lib/vz/private/920
Container private area was destroyed
200 OK
UPID:proxmox:00004D1E:000C7BAB:5013BA45:vzdestroy:920:root@pam:
Command finished

Shell dropper:


./proxbash.sh shelldrop 103
Entering CT 103
entered into CT 103
root@freedombox:/# whoami
root
root@freedombox:/# uname -a
Linux freedombox 2.6.32-11-pve #1 SMP Wed Apr 11 07:17:05 CEST 2012 i686 athlon i386 GNU/Linux
root@freedombox:/# exit
logout
exited from CT 103
Command finished

(Note: fuck stupid pseudo-terminals and ssh. But after a few hours, nano and dialog now work...)

So you need to deploy 120 vms?


#!/bin/bash
./proxbash.sh createct test1 "passw0rd" centos5 512 5 10.0.0.5 301
./proxbash.sh createct test2 "passw0rd" ubuntu12 512 5 10.0.0.6 302
./proxbash.sh createct test3 "passw0rd" ubuntu10 512 5 10.0.0.7 303
./proxbash.sh createct test4 "WhyUNoPassw0rd" centos6 1024 5 10.0.0.8 304
[...]

(note how you can also give the ct an vmid)

You need to delete them?


#!/bin/bash
./proxbash.sh deletect 301
./proxbash.sh deletect 302
./proxbash.sh deletect 303
./proxbash.sh deletect 304
[...]

Will be released under my regular license (MIT/X11). Needs SSH passwordles key auth to the proxmox vm. Templates are defined via a case and need to be in the proxmox host. Supports multiple proxmox nodes.

Planned is KVM. Also planned is set command execution (install git, run Chef, deploy app e.d.) Written all in bash.

Opinions?

Quis custodiet ipsos custodes?
http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
Thanked by 3jcaleb Mon5t3r ynzheng

Comments

Sign In or Register to comment.