Cinnamon 2.4.6, change Alt-Tab/Control-Alt-Tab behaviour

I was annoyed of cinnamons Alt-Tab and Control-Alt-Tab handling. So I just switched it.

$ dconf write /org/cinnamon/desktop/keybindings/wm/switch-panels "['<Control><Alt>Tab']"
$ dconf write /org/cinnamon/desktop/keybindings/wm/switch-windows "['<Alt>Tab']"

Not Alt-Tab cycles all the windows of all workspaces. Control-Alt-Tab cycles the windows on the current workspace only.

oslo.messaging example

Just a little example how to use oslo.messaging without much around it. You need to have a running rabbitmq (apt-get install rabbitmq-server on ubuntu ;)).

Add user testing to rabbitmq

# rabbitmqctl add_user testing test

# rabbitmqctl set_permissions -p / testing '.*' '.*' '.*'

Setting up a virtualenv and installing oslo.messaging into it. You need to have python-dev installed.

$ virtualenv testing

$ . testing/bin/activate
$ pip install --upgrade pip # to be sure, pip is able to manage wheel
$ pip install --upgrade setuptools # for entry point discovery
$ pip install oslo.messaging

consumer part:

#!/usr/bin/env python

# coding: utf-8

from oslo.config import cfg
from oslo import messaging
import logging

import eventlet

eventlet.monkey_patch()

logging.basicConfig()
log = logging.getLogger()

log.addHandler(logging.StreamHandler())
log.setLevel(logging.INFO)

class NotificationHandler(object):
    def info(self, ctxt, publisher_id, event_type, payload, metadata):
        if publisher_id == 'testing':
            log.info('Handled')
            return messaging.NotificationResult.HANDLED

    def warn(self, ctxt, publisher_id, event_type, payload, metadata):
        log.info('WARN')

    def error(self, ctxt, publisher_id, event_type, payload, metadata):
        log.info('ERROR')

log.info('Configuring connection')
transport_url = 'rabbit://testing:test@10.0.80.12:5672/'
transport = messaging.get_transport(cfg.CONF, transport_url)

targets = [messaging.Target(topic='monitor')]
endpoints = [NotificationHandler()]

server = messaging.get_notification_listener(transport, targets, endpoints, allow_requeue=True, executor='eventlet')
log.info('Starting up server')
server.start()
log.info('Waiting for something')
server.wait()

producer part:

#!/usr/bin/env python

# coding: utf-8

from oslo.config import cfg
from oslo import messaging
import logging

logging.basicConfig()
log = logging.getLogger()

log.addHandler(logging.StreamHandler())
log.setLevel(logging.INFO)

transport_url = 'rabbit://testing:test@10.0.80.12:5672/'
transport = messaging.get_transport(cfg.CONF, transport_url)

driver = 'messaging'

notifier = messaging.Notifier(transport, driver=driver, publisher_id='testing', topic='monitor')

notifier.info({'some': 'context'}, 'just.testing', {'heavy': 'payload'})

OpenStack + LXC + OpenContrail

Update: Patch is available in nova-contrail-vif-driver .

The last two days I worked on the integration of LXC into OpenContrail and OpenStack (icehouse). OpenStack does not support LXC in the first place. However, it is still included into nova and working via the libvirt driver. So I edited /etc/nova/nova.confand enabled lxc for libvirt.

[libvirt]

vif_driver=nova_contrail_vif.contrailvif.VRouterVIFDriver
virt_type=lxc

First I just tried to boot a usual kvm-Image, and it turned out, that it almost works. For lxc the image is mounted via qemu-nbdsomewhere to /var/lib/nova/instances/7849061d-740f-4727-9fa8-eca84bb3d77b/rootfs, but nova does not take care about partitions. So the mount failed:

2014-08-22 14:37:28.456 28050 ERROR nova.virt.disk.api [req-4982f8a8-cb29-4080-a0be-3a40d5a3e197 eb4ba78065e04df194d3a28f98a6eeac eaef37b7d8c24725bfc8c4e4090b4d97] Failed to mount container filesystem '<nova.virt.disk.api._DiskImage object at 0x43d5350>' on '/var/lib/nova/instances/77d6a580-eaba-4e8f-99e2-f9810df74f24/rootfs':

--
Failed to mount filesystem: Unexpected error while running command.
Command: sudo nova-rootwrap /etc/nova/rootwrap.conf mount /dev/nbd8 /var/lib/nova/instances/77d6a580-eaba-4e8f-99e2-f9810df74f24/rootfs
Exit code: 32
Stdout: ''
Stderr: 'mount: block device /dev/nbd8 is write-protected, mounting read-only\nmount: you must specify the filesystem type\n'

