blob: 58d06861db267153d0c1a79f2dbd7bbefe52532f [file] [log] [blame]
David Garciad680be42021-08-17 11:03:55 +02001#!/bin/bash
2# Copyright 2021 Canonical Ltd.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15#
16# For those usages not covered by the Apache License, Version 2.0 please
17# contact: legal@canonical.com
18#
19# To get in touch with the maintainers, please contact:
20# osm-charmers@lists.launchpad.net
21##
22
23MODULES="lcm pol mon ro nbi"
24
25
beierlme830f622022-01-18 12:52:23 -050026PRIVATE_KEY=${1:-$HOME/.ssh/id_rsa}
27echo "Using $PRIVATE_KEY key."
28[ -f $PRIVATE_KEY ] || (echo "$PRIVATE_KEY file does not exist" && exit 1)
29PRIVATE_KEY_CONTENT=`cat $PRIVATE_KEY`
David Garciad680be42021-08-17 11:03:55 +020030
31mkdir -p ~/.ssh/config.d
32echo "" | tee ~/.ssh/config.d/osm
33
34
35for module in $MODULES; do
36 if [[ `juju config -m osm $module debug_mode` == "true" ]]; then
37 pod_name=`microk8s.kubectl -n osm get pods | grep -E "^$module-" | grep -v operator | cut -d " " -f 1`
David Garcia01972d22021-10-11 19:52:33 +020038 pod_ip=`microk8s.kubectl -n osm get pods $pod_name -o yaml | yq e .status.podIP -`
David Garciad680be42021-08-17 11:03:55 +020039 echo "Host $module
40 HostName $pod_ip
41 User root
42 # StrictHostKeyChecking no
beierlme830f622022-01-18 12:52:23 -050043 IdentityFile $PRIVATE_KEY" | tee -a ~/.ssh/config.d/osm
David Garciad680be42021-08-17 11:03:55 +020044 fi
45done
46
47
48import_osm_config="Include config.d/osm"
49touch ~/.ssh/config
50grep "$import_osm_config" ~/.ssh/config || ( echo -e "$import_osm_config\n$(cat ~/.ssh/config)" > ~/.ssh/config )