All Articles

openSUSE Leap: LibVirt And NetworkManager

I recently switched to Leap from 13.2. First time i have seen the next generation of kde and plasma. So far i like the experience. But i miss some stuff :(. If some dev out there needs an idea for his next little plasma widget project please consider porting service monitor. That widget alone could bring me back to kde4 :).

As i did a clean reinstall once again resolv.conf was not updated when starting my libvirt networks so no dns resolve of vm names. Not sure if that is a bug or expected behaviour but i had it with 13.2 too and consider it a REAL bug. Or at least major annoyance.

Adding the ip address statically to resolv.conf is not a option. This is a notebook so most services do not get started on default. Which includes libvirtd.

The solution i came up with is to add a libvirt hook that registers the libvirt dnsmasq instance with netconfig when starting libvirt networks and removing it when stopping it. Not much explanation … just code for your convenience.

The script could be improved i guess. Check if dhcp is configured for the network and so on or if dnsmasq is configured for the network in libvirt. But for me it works as is.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 #!/bin/sh
 # vim: et sw=0
 # See https://www.libvirt.org/hooks.html
 OBJECT="${1}"
 OPERATION="${2}"
 SUB_OPERATION="${3}"
 EXTRA_ARGS="${4}"
 # Get the configuration from STDIN
 config=$(cat)
 # Extract the interface and ip addr
 iface=$(sed -ne "s/^.*bridge *name='\([a-zA-Z0-9_]*\).*$/\1/p;" <<<"${config}")
 ipaddr=$(sed -ne "s/^.*ip *address *= *'\([0-9.]*\).*$/\1/p;"   <<<"${config}")
 function check_suboperation() {
   local operation= shift;
   local expected= shift;
   if [ "${oper}" != "${expected}" ]; then
     echo "WARN: Unknown sub-operation ${oper} encountered!" >&2
     exit 1
   fi
 }
 case "${OPERATION}" in
   started)
     check_suboperation "${SUB_OPERATION}" "begin"
     netconfig modify -v --service libvirt --interface "${iface}" -v <<< "DNSSERVERS='${ipaddr}'"
     ;;
   stopped)
     check_suboperation "${SUB_OPERATION}" "begin"
     netconfig remove -v --service libvirt --interface "${iface}" -v <<< "DNSSERVERS='${ipaddr}'"
     ;;
 esac
 exit 0

This script is put under the unlicense license

Hello Again

Long time … no see. Actually two years no blog entry. Real life and especially the job demanded all my time. On top of it the real life job was filled up with boring and uninteresting work not worth blogging about. But thankfully that changed.

I hope to be able to blog more in the next months. It will be less build-tool and more ansible, jenkins, docker and automation in general. And python. And IDEA.

Build-tool is gone

Btw. for those of you out there that actually used build-tool here the official announcement: Its dead. And dead does not even get it right. Its gone. As in i no longer have the source code. Apparently gitorious AND rubyforge went down while i was away. My desktop too and out of a sense of false security i thought its safe out there in the wild wild internet :). The gems are naturally still available but not useful anymore.

New Blog

I moved my blog from ModX (which i took down quite some time ago) to the pelican static site generator . A lack of time and a unfamiliarity with it let me fall behind security updates so badly taking down the site was the only option left.

The decision was between using a hosted blog or a static site generator in a language i am familiar with. Which means pelican was the natural selection.

And so far i am loving it. Much easier.