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?
https://raymii.org - https://cipherli.st
Thanked by 3jcaleb Mon5t3r ynzheng

Comments

  • Cool work mate, look forward to kvm support

    I use http://tuxlite.com to configure all my VPSes and I love it!

  • JarJar Member

    Seems like you could drop the proxmox overhead and just use the OpenVZ CLI tools, but good work either way :)

  • PatsPats Member

    very nice... :) can you do re-install template to a existing container.

  • RaymiiRaymii Member

    @djvdorp for the KVM it's imho better to use the web interface. You then can right away use the proxmox java console to get into the vm. If you use the command line a graphical install console would be a bit hard.

    @jarland correct but the install op openvz is very easy and fast, and it allows openvz and KVM machines without a lot of hassle. If your need to set it up yourself it would take longer then just popping in the proxmox cd.

    @pats I'm looking in the API docs, but I cannot seem to find that. I've heard multiple people complain about that. Recreating the container would be the temp solution.

    2 new features first: container info:

    
    ./proxbash.sh ctinfo 103
    CT 103 info:
    200 OK
    {
       "cpu" : 0.00123341974037341,
       "cpus" : 1,
       "disk" : 489906176,
       "diskread" : 627728384,
       "diskwrite" : 68669440,
       "failcnt" : 0,
       "ha" : 0,
       "ip" : "192.168.0.33",
       "maxdisk" : 32212254720,
       "maxmem" : 536870912,
       "maxswap" : 536870912,
       "mem" : 26984448,
       "name" : "freedombox.raymii.nl",
       "netin" : 11846189,
       "netout" : 462376,
       "nproc" : "18",
       "status" : "running",
       "swap" : 6492160,
       "type" : "openvz",
       "uptime" : 49379
    }
    
    

    And nicest one, command execution in CT:

    
    ./proxbash.sh execinct 103  "uname -a; hostname; whoami; w"
    Executing on 103
    Linux freedombox 2.6.32-11-pve #1 SMP Wed Apr 11 07:17:05 CEST 2012 i686 athlon i386 GNU/Linux
    freedombox
    root
     01:40:55 up 13:46,  0 users,  load average: 0.18, 0.07, 0.02
    USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
    Command finished
    
    

    So, now imagine:

    
    ./proxbash.sh  createct web21 "passw0rd" ubuntu12 512 5 192.168.0.98
    ./proxbash.sh execinct 1021 "apt-get update; apt-get install git-core ruby; gem install chef capistrano; cap deploy"
    
    

    from zero to full deploy of your app (assuming you have a cap script and a chef config, but can also be a shell script or whatever) in no time with only two commands?

    Quis custodiet ipsos custodes?
    https://raymii.org - https://cipherli.st
  • yomeroyomero Member

    If you can get to input it an script to execute, maybe I am sold.

  • PatsPats Member

    @Raymii said: Recreating the container would be the temp solution.

    ok so a feature that way would be nice.. ./proxbash.sh retemplate debian6min 103

    internally it gets the values 'ctinfo' & recreates the container with template debian6min

  • RaymiiRaymii Member

    @yomero executing a script I wrote, which should fail because no X, but script executes

    
    ./proxbash.sh execinct 103 "wget http://raymii.org/cms/content/downloads/easyconverter.sh; chmod +x easyconverter.sh; ./easyconverter.sh"
    Executing on 103
    --2012-07-29 10:07:34--  http://raymii.org/cms/content/downloads/easyconverter.sh
    Resolving raymii.org (raymii.org)... 46.228.207.134, 209.141.58.75, 81.30.145.69, ...
    Connecting to raymii.org (raymii.org)|46.228.207.134|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 3619 (3.5K) [application/x-sh]
    Saving to: `easyconverter.sh'
    
         0K ...                                                   100% 13.0K=0.3s
    
    2012-07-29 10:07:35 (13.0 KB/s) - `easyconverter.sh' saved [3619/3619]
    
    ./easyconverter.sh: line 39: zenity: command not found
    ./easyconverter.sh: line 22: zenity: command not found
    Connection to 192.168.0.25 closed.
    Command finished
    
    

    @Pats It is faster to just recreate the container yourself. pvesh outputs the variables all in json-like format and bash does not like to parse that. I can do it, but it would require a lot of effort for a feature that I'm not going to use a lot. Also, because it is requested a lot, I hope the proxmox team builds it in so that I only have to do an API call. If they do that, i'll add it.

    Quis custodiet ipsos custodes?
    https://raymii.org - https://cipherli.st
  • RaymiiRaymii Member

    Release!!!!!!!

    First version released: https://raymii.org/cms/p_Proxbash_-_Bash_script_to_manage_Proxmox_VE

    (and if the cluster is not up to date yet: http://let.raymii.org/cms/p_Proxbash_-_Bash_script_to_manage_Proxmox_VE )

    comments and such are very welcome.

    btw @kuJoe do you still use Proxmox?

    Quis custodiet ipsos custodes?
    https://raymii.org - https://cipherli.st
    Thanked by 1Pats
  • KuJoeKuJoe Member
    edited July 2012

    @Raymii said: btw @kuJoe do you still use Proxmox?

    Nope, too many problems with it. I do everything via CLI now.

    -Joe @ SecureDragon - LEB's Powered by Wyvern in FL, CO, CA, IL, NJ, GA, TX, and AZ
    Test our network here: Drgn.biz
  • RaymiiRaymii Member

    Problems like?

    Quis custodiet ipsos custodes?
    https://raymii.org - https://cipherli.st
  • KuJoeKuJoe Member

    Performance issues (mostly disk I/O) Security issues (Debian 5 is EOL) Usability issues (Proxmox 2.x did not fit my needs at all)

    -Joe @ SecureDragon - LEB's Powered by Wyvern in FL, CO, CA, IL, NJ, GA, TX, and AZ
    Test our network here: Drgn.biz
  • PatsPats Member
    edited July 2012

    @KuJoe said: Security issues (Debian 5 is EOL)

    the bare metal is Debian 6 and i also installed manually on Debian6 64bit

    can u elaborate on - Performance issues (mostly disk I/O) ?

  • KuJoeKuJoe Member

    @Pats said: the bare metal is Debian 6

    Proxmox 1.9 (the only one I will use) is Debian 5. :(

    @Pats said: can u elaborate on - Performance issues (mostly disk I/O) ?

    Here's what I experienced with the exact same hardware: Max write speeds with Proxmox installed = ~50MB/s Max write speeds without Proxmox installed = ~160MB/s

    These results are the same regardless if I use OpenVZ or KVM so I just dropped Proxmox all together for the increased performance.

    -Joe @ SecureDragon - LEB's Powered by Wyvern in FL, CO, CA, IL, NJ, GA, TX, and AZ
    Test our network here: Drgn.biz
  • yomeroyomero Member

    So, this are kernel issues with your hardware I guess

  • KuJoeKuJoe Member

    Probably, the Proxmox kernel was the only thing different besides the software itself but the software shouldn't have any impact on the performance I would think. I tried 4 different hardware setups without any luck though.

    -Joe @ SecureDragon - LEB's Powered by Wyvern in FL, CO, CA, IL, NJ, GA, TX, and AZ
    Test our network here: Drgn.biz
  • RaymiiRaymii Member

    @KuJoe why do you only want to use ProxMox 1.9? I've only used it since 2...

    Quis custodiet ipsos custodes?
    https://raymii.org - https://cipherli.st
  • KuJoeKuJoe Member

    @Raymii said: @KuJoe why do you only want to use ProxMox 1.9? I've only used it since 2...

    2.0 is to complex and does not fit my needs. I was only using Proxmox for internal services and 2.0 offers to many extras that make using it both difficult and annoying for my needs. I do not need user accounts, groups, or permissions and setting up these things is time wasted and adds a larger attack surface for hackers. 1.9 was very basic and fit my needs perfectly as far as a web interface goes, it was unfortunate that 2.0 did not follow in its footsteps.

    To give you an idea, this is infinitely times better than Proxmox for my uses.

    -Joe @ SecureDragon - LEB's Powered by Wyvern in FL, CO, CA, IL, NJ, GA, TX, and AZ
    Test our network here: Drgn.biz
  • yomeroyomero Member

    Complex? Bah! I got it in a couple of days! (like a baussss!)

    Ok ok tbh, I don't have idea on the clustering stuff and the live migration with LVM (wtf?)

    And if you don't need permissions, just use the root account like me :P

  • RaymiiRaymii Member

    @KuJoe would you consider using it again (maybe with the bash script?)

    Quis custodiet ipsos custodes?
    https://raymii.org - https://cipherli.st
  • KuJoeKuJoe Member

    @Raymii I don't really have a need anymore. Everything I need I can do through the CLI, if anything I'll make a simple PHP page to manage my services.

    -Joe @ SecureDragon - LEB's Powered by Wyvern in FL, CO, CA, IL, NJ, GA, TX, and AZ
    Test our network here: Drgn.biz
  • RaymiiRaymii Member
    Quis custodiet ipsos custodes?
    https://raymii.org - https://cipherli.st
  • KuJoeKuJoe Member

    @Raymii Yes, just like that. As long as it can run on the OpenVZ server itself.

    -Joe @ SecureDragon - LEB's Powered by Wyvern in FL, CO, CA, IL, NJ, GA, TX, and AZ
    Test our network here: Drgn.biz
  • RaymiiRaymii Member

    @Kujoe thinking of turning it into a ruby on rails web application. For Proxmox.

    Quis custodiet ipsos custodes?
    https://raymii.org - https://cipherli.st
  • KuJoeKuJoe Member

    Well it does look nice, I'm sure somebody will use it.

    -Joe @ SecureDragon - LEB's Powered by Wyvern in FL, CO, CA, IL, NJ, GA, TX, and AZ
    Test our network here: Drgn.biz
Sign In or Register to comment.