X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lbuild-initvm.sh;h=5dedf7f8b31797f2762ccd6a7c17ca47d74b4b68;hb=cc5a9338d1528a7fec60f496bfba7b8b28a80539;hp=e4d3c6afe300ec7dce8866a3855a8a430ae590f8;hpb=140ec07b8ce5a7f3994f1c0f14a22c8a04940691;p=build.git diff --git a/lbuild-initvm.sh b/lbuild-initvm.sh index e4d3c6af..5dedf7f8 100755 --- a/lbuild-initvm.sh +++ b/lbuild-initvm.sh @@ -57,22 +57,21 @@ function gethostbyname () { # e.g. 21 -> 255.255.248.0 function masklen_to_netmask () { local masklen=$1; shift - python <=1 and masklen<=32): - print "Wrong masklen",masklen +masklen = $masklen +if not (1 <= masklen <= 32): + print("Wrong masklen", masklen) exit(1) -result=[] +result = [] for i in range(4): - if masklen>=8: + if masklen >= 8: result.append(8) - masklen-=8 + masklen -= 8 else: result.append(masklen) - masklen=0 -print ".".join([ str(256-2**(8-i)) for i in result ]) - + masklen = 0 +print(".".join([ str(256-2**(8-i)) for i in result ])) EOF } @@ -784,13 +783,17 @@ function wait_for_ssh () { local counter=1 while [ "$current_time" -lt "$stop_time" ] ; do - echo "$counter-th attempt to reach sshd in container $lxc ..." - [ -z "$guest_ip" ] && guest_ip=$(guest_ipv4 $lxc) - [ -n "$guest_ip" ] && ssh -o "StrictHostKeyChecking no" $guest_ip 'uname -i' && { - success=true; echo "SSHD in container $lxc is UP on IP $guest_ip"; break ; } || : - counter=$(($counter+1)) - sleep 10 - current_time=$(date +%s) + echo "$counter-th attempt to reach sshd in container $lxc ..." + [ -z "$guest_ip" ] && guest_ip=$(guest_ipv4 $lxc) + [ -n "$guest_ip" ] && ssh -o "StrictHostKeyChecking no" $guest_ip 'uname -i' && { + success=true; echo "SSHD in container $lxc is UP on IP $guest_ip"; break ; } || : + # some of our boxes have gone through a long upgrade historically, and + # so they don't end up with the same gid mapping for the ssh_keys + # group as the ones in the guest that result from a fresh install + virsh -c lxc:/// lxc-enter-namespace $lxc /bin/bash -c "chown root:ssh_keys /etc/ssh/*_key" || : + counter=$(($counter+1)) + sleep 10 + current_time=$(date +%s) done # Thierry: this is fatal, let's just exit with a failure here @@ -864,6 +867,8 @@ function main () { local lxc_root=$(lxcroot $lxc) # rainchecks + # when using with the -i option, checking that $lxc_root is void + # is a little too much stress.. almost_empty $lxc_root || \ { echo "container $lxc already exists in $lxc_root - exiting" ; exit 1 ; } virsh -c lxc:/// domuuid $lxc >& /dev/null && \ @@ -872,9 +877,13 @@ function main () { # if IMAGE, copy the provided rootfs to lxc_root if [ -n "$IMAGE" ] ; then - [ ! -d "$IMAGE" ] && \ - { echo "$IMAGE rootfs folder does not exist - exiting" ; exit 1 ; } - rsync -a $IMAGE/ $lxc_root/ + if [ ! -d "$IMAGE" ]; then + echo "$IMAGE rootfs folder does not exist - exiting" + exit 1 + else + echo "Copying $IMAGE into $lxc_root with rsync --archive --delete" + rsync --archive --delete $IMAGE/ $lxc_root/ + fi fi # check we've exhausted the arguments