addition of query for port cols, beginning of acquiring port cols

This commit is contained in:
Dipti
2021-02-10 02:12:49 -08:00
parent c3c0924cda
commit 1b7a29f77e
3 changed files with 50 additions and 27 deletions

View File

@@ -619,18 +619,18 @@ class LFCliBase:
#================ Pandas Dataframe Functions ======================================
#takes any dataframe and returns the specified outputfile format of it
def df_to_file(dataframe, outputfile_name_path):
def df_to_file(dataframe=None, output_f=None):
df = dataframe
if output_file_type == 'hdf':
return df.to_hdf(output_file_type, 'table', append=True)
if output_file_type == 'parquet':
return df.to_parquet(output_file_type, engine='pyarrow')
if output_file_type == 'png':
if output_f == 'hdf':
return df.to_hdf(output_f, 'table', append=True)
if output_f == 'parquet':
return df.to_parquet(output_f, engine='pyarrow')
if output_f == 'png':
fig = df.plot().get_figure()
return fig.savefig(output_file_type)
if output_file_type.lower() in ['excel', 'xlsx'] or report_file.split('.')[-1] == 'xlsx':
return df.to_excel(output_file_type, index=False)
if output_file_type == 'df':
return fig.savefig(output_f)
if output_f.lower() in ['excel', 'xlsx']:
return df.to_excel(output_f, index=False)
if output_f == 'df':
return df
supported_formats = ['csv', 'json', 'stata', 'pickle','html']
#for format in supported_formats:
@@ -638,7 +638,10 @@ class LFCliBase:
# return exec('df.to_' + x + '("'+file_name'")')
#takes any format of a file and returns a dataframe of it
def file_to_df(file_type, file_name):
def file_to_df(file_name=None):
pass
def compare_two_df(dataframe_one=None,dataframe_two=None):
pass
def append_df_to_file(dataframe, file_name):

View File

