blob: ab8e8dfca8723d0a0808955187c63b251da8ac4c [file] [log] [blame]
Sean Dagueaf9bf862015-04-16 08:58:32 -04001#!/bin/bash
2#
3# Copyright 2015 Hewlett-Packard Development Company, L.P.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17# Ping a neutron guest using a network namespace probe
18
19set -o errexit
20set -o pipefail
21
22TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
23
24# This *must* be run as the admin tenant
25source $TOP_DIR/openrc admin admin
26
27function usage {
28 cat - <<EOF
29ping_neutron.sh <net_name> [ping args]
30
31This provides a wrapper to ping neutron guests that are on isolated
32tenant networks that the caller can't normally reach. It does so by
Brian Haley6764eab2023-05-12 16:34:08 -040033using either the DHCP or Metadata network namespace to support both
34ML2/OVS and OVN.
Sean Dagueaf9bf862015-04-16 08:58:32 -040035
36It takes arguments like ping, except the first arg must be the network
37name.
38
39Note: in environments with duplicate network names, the results are
40non deterministic.
41
42This should *really* be in the neutron cli.
43
44EOF
45 exit 1
46}
47
Brian Haley6764eab2023-05-12 16:34:08 -040048# BUG: with duplicate network names, this fails pretty hard since it
49# will just pick the first match.
50function _get_net_id {
51 openstack --os-cloud devstack-admin --os-region-name="$REGION_NAME" --os-project-name admin --os-username admin --os-password $ADMIN_PASSWORD network list | grep $1 | head -n 1 | awk '{print $2}'
52}
53
Sean Dagueaf9bf862015-04-16 08:58:32 -040054NET_NAME=$1
55
56if [[ -z "$NET_NAME" ]]; then
57 echo "Error: net_name is required"
58 usage
59fi
60
Stanislaw Szydloaa81e2e2015-07-27 10:54:44 +020061REMAINING_ARGS="${@:2}"
Sean Dagueaf9bf862015-04-16 08:58:32 -040062
Brian Haley6764eab2023-05-12 16:34:08 -040063NET_ID=`_get_net_id $NET_NAME`
64NET_NS=$(ip netns list | grep "$NET_ID" | head -n 1)
Sean Dagueaf9bf862015-04-16 08:58:32 -040065
66# This runs a command inside the specific netns
Brian Haley6764eab2023-05-12 16:34:08 -040067NET_NS_CMD="ip netns exec $NET_NS"
Sean Dagueaf9bf862015-04-16 08:58:32 -040068
Stanislaw Szydloaa81e2e2015-07-27 10:54:44 +020069PING_CMD="sudo $NET_NS_CMD ping $REMAINING_ARGS"
Sean Dagueaf9bf862015-04-16 08:58:32 -040070echo "Running $PING_CMD"
71$PING_CMD