IPAddress for local Virtual Machines

When running Fedora as a KVM/Qemu  host for  virtual machines, you have the issue that you don’t know the IP Address for a virtual machine once you create it.  IP addresses that are assigned via

The MAC Address is in the config file saved in

/etc/libvirt/qemu/$VMNAME.xml

Once you start the virtual machine, you can fetch the IP Address from the DHCP lease file in:

/var/lib/dnsmasq/dnsmasq.leases

To correlate the two:

 

#!/bin/bash

VMNAME=$1

MAC=`cat /etc/libvirt/qemu/$VMNAME.xml |   xml2 | awk 'BEGIN{FS="="} /mac..address/ {print $2}'`

IP=`grep $MAC /var/lib/dnsmasq/dnsmasq.leases | cut -d' ' -f3`

#$VMNAME has MAC $MAC and IPAddress $IP
echo $IP

 

This must be called as root or via sudo.

UPDATE:

Chris Lalancette notes that the cannonical version of the MAC address can be found using

virsh -c qemu:///system dumpxml $VMNAME

Removing empy comment blocks

Eclipse can automate a lot of stuff for you. One thig is did for me was automating the serialVersionId generation for all the serializable classes in my tree.
They look like this:

    /**
     *
     */
     private static final long serialVersionUID = -9031744976450947933L;

However, it put an empty block comment in on top of them, something I didn’t notice until I had mixed in this commit with another. So, I want to remove those empty comment blocks.

#!/bin/bash

for JAVAFILE in `find . -name \*.java`
do
     sed -n '1h;1!H;${;g;s! */\*\*\n *\* *\n *\*/ *\n!!g;p;}' \
         < $JAVAFILE > $JAVAFILE.new
     mv $JAVAFILE.new $JAVAFILE
done

Thanks to this article for how to do the multiline search and replace.
http://austinmatzko.com/2008/04/26/sed-multi-line-search-and-replace/

Snapshot VMs

This past week at the  Red Hat summit I got the chance to demonstrate Enterprise IPA, the Red Hat version of FreeIPA, at the Red Hat booth.  One of the aspects of IPA we want to showcase is registering client systems.  That means that I wanted to be able to get a client system in the pre-installed state pretty very quickly.  My approach was to use Qemu/KVM virtual machines.  I had one VM image that I did not touch, and all the rest of the virtual machines will be snapshots that overlay that image.

Continue reading

Popup notifications

I am easily distracted. If a build takes more than say, three seconds, I usually will flip to doing something else. This means that I often miss when a build is completed, and end up losing a few minutes here, a few minute there.

Well no longer. I use Zenity! What is this you ask? I didn’t know either until today. Zenity is a command line tool for making a popup window appear.

Now My build scripts look like this:

mvn -o -Pdev install
zenity –info –text “Build is completed”

This kicks off the build, and, when it is done, I get a lovely popup window telling me: the build has completed.

As the Corollary to Murphy’s law states: If its stupid, but it works, it ain’t stupid.

Why zenity? I mean, there are at least a dozen different ways to popup a window. Well, in keeping with that Cardinal programmer virtue of laziness, it is because zenity is in the Fedora11 repo, and I am running Fedora 11. yum install is my friend.

Yes, I realize that if I were cooler, I would make my script tell me success versus failure, and pop up the appropriate window for that. I’m not that cool.

OK, I wanto to be cool. Here’s the new version:

mvn -o -Pdev install && zenity –info –text “Build is completed” || zenity –warning –text “Build Failed”

This pops up a warning message box on mvn returning non-zero for failure. Note the use of the && and the ||. The evaluation of this is kind of cool: The && (logical and) has short circuit semantics, so the second portion only gets evaluated if the first part evaluates to true. However, the || (logical or) only gets evaluated if everything before it fails.

Highlander Syndrome in Package Management

Somewhere between systems work and application development lies the realm of package management. There are two main schools of thought in package management: inclusive of exclusive. If you are inclusive, you want everything inside a package management system, and everything should be inside one package management system. If you are exclusive, you want the system to provide little more than an operational environment, and you will manage your own applications thank-you-very-much.

One problem with the inclusive approach is, in the attempt to clean up old versions, you often end up with The Highlander Syndrome. There can be only one version of a library or binary installed on your system. The Exclusive approach is more end application focused. I may need to run a different version of Python than is provided by the system, and I don’t want to be locked in to using only the version installed system wide. In fact, I may require several different versions, and each of these require their own approach.

