blob: 8b2751f45995c1fe13a20ceaa46fd2c0c2062fa3 [file] [log] [blame]
Yang Xu0f1ee9e2018-11-21 23:20:25 -05001#! /usr/bin/python
2
3import sys
4import logging
5import requests
6import json
7from datetime import datetime
8import time
9
Yang Xu9eae1542018-11-27 13:00:05 -050010gmux_ip = ''
Yang Xu0f1ee9e2018-11-21 23:20:25 -050011logging.basicConfig(level=logging.DEBUG, format='%(message)s')
12logger = logging.getLogger('')
13headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
14auth = 'admin', 'admin'
Yang Xu9eae1542018-11-27 13:00:05 -050015base_url = ''
Yang Xu0f1ee9e2018-11-21 23:20:25 -050016
17def 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
28def 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
46def 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
51def 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
56if __name__ == '__main__':
Yang Xu9eae1542018-11-27 13:00:05 -050057 gmux_ip = sys.argv[1]
58 base_url = 'http://{0}:8183/restconf/config/ietf-interfaces:interfaces'.format(gmux_ip)
Yang Xu0f1ee9e2018-11-21 23:20:25 -050059 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()