Yang Xu | 0f1ee9e | 2018-11-21 23:20:25 -0500 | [diff] [blame] | 1 | #! /usr/bin/python |
| 2 | |
| 3 | import sys |
| 4 | import logging |
| 5 | import requests |
| 6 | import json |
| 7 | from datetime import datetime |
| 8 | import time |
| 9 | |
Yang Xu | 9eae154 | 2018-11-27 13:00:05 -0500 | [diff] [blame^] | 10 | gmux_ip = '' |
Yang Xu | 0f1ee9e | 2018-11-21 23:20:25 -0500 | [diff] [blame] | 11 | logging.basicConfig(level=logging.DEBUG, format='%(message)s') |
| 12 | logger = logging.getLogger('') |
| 13 | headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} |
| 14 | auth = 'admin', 'admin' |
Yang Xu | 9eae154 | 2018-11-27 13:00:05 -0500 | [diff] [blame^] | 15 | base_url = '' |
Yang Xu | 0f1ee9e | 2018-11-21 23:20:25 -0500 | [diff] [blame] | 16 | |
| 17 | def list_interface(): |
| 18 | url = base_url |
| 19 | logger.info(url) |
| 20 | r = requests.get(url, headers=headers, auth=auth) |
| 21 | logger.debug(r) |
| 22 | response = r.json() |
| 23 | |
| 24 | logger.debug('---------------------------------------------------------------') |
| 25 | logger.debug(json.dumps(response, indent=4, sort_keys=True)) |
| 26 | logger.debug('---------------------------------------------------------------') |
| 27 | |
| 28 | def clean_gmux(): |
| 29 | url = base_url |
| 30 | r = requests.get(url, headers=headers, auth=auth) |
| 31 | response = r.json() |
| 32 | |
| 33 | interfaces = response.get('interfaces').get('interface') |
| 34 | for inf in interfaces: |
| 35 | name = inf.get('name') |
| 36 | if name.startswith('vxlanTun10'): |
| 37 | logger.debug('name = {0}'.format(name)) |
| 38 | delete_interface_v3po_l2(name) |
| 39 | |
| 40 | for inf in interfaces: |
| 41 | name = inf.get('name') |
| 42 | if name.startswith('vxlanTun10'): |
| 43 | logger.debug('name = {0}'.format(name)) |
| 44 | delete_interface(name) |
| 45 | |
| 46 | def delete_interface_v3po_l2(interface_name): |
| 47 | url = '{0}/interface/{1}/v3po:l2'.format(base_url, interface_name) |
| 48 | r = requests.delete(url, headers=headers, auth=auth) |
| 49 | logger.debug(r) |
| 50 | |
| 51 | def delete_interface(interface_name): |
| 52 | url = '{0}/interface/{1}'.format(base_url, interface_name) |
| 53 | r = requests.delete(url, headers=headers, auth=auth) |
| 54 | logger.debug(r) |
| 55 | |
| 56 | if __name__ == '__main__': |
Yang Xu | 9eae154 | 2018-11-27 13:00:05 -0500 | [diff] [blame^] | 57 | gmux_ip = sys.argv[1] |
| 58 | 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] | 59 | logger.debug('---------------------------------------------------------------') |
| 60 | logger.debug('list interfaces before cleaning gmux') |
| 61 | list_interface() |
| 62 | clean_gmux() |
| 63 | logger.debug('---------------------------------------------------------------') |
| 64 | logger.debug('list interfaces after cleaning gmux') |
| 65 | list_interface() |