Virtualisoidut työasemat – Case Kankaanpää
4.11.2011Beta labs: Finally managed to connect IPA server to RHEV 3 beta
7.11.2011
Red Hat Enterprize Virtualization
RHEV3 hypervisor still has a ”bonding problem”, i.e. bonding fails if you try to use an adapter which is in use. You can not bond it using management UI.
I have fixed this by writing my own scripts which unpersist -> modify -> persist ifcfg files. For more complicated operations, I have written scripts system (OO) which is intended to run in a virtual machine – system injects hypervisor machine(s) during the system startup – if one does not want to persist changes to the runtime image. System configures things like network devices, iptables and selinux.
#!/bin/sh # # vaccinate_hypervisor_for_arlslab_turku for arlslab-base # # @ arl // 2011 // (c) arlslab / Netorek # # Configurable options. # BASEDIR="/etc/sysconfig/network-scripts" TZ="UTC-3" #DEBUG=echo # # Configurable setup. # bonds="bond0" bond0_eths="eth0,eth1" eths="eth0,eth1" # helper - could be checked from bonds eth0_bond=bond0 eth1_bond=bond0 bridges="rhevm,core,base,comm,mgmt" rhevm_vlan=0 mgmt_vlan=50 core_vlan=51 base_vlan=52 comm_vlan=53 # # Manifest. # HYPERVISOR=`ifconfig rhevm | grep "inet addr" | sed -e 's%^.*inet addr:[0-9]*.[0-9]*.[0-9]*.([0-9]*) .*$%1%'` echo "HYPERVISOR: ${HYPERVISOR=}" # # Subroutines. # backup() { SUBDIR=`TZ=${TZ} date +%Y%m%d-%H%M` mkdir -p "${BASEDIR}/.SAVE/${SUBDIR}" cp "${BASEDIR}"/ifcfg-* "${BASEDIR}/.SAVE/${SUBDIR}/" } do_unpersist() { if [ -f "$1" ]; then unpersist "$1" fi } do_persist() { persist "$1" } do_persist_all() { persist "${BASEDIR}/ifcfg-"* } do_check() { if [ -f "${BASEDIR}/vaccinate_hypervisor" ]; then echo "Already vaccinated" exit 42 fi } do_tag() { touch "${BASEDIR}/vaccinate_hypervisor" do_persist "${BASEDIR}/vaccinate_hypervisor" } networking_start() { service network start } networking_stop() { service network stop } bonding_modprobe() { if [ -f /etc/modprobe.d/bonding.conf ]; then do_unpersist /etc/modprobe.d/bonding.conf mv /etc/modprobe.d/bonding.conf /var/tmp/ else touch /etc/modprobe.d/bonding.conf do_persist /etc/modprobe.d/bonding.conf do_unpersist /etc/modprobe.d/bonding.conf fi cat > "/etc/modprobe.d/bonding.conf" <<EOF # # /etc/modprobe.d/bonding.conf for a RHEV hypervisor # # @ arl // 2010-2011 // (c) arlslab # # bond0 # alias bond0 bonding options bond0 mode=0 miimon=150 # # # EOF EOF do_persist /etc/modprobe.d/bonding.conf } # # Remove *runtime* interfaces so that there would be no conflicts # when networks is started again. # vlan_interfaces_remove() { ls /sys/class/net/ | egrep -E 'eth(.*).([0-9]*)' | while read interface do ETH=`echo $interface | cut -f1 -d.` VLAN=`echo $interface | cut -f2 -d.` ifconfig $interface down vconfig rem $interface done echo $eths | sed -e 's%,%n%g' | while read interface do unpersist "${BASEDIR}/ifcfg-"$interface"."* rm -f "${BASEDIR}/ifcfg-"$interface"."* done } eth_construct_interface() { do_unpersist "${BASEDIR}/ifcfg-$1" MAC=`grep HWADDR ${BASEDIR}/ifcfg-$1` BOND=`eval echo \$$1_bond` # $DEBUG "eth $1: bond: $BOND" cat > "${BASEDIR}/ifcfg-$1" <<EOF # # $1 # DEVICE=$1 # # Linux setup # TYPE=Ethernet BOOTPROTO=none ONBOOT=yes # # Device setup # $MAC MASTER=$BOND SLAVE=yes # # Network setup # #VLAN=yes # # # EOF EOF do_persist "${BASEDIR}/ifcfg-$1" } eth_construct_interfaces() { echo $eths | sed -e 's%,%n%g' | while read interface do eth_construct_interface $interface done } bond_construct_vlan() { echo $bridges | sed -e 's%,%n%g' | while read interface do VLAN=`eval echo \$${interface}_vlan` # $DEBUG "bond $1: VLAN = $VLAN (interface: $interface)" if [ "$VLAN"x = "0x" ]; then do_unpersist "${BASEDIR}/ifcfg-$1" cat > "${BASEDIR}/ifcfg-$1" <<EOF # # $1 # DEVICE=$1 # # Linux setup # BOOTPROTO=none ONBOOT=yes BRIDGE=$interface # # Network setup # #VLAN=no # # # EOF EOF do_persist "${BASEDIR}/ifcfg-$1" else do_unpersist "${BASEDIR}/ifcfg-$1.$VLAN" cat > "${BASEDIR}/ifcfg-$1.$VLAN" <<EOF # # $1.$VLAN # DEVICE=$1.$VLAN # # Linux setup # BOOTPROTO=none ONBOOT=yes BRIDGE=$interface # # Network setup # VLAN=yes # # # EOF EOF do_persist "${BASEDIR}/ifcfg-$1.$VLAN" fi done } bond_construct_interface() { do_unpersist "${BASEDIR}/ifcfg-$1" ETHS=`eval echo \$$1_eths` SLAVE0=`echo $ETHS | cut -f1 -d,` SLAVE1=`echo $ETHS | cut -f2 -d,` cat > "${BASEDIR}/ifcfg-$1" <<EOF # # $1 # DEVICE=$1 # # Linux setup # TYPE=Ethernet BOOTPROTO=none ONBOOT=yes # # Network setup # VLAN=yes # # Bonding setup # BONDING_MASTER=yes BONDING_SLAVE0=$SLAVE0 BONDING_SLAVE1=$SLAVE1 # # # EOF EOF bond_construct_vlan $1 do_persist "${BASEDIR}/ifcfg-$1" } bond_construct_interfaces() { echo $bonds | sed -e 's%,%n%g' | while read interface do bond_construct_interface $interface done } bridge_construct_interface() { do_unpersist "${BASEDIR}/ifcfg-$1" BOOTPROTO=none if [ "$1" = "rhevm" ]; then BOOTPROTO=dhcp fi cat > "${BASEDIR}/ifcfg-$1" <<EOF # # $1 # DEVICE=$1 # # Linux setup # TYPE=Bridge ONBOOT=yes BOOTPROTO=$BOOTPROTO # # Network setup # # # Bridge setup # DELAY=0 STP=on # # # EOF EOF do_persist "${BASEDIR}/ifcfg-$1" } bridge_construct_interfaces() { echo $bridges | sed -e 's%,%n%g' | while read interface do bridge_construct_interface $interface done } bridge_interface_remove() { ifconfig $1 down brctl delbr $1 } bridge_interfaces_remove() { echo $bridges | sed -e 's%,%n%g' | while read interface do bridge_interface_remove $interface done } # # MAIN # do_check networking_stop backup vlan_interfaces_remove # safety networking_stop eth_construct_interfaces bond_construct_interfaces bridge_interfaces_remove bridge_construct_interfaces bonding_modprobe networking_start do_persist_all do_tag # # # EOF