Monday, May 27, 2013

Vagrant and libvirt (Holy Grail?)

After looking at the vagrant-kvm plugin I found a list of all the Vagrant plugins. This turns out to have vagrant-libvirt as a plugin. libvirt is a library used to control many different virtualization technologies. You can think of it as a common API for hypervisors like KVM/QEMU, Xen, LXC, OpenVZ, Virtualbox, VMware, and Hyper-V. From my experience with OpenStack, I quickly understood the power of this plugin.

In the README for vargrant-libvirt it explains the installation process very clearly. One of the things that makes vagrant really nice now is that you can setup simple puppet or chef provisioning to the instance that you create. It is just a simple configuration change to the Vagrantfile and you are on your way.

Here is the base Vagrantfile for libvirt.

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Example configuration of new VM..
#
#config.vm.define :test_vm do |test_vm|
# Box name
#test_vm.vm.box = "centos64"
# Interfaces for VM
#
# Hostonly network is not supported in this version of provider. Bridged
# interface with network id specified can be created.
#test_vm.vm.network :bridged, :bridge => "default", :adapter => 1
#end
# Options for libvirt vagrant provider.
config.vm.provider :libvirt do |libvirt|
# A hypervisor name to access. Different drivers can be specified, but
# this version of provider creates KVM machines only. Some examples of
# drivers are qemu (KVM/qemu), xen (Xen hypervisor), lxc (Linux Containers),
# esx (VMware ESX), vmwarews (VMware Workstation) and more. Refer to
# documentation for available drivers (http://libvirt.org/drivers.html).
libvirt.driver = "qemu"
# The name of the server, where libvirtd is running.
libvirt.host = "localhost"
# If use ssh tunnel to connect to Libvirt.
libvirt.connect_via_ssh = false
# The username and password to access Libvirt. Password is not used when
# connecting via ssh.
libvirt.username = "root"
#libvirt.password = "secret"
# Libvirt storage pool name, where box image and instance snapshots will
# be stored.
libvirt.storage_pool_name = "default"
end
end
view raw Vagrantfile hosted with ❤ by GitHub

Wednesday, May 8, 2013

Using Vagrant outside of the "Norm"

Vagrant has come along way with the version 1.0. Now you are freed from the handcuffs of Virtualbox. This is great news to be able to use any type of virtual machine. KVM is a common virtual machine used in production environments and its built in to linux. All it takes is installing a few packages and you can be up and running vagrant with kvm.

There is are a couple things that we need do first.
Install Vagrant's latest version from the download site.

Then install the plugin.
vagrant plugin install vagrant-kvm
vagrant plugin list
view raw gistfile1.sh hosted with ❤ by GitHub
Once installed then we need to get a box and convert it for the kvm provider.
#!/bin/bash
# get-vagrant-box.sh
vagrant box add precise64 http://files.vagrantup.com/precise64.box
pushd ~/.vagrant.d/boxes/precise64/
cp -R virtualbox/ kvm
cd kvm
# copy the Vagrantfile and metadata.json file in this directory
pwd
popd
{"provider": "kvm"}
view raw metadata.json hosted with ❤ by GitHub
# Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.base_mac = "00163e779fe9"
config.vm.network :private_network, ip: "192.168.2.100"
end
# Load include vagrant file if it exists after the auto-generated
# so it can override any of the settings
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
load include_vagrantfile if File.exist?(include_vagrantfile)
view raw Vagrantfile hosted with ❤ by GitHub

Here is a simple Vagrantfile you need to spin up your own KVM vagrant instance.
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
end
view raw Vagrantfile hosted with ❤ by GitHub

This is about as easy as it gets.
vagrant up provider=kvm

The code base for vagrant-kvm is located here. https://github.com/adrahon/vagrant-kvm#quick-start

Monday, May 6, 2013

My git .gitconfig customization

My .gitconfig has a couple nice alias's that i have found extremely helpful. I've found a couple around the internet as well and i think they are useful.

[user]
name = Craig Vyvial
email = cp16net@gmail.com
[color]
ui = true
branch = auto
diff = auto
interactive = auto
status = auto
# common alias
[alias]
s = status -s -b -uno
st = status
br = branch
ba = branch -a -v -v
co = checkout
# exotic alias
[alias]
# when was this file last updated, on each local branch
wwflu = "!f() { for b in $(git rev-parse --symbolic --branches); do echo -e `git log --format=%at:%ar -1 $b -- \"$1\"`\\\\t$b; done | sort -r |cut -f2 -d: ; }; f"
view raw .gitconfig hosted with ❤ by GitHub