CPAN, Pear, and Maven have provide language specific approaches level APIs to resolving dependencies at the per application level. Maven is particualrly good at providing multiple versions of the API: I errs so far this way that often the same Jar file will exist multiple times in the maven repository, but under different paths.

There should be middle ground for the end user between all or nothing in package managemnt. As a system administrator, I don’t want users running “just any” software on their system, but as an end user I don’t want to be locked in to a specific version of a binary.

If the role of application maintainer is split from the role of system administrator, than the people that fill those two roles may have reason to use a different approach to package management. Since the app developer can’t be trusted, the sys admin doesn’t provide root access. With no root access, the app developer can’t deploy an RPM/Deb/MSI. The app developer doesn’t want the system administrator updating the packages that the app depends on just because there is a new bugfix/feature pack. So, the app developer doesn’t use the libraries provided by the distribution, but instead provides a limited set. Essentially, the system has two administrators, two sets of policy, and two mechanisms for applying that policy.

Each scripting language has its own package management system, but the binary languages tend to use the package management system provide by the operating system.  Most Scripting language programmers prefer to work inside their language of choice, so the Perl system is written in perl, the emacs system is written in LISP, the Python one in Python and so on.  The Wikipedia article goes into depth on the subject, so I’ll refrain from rewritintg that here.

A Package management system is really a tuple.  The variables of that system are:

  • The binary format of the package
  • The database used to track the state of the system
  • The mechanism used to fetch packages
  • The conventions for file placement

There is some redundancy in this list.  A file in the package my also be considered a capability, as is the “good name” of the package.  A package contain empty sets for some of the items in this list.  For example, an administrative package may only specify the code to be executed during install, but may not place any files on a file system.  At the other extreme, a package may provide a set of files with no executable code to be run during the install process.

Of these items, it is the conventions that really prevent interoperability.  This should come as no surprise:  It is always easier to write an adapter on top of an explicit interface than an implicit one.  The Linux Standards Base helps, as does the standards guidelines posted by Debian, Red Hat, and other distribution providers.  However, if you look at the amount of traffic on the mailing lists regarding “file X is in the wrong place for its type” you can understand why automating a cross package install is tricky.  Meta package management schemes attempt to mitigate the problem, but they can really only deal with thing that are in the right place.

Take the placement of 64 bit binaries.  For library files, Red Hat has provided a dual system:  put 32 bit libriares under /usr/lib and 64 bit librareis under /usr/lib64.  Debian puts them all into the same directory, and uses naming to keep them apart.  In neither case, however, did they provide a place to make 32 and 64 bit binaries co-exist. How much easier would migration have been if we had /usr/bin32 and /usr/bin64, with a symlink from either into /usr/bin?

Thus we see a couple of the dimensions of the problem.  An application should have a good name:  web server, mail client,  and so on.  A system should support multiple things which provide this capability, a reasonable default, and customizability for more advanced users.The system should provide protection against  applications with known security holes, but provide for the possibility of multiple implementations released at different points in time.

    An interesting take on package management comes from OSGi.  It is a language specific package management approach, specifically for Java.  It takes advantage of portions of the the Java language to allow the deployment of multiple versions of the same package inside a since Process.  When I mentioned this to some old time Linux sys admins, they blanched.  OSGi does not specify how to fetch the packages, much like RPM without YUM or DPKG  with out APT.  OSGi packages are installed into the application.  As such, they are much more like shared libraries, with specific code sections run on module load and unload.  Different OSGi container provide different sets of rules, but basically the packages must exist inside of a subset of directories in order to be available for activation.  I have heard an interesting idea that the JPackage/RPM approach and OSGi should ideally merge in the future.  To install a Jar into your OSGi container, you would have to install an RPM.

    One additional issue on the Java/RPM front is Maven.  Both Maven and RPM want to run the entire build process from start to finish.  Both have the concept of a local Database of packages to resolve dependencies.  For long term Java/RPM peaceful coexistence, RPM is going to have to treat Maven as a first class citizen, the way that it does make.  Maven should provide a means to generate a spec file that has the absolute minimum in it to track dependencies, and to kick off an RPM build of the Maven artifacts.

    interface2addr

    This little script will give you the ipv4 address for a given network interface, or list all of them if you leave the parameter blank:

    #!/bin/bash

    INTERFACE=$1

    /sbin/ifconfig $INTERFACE | grep “inet addr” | cut -d\: -f 2 | cut -d” ” -f 1

    Call it like this:

    ~/bin/interface2addr eth0