Ejemplo n.º 1
0
def group_name_usage(report_columns_usage_dct, device_rename_df, max_title,
                     force_group_name_usage_update_flag):
    """
    Function to determine if device alias Group_Name column required in report tables.
    Value (True or False) written to the dictonary so no need to return value.
    """

    info = f'Device Group Name usage'

    # if all devices were renamed and force flag is off column is dropped from report tables
    if device_rename_df['Device_Host_Name_rename'].notna().all(
    ) and not force_group_name_usage_update_flag:
        report_columns_usage_dct['group_name_usage'] = False
        print(info, end=" ")
        status_info('off', max_title, len(info))
    # if no information in report_columns_usage_dct or force flag is on or any device keep old name
    # ask user input
    elif report_columns_usage_dct.get('group_name_usage') is None or \
            force_group_name_usage_update_flag or \
                device_rename_df['Device_Host_Name_rename'].isna().any():
        print('\n')
        reply = reply_request(
            'Do you want to use Alias Group Device names? (y)es/(n)o: ')
        print('\n')
        if reply == 'y':
            report_columns_usage_dct['group_name_usage'] = True
            print(info, end=" ")
            status_info('on', max_title, len(info))
        else:
            report_columns_usage_dct['group_name_usage'] = False
            print(info, end=" ")
            status_info('off', max_title, len(info))
Ejemplo n.º 2
0
def download_summary(ns_3par_df, report_data_lst):
    """Function to print configurations download from STATs summary and
    save summary to file if user agreed"""

    if not 'STATs_status' in ns_3par_df.columns and \
        not 'Local_status' in ns_3par_df.columns:
        ns_3par_df['Status'] = 'skip'

    print('\n')
    print('3PAR Storage Systems configuaration download summary')
    print(ns_3par_df)
    print('\n')

    # if 'STATs_status' in ns_3par_df.columns and \
    #     ns_3par_df['STATs_status'].isin(['skip', 'fail']).any():
    # print('Some configurations are missing.')
    query = 'Do you want to SAVE download SUMMARY? (y)es/(n)o: '
    reply = reply_request(query)
    if reply == 'y':
        save_xlsx_file(ns_3par_df,
                       'stats_summary',
                       report_data_lst,
                       force_flag=True)
Ejemplo n.º 3
0
def define_device_to_rename(portshow_aggregated_df, device_rename_df,
                            max_title, force_form_update_flag,
                            force_change_data_lst, report_data_lst):
    """
    Function to define (create new, return previously saved or return empty) 
    device_rename_df DataFrame to apply device rename schema
    """

    # if device_rename_df DataFrame doesn't exist (1st iteration)
    # or force flag to change device_rename_df DataFrame is on
    # or some related DataFrames was forcibly changed
    if device_rename_df is None or force_form_update_flag:
        print('\n')
        if force_change_data_lst:
            print(
                f"Request to force change of {', '.join(force_change_data_lst)} data was received."
            )
        reply = reply_request(
            'Do you want to change auto assigned device names? (y)es/(n)o: ')
        if reply == 'y':
            # if device_rename_df DataFrame doesn't exist (1st iteration)
            if device_rename_df is None:
                # create new device rename DataFrame
                manual_device_rename_df = create_device_rename_form(
                    portshow_aggregated_df)
            else:
                # if any related DataFrames was forcibly changed ask if device rename form reset required
                if force_change_data_lst:
                    reply = reply_request(
                        'Do you want to apply previously saved device rename schema? (y)es/(n)o: '
                    )
                    if reply == 'y':
                        print('\n')
                        return device_rename_df
                    else:
                        print('\n')
                        reply = reply_request(
                            'Do you want to reset device rename form? (y)es/(n)o: '
                        )
                        if reply == 'y':
                            # create new device rename DataFrame
                            manual_device_rename_df = create_device_rename_form(
                                portshow_aggregated_df)
                        else:
                            # use saved device rename DataFrame
                            manual_device_rename_df = device_rename_df.copy()
                else:
                    # if no force change in related DataFrames but device_rename_df DataFrame
                    # change initiated use saved device rename DataFrame
                    manual_device_rename_df = device_rename_df.copy()

            # save manual_device_rename_df DataFrame to excel file to use at as form to fill
            sheet_title = 'device_rename_form'
            file_path = save_xlsx_file(manual_device_rename_df,
                                       sheet_title,
                                       report_data_lst,
                                       force_flag=True)
            file_name = os.path.basename(file_path)
            file_directory = os.path.dirname(file_path)
            print(
                f"\nTo rename devices put new names into the '{file_name}' file, '{sheet_title}' sheet in\n'{file_directory}' directory"
            )
            print('ATTN! CLOSE file after changes were made\n')
            # complete the manual_device_rename_df form and import it
            reply = reply_request("When finish enter 'yes': ", ['yes'])
            if reply == 'y':
                print('\n')
                device_rename_df = dataframe_import(sheet_title,
                                                    max_title,
                                                    init_file=file_path,
                                                    header=2)

        else:
            # if don't change auto assigned names save empty device_rename_df DataFrame
            device_rename_columns = [
                'Fabric_name', 'Device_Host_Name', 'Group_Name', 'deviceType',
                'deviceSubtype', 'Device_Host_Name_rename'
            ]
            device_rename_df = pd.DataFrame(columns=device_rename_columns)
    else:
        # check loaded device_rename_df DataFrame (if it's empty)
        device_rename_df = verify_data(report_data_lst, ['device_rename'],
                                       device_rename_df,
                                       show_status=False)

    return device_rename_df
