Tuesday, January 24, 2017

Migrating Proxmox VMs with Python

Using the Proxmox API with Python to Migrate Virtual Machines

I hate doing repetitive tasks, and am always on the lookout for a way to save myself time.

I noticed the other day how much time it was taking me to move virtual machines around using the Proxmox web interface. When doing updates I like to move all the virtual machines off of the machine being updated in the cluster. This is easy to do with the "migrate all" option inside of the web interface. However moving those machines back to the original host was a pain and required a lot of clicking. So I spent an hour and whipped up a quick and dirty python script to do the migrations for me. It only works with KVM based virtual machines right now but it would be simple to adapt to move container based virtual machines. It also only authenticates against PAM right now, again it would be a fairly trivial change to fix that.

Usage

To use the script edit the PROXMOX_HOST global variable and put in the host, FQDN or IP address of your proxmox cluster and adjust the Proxmox port if necessary. Then just call:
./proxmoxMigrate.py -n <node where vms currently reside> -t <node where you want them to end up> <space seperated list of VM ids>

For example:
./proxmoxMigrate.py -n proxmox1 -t proxmox2 100 101 103 104


The Script


Thursday, January 12, 2017

Monitoring the Network

Network Monitoring with collectd

Scattered around campus is a few thousand network ports. Most of the ports I don't care what they are doing so no alerting needed but, occasionally when there is an issue and it is nice to have an idea of what the network looked like historically. Enter the SNMP plugin for collectd. I chose collectd because of the vast number of plugins available for it, the fact that its config is file based and that it can be scaled horizontally. Having a file based configuration allows me to check my changes into version control allowing easier auditing and disaster recovery.

Installing collectd and related tools is as simple as enabling the EPEL repository and doing a:
yum install collectd-rrdtool collectd-snmp httpd php git

That  installs everything you need to start graphing your network ports. We will use Collectd Graph Panel to view the pretty graphs that collectd makes.

Simple collectd Configuration

FQDNLookup true

LoadPlugin rrdtool
<plugin rrdtool>
       DataDir "/var/lib/collectd/rrd"
       CacheTimeout 120
       CacheFlush   900
</plugin>

LoadPlugin snmp
<plugin snmp>
   <data std_traffic>
       Type "if_octets"
       Table true
       Instance "IF-MIB::ifDescr"
       Values "IF-MIB::ifInOctets" "IF-MIB::ifOutOctets"
   </data>
   <host "my.host.name">
       Address "192.168.1.40"
       Version 2
       Community "public"
       Collect "std_traffic"
   </host>
</plugin>

Collectd Graph Panel Installation

To install the Collectd Graph Panel just clone the git repository into your web root and it works pretty much out of the box.
git clone https://github.com/pommi/CGP.git

Conclusion

That's it! Really that is all that is needed to start graphing your network ports. This provides a basic system that can easily be expanded and tweaked based on your needs.