Not much to do to fix this. Edit /usr/lib/python2.7/dist-packages/nova/virt/disk/api.pyline 380 and add partition=1:

img = _DiskImage(image=image, use_cow=use_cow, mount_dir=container_dir, partition=1)

Restarting nova-compute. The image can be mounted, but the instance will not start because of the network anyway.

I created a VIF Driver to install necessary devices. It just bases on the Nova Driver of OpenContrail, but uses bridges instead of tap-devices. https://github.com/chrigl/nova-lxc-contrail-vif

Install this driver:

$ git clone git@github.com:chrigl/nova-lxc-contrail-vif.git

$ cd nova-lxc-contrail-vif
$ pip install .

And enable it in /etc/nova/nova.conf:

[libvirt]

vif_driver=nova_lxc_contrail_vif.contrailvif.VRouterVIFDriver
virt_type=lxc

Basically thats it. The instances should spawn and get an internal ip address. If they are in the same network, they should reach each other.

This is totally just a proof of concept, and I didn't do any tests within those containers. So I don't know anything about the forced limitations, like RAM, CPU or disk space, yet.

However. It was fun (and a bit painful for sure) digging into several parts of OpenContrail, libvirt, lxc and OpenStack. After the unsuccessful tests in OpenStack, I decided to start from the bottom up. First I installed lxc to get a feeling for how it is working, how limits are set, and especially how network interfaces are assigned to a container. Hint. Yes, it is possible to assign bare ethernet devices into a container. I will describe later, why I had to implement the stuff using brigdes.

Stepping one layer up, I defined some LXCs by using bare libvirt without any OpenStack on top. First using the libvirt default network, then using bridges, because it is well documented. Trying to assign a real ethernet device failed, since this is not yet supported by libvirt o_O There is already a patch for libvirt: http://www.redhat.com/archives/libvir-list/2014-February/msg00234.html

I learned much so far. The next step for me, was having a look into the OpenContrail network driver for nova. By default this driver creates tap devices and pass them into kvm-VMs via virtio and passthrough. However, as I learned so far. Libvirt is not able to pass a network device to LXCs directly. So I came up with the idea, just setting a bridge onto the tap device. This didn't work in the first place either, since OpenContrail decides about the state of the VM by getting the state of the tap device (UP|DOWN). But since the LXC was not running directly ontop of this device, it was DOWN all the time. Even if i tried to enable it with ip link set tabXYZ up. I started tcpdumpand saw data on my created bridge, but not on the device, assigned to the bridge!? So the really really last try for today was, registering the bridge instead of the tap device to OpenContrail. And it magically worked!

Fun fact: After assigning the bridge to OpenContrail, the created LXCs behaved strange. Really strange. So they start, but didn't find the metadata service. It felt like sometimes it worked and sometimes not. While debugging with pinging the gateway ip, it turned out, network works if tcpdump is running. If I stopped my tcpdump session, the ping stucks. It took me some time to realize tcpdump is switching promiscous mode on start and end. The quite simple solution: turning permiscous mode on by default.

[update] If you build your own images make sure it contains /sbin/init. nova uses this as init.

<domain type='lxc' id='22415'>

  [...]
  <os>
    <type arch='x86_64'>exe</type>
    <init>/sbin/init</init>
    <cmdline>console=tty0 console=ttyS0 console=ttyAMA0</cmdline>
  </os>
  [...]
</domain>

EuroPython 2014 - Tag 5

Heute ist der letzte Tag der diesjährigen EuroPython.

Gestartet bin ich mit dem Vortrag Everything You Always Wanted to Know About Memory in Python But Were Afraid to Ask von Piotr Przymus . Er beschreibt, dass sich vermutlich jeder, der c/c++ lernen musste, mit den Größen der verschiedenen Datentypen beschäftigt hat. In Python ist dies nicht der Fall. Auch ich habe mir bisher keine großen Gedanken darüber gemacht. Piotr zeigte die Größen von ein paar built-in Datentypen. Wegen des Overheads für den Garbage Collector fallen diese immer etwas opulenter aus als in c. Pjotr ist darauf eingegangen wie Python versucht die selben Werte für unterschiedliche Variablen nur einmal zu benuzten. Z.B. a=0, b=0, a is b ==> True. Wie das für Strings forciert werden kann, wie Listen und Dictionaries in Punkto preallocation arbeiten usw.

Der Talk Advanced Database Programming with Python von Marc-Andre Lemburg hat mein Vorurteil bestätigt, dass Entwickler und Datenbanken nicht so besonders gut zusammen passen. Es war zwar nicht alles Blödsinn, doch hat man einfach die Entwicklersicht auf die Dinge gemerkt. Die Krönung war Schlicht die Empfehlung zu random-IDs, statt auto_increment zu verwenden. Meine Gedanken dazu warum das für gewöhnlich eine schlechte Idee ist.