Ejemplo n.º 4
0
def fabriclabels_main(switchshow_ports_df, switch_params_df, fabricshow_df,
                      ag_principal_df, report_data_lst):
    """Function to set Fabric labels"""

    # report_data_lst contains information:
    # customer_name, dir_report, dir to save obtained data, max_title, report_steps_dct
    customer_name, report_path, _, max_title, report_steps_dct = report_data_lst

    # names to save data obtained after current module execution
    data_names = ['fabric_labels']
    # service step information
    print(f'\n\n{report_steps_dct[data_names[0]][3]}\n')

    # load data if they were saved on previos program execution iteration
    data_lst = load_data(report_data_lst, *data_names)
    # unpacking DataFrames from the loaded list with data
    # pylint: disable=unbalanced-tuple-unpacking
    fabricshow_ag_labels_df, = data_lst

    # list of data to analyze from report_info table
    analyzed_data_names = []
    # force run when any data from data_lst was not saved (file not found) or
    # procedure execution explicitly requested for output data or data used during fn execution
    force_run = verify_force_run(data_names, data_lst, report_steps_dct,
                                 max_title, analyzed_data_names)

    if force_run:
        print('\nSETTING UP FABRICS NAMES AND LABELS  ...\n')

        fabricshow_summary_df = auto_fabrics_labeling(switchshow_ports_df,
                                                      switch_params_df,
                                                      fabricshow_df,
                                                      report_data_lst)

        # display automatic fabric labeling
        info_labels = [
            'Fabric_name', 'Fabric_label', 'chassis_name',
            'Principal_switch_name', 'Fabric_ID', 'FC_Route', 'Total_switch',
            'Domain_IDs', 'Switch_names', 'Device_ports', 'Online_ports',
            'LS_type', 'Fabric_Name'
        ]
        # service file name for detailed information
        current_date = str(date.today())
        file_name = customer_name + '_' + report_steps_dct[
            'fabricshow_summary'][2] + '_' + current_date + '.xlsx'
        # file_name = customer_name + '_analysis_report_' + current_date + '.xlsx'
        print('\nAutomatic fabrics labeling\n')
        # set option to show all columns
        with pd.option_context('display.max_columns', None,
                               'display.expand_frame_repr', False):
            # pd.set_option('max_columns', None)
            # pd.set_option('expand_frame_repr', False)
            print(fabricshow_summary_df.loc[:, info_labels])
        print(
            f"\nFor detailed switch port types and numbers statistic in each fabric check '{file_name}' file 'fabricshow_statistics' sheet in"
        )
        print(f'{report_path} directory')
        print('ATTN! CLOSE file after check\n')

        # ask user if Automatic Fabric labeling need to be corrected
        query = 'Do you want to change Fabrics Names or Labels? (y)es/(n)o: '
        reply = reply_request(query)
        if reply == 'y':
            # saving DataFrame to Excel to check during manual labeling if required
            save_xlsx_file(fabricshow_summary_df,
                           'fabricshow_summary',
                           report_data_lst,
                           force_flag=True)
            fabricshow_summary_df = manual_fabrics_labeling(
                fabricshow_summary_df, info_labels)

        # takes all switches working in Native and AG switches
        # merge the in one DataFrame and identify which Fabrics they belong too with fabricshow_summary DataFrame
        fabricshow_ag_labels_df = native_ag_labeling(fabricshow_df,
                                                     ag_principal_df,
                                                     fabricshow_summary_df)

        # # disable option to show all columns
        # pd.reset_option('max_columns')
        # pd.reset_option('expand_frame_repr')

        # create list with partitioned DataFrames
        data_lst = [fabricshow_ag_labels_df]
        # saving data to json or csv file
        save_data(report_data_lst, data_names, *data_lst)
    # verify if loaded data is empty and replace information string with empty DataFrame
    else:
        fabricshow_ag_labels_df = verify_data(report_data_lst, data_names,
                                              *data_lst)
        data_lst = [fabricshow_ag_labels_df]
    # save data to excel file if it's required
    for data_name, data_frame in zip(data_names, data_lst):
        save_xlsx_file(data_frame, data_name, report_data_lst)

    return fabricshow_ag_labels_df
