-
Notifications
You must be signed in to change notification settings - Fork 35
/
f5-export_wideip_config.py
73 lines (64 loc) · 3.16 KB
/
f5-export_wideip_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from datetime import datetime
import argparse
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd
def get_wideip(bigip,user,password):
auth = HTTPBasicAuth('{}'.format(user), '{}'.format(password))
headers = {'Content-Type': "application/json"}
req_vss = requests.get('https://{}/mgmt/tm/gtm/wideip/a?expandSubcollections=true'.format(bigip), headers=headers, auth=auth, verify=False)
wideip_info =req_vss.json()
wideips = wideip_info['items']
df = pd.DataFrame(columns = ['WideIP', 'Pools', 'Last Resort Pool', 'Pool LB Mode', 'Persistence', 'Persistence TTL', 'Persistence CIDR IPv4', 'Persistence CIDR IPv6', 'iRules'])
for wideip in wideips:
### Processing Pools ###
try :
Pools = wideip["pools"]
PoolList = ""
for pool in Pools:
poolName=pool['name']
poolOrder=pool['order']
poolRatio=pool['ratio']
poolInfo=str(poolName + " order: " + str(poolOrder) + " ratio: " + str(poolRatio))
PoolList += str(poolInfo + "; ")
except:
pool = "none"
### Processing last resort pool ###
if wideip['lastResortPool'] :
lastResortPool = wideip['lastResortPool']
else :
lastResortPool = "none"
### Processing Persistence parameters###
PersistenceVAL =wideip['persistence']
if PersistenceVAL == "disabled" :
ttlPersistence = 'Not Apply'
persistCidrIpv4 = 'Not Apply'
persistCidrIpv6 = 'Not Apply'
else :
ttlPersistence = wideip['ttlPersistence']
persistCidrIpv4 = wideip['persistCidrIpv4']
persistCidrIpv6 = wideip['persistCidrIpv6']
### Processing iRules ###
try :
iRules = wideip["rules"]
iRulesList = ""
for irule in iRules:
iRulesList += str(irule + ", ")
except :
iRulesList = "none"
### Formatting wideIP configuration ###
tmp = {'WideIP':wideip['name'], 'Pools':PoolList, 'Last Resort Pool': lastResortPool, 'Pool LB Mode':wideip['poolLbMode'], 'Persistence':wideip['persistence'], 'Persistence TTL': ttlPersistence, 'Persistence CIDR IPv4': persistCidrIpv4, 'Persistence CIDR IPv6': persistCidrIpv6, 'iRules':iRulesList}
df_dictionary = pd.DataFrame([tmp])
df = pd.concat([df, df_dictionary], ignore_index=True)
return df
def main():
currentTime = datetime.now()
parser = argparse.ArgumentParser(description = "This *Python* script helps to export BIGIP's wideIPs configuration to a CSV file", epilog='The script generates a CSV file named as: WideIPInfo-<hostname>_<date>.csv')
parser.add_argument('--bigip', type=str, required=True)
parser.add_argument('--user', type=str, required=True)
parser.add_argument('--password', type=str, required=True)
args = parser.parse_args()
wideip = get_wideip(args.bigip, args.user, args.password)
wideip.to_csv("WideIPInfo-{}_{}.csv".format(args.bigip,currentTime.strftime("%m-%d-%Y")), index = False, sep=',', encoding='utf-8')
if __name__ == "__main__":
main()