Adding tools for next version of warden.
Change-Id: I35b0ac57b54b0bf7b8c6b6a40e02f050b3fcc7f1
diff --git a/utils/warden/bin/cell-def b/utils/warden/bin/cell-def
new file mode 100755
index 0000000..12fd284
--- /dev/null
+++ b/utils/warden/bin/cell-def
@@ -0,0 +1,16 @@
+#!/bin/bash
+# Creates a cell definition from the given name and LXC info
+
+name="$1"
+apps="${2:-drivers,openflow,proxyarp,mobility,pathpainter}"
+
+echo "export ONOS_CELL=borrow"
+echo "export ONOS_NIC=\"10.128.11.*\""
+
+sudo lxc-ls -F "name,ipv4" --fancy | grep $name | \
+ sed "s/^$name/OC/" | tr "[:lower:]" "[:upper:]" | \
+ sed -r 's/[ ]+/\=/;s/^/export /'
+
+echo "export OCT=\"\$OC1\""
+echo "export ONOS_USE_SSH=true"
+echo "export ONOS_APPS=${apps}"
diff --git a/utils/warden/bin/clone-node b/utils/warden/bin/clone-node
new file mode 100755
index 0000000..8e60d40
--- /dev/null
+++ b/utils/warden/bin/clone-node
@@ -0,0 +1,27 @@
+#!/bin/bash
+# Creates a new node from the base image.
+
+base="$1"
+ip="$2"
+name="$3"
+key="$4"
+
+sudo lxc-clone -o $base -n $name
+
+sudo chmod 777 /var/lib/lxc
+sudo chmod 777 /var/lib/lxc/$name
+sudo chmod 666 /var/lib/lxc/$name/config
+
+sudo cat >>/var/lib/lxc/$name/config <<EOF
+lxc.network.ipv4 = ${ip}/16
+lxc.network.ipv4.gateway = 10.128.0.1
+EOF
+
+sudo chmod 644 /var/lib/lxc/$name/config
+sudo chmod 750 /var/lib/lxc/$name
+sudo chmod 700 /var/lib/lxc
+
+sudo lxc-start -d -n $name
+sudo lxc-attach -n $name -- ping -c1 8.8.8.8
+sudo lxc-attach -n $name -- bash -c "echo $key >> /home/sdn/.ssh/authorized_keys"
+sudo lxc-ls --fancy
diff --git a/utils/warden/bin/create-cell b/utils/warden/bin/create-cell
new file mode 100755
index 0000000..f24a386
--- /dev/null
+++ b/utils/warden/bin/create-cell
@@ -0,0 +1,14 @@
+#!/bin/bash
+# Creates a new cell.
+
+name="$1"
+ipx="$2"
+key="$3"
+
+cd $(dirname $0)
+
+./clone-node base-mininet ${ipx/x/0} $name-mn "$key"
+
+for n in {1..3}; do
+ ./clone-node base-onos ${ipx/x/$n} $name-$n "$key"
+done
diff --git a/utils/warden/bin/destroy-cell b/utils/warden/bin/destroy-cell
new file mode 100755
index 0000000..c39d5fe
--- /dev/null
+++ b/utils/warden/bin/destroy-cell
@@ -0,0 +1,12 @@
+#!/bin/bash
+# Destroys an LXC cell with the specified name.
+
+name=$1
+
+cd $(dirname $0)
+
+./destroy-node $name-mn
+
+for n in {1..3}; do
+ ./destroy-node $name-$n
+done
diff --git a/utils/warden/bin/destroy-node b/utils/warden/bin/destroy-node
new file mode 100755
index 0000000..b315d41
--- /dev/null
+++ b/utils/warden/bin/destroy-node
@@ -0,0 +1,9 @@
+#!/bin/bash
+# Destroys an LXC node with the specified name.
+
+name=$1
+[ "$name" = "onos-base" ] && echo "Don't do that!" && exit 1
+[ "$name" = "mininet-base" ] && echo "Don't do that!" && exit 1
+
+sudo lxc-stop -n $name
+sudo lxc-destroy -n $name