Ejemplo n.º 5
0
def manual_fabrics_labeling(fabricshow_summary_df, info_labels):
    """Function to manual change Fabric Name and Fabric Label."""
    # copy of initial fabricshow_summary DataFrame
    # to be able to reset all changes
    fabricshow_summary_default_df = fabricshow_summary_df.copy()
    # convert DataFrame indexes to string versions
    fabric_indexes_str_lst = [str(i) for i in fabricshow_summary_df.index]
    # DataFrame operation options (save, reset, exit)
    opeartion_options_lst = ['s', 'r', 'v', 'x']
    # aggregated list of available operations
    full_options_lst = fabric_indexes_str_lst + opeartion_options_lst
    # parameters to change
    rename_options_dct = {'NAME': 'Fabric_name', 'LABEL': 'Fabric_label'}

    # user input from full_options_lst
    # initial value is None to enter while
    input_option = None
    # work with DataFrame until it is saved or exit without saving
    while not input_option in ['s', 'x']:

        fabricshow_summary_df.sort_values(by=[
            'Fabric_name', 'Fabric_label', 'Principal_switch_name',
            'Domain_IDs'
        ],
                                          inplace=True,
                                          ignore_index=True)
        # no need to print fabric info after verification
        if input_option != 'v':
            # printing actual fabricshow_summary DataFrame
            print('\nCurrent fabric labeling\n')
            print(fabricshow_summary_df.loc[:, info_labels])

        # printing menu options to choose to work with DataFrame
        # save, reset, exit or fabric index number to change
        print(
            '\nS/s - Save changes in labeling\nR/r - Reset to default labeling\nV/v - Veriify labeling\nX/x - Exit without saving'
        )
        print(
            f"{', '.join(fabric_indexes_str_lst)} - Choose fabric index to change labeling\n"
        )
        # reset input_option value after each iteration to enter while loop
        input_option = reply_request("Choose option: ",
                                     reply_options=full_options_lst,
                                     show_reply=True)

        # user input is fabric index to change labeling
        if input_option in fabric_indexes_str_lst:
            print('\n')
            # make copy of actual fabricshow_summary DataFrame
            # to be able to reset current iteration changes
            fabricshow_summary_before_df = fabricshow_summary_df.copy()

            # convert user input fabric number to integer
            fabric_num = int(input_option)
            # printing information for current fabric
            print(fabricshow_summary_df.iloc[fabric_num])
            print('\n')

            # list to save user input
            reply_lst = []
            # initial user input to check if nan is entered
            value = 'empty'
            # ask user to change labels and names by looping over rename_options_dct
            for option_name, option_column in rename_options_dct.items():
                if value:
                    reply = reply_request(
                        f'Do you want to change Fabric {option_name}? (y)es/(n)o: '
                    )
                    # save user input to the list
                    reply_lst.append(reply)
                    # if user want to change name or label ask to enter new value
                    if reply == 'y':
                        current_value = fabricshow_summary_df.loc[
                            fabric_num, rename_options_dct[option_name]]
                        value = input(
                            f'\nEnter new Fabric {option_name}. 0 or None will remove fabric from assessment. Current value is {current_value}: '
                        )
                        value = value.strip()
                        # 0 or None means no labeling
                        if value.lower() in ['0', 'none']:
                            value = None
                            fabricshow_summary_df.loc[
                                fabric_num,
                                ['Fabric_name', 'Fabric_label']] = [
                                    np.nan, np.nan
                                ]
                        elif len(value) == 0:
                            value = current_value
                            print(f'Fabric {option_name} was not changed')
                        else:
                            # change values in fabricshow_summary DataFrame
                            fabricshow_summary_df.loc[fabric_num,
                                                      option_column] = value
            # if user didn't reply "no" two times
            if reply_lst != ['n'] * 2:
                print('\n')
                # print current fabric information after change
                print(fabricshow_summary_df.iloc[fabric_num])
                print('\n')
                # verify if Fabric names or label is NaN and ask input
                label_name_uniformity = fabricshow_summary_df.loc[
                    fabric_num,
                    rename_options_dct.values()].isna().nunique() == 1
                if not label_name_uniformity:
                    print(
                        'Fabric NAME and Fabric LABEL fields BOTH must have values'
                    )
                    # verify which label have Nan value
                    nan_option_name, = [
                        key for key, value in rename_options_dct.items()
                        if pd.isna(fabricshow_summary_df.loc[fabric_num,
                                                             value])
                    ]
                    while True:
                        current_value = fabricshow_summary_df.loc[
                            fabric_num, rename_options_dct[nan_option_name]]
                        value = input(
                            f'\nEnter new Fabric {nan_option_name}. Current value is {current_value}: '
                        )
                        value = value.strip()
                        # 0, None or '' means no labeling
                        if value in ['0', 'None', '', 'none']:
                            print(f"Fabric {nan_option_name} must have value.")
                            continue
                        else:
                            fabricshow_summary_df.loc[
                                fabric_num,
                                rename_options_dct[nan_option_name]] = value
                            print('\n')
                            # print current fabric information after change
                            print(fabricshow_summary_df.iloc[fabric_num])
                            print('\n')
                            break

                reply = reply_request(
                    'Do you want to keep changes? (y)es/(n)o: ')
                # when user doesn't want to keep data fabricshow_summary DataFrame
                # returns to the state saved bedore current iteration
                if reply == 'n':
                    fabricshow_summary_df = fabricshow_summary_before_df.copy()
        # user input is verify fabric labeling
        elif input_option == 'v':
            count_labels_df = verify_fabric_labels(fabricshow_summary_df)
            print('\n', count_labels_df, '\n')
        # user input is save current labeling configuration and exit
        elif input_option == 's':
            count_labels_df = verify_fabric_labels(fabricshow_summary_df)
            print('\n', count_labels_df, '\n')
            # check for errors in fabric labeling
            if (count_labels_df['Verification'] == 'ERROR').any():
                print(
                    'There is an error in fabric labeling. Please re-label fabrics.'
                )
                input_option = None
            else:
                # if fabric labeling is ok request to save
                reply = reply_request(
                    'Do you want to save changes and exit? (y)es/(n)o: ')
                # for save option do nothing and while loop stops on next condition check
                if reply == 'y':
                    print('\nSaved fabric labeling\n')
                else:
                    input_option = None
        # user input is reset current labeling configuration and start labeling from scratch
        elif input_option == 'r':
            reply = reply_request(
                'Do you want to reset fabric labeling to original values? (y)es/(n)o: '
            )
            # for reset option actual fabricshow_summary DataFrame returns back
            # to initial DataFrame version and while loop don't stop
            if reply == 'y':
                fabricshow_summary_df = fabricshow_summary_default_df.copy()
                print('\nFabric labeling has been reset to original version\n')
        # user input is exit without saving
        elif input_option == 'x':
            reply = reply_request(
                'Do you want to leave without saving? (y)es/(n)o: ')
            # for exit option DataFrame returns back to initial version
            # and while loop stops
            if reply == 'y':
                fabricshow_summary_df = fabricshow_summary_default_df.copy()
                print('\nKeeping original labeling version\n')
            else:
                input_option = None
    else:
        # show actual version of DataFrame after user inputs save or exit
        print(fabricshow_summary_df.loc[:, info_labels])
        print('\n')

    return fabricshow_summary_df
