Thomas Vachuska | 0fdf7c9 | 2016-05-05 17:01:39 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Creates a new node from the base image. |
| 3 | |
| 4 | base="$1" |
| 5 | ip="$2" |
| 6 | name="$3" |
Thomas Vachuska | e91541f | 2016-05-05 23:15:41 -0700 | [diff] [blame] | 7 | shift 3 |
| 8 | key="$@" |
Thomas Vachuska | 0fdf7c9 | 2016-05-05 17:01:39 -0700 | [diff] [blame] | 9 | |
| 10 | sudo lxc-clone -o $base -n $name |
| 11 | |
| 12 | sudo chmod 777 /var/lib/lxc |
| 13 | sudo chmod 777 /var/lib/lxc/$name |
| 14 | sudo chmod 666 /var/lib/lxc/$name/config |
| 15 | |
| 16 | sudo cat >>/var/lib/lxc/$name/config <<EOF |
| 17 | lxc.network.ipv4 = ${ip}/16 |
| 18 | lxc.network.ipv4.gateway = 10.128.0.1 |
| 19 | EOF |
| 20 | |
| 21 | sudo chmod 644 /var/lib/lxc/$name/config |
| 22 | sudo chmod 750 /var/lib/lxc/$name |
| 23 | sudo chmod 700 /var/lib/lxc |
| 24 | |
| 25 | sudo lxc-start -d -n $name |
| 26 | sudo lxc-attach -n $name -- ping -c1 8.8.8.8 |
| 27 | sudo lxc-attach -n $name -- bash -c "echo $key >> /home/sdn/.ssh/authorized_keys" |
Thomas Vachuska | 6cda04b | 2016-05-06 12:46:08 -0700 | [diff] [blame] | 28 | sudo lxc-attach -n $name -- bash -c "sed -i \"s/127.0.1.1.*/127.0.1.1 $name/\" /etc/hosts" |