Fedora KVM with simple network forwards

Recently I’ve been teaching python to some high school students. It has been going well, but the development environment we had access to left a little bit to be desired. We were working with ages old solaris, vi only, and no real access to newer gnu (or other) tools. So a new setup was required, I went off to investigate.

I started with chroot, since a buddy, Daniel Thau, had used it extensively for running multiple operating systems side by side. He’d pointed me in the directions of febootstrap and that seemed like it’d work fine. I was able to make a sandbox, get ssh running on 2022 and then have my dlink route that to my box. Success!

But I found that a bit messy, and a bit limited. I wanted to lock down how much of my resources they could use, and I didn’t want to have to give access to some of my root file systems directly; /proc, /dev, etc. So I looked around a bit more, and stumbled on using KVM indirectly via the new virt-manager toolset that fedora 12 and 13 provide. Installation was as simple as:

yum install qemu-kvm virt-manager virt-viewer python-virtinst

But it also seems that from the techotopia article I followed for some of this that one could also just do:

yum groupinstall 'Virtualization'

I have to say it’s a pretty swank set of tools. It’s free, it works on KVM or Xen. KVM usage requires no special kernel and as such, no reboot. The setup was simple, and gave out a vnc port to connect to from the get go. It is also trivial to connect to a setup on machine A with virt-manager on machine B over ssh. If you want more information, fedora has a nice writeup, and libvirt has a more distro agnostic set of docs.

Problem was though that the networking was virtual, and didn’t pull an IP address from my router, so it wasn’t public. There were a few sections here and there describing how to switch to bridged, and I tried them. They didn’t work for me, either I suck at following directions, or they just won’t work how I expect them to. You can see for yourself here at how I attempted network bridging.

What I did was much more in my realm of knowledge, is simpler than all the other options, and is something I can make changes to w/o killing my network connectivity. iptables! I just used NAT forwarding. It was 2 lines, put in my pre-existing firewall script. So to get my local box 192.168.1.199 on port 2022 to forward to its internal virtual network of 192.168.100.2 at port 22 was as plain as this:

iptables -t nat -I PREROUTING -p tcp --dport 2022 -j DNAT --to-destination 192.168.100.2:22
iptables -I FORWARD -p tcp --dport 22 -d 192.168.100.2 -j ACCEPT

One preroute rule to grab the port incoming, and one forward rule to pass said packets along. Now I have connectivity into my class virtual machine, and I don’t have to do much to add more ports as needed. I am pretty happy with the setup so far. It’s really nice to be able to connect remotely, vnc or ssh now, as well as know that I’ve limited the ram and cpu time the class can use on my box. I am interested to hear if anyone else is doing similar things with virtualization on their desktops.

Fedora with awesome window manager

I have recently gotten into tiling window managers. Awesome being the one I’ve found I like to use the most. There are others and they all have their merits, I just settled on this one, and then got comfortable. I also am a bit of a mutt in what distro’s I use. Work they put ubuntu on my box, home I have usually used fedora but now it’s fedora on the desktop and arch on the laptop.

So the issue was arch and ubuntu both had awesome in the package repos, and fedora did not. There is discussion out there as to why this was, and you might be interested in it. Me, I just wanted to use awesome. So using the directions from the awesome wiki and grabbing the required source rpms cairo-1.8.8-3.fc12.src.rpm and awesome-3.4.4-1.fc12.src.rpm, I now have awesome on my desktop.

Here are some of the docs and sources I used:

How fabric gets it right

I like fabric. A lot. Its a easy to use tool that continually makes my life simpler, and my projects smarter and more automated. Not much out there can really say that. At least nothing I use daily, without noticing, and dependably.

I used to use vellum, and that did what I needed. But fabric being under active development, and getting new features each version it seems is a huge plus. That and it does the network stuff for you, along with the nitty gritty.

Recently I have been giving presentations to the Ohio State University’s Open Source Club about gnu tools, python tools, and soon some cli apps. Fabric really helped make this simple for me to get a whole system down for making and uploading these.

I made all of those presentations in restrctured text, and compiled them into their final formats. All of which was scripted in fabric. I became really attached to ReST after getting introduced to it watching Catherine Devlin give a talk about restructured text at Ohio Linux Fest. I ended up finding a cool rst2s5 command that makes nice presentations and with a little tweaking it now also has syntax highlighted code blocks, and can make nice pdfs.

In starting to use fabric you’ll notice the basic idea is that you’d make a fabfile that works a lot like a Makefile or a SConstruct file would, with make and scons respectively. You’ll make calls with the fab command in the directory the fabfile is located and it will supply the targets.