Ejemplo n.º 6
0
def err_sfp_cfg_analysis_main(portshow_aggregated_df, sfpshow_df,
                              portcfgshow_df, report_columns_usage_dct,
                              report_data_lst):
    """Main function to add porterr, transceiver and portcfg information to portshow DataFrame"""

    # report_data_lst contains information:
    # customer_name, dir_report, dir to save obtained data, max_title, report_steps_dct
    *_, max_title, report_steps_dct = report_data_lst
    portshow_sfp_force_flag = False
    portshow_sfp_export_flag, *_ = report_steps_dct['portshow_sfp_aggregated']

    # names to save data obtained after current module execution
    data_names = [
        'portshow_sfp_aggregated', 'Ошибки', 'Параметры_SFP',
        'Параметры_портов'
    ]
    # service step information
    print(f'\n\n{report_steps_dct[data_names[0]][3]}\n')

    # load data if they were saved on previos program execution iteration
    data_lst = load_data(report_data_lst, *data_names)
    # unpacking DataFrames from the loaded list with data
    # pylint: disable=unbalanced-tuple-unpacking
    portshow_sfp_aggregated_df, error_report_df, sfp_report_df, portcfg_report_df = data_lst

    # list of data to analyze from report_info table
    analyzed_data_names = [
        'portshow_aggregated', 'sfpshow', 'portcfgshow', 'portcmd',
        'switchshow_ports', 'switch_params_aggregated', 'fdmi',
        'device_rename', 'report_columns_usage_upd', 'nscamshow', 'nsshow',
        'alias', 'blade_servers', 'fabric_labels'
    ]

    # force run when any data from data_lst was not saved (file not found) or
    # procedure execution explicitly requested for output data or data used during fn execution
    force_run = verify_force_run(data_names, data_lst, report_steps_dct,
                                 max_title, analyzed_data_names)

    if force_run:
        # import transeivers information from file
        sfp_model_df = dataframe_import('sfp_models', max_title)
        # current operation information string
        info = f'Updating connected devices table'
        print(info, end=" ")
        # add sfpshow, transceiver information and portcfg to aggregated portcmd DataFrame
        portshow_sfp_aggregated_df = port_complete(portshow_aggregated_df,
                                                   sfpshow_df, sfp_model_df,
                                                   portcfgshow_df)
        # after finish display status
        status_info('ok', max_title, len(info))

        # warning if UKNOWN SFP present
        if (portshow_sfp_aggregated_df['Transceiver_Supported'] ==
                'Unknown SFP').any():
            info_columns = [
                'Fabric_name', 'Fabric_label', 'configname', 'chassis_name',
                'chassis_wwn', 'slot', 'port', 'Transceiver_Supported'
            ]
            portshow_sfp_info_df = portshow_sfp_aggregated_df.drop_duplicates(
                subset=info_columns).copy()
            unknown_count = len(portshow_sfp_info_df[
                portshow_sfp_info_df['Transceiver_Supported'] ==
                'Unknown SFP'])
            info = f'{unknown_count} {"port" if unknown_count == 1 else "ports"} with UNKNOWN supported SFP tag found'
            print(info, end=" ")
            status_info('warning', max_title, len(info))
            # ask if save portshow_aggregated_df
            if not portshow_sfp_export_flag:
                reply = reply_request(
                    "Do you want to save 'portshow_sfp_aggregated'? (y)es/(n)o: "
                )
                if reply == 'y':
                    portshow_sfp_force_flag = True

        # create reaport tables from port_complete_df DataFrtame
        error_report_df, sfp_report_df, portcfg_report_df = \
            create_report_tables(portshow_sfp_aggregated_df, data_names[1:], report_columns_usage_dct, max_title)
        # saving data to json or csv file
        data_lst = [
            portshow_sfp_aggregated_df, error_report_df, sfp_report_df,
            portcfg_report_df
        ]
        save_data(report_data_lst, data_names, *data_lst)
    # verify if loaded data is empty and reset DataFrame if yes
    else:
        portshow_sfp_aggregated_df, error_report_df, sfp_report_df, portcfg_report_df \
            = verify_data(report_data_lst, data_names, *data_lst)
        data_lst = [
            portshow_sfp_aggregated_df, error_report_df, sfp_report_df,
            portcfg_report_df
        ]
    # save data to excel file if it's required
    for data_name, data_frame in zip(data_names, data_lst):
        force_flag = False
        if data_name == 'portshow_sfp_aggregated':
            force_flag = portshow_sfp_force_flag
        save_xlsx_file(data_frame,
                       data_name,
                       report_data_lst,
                       force_flag=force_flag)

    return portshow_sfp_aggregated_df