Schlomo Schapiro hat einen weiteren Talk aus dem ImmobilienScout24 Umfld und seiner persönlichen Erfahrung gemacht. Er beschrieb welche Möglichkeiten es für Unternehmen gibt mit open source software zu arbeiten und vor allem dazu beizutragen. ImmobilienScout24 hat schon häufig die Entwickler eines Projektes für Support bezahlt. Magischer Weise ist bei diesem Support auch ein Feature hinten raus gefallen. Wichtig ist Code erweiterbar zu gestalten, so dass es möglich ist auch Features aufzunehmen, die vielleicht nur einen extremen Spezialfall abdecken, dafür aber niemand anderes stören. Als Beispiele nannte Schlomo subversion und icinga.

Im Nachmittagprogramm habe ich mich mit ein paar Leuten zusammen gesetzt und wir haben einen Blick auf den Nix package manager geworfen. Dabei habe ich ein docker image mit Nix auf Basis des busybox-Images erstellt. Darauf aufbauend könnte jeder von Nix verteilte Service installiert und ausgeliefert werden. Vielleicht wäre das eine einfache Möglichkeit eine Applikation inklusiver aller Abhängigkeiten zu verteilen, bei der vor allem auch neuere Software als z.B. in den Ubuntu Cloud Images benutzt/benötigt wird.

EuroPython 2014 - Tag 4

Gestartet bin ich heute mit dem Vortrag The Shogun Machine Learning Toolbox von Heiko Strathmann . Ein Framework zum finden von bekannten Strukturen in Daten. Ein Beispiel ist das Auffinden von HIV in beliebiger DNA. Die Software ist in C++ geschrieben, bietet aber mittels swig Bindings für allerhand Sprachen. Es ist also egal in welcher Sprache man entwickelt, die zugrunde liegenden Algorithmen arbeiten immer gleich schnell. Shogun ist nicht als verteiltes System ausgelegt, sondern darauf auf dem Desktop zu laufen.

In The Return of "The Return of Peer to Peer Computing" hat Nicholas Tollervey , den letztjährigen Vortrag von Holger Krekel aufgegriffen. Dabei verglich er Politik mit Prgrammieren und hat Ideen gegeben, was Entwickler der vollständigen Überwachung entgegensetzen können.

Naomi Ceder hat in ihrem Talk Farewell and Welcome Home: Python in Two Genders über ihre Transition gesprochen. Vor, während und nach dieser Zeit hat sie sich aktiv in der Python-Community beteiligt. Sie erzählte von ihren Erfahrungen auch außerhalb der Community und womit sie lernen musste umzugehen.

Aus den Lightning Talks ist mir die network address manupulation library netaddr hängen geblieben. Außerdem ein 13 jähriges Mädchen, die einen souveränen Beitrag dazu gemacht hat, wie sie versucht Mädchen zwischen 13 und 18 Jahren von 90% Konsumenten und 10% Produzenten zu 50/50 zu bringen. Das Video der Lighning Talks ist bereits online . Ab 12:00.

EuroPython 2014 - Tag 3

Heute habe ich einen gemischten Tag gemacht. Ein paar Vorträge zu Programmierthemen wie gevent, jedi oder SQLAlchemy, dazu DevOps- und Plattformvorträge.

Besonders gut gefallen hat mir der Vortrag DevOps Risk Mitigation: Test Driven Infrastructure von Schlomo Schapiro . Schlomo zeigt wie die Deploymentchain bei ImmobilienScout24 funktioniert, wie, und vor allem dass sie alles mögliche Testen. Die Tests sind mittlerweile so komplett, dass sie sich soweit darauf verlassen können, und Code automatisch in production schieben. Dabei werden an allen Stellen RPM-Pakete eingesetzt. Nicht nur für Applikationenen selbst, sondern auch zum Verteilen der Konfigurationen.

Der Talk An HTTP request's journey through a platform-as-a-service von Giles Thomas beschreibt tatsächlich wie die ankommende Anfrage das richtige Backend finden und ggf. überhaupt erst einen Start der Applikation triggert. Ebenfalls Interessant zu sehen.

Ein Einblick in die Entwicklung hinter Jedi hat der Talk I`dentifying Bugs Before Runtime With Jedi`_ von Dave Halter gegeben. Jedi kann nicht nur als sehr gute Autovervollständigung verwendet werden, sondern auch als sehr viel besserer lint-Ersatz dienen. Ich werde Jedi in der Zukunft ausprobieren und sehen ob es mir bei der Entwicklung hilft.