Below in this example, two targets are made, pack and deploy. The pack target will just makes a tarball, using the local function fabric provides. The deploy target calls pack to make this tarball, then using the put function will place the tarball into the tmp directory, then change into the web dir provided, and extract the archive. It knows automaticly to do this to both hosts I provided, and since I am using an ssh key does all this trickery autonomously.

fabfile.py

from fabric.api import *

env.user = 'username'
env.hosts = ['host1.com', 'host2.com']

def pack():
    local('tar czf /tmp/project_foo.tgz project_foo/', capture=False)

def deploy():
    pack()
    put('/tmp/project_foo.tgz', '/tmp/')

    with cd('/var/www/foo/'):
        run('tar xzf /tmp/project_foo.tgz')

Fabric can do a lot more than just this, and its docs have a lot of detail, and explain most everything well.

A last example of some a cool fabric config would be the one I use to publish my presentations to this site.

fabfile.py

#!/usr/bin/env python

from fabric.api import *

env.roledefs = {
    'production': ["morgangoose.com"],
    }


def setup_vars(project):    
    global presentation
    global presentation_archive
    global rst_source
    global pdf

    project = project.strip("/")
    presentation = project
    presentation_archive = "%s.tar.gz" % presentation
    rst_source = "%s.rst" % presentation
    pdf = "%s.pdf" % presentation

@roles('production')
def upload(project):
    env.user = "username"
    p_dir = "/var/www/html/p/"

    package(project)
    put(presentation_archive, p_dir)
    put("%s/%s" % (presentation, pdf), p_dir)
    with cd(p_dir):
        run("rm -rf %s/" % presentation)
        run("tar zxvf %s" % presentation_archive)

    local("rm -f %s" % presentation_archive)        

def package(project):
    setup_vars(project)
    make_presentation()
    local("tar zcvf %s %s" % (presentation_archive, presentation))

def make_presentation():
    #PDF first
    local("rst2pdf %s/%s -o %s/%s" % (
        presentation, rst_source, presentation, pdf, ))

    #Then s5 html presentation
    local("python rst-directive.py \
            --stylesheet=pygments.css \
            --theme=small-black \
            --quiet \
            %s/%s > %s/index.html"
% (
                presentation, rst_source, presentation, ))

def new(project):
    setup_vars(project)
    local("mkdir -p %s/{,files}" % presentation)
    local("cp -R ui %s/" % presentation)
    local("touch %s/%s" % (presentation, rst_source))

This has some more complicated bits, where it uses the role decorator to specify only to use the hosts listed in the production role definitions.

It also takes advantage of an awesome feature I didn’t know fabric had where, one can send arguments to a fabric target. So the project parameter in the targets here can be, and is, supplied via the command line.

For example, I used this to deploy the updates to my most recent presentation:

$ fab upload:tool_oriented_python

That’s telling fabric to run the upload target, and send the string “tool_oriented_python” as an argument to the function.

If you forget the targets you have just do:

$ fab -l

GNU tools presentation

The other day, I gave a presentation to the Ohio State University, Open Source Club. It was on a smattering of command line utilities that I use on a daily basis, as well as a quick intro to regex usage.

It is all accessible on my site here and in pdf form.

It was pretty long, and presenting it took a little over an hour. I plan on distilling the parts I liked talking about into more concise presentations, and also a blog post or two.

Awk and find will most likely be their own posts/presentations. I think I need to learn some more of the advanced uses of sed, and revisit that section to make it a bit more clear.

Logitech MX Revolution configuration

The other day @shuckins mentioned that

I’m finding the MX Revolution quite awesome except that I really miss my scroll wheel click button.

This was an issue that I had when I started using this mouse as well. The key feature of the mouse being that a middle click will switch the scroll wheel from smooth movement to discrete (chunky?) movement and back again. This is actually very cool to use once you’ve gotten accustomed to having the option of scrolling down a page with fine control of speed/distance and then click once to then flick back up to the top of a page.

What I did to make my life easier with this mouse was setup the thumb scroll wheel to act as my middle click that I was accustomed to having. I accomplished this via the btnx-config program as available from the btnx website.



Once I found out how easy it was to get the middle click from the thumb wheel I decided to make the thumb up/down also have some functionality. If you use firefox and/or gnome terminal I find the most useful thing to map was thumb up to shift pageup and thumb down to shift pagedown.



With these set this way I can switch tabs on both firefox and gnome-terminal w/o moving back to the keyboard. The other neat thing I found (when I actually noticed) was that this mapping holds even when using synergy to control two (or more) machines.

The mouse works great, and I haven’t in recent memory ever like a mouse as much as I have this one. Couple the nice manufacturing with the ease of button configuration provided by the great programmers of btnx and I think its the perfect mouse for a programmer. Especially one who doesn’t like to have to constantly switch between using the mouse and keyboard.