Ejemplo n.º 7
0
def warning_notification(portshow_aggregated_df, switch_params_aggregated_df,
                         nsshow_unsplit_df, expected_ag_links_df,
                         report_data_lst):
    """Function to show WARNING notification if any deviceType is UNKNOWN,
    if any PortSymb or NodeSymb was not parsed or if new switch founded which was
    not previously discovered"""

    *_, max_title, report_steps_dct = report_data_lst
    portshow_force_flag = False
    nsshow_unsplit_force_flag = False
    expected_ag_links_force_flag = False

    portshow_export_flag, *_ = report_steps_dct['portshow_aggregated']
    nsshow_unsplit_export_flag, *_ = report_steps_dct['nsshow_unsplit']
    expected_ag_links_export_flag, *_ = report_steps_dct['expected_ag_links']

    # warning if UKNOWN device class present
    if (portshow_aggregated_df['deviceType'] == 'UNKNOWN').any():
        unknown_count = len(portshow_aggregated_df[
            portshow_aggregated_df['deviceType'] == 'UNKNOWN'])
        info = f'{unknown_count} {"port" if unknown_count == 1 else "ports"} with UNKNOWN device Class found'
        print(info, end=" ")
        status_info('warning', max_title, len(info))
        # ask if save portshow_aggregated_df
        if not portshow_export_flag:
            reply = reply_request(
                "Do you want to save 'portshow_aggregated'? (y)es/(n)o: ")
            if reply == 'y':
                portshow_force_flag = True
    # warning if any values in PortSymb or NodeSymb were not parsed
    if not nsshow_unsplit_df.empty:
        portsymb_unsplit_count = nsshow_unsplit_df['PortSymb'].notna().sum()
        nodesymb_unsplit_count = nsshow_unsplit_df['NodeSymb'].notna().sum()
        unsplit_lst = [[portsymb_unsplit_count, 'PortSymb'],
                       [nodesymb_unsplit_count, 'NodeSymb']]
        unsplit_str = ' and '.join(
            [str(num) + " " + name for num, name in unsplit_lst if num])
        info = f'{unsplit_str} {"is" if portsymb_unsplit_count + nodesymb_unsplit_count == 1 else "are"} UNPARSED'
        print(info, end=" ")
        status_info('warning', max_title, len(info))
        # ask if save nsshow_unsplit
        if not nsshow_unsplit_export_flag:
            reply = reply_request(
                "Do you want to save 'nsshow_unsplit'? (y)es/(n)o: ")
            if reply == 'y':
                nsshow_unsplit_force_flag = True
    # warning if unknown switches was found
    switch_name_set = set(switch_params_aggregated_df['switchName'])
    # all founded switches in portshow_aggregated_df
    mask_switch = portshow_aggregated_df['deviceType'] == 'SWITCH'
    portshow_switch_name_set = set(
        portshow_aggregated_df.loc[mask_switch, 'Device_Host_Name'])
    # if unknown switches found
    if not portshow_switch_name_set.issubset(switch_name_set):
        unknown_count = len(
            portshow_switch_name_set.difference(switch_name_set))
        info = f'{unknown_count} NEW {"switch" if unknown_count == 1 else "switches"} detected'
        print(info, end=" ")
        status_info('warning', max_title, len(info))
        # ask if save portshow_aggregated_df
        if not portshow_export_flag and not portshow_force_flag:
            reply = reply_request(
                "Do you want to save 'portshow_aggregated'? (y)es/(n)o: ")
            if reply == 'y':
                portshow_force_flag = True
    # if any unconfirmed AG links found
    if not expected_ag_links_df.empty:
        unknown_count = expected_ag_links_df['chassis_name'].notna().sum()
        info = f'{unknown_count} AG {"link" if unknown_count == 1 else "links"} detected'
        print(info, end=" ")
        status_info('warning', max_title, len(info))
        # ask if save expected_ag_links_df
        if not expected_ag_links_export_flag:
            reply = reply_request(
                "Do you want to save 'expected_ag_link'? (y)es/(n)o: ")
            if reply == 'y':
                expected_ag_links_force_flag = True
    return portshow_force_flag, nsshow_unsplit_force_flag, expected_ag_links_force_flag
