New tool to generate lxd images from an OSM installation and push them to ETSI FTP 99/5699/5
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 17 Nov 2017 14:33:02 +0000 (15:33 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 23 Nov 2017 17:14:23 +0000 (18:14 +0100)
Change-Id: If178de582660690ff3f04af6fa1ef2961e7b1c24
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
tools/gen-lxdimages.sh [new file with mode: 0755]

diff --git a/tools/gen-lxdimages.sh b/tools/gen-lxdimages.sh
new file mode 100755 (executable)
index 0000000..10c59b9
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/bash
+
+function usage() {
+    echo -e "usage: $0 [OPTIONS]"
+    echo -e "  OPTIONS"
+    echo -e "     -c <COMPONENT>:    the component whose lxd image has to be generated. Allowed values: RO, VCA, SOUI, MON"
+    echo -e "     -R <RELEASE>:      push images to specific RELEASE folder"
+}
+
+GEN_ALL="y"
+GEN_RO=""
+GEN_VCA=""
+GEN_SOUI=""
+GEN_MON=""
+RELEASE="ReleaseTHREE"
+
+while getopts ":h" o; do
+    case "${o}" in
+        h)
+            usage
+            exit 0
+            ;;
+        R)
+            RELEASE="${OPTARG}"
+            ;;
+        c)
+            [ "${OPTARG}" == "RO" ] && GEN_ALL="" && GEN_RO="y" && continue
+            [ "${OPTARG}" == "VCA" ] && GEN_ALL="" && GEN_VCA="y" && continue
+            [ "${OPTARG}" == "SOUI" ] && GEN_ALL="" && GEN_SOUI="y" && continue
+            [ "${OPTARG}" == "MON" ] && GEN_ALL="" && GEN_MON="y" && continue
+            echo -e "Invalid option: '--$OPTARG'\n" >&2
+            usage && exit 1
+            ;;
+        *)
+            usage && exit 1
+            ;;
+    esac
+done
+
+[ "$GEN_ALL" == "y" ] && GEN_RO="y" && GEN_VCA="y" && GEN_SOUI="y" && GEN_MON="y"
+
+echo "Stopping containers"
+lxc stop RO
+lxc stop VCA
+lxc stop SO-ub
+#lxc stop MON
+
+echo "Saving containers as images in local lxd server"
+OSM_RO_IMAGE="osm-ro"
+OSM_VCA_IMAGE="osm-vca"
+OSM_SOUI_IMAGE="osm-soui"
+OSM_MON_IMAGE="osm-mon"
+
+[ -n "$GEN_RO" ] && lxc publish --public RO --alias ${OSM_RO_IMAGE}
+[ -n "$GEN_VCA" ] && lxc publish --public VCA --alias ${OSM_VCA_IMAGE}
+[ -n "$GEN_SOUI" ] && lxc publish --public SO-ub --alias ${OSM_SOUI_IMAGE}
+#[ -n "$GEN_MON" ] && lxc publish --public MON --alias ${OSM_MON_IMAGE}
+#lxc image list
+
+#echo "Copying images to a remote lxd server"
+#[ -n "$GEN_RO" ] && lxc image copy ${OSM_RO_IMAGE} remote:
+#[ -n "$GEN_VCA" ] && lxc image copy ${OSM_VCA_IMAGE} remote:
+#[ -n "$GEN_SOUI" ] && lxc image copy ${OSM_SOUI_IMAGE} remote:
+#[ -n "$GEN_MON" ] && lxc image copy ${OSM_MON_IMAGE} remote:
+
+echo "Exporting images as targz"
+TEMPDIR="$(mktemp -d -q --tmpdir "osmlxd.XXXXXX")"
+trap 'rm -rf "$TEMPDIR"' EXIT
+RELEASE_DIR="${TEMPDIR}/${RELEASE}"
+
+[ -n "$GEN_RO" ] && lxc image export ${OSM_RO_IMAGE} $RELEASE_DIR/${OSM_RO_IMAGE}
+[ -n "$GEN_VCA" ] && lxc image export ${OSM_VCA_IMAGE} $RELEASE_DIR/${OSM_VCA_IMAGE}
+[ -n "$GEN_SOUI" ] && lxc image export ${OSM_SOUI_IMAGE} $RELEASE_DIR/${OSM_SOUI_IMAGE}
+#[ -n "$GEN_MON" ] && lxc image export ${OSM_MON_IMAGE} $RELEASE_DIR/${OSM_MON_IMAGE}
+[ -n "$GEN_RO" ] && chmod +r $RELEASE_DIR/${OSM_RO_IMAGE}
+[ -n "$GEN_VCA" ] && chmod +r $RELEASE_DIR/${OSM_VCA_IMAGE}
+[ -n "$GEN_SOUI" ] && chmod +r $RELEASE_DIR/${OSM_SOUI_IMAGE}
+#[ -n "$GEN_MON" ] && chmod +r $RELEASE_DIR/${OSM_MON_IMAGE}
+
+echo "Pushing images to ETSI FTP server"
+RSYNC_USER_HOST=osmusers@osm-download.etsi.org
+RSYNC_OPTIONS="--delete --password-file rsync.pass"
+cd $TEMPDIR && rsync -avR $RSYNC_OPTIONS $RELEASE rsync://$RSYNC_USER_HOST/repos/osm/lxd
+
+