|
| 1 | +#! /usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright (C) 2009 - 2019 Internet Neutral Exchange Association Company Limited By Guarantee. |
| 4 | +# All Rights Reserved. |
| 5 | +# |
| 6 | +# This file is part of IXP Manager. |
| 7 | +# |
| 8 | +# IXP Manager is free software: you can redistribute it and/or modify it |
| 9 | +# under the terms of the GNU General Public License as published by the Free |
| 10 | +# Software Foundation, version 2.0 of the License. |
| 11 | +# |
| 12 | +# IXP Manager is distributed in the hope that it will be useful, but WITHOUT |
| 13 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | +# more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License v2.0 |
| 18 | +# along with IXP Manager. If not, see: |
| 19 | +# |
| 20 | +# http://www.gnu.org/licenses/gpl-2.0.html |
| 21 | +# |
| 22 | +# Barry O'Donovan <[email protected]> 2016 |
| 23 | + |
| 24 | +# Example script for updating AS112 Bird BGP configs |
| 25 | + |
| 26 | + |
| 27 | +# For keys, see: http://docs.ixpmanager.org/features/api/ |
| 28 | + |
| 29 | + |
| 30 | +KEY="r8sFfkGamCjrbbLC12yIoCJooIRXzY9CYPaLVz92GFQyGqLq" |
| 31 | +BIRDBIN="/usr/sbin/bird" |
| 32 | + |
| 33 | +URL="http://127.0.0.1/api/v4/router/gen-config" |
| 34 | +URL_DONE="http://127.0.0.1/api/v4/router/updated" |
| 35 | +ETCPATH="/usr/local/etc/bird" |
| 36 | +RUNPATH="/var/run/bird" |
| 37 | +LOGPATH="/var/log/bird" |
| 38 | +BIN="/usr/sbin/bird" |
| 39 | + |
| 40 | +mkdir -p $ETCPATH |
| 41 | +mkdir -p $LOGPATH |
| 42 | +mkdir -p $RUNPATH |
| 43 | + |
| 44 | +if [[ -n $1 && $1 = '--quiet' ]]; then |
| 45 | + export QUIET=1 |
| 46 | +else |
| 47 | + export QUIET=0 |
| 48 | + echo -en "\nIXP AS112 BGPd Lisenters\n==============================\n\n" |
| 49 | + echo -e "Verbose mode enabled. Issue --quiet for non-verbose mode (--debug also available)\n" |
| 50 | +fi |
| 51 | + |
| 52 | +if [[ -n $1 && $1 = '--debug' ]]; then |
| 53 | + export QUIET=1 |
| 54 | + export DEBUG=1 |
| 55 | +else |
| 56 | + export DEBUG=0 |
| 57 | +fi |
| 58 | + |
| 59 | +function log { |
| 60 | + if [[ $QUIET -eq 0 && $DEBUG -eq 0 ]]; then |
| 61 | + echo -en $1 |
| 62 | + fi |
| 63 | +} |
| 64 | + |
| 65 | +# These are the handles as configured in your IXP Manager - see: http://docs.ixpmanager.org/features/routers/ |
| 66 | +# |
| 67 | +# This script assumes v6 versions end in -ipv6 |
| 68 | + |
| 69 | +for handle in as112-vix1-ipv4 as112-vix1-ipv6 as112-vix2-ipv4 as112-vix2-ipv6; do |
| 70 | + |
| 71 | + log "Instance for ${handle}:\tConfig: " |
| 72 | + |
| 73 | + cmd="curl --fail -s -H \"X-IXP-Manager-API-Key: ${KEY}\" ${URL}/${handle} >${ETCPATH}/bird-${handle}.conf" |
| 74 | + |
| 75 | + if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi |
| 76 | + eval $cmd |
| 77 | + |
| 78 | + if [[ $? -eq 0 ]]; then |
| 79 | + log "DONE \tDaemon: " |
| 80 | + else |
| 81 | + log "ERROR\n" |
| 82 | + continue |
| 83 | + fi |
| 84 | + |
| 85 | + # are we running or do we need to be started? |
| 86 | + cmd="${BIN}c -s ${RUNPATH}/bird-${handle}.ctl configure" |
| 87 | + if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi |
| 88 | + eval $cmd &>/dev/null |
| 89 | + |
| 90 | + if [[ $? -eq 0 ]]; then |
| 91 | + log "RECONFIGURED \tIXP Manager Updated:" |
| 92 | + else |
| 93 | + cmd="${BIN} -c ${ETCPATH}/bird-${handle}.conf -s ${RUNPATH}/bird-${handle}.ctl" |
| 94 | + |
| 95 | + if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi |
| 96 | + eval $cmd &>/dev/null |
| 97 | + |
| 98 | + if [[ $? -eq 0 ]]; then |
| 99 | + log "STARTED \tIXP Manager Updated:" |
| 100 | + else |
| 101 | + log "ERROR\n" |
| 102 | + continue |
| 103 | + fi |
| 104 | + fi |
| 105 | + |
| 106 | + # tell IXP Manager the router has been updated: |
| 107 | + cmd="curl -s -X POST -H \"X-IXP-Manager-API-Key: ${KEY}\" ${URL_DONE}/${handle} >/dev/null" |
| 108 | + if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi |
| 109 | + eval $cmd |
| 110 | + |
| 111 | + if [[ $? -eq 0 ]]; then |
| 112 | + log "DONE" |
| 113 | + else |
| 114 | + log "ERROR\n" |
| 115 | + continue |
| 116 | + fi |
| 117 | + |
| 118 | + log "\n" |
| 119 | +done |
| 120 | + |
| 121 | +log "\n" |
0 commit comments