Ejemplo n.º 8
0
def configs_download(ns_3par_df, project_folder, local_3par_folder, comp_keys,
                     match_keys, comp_dct, report_data_lst):
    """Function to prepare 3PAR configuration files for parsing. 
    Download in from STATs and local (defined in report.xlsx file) folders"""

    *_, max_title, _ = report_data_lst

    # folder for 3par config files download is in project folder
    download_folder = os.path.join(project_folder, '3par_configs')
    # verify if download folder exist (created on previous iterations)
    download_folder_exist = verify_download_folder(download_folder,
                                                   create=False)

    # if download folder exist and there are 3par config files
    # ask if user wants to use them or download new files after removing existing
    if download_folder_exist:
        configs_downloaded_lst = find_files(
            download_folder,
            max_title,
            filename_contains=comp_dct['configname_3par'])
        if configs_downloaded_lst:
            print(
                f'{len(configs_downloaded_lst)} 3PAR configuration files found in download folder.'
            )
            print(
                'Do you want to USE EXISTING FILES to extract port and host information?'
            )
            print(
                "If you want to update configuarion files and reply 'no' then existing files are removed."
            )
            query = "Please select '(y)es' (use existing) or '(n)o' (update): "
            reply = reply_request(query)
            if reply == 'n':
                # delete 3par config files
                remove_files(configs_downloaded_lst, max_title)
            else:
                return configs_downloaded_lst

    # download from STATs
    query = 'Do you want DOWNLOAD configuration files from STATs? (y)es/(n)o: '
    reply = reply_request(query)
    if reply == 'y':
        query = 'Are you connected to HPE network?: '
        reply = reply_request(query)
        if reply == 'y':
            # download configs from STATs
            ns_3par_df = stats_download(ns_3par_df, download_folder, max_title)
        else:
            print('STATs is only available within HPE network.')

    # find configuration files in local 3PAR folder
    if local_3par_folder:
        configs_local_lst = find_files(
            local_3par_folder,
            max_title,
            filename_contains=comp_dct['configname_3par'])
        if configs_local_lst:
            print('\n')
            print(
                f'{len(configs_local_lst)} 3PAR configuration files found in local folder.'
            )
            query = 'Do you want COPY configuration files from LOCAL to download folder? (y)es/(n)o: '
            reply = reply_request(query)
            if reply == 'y':
                # download configs from loacl folder
                ns_3par_df = local_download(ns_3par_df, configs_local_lst,
                                            download_folder, comp_keys,
                                            match_keys, comp_dct, max_title)

    download_summary(ns_3par_df, report_data_lst)
    # create configs list in download folder if it exist (if user reject download config files
    # from both sources download folder is not created)
    download_folder_exist = verify_download_folder(download_folder,
                                                   create=False)
    if download_folder_exist:
        configs_3par_lst = find_files(
            download_folder,
            max_title,
            filename_contains=comp_dct['configname_3par'])
        return configs_3par_lst
    else:
        return []