aboutsummaryrefslogtreecommitdiffstats
path: root/test/vcpe/cleanvGMUX.py
blob: 93135fb0ca986d89750edd5c12d1fa88b3a16466 (plain)
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
#!/usr/bin/env python

import sys
import logging
import requests
import json

gmux_ip = ''
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
logger = logging.getLogger('')
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
auth = 'admin', 'admin'
base_url = ''

def list_interface():
    url = base_url
    logger.info(url)
    r = requests.get(url, headers=headers, auth=auth)
    logger.debug(r)
    response = r.json()

    logger.debug('---------------------------------------------------------------')
    logger.debug(json.dumps(response, indent=4, sort_keys=True))
    logger.debug('---------------------------------------------------------------')

def clean_gmux():
    url = base_url
    r = requests.get(url, headers=headers, auth=auth)
    response = r.json()

    interfaces = response.get('interfaces').get('interface')
    for inf in interfaces:
        name = inf.get('name')        
        if name.startswith('vxlanTun10'):       
            logger.debug('name = {0}'.format(name))
            delete_interface_v3po_l2(name)

    for inf in interfaces:
        name = inf.get('name')        
        if name.startswith('vxlanTun10'):       
            logger.debug('name = {0}'.format(name))
            delete_interface(name)

def delete_interface_v3po_l2(interface_name):
    url = '{0}/interface/{1}/v3po:l2'.format(base_url, interface_name)
    r = requests.delete(url, headers=headers, auth=auth)
    logger.debug(r)

def delete_interface(interface_name):
    url = '{0}/interface/{1}'.format(base_url, interface_name)
    r = requests.delete(url, headers=headers, auth=auth)
    logger.debug(r)
        
if __name__ == '__main__':
    gmux_ip = sys.argv[1]
    base_url = 'http://{0}:8183/restconf/config/ietf-interfaces:interfaces'.format(gmux_ip)
    logger.debug('---------------------------------------------------------------')
    logger.debug('list interfaces before cleaning gmux')
    list_interface()
    clean_gmux()
    logger.debug('---------------------------------------------------------------')
    logger.debug('list interfaces after cleaning gmux')
    list_interface()