Skip to content

Commit c0e64ad

Browse files
committed
first public release of cloudstackOps
0 parents  commit c0e64ad

37 files changed

+6730
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
*.swp
3+
config

README.md

Lines changed: 570 additions & 0 deletions
Large diffs are not rendered by default.

checkRedundantRouters.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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

cleanDHCPipaddress.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
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 clean old DHCP ip address config
23+
# Remi Bergsma - [email protected]
24+
25+
# Config files
26+
DHCP_LEASES="/var/lib/misc/dnsmasq.leases"
27+
DHCP_HOSTS="/etc/dhcphosts.txt"
28+
HOSTS="/etc/hosts"
29+
30+
# Ip address is required argument
31+
ipv4=$1
32+
if [ ! $ipv4 ]
33+
then
34+
echo "Usage: $0 1.2.3.4 [0|1]"
35+
echo "first arg: ip address, second force no/yes"
36+
exit 1
37+
fi
38+
39+
# Be friendly, or use force
40+
FORCE=$2
41+
if [ ! $FORCE ]
42+
then
43+
FORCE=0
44+
fi
45+
46+
# Debug info
47+
echo "Cleaning $ipv4, force=$FORCE"
48+
49+
# Try to find mac address and hostname
50+
MAC=$(grep $ipv4 $DHCP_LEASES | awk '{print $2}')
51+
HOST=$(grep $ipv4 $DHCP_HOSTS | cut -d, -f4)
52+
53+
# Find mac address, alternative version
54+
if [ ! $MAC ]
55+
then
56+
MAC=$(grep $ipv4 $DHCP_HOSTS | cut -d, -f1)
57+
fi
58+
59+
# Need some force
60+
if [ $FORCE -eq 1 ]
61+
then
62+
# Clean ip address
63+
echo "Forcing removal of $ipv4 from $DHCP_HOSTS"
64+
sed -i /$ipv4,/d $DHCP_HOSTS
65+
66+
# Clean hosts file
67+
echo "Forcing removal of $ipv4 from $HOSTS"
68+
sed -i /"$ipv4 "/d $HOSTS
69+
70+
# Clean old mac
71+
if [ $MAC ]
72+
then
73+
echo "Forcing removal of $MAC from $DHCP_HOSTS"
74+
sed -i /$MAC/d $DHCP_HOSTS
75+
fi
76+
exit 0
77+
fi
78+
79+
# No mac found
80+
echo $MAC
81+
if [ ! $MAC ]
82+
then
83+
echo "Error: Could not find Mac address in $DHCP_LEASES"
84+
exit 1
85+
fi
86+
87+
echo $HOST
88+
if [ ! $HOST ]
89+
then
90+
echo "Error: Could not find hostname in $DHCP_HOSTS"
91+
exit 1
92+
fi
93+
94+
# Run the clean script with its required arguments
95+
echo "Running /opt/cloud/bin/edithosts.sh -m $MAC -4 $ipv4 -h $HOST to clean it up. If it does not work, run with force parameter:"
96+
echo "Force like this: $0 $ipv4 1"
97+
/opt/cloud/bin/edithosts.sh -m $MAC -4 $ipv4 -h $HOST
98+

cloudstackops/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Empty for now

0 commit comments

Comments
 (0)