########## networking utilities
function gethostbyname () {
local hostname=$1
- python -c "import socket; print socket.gethostbyname('"$hostname"')" 2> /dev/null
+ python3 -c "import socket; print(socket.gethostbyname('"$hostname"'))" 2> /dev/null
}
# e.g. 21 -> 255.255.248.0
function masklen_to_netmask () {
local masklen=$1; shift
- python <<EOF
+ python3 <<EOF
import sys
-masklen=$masklen
-if not (masklen>=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
}
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 ; } || :
+ # when migrating, sometimes we don't have the same uid/gid mapping
+ # for the ssh_keys group on both host boxes...
+ # also this is not wuite right, as *_key gets expanded in the host context
+ # but using "" or \ makes it litteral...
+ virsh -c lxc:/// lxc-enter-namespace $lxc /usr/bin/env 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
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 && \
# 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