@@ -1160,7 +1160,8 @@ class L3CXProfile(LFCliBase):
def monitor(self,
duration_sec=60,
monitor_interval=1,
col_names=None,
layer3_cols=None,
port_mgr_cols=None,
created_cx=None,
monitor=True,
report_file=None,
@@ -1182,7 +1183,7 @@ class L3CXProfile(LFCliBase):
raise ValueError("Monitor needs a list of Layer 3 connections")
if (monitor_interval is None) or (monitor_interval < 1):
raise ValueError("L3CXProfile::monitor wants monitor_interval >= 1 second")
if col_names is None:
if layer3_cols is None:
raise ValueError("L3CXProfile::monitor wants a list of column names to monitor")
if output_format is not None:
if output_format.lower() != report_file.split('.')[-1]:
@@ -1204,9 +1205,9 @@ class L3CXProfile(LFCliBase):
pass
#================== Step 1, set column names and header row
col_names=[self.replace_special_char(x) for x in col_names]
fields = ",".join(col_names)
header_row=col_names
layer3_cols=[self.replace_special_char(x) for x in layer3_cols]
fields = ",".join(layer3_cols)
header_row=layer3_cols
header_row.insert(0,'Timestamp milliseconds')
header_row.insert(0,'Timestamp')
@@ -1229,9 +1230,16 @@ class L3CXProfile(LFCliBase):
#csvwriter.writerow(arguments)
csvwriter.writerow(header_row)
#get shelf,resource,port to json_get from /port
cx_a_side_list=[]
port_info_dict=self.json_get("/endp/%s?fields=eid" % (cx_a_side_list))
# for x in range(0,int(round(iterations,0))):
while datetime.datetime.now() < end_time:
response = self.json_get("/endp/%s?fields=%s" % (created_cx, fields))
#get info from port manager with list of values from cx_a_side_list
if "endpoint" not in response or response is None:
print(response)
raise ValueError("Cannot find columns requested to be searched. Exiting script, please retry.")
@@ -1273,7 +1281,9 @@ class L3CXProfile(LFCliBase):
#here, do df to final report file output
if output_format.lower() != 'csv':
dataframe_output = self.file_to_df(report_file, output_format)
dataframe_output = self.file_to_df(file_name=report_file)
file_output_file = self.df_to_file(dataframe=dataframe_output, output_f=output_format)

View File

@@ -137,7 +137,8 @@ def main():
optional.append({'name':'--a_min','help':'--a_min bps rate minimum for side_a', 'default':256000})
optional.append({'name':'--b_min','help':'--b_min bps rate minimum for side_b', 'default':256000})
optional.append({'name':'--test_duration','help':'--test_duration sets the duration of the test', 'default':"2m"})
optional.append({'name':'--col_names','help':'Columns wished to be monitor', 'default':['name','tx bytes','rx bytes']})
optional.append({'name':'--layer3_cols','help':'Columns wished to be monitored from layer 3 endpoint tab', 'default':['name','tx bytes','rx bytes']})
optional.append({'name':'--port_mgr_cols','help':'Columns wished to be monitored from port manager tab', 'default':['ap','ip','rx bytes']})
optional.append({'name':'--compared_report','help':'report path and file which is wished to be compared with new report', 'default':None})
parser = LFCliBase.create_basic_argparse(
prog='test_ipv4_variable_time.py',
@@ -179,13 +180,14 @@ python3 ./test_ipv4_variable_time.py
--output_format csv
--report_file ~/Documents/results.csv (Example of csv file output - please use another extension for other file formats)
--compared_report ~/Documents/results_prev.csv (Example of csv file retrieval - please use another extension for other file formats) - UNDER CONSTRUCTION
--col_names 'name','tx bytes','rx bytes','dropped' (column names from the GUI to print on report - please read below to know what to put here according to preferences)
--layer3_cols'name','tx bytes','rx bytes','dropped' (column names from the GUI to print on report - please read below to know what to put here according to preferences)
--port_mgr_cols 'ap','ip' (column names from the GUI to print on report - please read below to know what to put here according to preferences)
--debug
===============================================================================
** FURTHER INFORMATION **
Using the col_names flag:
Currently the output function does not support inputting the columns in col_names the way they are displayed in the GUI. This quirk is under construction. To output
Currently the output function does not support inputting the columns in layer3_cols the way they are displayed in the GUI. This quirk is under construction. To output
certain columns in the GUI in your final report, please match the according GUI column display to it's counterpart to have the columns correctly displayed in
your report.
@@ -277,7 +279,7 @@ python3 ./test_ipv4_variable_time.py
print('Defaulting to csv data file output type, naming it data.csv.')
report_f= str(path)+'/data.csv'
output='csv'
if self.debug:
if args.debug:
print("Saving report data in ... " + report_f)
else:
report_f=args.report_file
@@ -328,17 +330,25 @@ python3 ./test_ipv4_variable_time.py
except:
raise ValueError('Try setting the upstream port flag if your device does not have an eth1 port')
if type(args.col_names) is not list:
col_names=list(args.col_names.split(","))
if type(args.layer3_cols) is not list:
layer3_cols=list(args.layer3_cols.split(","))
#send col names here to file to reformat
else:
col_names = args.col_names
layer3_cols = args.layer3_cols
#send col names here to file to reformat
if type(args.port_mgr_cols) is not list:
port_mgr_cols=list(args.port_mgr_cols.split(","))
#send col names here to file to reformat
else:
port_mgr_cols=args.port_mgr_cols
if args.debug:
print("Column names are...")
print(col_names)
print("Layer 3 Endp column names are...")
print(layer3_cols)
print("Port Manager column names are...")
print(port_mgr_cols)
ip_var_test.l3cxprofile.monitor(col_names=col_names,
ip_var_test.l3cxprofile.monitor(layer3_cols=layer3_cols,
port_mgr_cols=port_mgr_cols,
report_file=report_f,
duration_sec=ip_var_test.parse_time(args.test_duration).total_seconds(),
created_cx= layer3connections,