-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.py
127 lines (110 loc) · 4.81 KB
/
session.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
from Exscript.util.match import any_match
from Exscript.util.template import eval_file
from Exscript.util.start import quickstart
from Exscript.util.interact import read_login
from Exscript.protocols import SSH2
from Exscript import Host
from Exscript.util.file import get_hosts_from_file, get_accounts_from_file
from Exscript.util.start import start
import test_io
import logging
import parsing
import time
class Sessions(object):
def __init__(self, io):
self.hosts = []
self.accounts = []
self.io = io
self.hosts = get_hosts_from_file(self.io.rootDir + "/" + "hosts")
logging.info("read in hosts" + self.io.rootDir + "/" + "hosts")
if not self.hosts:
logging.info("EMPTY HOST FILE, exit ...")
exit(1)
for h in self.hosts:
logging.info("host:" + h.get_address())
self.accounts = get_accounts_from_file(io.rootDir + "/" + "accounts")
logging.info("read in accounts" + self.io.rootDir + "/" + "accounts")
if not self.accounts:
logging.info("EMPTY ACCOUNT FILE, exit ...")
exit(1)
for a in self.accounts:
logging.info("account:" + a.get_name())
def command_loop(self, job, host, conn):
conn.autoinit()
#conn.execute('show config run')
host = conn.get_host()
logging.info(host)
if not conn.is_app_authenticated() or not conn.is_app_authorized():
logging.info("authentication failed on " + host)
#get list of CPEs
logging.info('show bonding *')
conn.execute('show bonding *')
time.sleep(2)
resp = conn.response.split('\n')
bondings = parsing.handleShowBondingList(resp)
logging.info(','.join(bondings))
#for each bonding get test instance list
for b in bondings:
measurements = {}
bwm = {}
pm = {}
logging.info('show cfmSlaTest *')
conn.execute('cpe ' + str(b) + ' show cfmSlaTest *')
resp = conn.response.split('\n')
instance_ids = parsing.handleShowCfmSlaTestList(resp)
logging.info(str(b) + ': ' + ','.join(instance_ids))
#get bandwidth usages
logging.info('show statis policer *')
conn.execute('cpe ' + str(b) + ' show statistics policer *')
resp = conn.response.split('\n')
bwm = parsing.handleShowStatsPolicerAll(resp)
logging.info(bwm)
conn.execute('cpe ' + str(b) + ' show policerMapping *')
resp = conn.response.split('\n')
logging.info(resp)
pm = parsing.handleShowPolicerMappingAll(resp)
if pm:
logging.info(pm)
bwEntry = {}
bwEntry['ip'] = host
bwEntry['type'] = 4000
bwEntry['cpe'] = str(b)
for (uni, evc) in pm:
bwEntry['UNI'] = uni
bwEntry['EVC'] = evc
for key in bwm:
if key == pm[(uni, evc)]:
bwEntry['pirDrop'] = bwm[pm[(uni, evc)]]['pirDrop']
bwEntry['cirPass'] = bwm[pm[(uni, evc)]]['cirPass']
bwEntry['pirPass'] = bwm[pm[(uni, evc)]]['pirPass']
logging.info(bwEntry)
self.io.createBWReports(**bwEntry)
#get detailed measurements
for id in instance_ids:
logging.info('show cfmSlaTest ID')
cmd = 'cpe ' + str(b) + ' show cfmSlaTest ' + id
logging.info(cmd)
conn.execute(cmd)
resp = conn.response.split('\n')
#logging.info(resp)
measurements.update(parsing.get_test_instance_detail(resp))
logging.info(measurements)
logging.info('show pmstats cfmSlaTest ID')
cmd = 'cpe ' + str(b) + ' show pmstats cfmSlaTest ' + id + ' startInterval current'
logging.info(cmd)
conn.execute(cmd)
resp = conn.response.split('\n')
#logging.info(resp)
measurements.update(parsing.handleShowStatsCfmSlaTest(resp))
measurements['ip'] = host
measurements['type'] = 4000
measurements['cpe'] = str(b)
logging.info(measurements)
#test_io.createReports(self.io, measurements)
self.io.createReports(**measurements)
#logging.info(self.io.rootDir)
conn.send('logout force')
conn.close()
def parallelExec(self):
start(self.accounts, self.hosts, self.command_loop, max_threads = 5)