| David Garcia | d680be4 | 2021-08-17 11:03:55 +0200 | [diff] [blame] | 1 | #!/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 | |
| 23 | MODULES="lcm pol mon ro nbi" |
| 24 | |
| 25 | |
| beierlm | e830f62 | 2022-01-18 12:52:23 -0500 | [diff] [blame] | 26 | PRIVATE_KEY=${1:-$HOME/.ssh/id_rsa} |
| 27 | echo "Using $PRIVATE_KEY key." |
| 28 | [ -f $PRIVATE_KEY ] || (echo "$PRIVATE_KEY file does not exist" && exit 1) |
| 29 | PRIVATE_KEY_CONTENT=`cat $PRIVATE_KEY` |
| David Garcia | d680be4 | 2021-08-17 11:03:55 +0200 | [diff] [blame] | 30 | |
| 31 | mkdir -p ~/.ssh/config.d |
| 32 | echo "" | tee ~/.ssh/config.d/osm |
| 33 | |
| 34 | |
| 35 | for 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 Garcia | 01972d2 | 2021-10-11 19:52:33 +0200 | [diff] [blame] | 38 | pod_ip=`microk8s.kubectl -n osm get pods $pod_name -o yaml | yq e .status.podIP -` |
| David Garcia | d680be4 | 2021-08-17 11:03:55 +0200 | [diff] [blame] | 39 | echo "Host $module |
| 40 | HostName $pod_ip |
| 41 | User root |
| 42 | # StrictHostKeyChecking no |
| beierlm | e830f62 | 2022-01-18 12:52:23 -0500 | [diff] [blame] | 43 | IdentityFile $PRIVATE_KEY" | tee -a ~/.ssh/config.d/osm |
| David Garcia | d680be4 | 2021-08-17 11:03:55 +0200 | [diff] [blame] | 44 | fi |
| 45 | done |
| 46 | |
| 47 | |
| 48 | import_osm_config="Include config.d/osm" |
| 49 | touch ~/.ssh/config |
| 50 | grep "$import_osm_config" ~/.ssh/config || ( echo -e "$import_osm_config\n$(cat ~/.ssh/config)" > ~/.ssh/config ) |