Revert "Feature 11071: Modular OSM installation. Remove charms, juju and lxd"

This reverts commit a0f0d8ef4f2aa0dd227ecb651002490b66498bab.

Change-Id: I92394e4074dad4e457c107c58e4ebc17d507f8b2
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/tools/debug/charmed/README.md b/tools/debug/charmed/README.md
new file mode 100644
index 0000000..93bf7ee
--- /dev/null
+++ b/tools/debug/charmed/README.md
@@ -0,0 +1,147 @@
+<!--
+ Copyright 2020 Canonical Ltd.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ For those usages not covered by the Apache License, Version 2.0 please
+ contact: legal@canonical.com
+
+ To get in touch with the maintainers, please contact:
+ osm-charmers@lists.launchpad.net
+-->
+
+# Debugging Charmed OSM
+
+This document aims to provide the OSM community an easy way of testing and debugging OSM.
+
+Benefits:
+
+- Use upstream published images for debugging: No need to build local images anymore.
+- Easily configure modules for debugging_mode: `juju config <module> debug_mode=True debug_pubkey="ssh-rsa ..."`.
+- Debug in K8s: All pods (the debugged ones and the rest) will be running always in K8s.
+- Seemless setup: VSCode will connect through SSH to the pods.
+- Keep your changes save: Possibility to mount local module to the container; all the changes will be saved automatically to your local filesystem.
+
+## Install OSM
+
+Download the installer:
+
+```bash
+wget http://osm-download.etsi.org/ftp/osm-10.0-ten/install_osm.sh
+chmod +x install_osm.sh
+```
+
+Install OSM from master (tag=testing-daily):
+
+```bash
+./install_osm.sh -R testing-daily -r testing --charmed
+```
+
+Install OSM from a specific tag:
+
+```bash
+./install_osm.sh -R testing-daily -r testing --charmed --tag <X.Y.Z>
+```
+
+## Debugging
+
+Once the Charmed OSM installation has finished, you can select which applications you want to run with the debug mode.
+
+```bash
+# LCM
+juju config lcm debug_mode=True  debug_pubkey="`cat ~/.ssh/id_rsa.pub`"
+# MON
+juju config mon debug_mode=True  debug_pubkey="`cat ~/.ssh/id_rsa.pub`"
+# NBI
+juju config nbi debug_mode=True  debug_pubkey="`cat ~/.ssh/id_rsa.pub`"
+# RO
+juju config ro debug_mode=True  debug_pubkey="`cat ~/.ssh/id_rsa.pub`"
+# POL
+juju config pol debug_mode=True  debug_pubkey="`cat ~/.ssh/id_rsa.pub`"
+```
+
+Enabling the debug_mode will put a `sleep infinity` as the entrypoint of the container. That way, we can later connect to the pod through SSH in VSCode, and run the entrypoint of the application from the debugger.
+
+### Mounting local modules
+
+The Charmed OSM Debugging mode allows you to mount local modules to the desired charms. The following commands show which modules can be mounted in each charm.
+
+```bash
+LCM_LOCAL_PATH="/path/to/LCM"
+N2VC_LOCAL_PATH="/path/to/N2VC"
+NBI_LOCAL_PATH="/path/to/NBI"
+RO_LOCAL_PATH="/path/to/RO"
+MON_LOCAL_PATH="/path/to/MON"
+POL_LOCAL_PATH="/path/to/POL"
+COMMON_LOCAL_PATH="/path/to/common"
+
+# LCM
+juju config lcm debug_lcm_local_path=$LCM_LOCAL_PATH
+juju config lcm debug_n2vc_local_path=$N2VC_LOCAL_PATH
+juju config lcm debug_common_local_path=$COMMON_LOCAL_PATH
+# MON
+juju config mon debug_mon_local_path=$MON_LOCAL_PATH
+juju config mon debug_n2vc_local_path=$N2VC_LOCAL_PATH
+juju config mon debug_common_local_path=$COMMON_LOCAL_PATH
+# NBI
+juju config nbi debug_nbi_local_path=$LCM_LOCAL_PATH
+juju config nbi debug_common_local_path=$COMMON_LOCAL_PATH
+# RO
+juju config ro debug_ro_local_path=$RO_LOCAL_PATH
+juju config ro debug_common_local_path=$COMMON_LOCAL_PATH
+# POL
+juju config pol debug_pol_local_path=$POL_LOCAL_PATH
+juju config pol debug_common_local_path=$COMMON_LOCAL_PATH
+```
+
+### Generate SSH config file
+
+Preparing the pods includes setting up the `~/.ssh/config` so the VSCode can easily discover which ssh hosts are available
+
+Just execute:
+
+```bash
+./generate_ssh_config.sh
+```
+
+> NOTE: The public key that will be used will be `$HOME/.ssh/id_rsa.pub`. If you want to use a different one, add the absolute path to it as a first argument: `./generate_ssh_config.sh /path/to/key.pub`.
+
+### Connect to Pods
+
+In VScode, navigate to [Remote Explorer](https://code.visualstudio.com/docs/remote/ssh#_remember-hosts-and-advanced-settings), and select the pod to which you want to connect.
+
+You should be able to see the following hosts in the Remote Explorer:
+
+- lcm
+- mon
+- nbi
+- ro
+- pol
+
+Right click on the host, and "Connect to host in a New Window".
+
+### Add workspace
+
+The `./generate_ssh_config.sh` script adds a workspace to the `/root` folder of each pod, with the following name: `debug.code-workspace`.
+
+In the window of the connected host, go to `File/Open Workspace from File...`. Then select the `debug.code-workspace` file.
+
+### Run and Debug
+
+Open the `Terminal` tab, and the Python extension will be automatically downloaded. It will be installed in the remote pod.
+
+Go to the `Explorer (ctrl + shift + E)` to see the module folders in the charm. You can add breakpoints and start debugging. 
+
+Go to the `Run and Debug (ctrl + shift + D)` and press `F5` to start the main entrypoint of the charm.
+
+Happy debugging!
diff --git a/tools/debug/charmed/generate_ssh_config.sh b/tools/debug/charmed/generate_ssh_config.sh
new file mode 100755
index 0000000..58d0686
--- /dev/null
+++ b/tools/debug/charmed/generate_ssh_config.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+# Copyright 2021 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+MODULES="lcm pol mon ro nbi"
+
+
+PRIVATE_KEY=${1:-$HOME/.ssh/id_rsa}
+echo "Using $PRIVATE_KEY key."
+[ -f $PRIVATE_KEY ] || (echo "$PRIVATE_KEY file does not exist" && exit 1)
+PRIVATE_KEY_CONTENT=`cat $PRIVATE_KEY`
+
+mkdir -p ~/.ssh/config.d
+echo "" | tee ~/.ssh/config.d/osm
+
+
+for module in $MODULES; do
+    if [[ `juju config -m osm $module debug_mode` == "true" ]]; then
+      pod_name=`microk8s.kubectl -n osm get pods | grep -E "^$module-" | grep -v operator | cut -d " " -f 1`
+      pod_ip=`microk8s.kubectl -n osm get pods $pod_name -o yaml | yq e .status.podIP -`
+      echo "Host $module
+  HostName $pod_ip
+  User root
+  # StrictHostKeyChecking no
+  IdentityFile $PRIVATE_KEY" | tee -a ~/.ssh/config.d/osm
+    fi
+done
+
+
+import_osm_config="Include config.d/osm"
+touch ~/.ssh/config
+grep "$import_osm_config" ~/.ssh/config || ( echo -e "$import_osm_config\n$(cat ~/.ssh/config)" > ~/.ssh/config )
\ No newline at end of file
diff --git a/tools/promote-charms-and-snaps.sh b/tools/promote-charms-and-snaps.sh
new file mode 100755
index 0000000..1ace0dc
--- /dev/null
+++ b/tools/promote-charms-and-snaps.sh
@@ -0,0 +1,101 @@
+#!/bin/bash
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+CHANNEL=${1:-latest}
+SOURCE=${2:-beta}
+TARGET=${3:-candidate}
+echo "==========================================================="
+echo Promoting charms and snaps from $SOURCE to $TARGET
+echo ""
+
+for snap in osmclient ; do
+
+    echo "==========================================================="
+    echo "${snap}"
+
+    track="${CHANNEL}/${SOURCE}\\*"
+    SOURCE_REV=$(snapcraft revisions $snap | grep $track | tail -1 | awk '{print $1}')
+    track="${CHANNEL}/${TARGET}\\*"
+    TARGET_REV=$(snapcraft revisions $snap | grep $track | tail -1 | awk '{print $1}')
+
+    echo "$SOURCE: $SOURCE_REV, $TARGET: $TARGET_REV"
+
+    if [ -z $TARGET_REV ] || [ $SOURCE_REV -ne $TARGET_REV ]; then
+        echo "Promoting $SOURCE_REV to beta in place of $TARGET_REV"
+        track="${CHANNEL}/${TARGET}"
+        snapcraft release $snap $SOURCE_REV $track
+    fi
+
+done
+
+for charm in \
+    'osm' \
+    'osm-ha' \
+    'osm-grafana' \
+    'mongodb-exporter-k8s' \
+    'mysqld-exporter-k8s' \
+    'osm-lcm' \
+    'osm-mon' \
+    'osm-nbi' \
+    'osm-ng-ui' \
+    'osm-pol' \
+    'osm-ro' \
+    'osm-prometheus' \
+    'osm-vca-integrator' ; do
+
+    echo "==========================================================="
+    echo "${charm}"
+
+    charmcraft status $charm --format json > ${charm}.json
+    isCharm=$(grep architecture ${charm}.json | wc -l 2>/dev/null)
+    resourceArgument=""
+
+    if [ $isCharm -gt 0 ]; then
+        base=20.04
+        is2204=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"22.04\")"|wc -l)
+        if [ $is2204 -gt 0 ]; then
+            base=22.04
+        fi
+
+
+        SOURCE_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .version"|head -1)
+        TARGET_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$TARGET\")| .version"|head -1)
+
+
+        index=0
+        while [ $index -lt 5 ]; do
+            resourceName=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .resources[$index].name"|head -1)
+            resourceRevs=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .resources[$index].revision"|head -1)
+            if [ "$resourceName" != "null" ] ; then
+                resourceArgument=" $resourceArgument --resource ${resourceName}:${resourceRevs}"
+            else
+                break
+            fi
+            ((index=index+1))
+        done
+    else
+        SOURCE_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[].releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .version"|head -1)
+        TARGET_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[].releases[] | select(.channel==\"$CHANNEL/$TARGET\")| .version"|head -1)
+    fi
+
+    rm ${charm}.json
+    echo "$SOURCE: $SOURCE_REV, $TARGET: $TARGET_REV $resourceArgument"
+
+    if [ $TARGET_REV == "null" ] || [ $SOURCE_REV -gt $TARGET_REV ] ; then
+        echo Promoting ${charm} revision ${SOURCE_REV} to ${TARGET} ${resourceArgument}
+        charmcraft release ${charm} --revision=${SOURCE_REV}  ${resourceArgument} --channel=${CHANNEL}/$TARGET
+    fi
+
+done