Networking with Virtual PC 2007

I wrote a post last month about how impressed I was with Virtual PC 2007 and how it has changed the way I work. This is a follow-up about a networking problem that I didn’t discover until it was almost too late, as well as how to fix it.

I decided to install Vista Business on my laptop a few months ago, and aside from a few application compatibility issues, I’ve been pretty happy with it so far. One of the main problems is that Oracle 9i doesn’t work with Vista, and that’s a database we need to develop against. So, I fired up my Windows XP virtual machine, installed Oracle, and then connected to Oracle on the virtual machine just like I would if it were installed on another server. Everything was working smoothly… or so I thought.

A little background: The default networking option for your virtual PC is “Shared Networking.” This allows the virtual PC to share your host PC’s internet connection, but doesn’t allow the host PC to talk to the virtual PC. So, instead of using shared networking, I set the virtual machine to directly use my wireless network. Both the host PC and the virtual PC got separate IP addresses from the router, and could therefore talk to each other. The only thing I didn’t think about was that the second my laptop lost its connection to my router, I couldn’t communicate with the virtual PC.

So, there I was, minutes before a demo with an important client, and my application server couldn’t talk to my database, even though they were both on the same laptop.

The solution was relatively simple, but for some reason the information was really hard to find. First install Microsoft’s Loopback Adapter on the host PC, and then tell the virtual PC to use it for its network access. The process is explained very well here.

Version Labeling and Continuous Frustration

I approach continuous integration (CI) servers in the same way I do my IDE — as a tool of convenience for performing tasks I could choose to perform manually. I would no more have a build system reliant upon a specific CI server than I would write code that was only recognized by a specific IDE. Thankfully the CI servers with which I’ve worked conform to my philosophy. They do not seek to replace your build system as much as provide much needed automation. There is one area, though, where I feel CI servers violate this ideal, and that’s creating a unique build/version label.

Out-of-the-box, most CI servers provide a simple numbering scheme in order to produce a unique label for each build. Generating a build/version label is a task I prefer to happen within the build itself, so that the build is truly self-contained. Take our builds, for example. I’ve made use of the ant task buildnumber, so, upon a build, ant reads and increments a build-number property file and appends it to the project’s “base version,” the result being a label like “1.9.0.6″, where “6″ would be the build number. I imagine this is a common scenerio — indeed its why the <buildnumber> ant task exists. Once I launch an official build via command-line, label generation happens automatically, and the repository is tagged “Build 1.9.0.6″.

Introduce the CI server, though, and suddenly I’m having to jump through hoops to accommodate this setup. At the crux of the problem is this: from the CI server’s perspective, a build starts upon checkout or update of a project, and therefore wants to know the build label prior to actually running the build. That’s putting the cart before the horse, in my opinion, although I do understand the reasoning. Should access to the repository fail, for example, the CI server is able to report “1.9.0.6 Build failed due to VCS unavailability”.

What I’ve done is create a small script whose sole duty is to fetch the next build label for the CI server — fortunately the CI servers with which I’ve worked allow for pre-build script execution in some manner or another. With CruiseControl, I use an “antbootstrapper” to invoke a small ant build named “get-next-version.xml”. CruiseControl passes the value generated from that to the official build, so ant is invoked like so: “ant package -Dbuild.label=1.9.0.6″.

However, my work isn’t done. I still must ensure that my build-number property file is accurate, even if the build.label is being provided instead of being generated. So, in addition to configuring CruiseControl in the manner described, I also must have my build.xml extract the build number from the passed label (in this case, “6″), and update the build-number file appropriately.

Granted, I imagine most folks don’t rely on ant to generate build numbers, and therefore the CI server provided functionality is a convenient mechanism. The minority of us who do, though, ought to be able to supply build labels to the server in an easier fashion.

Raving about Virtual PC 2007

I think I can say this in all sincerity and without hyperbole: Microsoft Virtual PC 2007 has changed my life. Maybe I’m a little late jumping on the virtualization bandwagon, but now that I have, I’m grinning with Kool-Aid stained lips. Sure, I’ve known that the technology has been out there for a while, but for some reason I just didn’t realize how cool it would be. For me it is kind of like TiVo in the fact that it sounds really neat before you check it out, but once you’ve used it you just can’t possibly live without it.