Der Abend ist mit interessanten Menschen und Gesprächen beim Conference-Dinner und anschließender Party ausgeklungen. Ein großes Dankeschön an die Community, die dieses angenehme Umfeld geschaffen hat.

EuroPython 2014 - Tag 2

Heute habe ich mich hauptsächlich um OpenStack gekümmert. Zuerst im Trainig Making your first contribution to OpenStack von Julie Pichon.Es gab einen schnellen Überblick über die Services in OpenStack. Danach wurden alle für eine Contribution notwendigen Schritte erklärt. Außerdem wurden alle nötigen Accounts angelegt und miteinander verknüpft. Nach einem Einblick in das Bugtracking auf Launchpad wurden potentielle Tickets gesucht und Patches eingereicht.

Slides und Etherpad zum Traning.

Nach dem Trainig habe ich den Vortrag Marconi - OpenStack Queuing and Notification Service gehört, das eine Alternative zu Amazon SQS und Amazon SNS in sich vereinen soll. In der nächsten Version von OpenStack sollen die Core Services über Marconi sprechen. Da Marconi an Keystone angebunden ist, kann es bestimmt auch als Service für Kunden angeboten werden.

Zudem gab es noch einige interessante nicht-Vortrag-Gespräche zum Thema Virtualisierung, Orchestrierung und Packaging (Nix again ;)).

EuroPython 2014 - Tag 1

Da heute wenig Talks waren blieb viel Zeit für "Networking". Viele interessante Leute aus dem Umfeld von NixOS gesprochen, einige davon von RhodeCode . Kurzum haben die das Ziel reproduzierbar ein System mit allen benötigten Bibliotheken zu erstellen. Schöne Features sind die eingebauten atomaren Installationen und der eingebaute Rollback. Schlägt die Installation eines Paketes fehl, wird komplett zurück gerollt. Es wird kein kaputtes/pflegebedürftiges System hinterlassen. Auch wenn die Installation geklappt hat, kann vom Admin manuell zurückgerollt werden. Z.B. weil die neue Version einer Spezifischen Software Probleme verursacht. Nur die Dokumentation läßt noch arg zu wünschen übrig. Daran wird aber aktuell gearbeitet. NixOS ist absolut einen Test wert. Außerdem ging es natürlich auch um Cloud Platformen, OpenStack und Docker .

Heute Abend habe ich mein Notebook schon mal für das morgige Training Making your first contribution to OpenStack vorbereitet. Also eine VM mit DevStack ausgestattet. Freue mich schon :)

Alles in allem ein sehr schöner Tag. Eine angenehme Veranstaltung mit netten Menschen. Super Organisation des EP14- und BCC -Teams.

Update aus einem Lightning-Talks

https://packaging.python.org/en/latest/

calibre ebook library manager / calibredb

For managing my ebooks, I started to use calibre , and it turns out, calibre is a very flexible tool.

I am able to run it on my raspberry pi as a quite nice web app. Have a look at calibre-server . It is possible to "talk" to the library database with a command line interface called calibredb . With this, it is really easy to import/export/search stuff without using the usual GUI. callibredb allows you to create entirely new database, as well. If you are using tmpfs for /tmp and your memory is limited, set TMPDIR before you start.

$ export TMPDIR=/BIG_DISK/tmp

$ calibredb add -r /home/mpd/new_ebooks/ /BIG_DISK/calibre_library/

As another quite nice feature, calibre is able to convert from different formats to another. It is easily possible to convert a pdf to mobi - for example Sage A. Weils more than great thesis ceph - and read it on the kindle.

And there is a lot more. Give it a try :)

gvfs-mount -u und bash completion

Per gvfs eingehängte Devices oder Server-Verbindungen bequem per CLI aushängen. Da gvfs auf file://, sftp://, etc. basiert, darf der Doppelpunkt nicht als Worttrenner werdendet werden:

_gumount() {

        COMPREPLY=()
        local opts cur
        _get_comp_words_by_ref -n : cur
        opts=$(gvfs-mount -l -i | grep default_location | sed 's#.*default_location=\([^:]\+\):\(.*\)#\1\\:\2#')
        if [[ ! $opts ]] ; then
                return 1
        fi

        COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
        __ltrim_colon_completions "$cur"
        return 0
}
complete -F _gumount gumount

gmount() {
        if (($# != 1)) ; then
                cat <<EOF
Give me one device or network resource.
gmount /dev/sdc1
gmount sftp://leierkasten.local/root
EOF
                return 1
        fi
        opts=()
        if [[ -b $1 ]] ; then
                opts+=("-d")
        fi

        gvfs-mount "${opts[@]}" "$1"
}

Siehe auch: http://stackoverflow.com/questions/10528695/how-to-reset-comp-wordbreaks-without-effecting-other-completion-script/12495480