Changing system time in a virtual machine

 When working on a bug 748920 I needed to change the system time (RTC) in a KVM+libvirt virtual machine. I have found quite some obstacles I want to share.

The first possible source of your confusion might be the fact, that if you set your system time in the usual way using ‘date’ and ‘hwclock’, the change will persist VM reboot, but won’t persist VM shutdown. On shutdown the RTC is reset.

If you need to have a permanent system time change (persisting shutdown), you need to edit the libvirt configuration file for your VM. Issue this command:

$ virsh edit <domain_name>

Then edit the XML file according its documentation. Find this line:

<clock offset='utc'/>

and replace it with this line:

<clock offset='variable' adjustment='86400'/>

The adjustment parameter controls how much will the system time be shifted from current UTC time, the value is the number of seconds. In the example above I shifted the time one day into the future (86400 seconds). You can use negative values as well.

Save the file, boot your VM. The time should be shifted.

Be careful that currently Fedora boot breaks if you shift your time more than one day into the past, as says bug 748920.

Flattr this

The beauty of Pdb

I never used Pdb much. I always thought that I had to run my whole script through the debugger, set some breakpoints through obscure commands and whatnot. But it is not the case. I can do simply this:

#!/usr/bin/env python
import pdb

Now you run your script as usual, and it stops at the pdb.set_trace() line and opens up a Pdb prompt. Then you can go line by line, explore and set variable contents and find out the source of your problem. Great! This approach is convenient and easy to use.

You need to know just a several basic commands to be able to do quite a lot in the Pdb shell. Read this 10-minute introduction, it’s worth it: Debugging in Python


Flattr this

Desktop notifications in Firefox

At work I usually have a Google Calendar tab open in Firefox to remind me of my personal meetings. In Gnome 2 the reminder would flash the task bar and I would notice it. That is no longer the case in Gnome 3, the notification is no longer present. How to fix that?

Google Chrome has this concept of Desktop notifications. AFAIK it is a public spec, but it is not implemented in Firefox and not even being worked on. What a shame. But wait, have a look at this:

Unfortunately that doesn’t work due to a bug. But this version works:

Now you just need to enable Gentle Reminders in Labs section of your Google Calendar settings. Voila, it works! It leverages native Gnome 3 notifications (which are far from ideal, but much better than nothing). Hopefully I won’t miss my appointments from now on.

It also works for GMail and other web pages using webkit notifications.


Flattr this

IPython GUI

Did you know that IPython has GUI? I didn’t. Then I’ve found ipython-gui package by accident. Wow, what is this?

This package contains the gui of ipython, which requires PyQt.

Nice, let’s try that out. I installed ipython-gui and… nothing. No new desktop launcher installed. No new executable installed. No new man page. No documentation of any kind. Nothing. Inspecting man ipython yielded same (no) results.

After dozens minutes spent Googling, I finally found the magic command:

$ ipython qtconsole

Hah, you are no match for me, ipython developers, I’ve found it in the end!

So once we know how to run it, what does it do? Well it is an improved IPython console. Main features I noticed in the first few minutes:

  • Syntax highlighting.
  • Tab completion hints disappear nicely and don’t “reset” your current line.
  • Methods docstrings are shown in the form of tooltips immediately after typing the opening parenthesis.
  • True multi-line editing support. You can finally invoke a multi-line command from history and easily change a single line. Yes!


Flattr this