Created
November 3, 2014 18:44
-
-
Save freyes/599c1e1fb2f2212a7fc8 to your computer and use it in GitHub Desktop.
Patch a machine to use lxcbr0 in bridge mode and assign a static ip to the container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
/usr/bin/lxc-clone.real $@ | |
RET=$? | |
# hostname will be of the form juju-FOO-machine-NUM | |
X=$(hostname | cut -d'-' -f4) # here we grab NUM | |
# the 4th argument to lxc-clone is the new container's name that looks like juju-machine-NUM-lxc-CONTAINER_ID | |
COUNTER=$(echo $4 | cut -d'-' -f 5) | |
NEW_IP="10.5.${X}0.$(( $COUNTER + 20 ))" | |
echo "auto eth0 | |
iface eth0 inet static | |
address $NEW_IP | |
netmask 255.255.0.0 | |
gateway 10.5.0.1 | |
dns-nameservers 10.5.0.2 | |
dns-search openstacklocal | |
" > /var/lib/lxc/$4/rootfs/etc/network/interfaces.d/eth0.cfg | |
exit $RET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto lxcbr0 | |
iface lxcbr0 inet dhcp | |
bridge_ports eth2 | |
bridge_fd 0 | |
bridge_maxwait 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ex | |
# before using this you have to run 'juju add-machine lxc:NUM' to make juju prepare the template | |
# then just destroy the container with 'juju destroy-machine NUM/lxc/0' and then patch the machine | |
# with './patch-machine <NUM>' | |
MACHINE_ID=$1 | |
# creating bridge on eth2 | |
juju ssh $MACHINE_ID sudo service lxc-net stop | |
juju scp lxcbr0.cfg $MACHINE_ID:/tmp/ | |
juju ssh $MACHINE_ID sudo cp /tmp/lxcbr0.cfg /etc/network/interfaces.d/ | |
juju ssh $MACHINE_ID sudo ifup lxcbr0 | |
# patching lxc-clone to use static ips | |
juju ssh $MACHINE_ID sudo mv /usr/bin/lxc-clone /usr/bin/lxc-clone.real | |
juju scp lxc-clone-static-ip $MACHINE_ID:/tmp/ | |
juju ssh $MACHINE_ID sudo cp /tmp/lxc-clone-static-ip /usr/bin/ | |
juju ssh $MACHINE_ID sudo ln -s /usr/bin/lxc-clone-static-ip /usr/bin/lxc-clone | |
juju ssh $MACHINE_ID sudo chmod +x /usr/bin/lxc-clone-static-ip | |
juju ssh $MACHINE_ID sudo service lxc-net start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment