Bartek Grzybowski | fbbdbec | 2019-09-25 16:37:05 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Yang Xu | 0f1ee9e | 2018-11-21 23:20:25 -0500 | [diff] [blame] | 2 | |
| 3 | import sys |
| 4 | import logging |
| 5 | import requests |
| 6 | import json |
Yang Xu | 0f1ee9e | 2018-11-21 23:20:25 -0500 | [diff] [blame] | 7 | |
Yang Xu | 9eae154 | 2018-11-27 13:00:05 -0500 | [diff] [blame] | 8 | gmux_ip = '' |
Yang Xu | 0f1ee9e | 2018-11-21 23:20:25 -0500 | [diff] [blame] | 9 | logging.basicConfig(level=logging.DEBUG, format='%(message)s') |
| 10 | logger = logging.getLogger('') |
| 11 | headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} |
| 12 | auth = 'admin', 'admin' |
Yang Xu | 9eae154 | 2018-11-27 13:00:05 -0500 | [diff] [blame] | 13 | base_url = '' |
Yang Xu | 0f1ee9e | 2018-11-21 23:20:25 -0500 | [diff] [blame] | 14 | |
| 15 | def 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 | |
| 26 | def 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: |
| 33 | name = inf.get('name') |
| 34 | if name.startswith('vxlanTun10'): |
| 35 | logger.debug('name = {0}'.format(name)) |
| 36 | delete_interface_v3po_l2(name) |
| 37 | |
| 38 | for inf in interfaces: |
| 39 | name = inf.get('name') |
| 40 | if name.startswith('vxlanTun10'): |
| 41 | logger.debug('name = {0}'.format(name)) |
| 42 | delete_interface(name) |
| 43 | |
| 44 | def 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 | |
| 49 | def 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) |
| 53 | |
| 54 | if __name__ == '__main__': |
Yang Xu | 9eae154 | 2018-11-27 13:00:05 -0500 | [diff] [blame] | 55 | gmux_ip = sys.argv[1] |
| 56 | base_url = 'http://{0}:8183/restconf/config/ietf-interfaces:interfaces'.format(gmux_ip) |
Yang Xu | 0f1ee9e | 2018-11-21 23:20:25 -0500 | [diff] [blame] | 57 | 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() |