This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datagroup.py
99 lines (73 loc) · 2.77 KB
/
datagroup.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# the data file must be transferred to the target LTM via scp or something similar
# the file name and full path must match DG_SRC
import requests, json
# define program-wide variables
BIGIP_ADDRESS = '10.1.1.245'
BIGIP_USER = 'admin'
BIGIP_PASS = 'admin'
DG_FILE = 'Data'
DG_SRC1 = 'file:/var/tmp/PreviousData.txt'
DG_TYPE = 'string'
EXT_DG_NAME = 'Data'
DG_SRC2 = 'file:/var/tmp/CurrentData.txt'
# get data-group info
def get_dg(bigip):
r = bigip.get('%s/ltm/data-group' % BIGIP_URL_BASE)
print json.dumps(r.json())
def create_sys_file(bigip):
payload = {}
payload['name'] = DG_FILE
payload['separator'] = ':='
payload['sourcePath'] = DG_SRC1
payload['type'] = DG_TYPE
print json.dumps(payload)
r = bigip.post('%s/sys/file/data-group' % BIGIP_URL_BASE, data=json.dumps(payload))
print json.dumps(r.json())
def create_ext_dg(bigip):
payload = {}
payload['name'] = EXT_DG_NAME
payload['externalFileName'] = '/Common/%s' % DG_FILE
print json.dumps(payload)
r = bigip.post('%s/ltm/data-group/external' % BIGIP_URL_BASE, data=json.dumps(payload))
print json.dumps(r.json())
def update_sys_file(bigip):
payload = {}
payload['name'] = DG_FILE
payload['separator'] = ':='
payload['sourcePath'] = DG_SRC2
print json.dumps(payload)
r = bigip.put('%s/sys/file/data-group/%s' % (BIGIP_URL_BASE, DG_FILE), data=json.dumps(payload))
print json.dumps(r.json())
def update_ext_dg(bigip):
payload = {}
payload['name'] = EXT_DG_NAME
print json.dumps(payload)
r = bigip.put('%s/ltm/data-group/external/%s' % (BIGIP_URL_BASE, DG_FILE), data=json.dumps(payload))
print json.dumps(r.json())
def save_config(bigip):
payload = {}
payload['command'] = 'save'
print json.dumps(payload)
r = bigip.post('%s/sys/config' % BIGIP_URL_BASE, data=json.dumps(payload))
print json.dumps(r.json())
# REST resource for BIG-IP that all other requests will use
bigip = requests.session()
bigip.auth = (BIGIP_USER, BIGIP_PASS)
bigip.verify = False
bigip.headers.update({'Content-Type' : 'application/json'})
print "created REST resource for BIG-IP at %s..." % BIGIP_ADDRESS
# Requests requires a full URL to be sent as arg for every request, define base URL globally here
BIGIP_URL_BASE = 'https://%s/mgmt/tm' % BIGIP_ADDRESS
# get data info
get_dg(bigip)
print "got data group info"
create_sys_file(bigip)
print "created sys file for external data group"
create_ext_dg(bigip)
print "created external data group"
update_sys_file(bigip)
print "updated sys file for external data group"
update_ext_dg(bigip)
print "updated external data group"
save_config(bigip)
print "saved config"