Before I get into my thoughts and share a few tips I’ve picked up over the past few weeks, I’ll give a quick overview of the technology for those who aren’t up to speed. The idea behind virtualization is that you can use your existing computer to work as two or more computers at the same time. It’s a lot like remote desktop, but instead of viewing another computer in a window, you’re viewing a virtual computer in a window. This virtual machine has a separate operating system and installed software, but can share devices like DVD ROM drives and internet connections with the host operating system.

As you can probably guess, virtualization lends itself particularly well to software testing, where it’s often important to have access to different operating systems and browsers. With a few clicks of a mouse you can load a virtual Windows XP desktop, test your web based software on IE6, and then go right back to your Vista/IE7 desktop. If you screw up the virtual operating system you can just replace it with a backed up copy.

So, now that I have you convinced that you need virtualization, I’ll walk you through the relatively simple process of getting everything set up and configured. First of all, dig around in your bios and see if there is a configuration option for turning on virtual machine optimizations. I have a relatively new Dell laptop, and for some reason the Intel virtualization optimizations were turned off by default.

Virtualization Bios

Then download and install a copy of Virtual PC from Microsoft’s website. Sure, there’s other (and arguably better) virtualization software out there, but this is free!

So, once the software is installed create a new virtual machine. During this process you’ll be asked to define a new virtual hard disk. This is the single file that is used to store all of the virtual files for the virtual machine. Be careful with the size you choose for the disk; it’s a little confusing and I messed up the first time through. The number you choose will allow the virtual disk to grow to that size. It will not take up the space unless you actually use that much inside the virtual machine. Unfortunately, you can’t increase this later, so be careful to not choose a value that is too low. If you have extra disk space, I’d recommend going with 8 gigabytes. I’d also recomend bumping the memory up to at least 256MB or 512MB if you have a lot of memory.

Virtual Disk

Now you need to install the operating system. Put the windows install CD in the drive and fire up your virtual machine. It’s kind of strange seeing the familiar windows install screens from a desktop window, and this was my first “oh, cool” moment. Another thing I tripped over during the install was that my mouse would become stuck in the virtual machine window. To send control back to the host desktop, just hit the right Alt button.

The next step is to install the virtual machine additions inside your newly installed virtual operating system. These can be accessed from the “Action” menu and allow you to drag and drop files from the host desktop, fixes the mouse locking annoyance, and allows you to share files. This would also be a good time to download the latest OS updates from windows update and install any other software you’re going to be using.

Now that you have your virtual machine image just the way you want it, we’ll back it up. The first step is to run a disk defragmentation inside of the virtual machine. Then run the precompactor utility inside of the virtual machine. You can access this by going to the CD menu, choosing Capture ISO Image, and browsing to C:\Program Files\Microsoft Virtual PC\Virtual Machine Additions\Virtual Disk Precompactor.iso. Finally, perform the actual Virtual Disk Compression on the host machine via the virtual disk wizard (accessible under File in the console). You now have a .vhd file that is ready for backup. That way, if you screw up your virtual machine you can just replace one file and you’re back on your feet.

Please let me know in the comments if my notes were helpful or if I should change anything.

Burn Rubber, Not Gasoline

I am a car nut. I also love technology. Any time these two industries meet up together, I am a happy guy. Although electric vehicles have had a rocky start the last few decades, it seems that a few companies are making leaps and bounds relatively quietly. One of the more notable, Tesla Motors, has recently been making a few headlines. Imagine a car that has Porsche-like performance, Lotus-like appearance, yet only costs about a penny per mile to drive.

Tesla Roadster

It is by no means the cheapest electric vehicle choice out there, but very well may be the most practical to date. The motivating factor behind this is the Tesla’s incredible range. The company claims a 250 mile range before needing a recharge. That takes this from being a limited commuter car to a practical second vehicle. You still can’t reasonably drive it across the country, but there aren’t many people out there with the need to drive more than 250 miles a day. All you have to do is park it in the garage at night, plug it in, and it’s ready again for you in the morning.

Electric vehicles aren’t necessarily better for the environment, but they can be. It all depends on where your electric company derives its energy source from. If they are using hydro, wind based, or other environment friendly means, then the Tesla Roadster effectively becomes a zero emissions vehicle, reduces our dependency on petroleum based fuels, and ultimately makes the world a better place for our children. The roadster is currently sold out for 2007, and orders are already being lined up for 2008. Not everyone will be able to afford one yet, but as they become more popular and mass-production options bring the initial cost down, don’t be surprised if you see one next to you at the stop light. Don’t worry though, when he leaves you in the dust, it will be a much cleaner and quieter experience than you are used to.