|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +# Copyright 2015, Schuberg Philis BV |
| 4 | +# |
| 5 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 6 | +# or more contributor license agreements. See the NOTICE file |
| 7 | +# distributed with this work for additional information |
| 8 | +# regarding copyright ownership. The ASF licenses this file |
| 9 | +# to you under the Apache License, Version 2.0 (the |
| 10 | +# "License"); you may not use this file except in compliance |
| 11 | +# with the License. You may obtain a copy of the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, |
| 16 | +# software distributed under the License is distributed on an |
| 17 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 18 | +# KIND, either express or implied. See the License for the |
| 19 | +# specific language governing permissions and limitations |
| 20 | +# under the License. |
| 21 | + |
| 22 | +# Script to report redundant routers that run on the same pod |
| 23 | +# Remi Bergsma - [email protected] |
| 24 | + |
| 25 | +import time |
| 26 | +import sys |
| 27 | +import getopt |
| 28 | +from cloudstackops import cloudstackops |
| 29 | +import os.path |
| 30 | +from random import choice |
| 31 | +from prettytable import PrettyTable |
| 32 | + |
| 33 | +# Function to handle our arguments |
| 34 | + |
| 35 | + |
| 36 | +def handleArguments(argv): |
| 37 | + global DEBUG |
| 38 | + DEBUG = 0 |
| 39 | + global DRYRUN |
| 40 | + DRYRUN = 1 |
| 41 | + global domainname |
| 42 | + domainname = '' |
| 43 | + global configProfileName |
| 44 | + configProfileName = '' |
| 45 | + |
| 46 | + # Usage message |
| 47 | + help = "Usage: ./" + os.path.basename(__file__) + ' [options]' + \ |
| 48 | + '\n --config-profile -c \t\t\tSpecify the CloudMonkey profile name to get the credentials from (or specify in ./config file)' + \ |
| 49 | + '\n --debug\t\t\t\tEnable debug mode' + \ |
| 50 | + '\n --exec\t\t\t\tExecute for real (not needed for check* scripts)' |
| 51 | + |
| 52 | + try: |
| 53 | + opts, args = getopt.getopt( |
| 54 | + argv, "hc:d:p:", [ |
| 55 | + "config-profile=", "debug", "exec", "is-projectvm"]) |
| 56 | + except getopt.GetoptError as e: |
| 57 | + print "Error: " + str(e) |
| 58 | + print help |
| 59 | + sys.exit(2) |
| 60 | + |
| 61 | + if len(opts) == 0: |
| 62 | + print help |
| 63 | + sys.exit(2) |
| 64 | + |
| 65 | + for opt, arg in opts: |
| 66 | + if opt == '-h': |
| 67 | + print help |
| 68 | + sys.exit() |
| 69 | + elif opt in ("-c", "--config-profile"): |
| 70 | + configProfileName = arg |
| 71 | + elif opt in ("--debug"): |
| 72 | + DEBUG = 1 |
| 73 | + elif opt in ("--exec"): |
| 74 | + DRYRUN = 0 |
| 75 | + |
| 76 | + # Default to cloudmonkey default config file |
| 77 | + if len(configProfileName) == 0: |
| 78 | + configProfileName = "config" |
| 79 | + |
| 80 | +# Parse arguments |
| 81 | +if __name__ == "__main__": |
| 82 | + handleArguments(sys.argv[1:]) |
| 83 | + |
| 84 | +# Init our class |
| 85 | +c = cloudstackops.CloudStackOps(DEBUG, DRYRUN) |
| 86 | + |
| 87 | +if DEBUG == 1: |
| 88 | + print "Warning: Debug mode is enabled!" |
| 89 | + |
| 90 | +if DRYRUN == 1: |
| 91 | + print "Warning: dry-run mode is enabled, not running any commands!" |
| 92 | + |
| 93 | +# make credentials file known to our class |
| 94 | +c.configProfileName = configProfileName |
| 95 | + |
| 96 | +# Init the CloudStack API |
| 97 | +c.initCloudStackAPI() |
| 98 | + |
| 99 | +if DEBUG == 1: |
| 100 | + print "API address: " + c.apiurl |
| 101 | + print "ApiKey: " + c.apikey |
| 102 | + print "SecretKey: " + c.secretkey |
| 103 | + |
| 104 | +# Get the redundant routers |
| 105 | +redRouters = c.getRedundantRouters('{}') |
| 106 | + |
| 107 | +# Look for routers on the same POD |
| 108 | +if redRouters is not None and redRouters is not 1: |
| 109 | + for routerData in redRouters.itervalues(): |
| 110 | + if routerData is None or routerData == 1: |
| 111 | + continue |
| 112 | + if routerData['router'].podid == routerData['routerPeer'].podid: |
| 113 | + print "Warning: Router pair " + routerData['router'].name + " and " + routerData['routerPeer'].name + " run on same POD!" + " (" + routerData['router'].podid + " / " + routerData['routerPeer'].podid + ")" |
| 114 | + if DEBUG == 1: |
| 115 | + print "DEBUG: " + routerData['router'].name + " has peer " + routerData['routerPeer'].name |
0 commit comments