blob: f1e91a757588b73378c92ff10391e5aec34cb3e3 [file] [log] [blame]
Bartek Grzybowskifbbdbec2019-09-25 16:37:05 +02001#!/usr/bin/env python
Yang Xu0f1ee9e2018-11-21 23:20:25 -05002
3import sys
4import logging
5import requests
6import json
Yang Xu0f1ee9e2018-11-21 23:20:25 -05007
Yang Xu9eae1542018-11-27 13:00:05 -05008gmux_ip = ''
Yang Xu0f1ee9e2018-11-21 23:20:25 -05009logging.basicConfig(level=logging.DEBUG, format='%(message)s')
10logger = logging.getLogger('')
11headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
12auth = 'admin', 'admin'
Yang Xu9eae1542018-11-27 13:00:05 -050013base_url = ''
Yang Xu0f1ee9e2018-11-21 23:20:25 -050014
15def list_interface():
16 url = base_url
17 logger.info(url)
18 r = requests.get(url, headers=headers, auth=auth)
19 logger.debug(r)
20 response = r.json()
21
22 logger.debug('---------------------------------------------------------------')
23 logger.debug(json.dumps(response, indent=4, sort_keys=True))
24 logger.debug('---------------------------------------------------------------')
25
26def clean_gmux():
27 url = base_url
28 r = requests.get(url, headers=headers, auth=auth)
29 response = r.json()
30
31 interfaces = response.get('interfaces').get('interface')
32 for inf in interfaces:
Bartek Grzybowskid8affb32020-03-04 15:45:08 +010033 name = inf.get('name')
34 if name.startswith('vxlanTun10'):
Yang Xu0f1ee9e2018-11-21 23:20:25 -050035 logger.debug('name = {0}'.format(name))
36 delete_interface_v3po_l2(name)
37
38 for inf in interfaces:
Bartek Grzybowskid8affb32020-03-04 15:45:08 +010039 name = inf.get('name')
40 if name.startswith('vxlanTun10'):
Yang Xu0f1ee9e2018-11-21 23:20:25 -050041 logger.debug('name = {0}'.format(name))
42 delete_interface(name)
43
44def delete_interface_v3po_l2(interface_name):
45 url = '{0}/interface/{1}/v3po:l2'.format(base_url, interface_name)
46 r = requests.delete(url, headers=headers, auth=auth)
47 logger.debug(r)
48
49def delete_interface(interface_name):
50 url = '{0}/interface/{1}'.format(base_url, interface_name)
51 r = requests.delete(url, headers=headers, auth=auth)
52 logger.debug(r)
Bartek Grzybowskid8affb32020-03-04 15:45:08 +010053
Yang Xu0f1ee9e2018-11-21 23:20:25 -050054if __name__ == '__main__':
Yang Xu9eae1542018-11-27 13:00:05 -050055 gmux_ip = sys.argv[1]
56 base_url = 'http://{0}:8183/restconf/config/ietf-interfaces:interfaces'.format(gmux_ip)
Yang Xu0f1ee9e2018-11-21 23:20:25 -050057 logger.debug('---------------------------------------------------------------')
58 logger.debug('list interfaces before cleaning gmux')
59 list_interface()
60 clean_gmux()
61 logger.debug('---------------------------------------------------------------')
62 logger.debug('list interfaces after cleaning gmux')
63 list_interface()