X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lbuild-initvm.sh;h=e357a09bffec113d0d1ed11834481211b4553e30;hb=b9d5bfa94fbd61ddd0fc43004eb2f832f95295b8;hp=ad83d46956aa86c51e64c39833d5091fc5cf48a7;hpb=5097e161a9e86540782b27016d9fdc6730b84777;p=build.git diff --git a/lbuild-initvm.sh b/lbuild-initvm.sh index ad83d469..e357a09b 100755 --- a/lbuild-initvm.sh +++ b/lbuild-initvm.sh @@ -90,20 +90,25 @@ function package_method () { } ### return -# ifcfg for redhat's -# interfaces for older debian/uuntu -# systemd for more recent debian/ubuntu -function network_method () { +# ifcfg for fedora up to 36 +# networkmanager for fedora starting with f37 (probably works with older as well...) +# interfaces for older debian/uuntu +# systemd for more recent debian/ubuntu +function network_config_method () { local fcdistro=$1; shift case $fcdistro in - f[0-9]*|centos[0-9]*|sl[0-9]*) + # have not used centos or scientific linux for a very long time + #f[0-9]*|centos[0-9]*|sl[0-9]*) + f2*|f3[0-6]) echo ifcfg ;; + f3[7-9]|f[4-9]*) + echo networkmanager ;; wheezy|jessie|trusty|xenial|bionic) echo interfaces ;; focal|jammy) echo systemd ;; *) - echo "Unknown network_method for distro $fcdistro" ;; + echo "Unknown network_config_method for distro $fcdistro" ;; esac } @@ -298,21 +303,39 @@ EOF fedora_configure_systemd $lxc - local guest_ifcfg=${lxc_root}/etc/sysconfig/network-scripts/ifcfg-$VIF_GUEST - mkdir -p $(dirname ${guest_ifcfg}) - # starting with f27, we go for NetworkManager - # no more NM_CONTROLLED nonsense - if [ -n "$NAT_MODE" ]; then - write_guest_ifcfg_natip - else - write_guest_ifcfg_publicip - fi > $guest_ifcfg + fedora_configure_network $lxc [ -z "$IMAGE" ] && fedora_configure_yum $lxc $fcdistro $pldistro return 0 } +function fedora_configure_network() { + local lxc="$1" + case $(network_config_method $fcdistro) in + ifcfg) + # probably no longer useful + local guest_ifcfg=${lxc_root}/etc/sysconfig/network-scripts/ifcfg-$VIF_GUEST + mkdir -p $(dirname ${guest_ifcfg}) + if [ -n "$NAT_MODE" ]; then + write_guest_ifcfg_natip + else + write_guest_ifcfg_publicip + fi > $guest_ifcfg + ;; + networkmanager) + local guest_keyfile=${lxc_root}/etc/NetworkManager/system-connections/'Wired connection 1.nmconnection' + mkdir -p $(dirname "${guest_keyfile}") + if [ -n "$NAT_MODE" ]; then + write_guest_networkmanager_natip + else + write_guest_networkmanager_publicip + fi > "$guest_keyfile" + chmod 600 "$guest_keyfile" + ;; + esac +} + # this code of course is for guests that do run on systemd function fedora_configure_systemd() { set -e @@ -331,9 +354,7 @@ function fedora_configure_systemd() { # sed -i 's/After=dev-%i.device/After=/' ${lxc_root}/lib/systemd/system/getty\@.service ln -sf /dev/null ${lxc_root}/etc/systemd/system/"getty@.service" rm -f ${lxc_root}/etc/systemd/system/getty.target.wants/*service || : -# can't seem to handle this one with systemctl -# second part should trigger starting with fedora31, where the network target is not manually manageable - chroot ${lxc_root} $personality chkconfig network on || chroot ${lxc_root} $personality systemctl enable NetworkManager + chroot ${lxc_root} $personality systemctl enable NetworkManager } # overwrite container yum config @@ -427,7 +448,7 @@ EOF function debian_configure () { local lxc=$1; shift local fcdistro=$1; shift - case $(network_method $fcdistro) in + case $(network_config_method $fcdistro) in interfaces) local guest_interfaces=${lxc_root}/etc/network/interfaces ( [ -n "$NAT_MODE" ] \ @@ -485,6 +506,31 @@ Gateway=$GATEWAY EOF } +function uuid() { + python -c "import uuid; print(uuid.uuid1())" +} +# xxx this seems to be no longer needed ? +function write_guest_networkmanager_natip() { + cat << EOF +EOF +} +function write_guest_networkmanager_publicip() { + cat << EOF +[connection] +id=Wired connection 1 +uuid=$(uuid) +type=ethernet +autoconnect-priority=-999 +# setting this seems to be counter-productive +# interface-name=${VIF_GUEST} + +[ipv4] +address1=${GUEST_IP}/${MASKLEN},${GATEWAY} +dhcp-hostname=${GUEST_HOSTNAME} +method=auto +EOF +} + ############################## function setup_lxc() { @@ -532,7 +578,14 @@ function setup_lxc() { ### set up resolv.conf from host # ubuntu precise and on, /etc/resolv.conf is a symlink to ../run/resolvconf/resolv.conf [ -h $lxc_root/etc/resolv.conf ] && rm -f $lxc_root/etc/resolv.conf - cp /etc/resolv.conf $lxc_root/etc/resolv.conf + ### since fedora36, our hosts use systemd-resolved, but the guests can't use that + # so the administrator has the option to create /etc/resolv.conf.containers + # and if that file exists it will be copied in the containers instead of /etc/resolv.conf + if [ -f /etc/resolv.conf.containers ]; then + cp /etc/resolv.conf.containers $lxc_root/etc/resolv.conf + else + cp /etc/resolv.conf $lxc_root/etc/resolv.conf + fi ### and /etc/hosts for at least localhost [ -f $lxc_root/etc/hosts ] || echo "127.0.0.1 localhost localhost.localdomain" > $lxc_root/etc/hosts @@ -804,7 +857,7 @@ function post_install_myplc () { [ -f /etc/sysconfig/network ] || /bin/echo NETWORKING=yes > /etc/sysconfig/network # turn off regular crond, as plc invokes plc_crond - /sbin/chkconfig crond off + /sbin/chkconfig crond off >& /dev/null # customize root's prompt /bin/cat << PROFILE > /root/.profile