コード例 #1
0
ファイル: fabric.py プロジェクト: jconsoli/brcddb
def _maps_dashboard(fabric_obj):
    """Adds the MAPS dashboard to the worksheet.

    :param fabric_obj: Fabric object
    :type fabric_obj: brcddb.classes.fabric.FabricObj
    :rtype: None
    """
    global _row, _sheet, _hdr

    col = 1
    _row += 2
    border = report_fonts.border_type('thin')
    alignment = report_fonts.align_type('wrap')
    _sheet.merge_cells(start_row=_row,
                       start_column=col,
                       end_row=_row,
                       end_column=len(_hdr))
    cell = xl.get_column_letter(col) + str(_row)
    _sheet[cell].font = report_fonts.font_type('bold')
    _sheet[cell].alignment = alignment
    _sheet[cell] = 'MAPS Dashboard Alerts'
    font = report_fonts.font_type('std')
    i = 0
    for alert_obj in fabric_obj.r_alert_objects():
        if alert_obj.alert_num() in al.AlertTable.maps_alerts:
            _row += 1
            _sheet.merge_cells(start_row=_row,
                               start_column=col,
                               end_row=_row,
                               end_column=len(_hdr))
            for col in range(1, len(_hdr)):
                cell = xl.get_column_letter(col) + str(_row)
                _sheet[cell].border = border
            col = 1
            cell = xl.get_column_letter(col) + str(_row)
            _sheet[cell].font = font
            _sheet[cell].alignment = alignment
            _sheet[cell] = alert_obj.fmt_msg()
            i += 1
    if i == 0:
        _row += 1
        _sheet.merge_cells(start_row=_row,
                           start_column=col,
                           end_row=_row,
                           end_column=len(_hdr))
        for col in range(1, len(_hdr) + 1):
            cell = xl.get_column_letter(col) + str(_row)
            _sheet[cell].border = border
        col = 1
        cell = xl.get_column_letter(col) + str(_row)
        _sheet[cell].font = font
        _sheet[cell].alignment = alignment
        _sheet[cell] = 'None'
コード例 #2
0
ファイル: switch.py プロジェクト: jconsoli/brcddb
def _maps_dashboard(switch_obj):
    """Adds the MAPS dashboard to the worksheet.

    :param switch_obj: Switch object
    :type switch_obj: brcddb.classes.switch.SwitchObj
    :rtype: None
    """
    global row, sheet

    merge_len = 2  # NUmber of columns to be merged for the MAPS dashboard
    col = 1
    row += 2
    border = report_fonts.border_type('thin')
    alignment = report_fonts.align_type('wrap')
    sheet.merge_cells(start_row=row, start_column=col, end_row=row, end_column=col + merge_len)
    cell = xl.get_column_letter(col) + str(row)
    sheet[cell].font = report_fonts.font_type('bold')
    sheet[cell].alignment = alignment
    sheet[cell] = 'MAPS Dashboard Alerts'
    font = report_fonts.font_type('std')
    i = 0
    for alert_obj in switch_obj.r_alert_objects():
        if alert_obj.alert_num() in al.AlertTable.maps_alerts:
            row += 1
            sheet.merge_cells(start_row=row, start_column=col, end_row=row, end_column=col + merge_len)
            for col in range(1, merge_len + 2):
                cell = xl.get_column_letter(col) + str(row)
                sheet[cell].border = border
            col = 1
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].font = font
            sheet[cell].alignment = alignment
            sheet[cell] = alert_obj.fmt_msg()
            i += 1
    if i == 0:
        row += 1
        sheet.merge_cells(start_row=row, start_column=col, end_row=row, end_column=col + merge_len)
        for col in range(1, merge_len + 2):
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].border = border
        col = 1
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = font
        sheet[cell].alignment = alignment
        sheet[cell] = 'None'
コード例 #3
0
ファイル: fabric.py プロジェクト: jconsoli/brcddb
def _setup_worksheet(wb, tc, sheet_i, sheet_name, sheet_title):
    """Creates a fabric detail worksheet for the Excel report.

    :param wb: Workbook object
    :type wb: class
    :param tc: Table of context page. A link to this page is place in cell A1
    :type tc: str, None
    :param sheet_name: Sheet (tab) name
    :type sheet_name: str
    :param sheet_i: Sheet index where page is to be placed.
    :type sheet_i: int
    :param sheet_title: Title to be displayed in large font, hdr_1, at the top of the sheet
    :type sheet_title: str
    :rtype: None
    """
    global _row, _sheet, _hdr

    # Create the worksheet, add the headers, and set up the column widths
    _sheet = wb.create_sheet(index=sheet_i, title=sheet_name)
    _sheet.page_setup.paperSize = _sheet.PAPERSIZE_LETTER
    _sheet.page_setup.orientation = _sheet.ORIENTATION_LANDSCAPE
    _row = 1
    col = 1
    if isinstance(tc, str):
        cell = xl.get_column_letter(col) + str(_row)
        _sheet[cell].hyperlink = '#' + tc + '!A1'
        _sheet[cell].font = report_fonts.font_type('link')
        _sheet[cell] = 'Contents'
        col += 1
    cell = xl.get_column_letter(col) + str(_row)
    _sheet[cell].font = report_fonts.font_type('hdr_1')
    _sheet[cell] = sheet_title
    _sheet.merge_cells(start_row=_row,
                       start_column=col,
                       end_row=_row,
                       end_column=len(_hdr))
    _sheet.freeze_panes = _sheet['A2']

    # Set the column width
    col = 1
    for k, v in _hdr.items():
        _sheet.column_dimensions[xl.get_column_letter(col)].width = v
        col += 1
コード例 #4
0
ファイル: bp.py プロジェクト: jconsoli/brcddb
def bp_page(wb, tc, sheet_name, sheet_i, sheet_title, obj, display,
            display_tbl):
    """Creates a best practice violation worksheet for the Excel report.

    :param wb: Workbook object
    :type wb: class
    :param tc: Table of context page. A link to this page is place in cell A1
    :type tc: str, None
    :param sheet_name: Sheet (tab) name
    :type sheet_name: str
    :param sheet_i: Sheet index where page is to be placed.
    :type sheet_i: int
    :param sheet_title: Title to be displayed in large font, hdr_1, at the top of the sheet
    :type sheet_title: str
    :param obj: Project or fabric object.
    :type obj: brcddb.classes.project.ProjectObj, brcddb.classes.fabric.FabricObj
    :param display: List of parameters to display.
    :type display: list, tuple
    :param display_tbl: Display control table. See brcddb.report.report_tables.display_tbl
    :rtype: None
    """
    # Validate the user input
    err_msg = list()
    if obj is None:
        err_msg.append('obj was not defined.')
    elif not bool('ProjectObj' in str(type(obj))
                  or 'FabricObj' in str(type(obj))):
        err_msg.append('Invalid object type: ' + str(type(obj)) + '.')
    if display is None:
        err_msg.append('display not defined.')
    if len(err_msg) > 0:
        brcdapi_log.exception(err_msg, True)
        return

    # Create the worksheet, add the headers, and set up the column widths
    sheet = wb.create_sheet(index=sheet_i, title=sheet_name)
    sheet.page_setup.paperSize = sheet.PAPERSIZE_LETTER
    sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
    col = 1
    row = 1
    if isinstance(tc, str):
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].hyperlink = '#' + tc + '!A1'
        sheet[cell].font = report_fonts.font_type('link')
        sheet[cell] = 'Contents'
        col += 1
    cell = xl.get_column_letter(col) + str(row)
    sheet[cell].font = report_fonts.font_type('hdr_1')
    sheet[cell] = sheet_title
    sheet.freeze_panes = sheet['A3']
    col = 1
    row += 1
    for k in display:
        if k in display_tbl and 'dc' in display_tbl[
                k] and display_tbl[k]['dc'] is True:
            continue
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = report_fonts.font_type('bold')
        sheet[cell].border = report_fonts.border_type('thin')
        if k in display_tbl:
            if 'c' in display_tbl[k]:
                sheet.column_dimensions[xl.get_column_letter(
                    col)].width = display_tbl[k]['c']
            try:
                if display_tbl[k]['v']:
                    sheet[cell].alignment = report_fonts.align_type(
                        'wrap_vert_center')
                else:
                    sheet[cell].alignment = report_fonts.align_type('wrap')
            except:
                sheet[cell].alignment = report_fonts.align_type('wrap')
            if 'd' in display_tbl[k]:
                sheet[cell] = display_tbl[k]['d']
            else:
                sheet[
                    cell] = k  # This happens when a new key is introduced before the display tables have been updated
        else:
            sheet[
                cell] = k  # This happens when a new key is introduced before the display tables have been updated
        col += 1

    # Get a list of fabric objects and initialize alert_list
    if 'ProjectObj' in str(type(obj)):
        fab_list = obj.r_fabric_objects()
        chassis_list = obj.r_chassis_objects()
        switch_list = obj.r_switch_objects()
    else:
        fab_list = [obj]
        chassis_list = obj.r_project_obj().r_chassis_objects()
        switch_list = obj.r_project_obj().r_switch_objects()
    alert_list = list()

    # Get all the chassis alerts
    for tobj in chassis_list:
        tl = list()
        for sev in (al.ALERT_SEV.ERROR,
                    al.ALERT_SEV.WARN):  # Display errors first
            tl.extend(
                _add_alerts(tobj, 'Chassis', sev,
                            brcddb_chassis.best_chassis_name(tobj), ''))
        if len(tl) > 0:
            alert_list.append([''])
            alert_list.append(
                ['Chassis: ' + brcddb_chassis.best_chassis_name(tobj)])
            alert_list.extend(tl)

    # Get all the fabric alerts
    for fab_obj in fab_list:
        tl = list()
        for sev in (al.ALERT_SEV.ERROR,
                    al.ALERT_SEV.WARN):  # Display errors first
            tl.extend(
                _add_alerts(fab_obj, 'Fabric', sev,
                            brcddb_fabric.best_fab_name(fab_obj), ''))
            for tobj in fab_obj.r_zonecfg_objects():
                tl.extend(
                    _add_alerts(tobj, 'ZoneCfg', sev, tobj.r_obj_key(), ''))
            for tobj in fab_obj.r_zone_objects():
                tl.extend(_add_alerts(tobj, 'Zone', sev, tobj.r_obj_key(), ''))
            for tobj in fab_obj.r_alias_objects():
                tl.extend(_add_alerts(tobj, 'Alias', sev, tobj.r_obj_key(),
                                      ''))
            for tobj in fab_obj.r_login_objects():
                tl.extend(_add_alerts(tobj, 'Login', sev, tobj.r_obj_key(),
                                      ''))
            for tobj in fab_obj.r_fdmi_node_objects():
                tl.extend(
                    _add_alerts(tobj, 'FDMI_Node', sev, tobj.r_obj_key(), ''))
            for tobj in fab_obj.r_fdmi_port_objects():
                tl.extend(
                    _add_alerts(tobj, 'FDMI_Port', sev, tobj.r_obj_key(), ''))
        if len(tl) > 0:
            alert_list.append([''])
            alert_list.append(
                ['Fabric: ' + brcddb_fabric.best_fab_name(fab_obj, True)])
            alert_list.extend(tl)

    # Get all the switch and port alerts
    for switch_obj in switch_list:
        tl = list()
        for sev in (al.ALERT_SEV.ERROR,
                    al.ALERT_SEV.WARN):  # Display errors first
            tl.extend(
                _add_alerts(switch_obj, 'Switch', sev,
                            brcddb_switch.best_switch_name(switch_obj), ''))
            for tobj in switch_obj.r_port_objects():
                tl.extend(
                    _add_alerts(tobj, 'Port', sev,
                                brcddb_port.best_port_name(tobj),
                                tobj.r_obj_key()))
        if len(tl) > 0:
            alert_list.append([''])
            alert_list.append([
                'Switch: ' + brcddb_switch.best_switch_name(switch_obj, True)
            ])
            alert_list.extend(tl)

    # Now add the alerts to the worksheet

    # Set up the cell formatting
    border = report_fonts.border_type('thin')
    alignment = report_fonts.align_type('wrap')
    font = report_fonts.font_type('std')

    # Add all alerts to the worksheet
    for x in alert_list:
        row += 1
        col = 1
        if len(x) == 0:
            row += 1
        elif len(x) == 1:
            sheet.merge_cells(start_row=row,
                              start_column=1,
                              end_row=row,
                              end_column=len(display))
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].font = report_fonts.font_type('hdr_2')
            if len(x[0]) > 0:
                sheet[cell].fill = report_fonts.fill_type('lightblue')
            sheet[cell] = x[0]
        else:
            for k in display:
                cell = xl.get_column_letter(col) + str(row)
                sheet[cell].border = border
                sheet[cell].font = font
                sheet[cell].alignment = alignment
                sheet[cell] = bp_case[k](x)
                col += 1
コード例 #5
0
ファイル: port.py プロジェクト: jconsoli/brcddb
def performance_dashboard(wb, tc, sheet_name, sheet_i, sheet_title, content):
    """Creates a dashboard worksheet for the Excel report.

    :param wb: Workbook object
    :type wb: class
    :param tc: Table of context page. A link to this page is place in cell A1
    :type tc: str, None
    :param sheet_name: Sheet (tab) name
    :type sheet_name: str
    :param sheet_i: Sheet index where page is to be placed.
    :type sheet_i: int
    :param sheet_title: Title to be displayed in large font, hdr_1, at the top of the sheet
    :type sheet_title: str
    :param content: Caller defined content. List of lists or tuples to add to the title page. For example:
            dashboard = collections.OrderedDict()
            dashboard['class-3-discards'] =     {'title' : 'Top 10 C3 Discards', 'port_list' : []}
            dashboard['in-crc-errors'] =        {'title' : 'Top 10 CRC With Good EOF', 'port_list' : []}
    :type content: list, tuple
    :rtype: None
    """

    hdr = collections.OrderedDict()
    # Key is the column header and value is the width
    hdr['Count'] = 14
    hdr['Fabric'] = 22
    hdr['Switch'] = 22
    hdr['Port'] = 7
    hdr['Type'] = 8
    hdr['Description'] = 117 - (hdr['Count'] + hdr['Switch'] + hdr['Switch'] +
                                hdr['Port'] + hdr['Type'])

    # Create the worksheet, add the title, and set up the column widths
    sheet = wb.create_sheet(index=sheet_i, title=sheet_name)
    sheet.page_setup.paperSize = sheet.PAPERSIZE_LETTER
    sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
    col = 1
    row = 1
    for k, v in hdr.items():
        sheet.column_dimensions[xl.get_column_letter(col)].width = v
        col += 1
    max_col = col - 1
    col = 1
    if isinstance(tc, str):
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].hyperlink = '#' + tc + '!A1'
        sheet[cell].font = report_fonts.font_type('link')
        sheet[cell] = 'Contents'
        col += 1
    cell = xl.get_column_letter(col) + str(row)
    sheet.merge_cells(start_row=row,
                      start_column=col,
                      end_row=row,
                      end_column=max_col)
    sheet[cell].font = report_fonts.font_type('hdr_1')
    sheet[cell] = sheet_title
    row += 2

    # Now add each dashboard item
    border = report_fonts.border_type('thin')
    font = report_fonts.font_type('std')
    alignment = report_fonts.align_type('wrap')
    for statistic in content.keys():
        db = content.get(statistic)
        col = 1

        # The individual dashboard title
        sheet.merge_cells(start_row=row,
                          start_column=1,
                          end_row=row,
                          end_column=max_col)
        for i in range(col, max_col + 1):
            cell = xl.get_column_letter(i) + str(row)
            sheet[cell].border = border
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = report_fonts.font_type('hdr_2')
        sheet[cell].fill = report_fonts.fill_type('lightblue')
        sheet[cell] = db.get('title')
        col = 1
        row += 1

        # Now the individual dashboard headers
        for k in hdr.keys():
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].border = border
            sheet[cell].font = report_fonts.font_type('bold')
            sheet[cell] = k
            col += 1

        # Now add the dashboard content
        port_list = db.get('port_list')
        if len(port_list) == 0:
            row += 1
        for port_obj in port_list:
            # Statistic
            col = 1
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].border = border
            sheet[cell].font = font
            sheet[cell].alignment = alignment
            sheet[cell] = port_obj.r_get('fibrechannel-statistics/' +
                                         statistic)
            col += 1

            # Fabric
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].border = border
            sheet[cell].font = font
            sheet[cell].alignment = alignment
            sheet[cell] = brcddb_fabric.best_fab_name(
                port_obj.r_switch_obj().r_fabric_obj())
            col += 1

            # Switch
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].border = border
            sheet[cell].font = font
            sheet[cell].alignment = alignment
            sheet[cell] = brcddb_switch.best_switch_name(
                port_obj.r_switch_obj())
            col += 1

            # Port
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].border = border
            sheet[cell].font = font
            sheet[cell].alignment = alignment
            sheet[cell] = port_obj.r_obj_key()
            col += 1

            # Port Type
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].border = border
            sheet[cell].font = font
            sheet[cell].alignment = alignment
            sheet[cell] = port_obj.c_login_type()
            col += 1

            # Description - Try FDMI first, then name server
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].border = border
            sheet[cell].font = font
            sheet[cell].alignment = alignment
            sheet[cell] = brcddb_port.port_best_desc(port_obj)
            row += 1
        row += 1
コード例 #6
0
ファイル: port.py プロジェクト: jconsoli/brcddb
def port_page(wb,
              tc,
              sheet_name,
              sheet_i,
              sheet_title,
              p_list,
              display,
              port_display_tbl,
              login_flag=False):
    """Creates a port detail worksheet for the Excel report.

    :param wb: Workbook object
    :type wb: class
    :param tc: Table of context page. A link to this page is place in cell A1
    :type tc: str, None
    :param sheet_name: Sheet (tab) name
    :type sheet_name: str
    :param sheet_i: Sheet index where page is to be placed.
    :type sheet_i: int
    :param sheet_title: Title to be displayed in large font, hdr_1, at the top of the sheet
    :type sheet_title: str
    :param p_list: List of port objects (PortObj) to display
    :type p_list: list, tuple
    :param display: List of parameters to display.
    :type display: list, tuple
    :param port_display_tbl: Display control table. See brcddb.report.report_tables.port_display_tbl
    :param login_flag: When True, include NPIV logins below the base port.
    :type login_flag: bool
    :return: openxl sheet
    :rtype: Worksheet
    """
    global port_case

    addl_row = dict(
    )  # I forgot all about logins and had to shoe horn in something to report the logins. This also meant
    # I had to shoe horn in a way to get the comments associated with logins, but only if login
    # information was requested, into the display.
    # To Do: Clean this up

    # Validate the user input
    err_msg = list()
    if p_list is None:
        err_msg.append('p_list was not defined.')
    elif not isinstance(p_list, (list, tuple)):
        err_msg.append('p_list was type ' + str(type(p_list)) +
                       '. Must be a list or tuple.')
    if display is None:
        err_msg.append('display not defined.')
    if len(err_msg) > 0:
        brcdapi_log.exception(err_msg, True)
        return None

    # Create the worksheet, add the headers, and set up the column widths
    sheet = wb.create_sheet(index=sheet_i, title=sheet_name)
    sheet.page_setup.paperSize = sheet.PAPERSIZE_LETTER
    sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
    col = 1
    row = 1
    if isinstance(tc, str):
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].hyperlink = '#' + tc + '!A1'
        sheet[cell].font = report_fonts.font_type('link')
        sheet[cell] = 'Contents'
        col += 1
    cell = xl.get_column_letter(col) + str(row)
    sheet[cell].font = report_fonts.font_type('hdr_1')
    sheet[cell] = sheet_title
    sheet.freeze_panes = sheet['A3']
    col = 1
    row += 1
    for k in display:
        if k in port_display_tbl and 'dc' in port_display_tbl[
                k] and port_display_tbl[k]['dc'] is True:
            continue
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = report_fonts.font_type('bold')
        sheet[cell].border = report_fonts.border_type('thin')
        if k in port_display_tbl:
            if 'c' in port_display_tbl[k]:
                sheet.column_dimensions[xl.get_column_letter(
                    col)].width = port_display_tbl[k]['c']
            try:
                if port_display_tbl[k]['v']:
                    sheet[cell].alignment = report_fonts.align_type(
                        'wrap_vert_center')
                else:
                    sheet[cell].alignment = report_fonts.align_type('wrap')
            except:
                sheet[cell].alignment = report_fonts.align_type('wrap')
            if 'd' in port_display_tbl[k]:
                sheet[cell] = port_display_tbl[k]['d']
            else:
                sheet[cell] = k
        else:
            brcdapi_log.exception('Item ' + k + ' not in port_display_tbl.',
                                  True)
            sheet[cell] = k
        col += 1

    # Add the ports
    row += 1
    for port_obj in p_list:
        if port_obj is None:
            row += 1
            continue
        col = 1
        # We don't want SIM ports
        login = [
            wwn for wwn in port_obj.r_login_keys()
            if port_obj.c_login_type() == 'F-Port'
        ]
        border = report_fonts.border_type('thin')
        lwwn = None if len(login) == 0 else login[0]
        font = report_utils.font_type(
            report_utils.combined_alert_objects(port_obj, lwwn))
        alignment = report_fonts.align_type('wrap')
        center_alignment = report_fonts.align_type('wrap_center')
        for k in display:
            if k in port_display_tbl and 'dc' in port_display_tbl[
                    k] and port_display_tbl[k]['dc'] is True:
                continue
            if len(login) > 1:
                addl_row.update({k: col})
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].border = border
            sheet[cell].font = font
            if k in port_display_tbl and 'm' in port_display_tbl[
                    k] and port_display_tbl[k]['m'] is True:
                sheet[cell].alignment = center_alignment
            else:
                sheet[cell].alignment = alignment
            if k in port_case:
                sheet[cell] = port_case[k](port_obj, k, lwwn)
            elif k in port_display_tbl:
                v = port_obj.r_get(k)
                if v is None:
                    v1 = ''
                else:
                    try:
                        v1 = brcddb_common.port_conversion_tbl[k][v]
                        if v1 is None:
                            raise
                    except:
                        v1 = v
                if isinstance(v1, bool):
                    sheet[cell] = '\u221A' if v1 else ''
                else:
                    sheet[cell] = v1
            else:
                sheet[cell].font = report_fonts.font_type('std')
                sheet[cell] = '' if port_obj.r_get(k) is None else str(
                    port_obj.r_get(k))
            col += 1
        row += 1

        # Now add the remaining logins
        if login_flag:
            for i in range(1, len(login)):
                font = report_utils.font_type(
                    report_utils.combined_login_alert_objects(
                        port_obj.r_fabric_obj().r_login_obj(login[i])))
                for k1 in addl_row:
                    cell = xl.get_column_letter(addl_row[k1]) + str(row)
                    sheet[cell].border = border
                    sheet[cell].font = font
                    sheet[cell].alignment = report_fonts.align_type('wrap')
                    if k1 == '_PORT_COMMENTS':
                        sheet[cell] = port_case[k1](port_obj, '', login[i])
                    elif k1 in port_case:
                        sheet[cell] = port_case[k1](port_obj, k1, login[i])
                    else:
                        buf = port_obj.r_fabric_obj().r_get(k1)
                        buf = '' if buf is None else buf
                        sheet[cell] = buf
                row += 1
    return sheet
コード例 #7
0
ファイル: switch.py プロジェクト: jconsoli/brcddb
def _add_switch(switch_obj, display):
    """Adds switch detail to the worksheet.

    :param switch_obj: Switch object
    :type switch_obj: brcddb.classes.switch.SwitchObj
    :param display: List of keys to display. Find next instance of switch_key_case. Much less complex than port_page()
    :type display: dict
    :rtype: None
    """
    global row, sheet, hdr, switch_key_case

    # Add the headers
    col = 1
    row += 2
    sheet.merge_cells(start_row=row, start_column=col, end_row=row, end_column=len(hdr))
    cell = xl.get_column_letter(col) + str(row)
    sheet[cell].font = report_fonts.font_type('hdr_2')
    sheet[cell] = brcddb_switch.best_switch_name(switch_obj, True)
    row += 1
    for k in hdr.keys():
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = report_fonts.font_type('bold')
        sheet[cell] = k
        col += 1

    # Add the MAPS dashboard
    _maps_dashboard(switch_obj)

    # Add the switch details
    border = report_fonts.border_type('thin')
    alignment = report_fonts.align_type('wrap')
    row += 1
    for k in display:
        font = report_utils.font_type_for_key(switch_obj, k)
        col = 1
        row += 1
        # Comments
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = font
        sheet[cell].border = border
        sheet[cell].alignment = alignment
        sheet[cell] = report_utils.comments_for_alerts(switch_obj, k)
        # Key description
        col += 1
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = font
        sheet[cell].border = border
        sheet[cell].alignment = alignment
        sheet[cell] = display[k] if k in display else k
        # Value
        col += 1
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = font
        sheet[cell].border = border
        sheet[cell].alignment = alignment
        v = switch_obj.r_get(k)
        if k in switch_key_case:
            sheet[cell] = switch_key_case[k](switch_obj, k)
        elif k in brcddb_common.switch_conversion_tbl:
            sheet[cell] = '' if v is None else brcddb_common.switch_conversion_tbl[k][v]
        else:
            if isinstance(v, bool):
                sheet[cell] = 'Yes' if v else 'No'
            else:
                sheet[cell] = v if isinstance(v, (str, int, float)) else '' if v is None else str(v)
コード例 #8
0
ファイル: zone.py プロジェクト: jconsoli/brcddb
def target_zone_page(fab_obj, tc, wb, sheet_name, sheet_i, sheet_title):
    """Creates a target zone detail worksheet for the Excel report.

    :param fab_obj: Fabric object
    :type fab_obj: brcddb.classes.fabric.FabricObj
    :param tc: Table of context page. A link to this page is place in cell A1
    :type tc: str, None
    :param wb: Workbook object
    :type wb: class
    :param sheet_name: Sheet (tab) name
    :type sheet_name: str
    :param sheet_i: Sheet index where page is to be placed.
    :type sheet_i: int
    :param sheet_title: Title to be displayed in large font, hdr_1, at the top of the sheet
    :type sheet_title: str
    :rtype: None
    """
    global _target_zone_hdr

    # Create the worksheet, add the headers, and set up the column widths
    sheet = wb.create_sheet(index=sheet_i, title=sheet_name)
    sheet.page_setup.paperSize = sheet.PAPERSIZE_LETTER
    sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
    col = 1
    row = 1
    if isinstance(tc, str):
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].hyperlink = '#' + tc + '!A1'
        sheet[cell].font = report_fonts.font_type('link')
        sheet[cell] = 'Contents'
        col += 1
    cell = xl.get_column_letter(col) + str(row)
    sheet[cell].font = report_fonts.font_type('hdr_1')
    sheet[cell] = sheet_title
    row += 2
    col = 1
    sheet.freeze_panes = sheet['A4']
    font = report_fonts.font_type('hdr_2')
    for k, d in _target_zone_hdr.items():
        sheet.column_dimensions[xl.get_column_letter(col)].width = d['c']
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = font
        sheet[cell].border = _border_thin
        sheet[cell].alignment = _align_wrap
        sheet[cell] = k
        col += 1

    # Fill out all the zone information for each target
    for t_login_obj in fab_obj.r_login_objects():
        server_l = t_login_obj.r_get('_zoned_servers')
        if server_l is None or len(server_l) == 0:
            continue

        # The target information
        row += 1
        col = 1
        for k, d in _target_zone_hdr.items():
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].font = report_utils.font_type(_filter_alerts([t_login_obj, t_login_obj.r_port_obj()])) \
                if k == 'Comments' else _bold_font
            sheet[cell].border = _border_thin
            sheet[cell].alignment = _align_wrap
            sheet[cell] = len(server_l) if k == 'Server' else d['a'](
                t_login_obj, t_login_obj.r_port_obj(), list())
            col += 1

        # The server information
        for wwn, zone_l in server_l.items():
            login_obj = fab_obj.r_login_obj(wwn)
            col = 1
            row += 1
            for k in _target_zone_hdr:
                cell = xl.get_column_letter(col) + str(row)
                sheet[cell].font = report_utils.font_type(_filter_alerts([login_obj, login_obj.r_port_obj()])) \
                    if k == 'Comments' else _std_font
                sheet[cell].border = _border_thin
                sheet[cell].alignment = _align_wrap
                sheet[cell] = '' if k == 'Target' else \
                    _target_zone_hdr[k]['a'](login_obj, login_obj.r_port_obj(), zone_l)
                col += 1

        row += 1
コード例 #9
0
ファイル: zone.py プロジェクト: jconsoli/brcddb
def alias_page(fab_obj, tc, wb, sheet_name, sheet_i, sheet_title):
    """Creates a port detail worksheet for the Excel report.

    :param fab_obj: Fabric object
    :type fab_obj: brcddb.classes.fabric.FabricObj
    :param tc: Table of context page. A link to this page is place in cell A1
    :type tc: str, None
    :param wb: Workbook object
    :type wb: class
    :param sheet_name: Sheet (tab) name
    :type sheet_name: str
    :param sheet_i: Sheet index where page is to be placed.
    :type sheet_i: int
    :param sheet_title: Title to be displayed in large font, hdr_1, at the top of the sheet
    :type sheet_title: str
    :rtype: None
    """
    global alias_hdr

    # Create the worksheet, add the headers, and set up the column widths
    sheet = wb.create_sheet(index=sheet_i, title=sheet_name)
    sheet.page_setup.paperSize = sheet.PAPERSIZE_LETTER
    sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
    col = 1
    row = 1
    if isinstance(tc, str):
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].hyperlink = '#' + tc + '!A1'
        sheet[cell].font = report_fonts.font_type('link')
        sheet[cell] = 'Contents'
        col += 1
    cell = xl.get_column_letter(col) + str(row)
    sheet[cell].border = _border_thin
    sheet[cell].font = report_fonts.font_type('hdr_1')
    sheet[cell] = sheet_title
    row += 2
    col = 1
    sheet.freeze_panes = sheet['A4']
    for k in alias_hdr:
        sheet.column_dimensions[xl.get_column_letter(
            col)].width = alias_hdr[k]['c']
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = report_fonts.font_type('hdr_2')
        sheet[cell].border = _border_thin
        sheet[cell].alignment = _align_wrap
        sheet[cell] = k
        col += 1

    # Fill out the alias information
    for alias_obj in fab_obj.r_alias_objects():
        mem_list = alias_obj.r_members().copy()
        mem = mem_list.pop(0) if len(mem_list) > 0 else None
        row += 1
        col = 1
        for k in alias_hdr:
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].font = report_utils.font_type(
                alias_obj.r_alert_objects()) if k == 'Comments' else _std_font
            sheet[cell].border = _border_thin
            sheet[cell].alignment = _align_wrap
            sheet[cell] = alias_hdr[k]['v'](alias_obj, mem)
            col += 1

        # Usually just one member per alias, but just in case...
        while len(mem_list) > 1:
            mem = mem_list.pop(0)
            row += 1
            col = 1
            for k in alias_hdr:
                cell = xl.get_column_letter(col) + str(row)
                sheet[cell].font = _std_font
                sheet[cell].border = _border_thin
                sheet[cell].alignment = _align_wrap
                sheet[cell] = alias_hdr[k]['m'](alias_obj, mem)
                col += 1
コード例 #10
0
ファイル: zone.py プロジェクト: jconsoli/brcddb
def zone_page(fab_obj, tc, wb, sheet_name, sheet_i, sheet_title):
    """Creates a zone detail worksheet for the Excel report.

    :param fab_obj: Fabric object
    :type fab_obj: brcddb.classes.fabric.FabricObj
    :param tc: Table of context page. A link to this page is place in cell A1
    :type tc: str, None
    :param wb: Workbook object
    :type wb: class
    :param sheet_name: Sheet (tab) name
    :type sheet_name: str
    :param sheet_i: Sheet index where page is to be placed.
    :type sheet_i: int
    :param sheet_title: Title to be displayed in large font, hdr_1, at the top of the sheet
    :type sheet_title: str
    :rtype: None
    """
    global _zone_hdr

    # Create the worksheet, add the headers, and set up the column widths
    sheet = wb.create_sheet(index=sheet_i, title=sheet_name)
    sheet.page_setup.paperSize = sheet.PAPERSIZE_LETTER
    sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
    col = 1
    row = 1
    if isinstance(tc, str):
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].hyperlink = '#' + tc + '!A1'
        sheet[cell].font = report_fonts.font_type('link')
        sheet[cell] = 'Contents'
        col += 1
    cell = xl.get_column_letter(col) + str(row)
    sheet[cell].font = report_fonts.font_type('hdr_1')
    sheet[cell] = sheet_title
    row += 2
    col = 1
    sheet.freeze_panes = sheet['A4']
    font = report_fonts.font_type('hdr_2')
    for k in _zone_hdr:
        sheet.column_dimensions[xl.get_column_letter(
            col)].width = _zone_hdr[k]['c']
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = font
        sheet[cell].border = _border_thin
        sheet[cell].alignment = report_fonts.align_type('wrap_vert_center') \
            if 'v' in _zone_hdr[k] and _zone_hdr[k]['v'] else _align_wrap
        sheet[cell] = k
        col += 1

    # Fill out all the zoning information
    row += 1
    col = 1
    for zone_obj in fab_obj.r_zone_objects():
        # The zone information
        fill = report_fonts.fill_type('lightblue')
        for k in _zone_hdr:
            cell = xl.get_column_letter(col) + str(row)
            if k == 'Comments':
                sheet[cell].font = report_utils.font_type(
                    zone_obj.r_alert_objects())
            else:
                sheet[cell].font = _bold_font
            sheet[cell].border = _border_thin
            sheet[cell].alignment = report_fonts.align_type('wrap_vert_center') \
                if 'v' in _zone_hdr[k] and _zone_hdr[k]['v'] else _align_wrap
            sheet[cell].fill = fill
            sheet[cell] = _zone_hdr[k]['z'](zone_obj)
            col += 1
        col = 1
        row += 1

        # The member information
        mem_list = list(zone_obj.r_pmembers())
        mem_list.extend(list(zone_obj.r_members()))
        for mem in mem_list:
            wwn_list = list()  # WWNs or d,i
            if fab_obj.r_alias_obj(mem) is None:
                wwn_list.append(mem)
            else:
                wwn_list.extend(fab_obj.r_alias_obj(mem).r_members())
            for wwn in wwn_list:
                if ',' in wwn:  # It's a d,i zone
                    port_obj = fab_obj.r_port_object_for_di(wwn)
                else:
                    port_obj = fab_obj.r_port_obj(wwn)
                if port_obj is None:
                    # Since brcddb_fabric.zone_analysis() already checked to see it's in another fabric, it would be
                    # much faster to check for the associated alert, but this was easier to code and time is not of the
                    # essence here.
                    for fobj in fab_obj.r_project_obj().r_fabric_objects():
                        if fab_obj.r_obj_key() != fobj.r_obj_key():
                            port_obj = fobj.r_port_obj(wwn)
                            if port_obj is not None:
                                break
                for k in _zone_hdr:
                    cell = xl.get_column_letter(col) + str(row)
                    # Display font based on alerts associated with the zone only, not members, for a zone object
                    if k == 'Comments':
                        alerts = [
                            a for a in zone_obj.r_alert_objects()
                            if a.is_flag() and a.p0() == wwn
                        ]
                        sheet[cell].font = report_utils.font_type(alerts)
                    else:
                        sheet[cell].font = _std_font
                    sheet[cell].border = _border_thin
                    sheet[cell].alignment = report_fonts.align_type('wrap_vert_center') \
                        if 'v' in _zone_hdr[k] and _zone_hdr[k]['v'] else _align_wrap
                    sheet[cell] = _zone_hdr[k]['m'](zone_obj, mem, wwn,
                                                    port_obj)
                    col += 1
                col = 1
                row += 1
コード例 #11
0
ファイル: zone.py プロジェクト: jconsoli/brcddb
__date__ = '17 Jul 2021'
__license__ = 'Apache License, Version 2.0'
__email__ = '*****@*****.**'
__maintainer__ = 'Jack Consoli'
__status__ = 'Released'
__version__ = '3.0.7'

import collections
import openpyxl.utils.cell as xl
import brcddb.brcddb_switch as brcddb_switch
import brcddb.report.fonts as report_fonts
import brcddb.brcddb_login as brcddb_login
import brcddb.report.utils as report_utils
import brcddb.app_data.alert_tables as al

_std_font = report_fonts.font_type('std')
_bold_font = report_fonts.font_type('bold')
_align_wrap = report_fonts.align_type('wrap')
_border_thin = report_fonts.border_type('thin')

##################################################################
#
#              Generic case methods
#
##################################################################


def _comment_case(obj, p0=None, p1=None, p2=None):
    return '\n'.join(
        [a.fmt_msg() for a in obj.r_alert_objects() if not a.is_flag()])
コード例 #12
0
def graph(wb, tc, sheet_name, sheet_i, data_ref):
    """Creates a dashboard worksheet for the Excel report.

    data_ref: The graph assumes that the first row of the data are the data lables

    +-----------+-----------+-------------------------------------------+
    | Member    | type      | Description                               |
    +===========+===========+===========================================+
    | title     | str       | Chart title                               |
    +-----------+-----------+-------------------------------------------+
    | sheet     | pointer   | Pointer to worksheet object returned from |
    |           |           | create_sheet()                            |
    +-----------+-----------+-------------------------------------------+
    | type      | str       | Chart type. See chart_types.              |
    +-----------+-----------+-------------------------------------------+
    | x         | dict      | See Axis dictionary below.                |
    +-----------+-----------+-------------------------------------------+
    | y         | dict      | Same as x but for the y axis.             |
    +-----------+-----------+-------------------------------------------+

    Axis dictionary

    +-----------+-----------+-------------------------------------------+
    | Member    | type      | Description                               |
    +===========+===========+===========================================+
    | title     | str       | Axis title.                               |
    +-----------+-----------+-------------------------------------------+
    | min_col   | int       | Starting column.                          |
    +-----------+-----------+-------------------------------------------+
    | max_col   | int       | Last column. Not used for the x axis.     |
    +-----------+-----------+-------------------------------------------+
    | min_row   | int       | Starting row. Should include the labels.  |
    +-----------+-----------+-------------------------------------------+
    | max_row   | int       | Row number for the last sample.           |
    +-----------+-----------+-------------------------------------------+

    :param wb: Workbook object
    :type wb: dict
    :param tc: Table of context page. A link to this page is place in cell A1
    :type tc: str, None
    :param sheet_name: Sheet (tab) name
    :type sheet_name: str
    :param sheet_i: Sheet index where page is to be placed.
    :type sheet_i: int
    :param data_ref: Chart type. See chart_types
    :type data_ref: dcit
    :rtype: None
    """

    # Create the worksheet, add the headers, and set up the column widths
    sheet = wb.create_sheet(index=sheet_i, title=sheet_name)
    sheet.page_setup.paperSize = sheet.PAPERSIZE_LETTER
    sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
    ref_sheet = data_ref['sheet']
    y = data_ref['y']
    x = data_ref['x']
    if isinstance(tc, str):
        sheet['A1'].hyperlink = '#' + tc + '!A1'
        sheet['A1'].font = report_fonts.font_type('link')
        sheet['A1'] = 'Contents'

    data = Reference(ref_sheet,
                     min_col=y['min_col'],
                     min_row=y['min_row'],
                     max_col=y['max_col'],
                     max_row=y['max_row'])
    # Chart with date axis
    chart = LineChart()
    chart.title = data_ref['title']
    chart.y_axis.title = y['title']
    chart.y_axis.crossAx = 500
    chart.x_axis = DateAxis(crossAx=100)
    chart.x_axis.title = x['title']

    chart.add_data(data, titles_from_data=True)
    dates = Reference(ref_sheet,
                      min_col=x['min_col'],
                      min_row=x['min_row'],
                      max_row=x['max_row'])
    chart.set_categories(dates)

    sheet.add_chart(chart, 'A2')
コード例 #13
0
ファイル: login.py プロジェクト: jconsoli/brcddb
def login_page(wb,
               tc,
               sheet_name,
               sheet_i,
               sheet_title,
               l_list,
               display,
               login_display_tbl,
               s=True):
    """Creates a login detail worksheet for the Excel report.

    :param wb: Workbook object
    :type wb: class
    :param tc: Table of context page. A link to this page is place in cell A1
    :type tc: str, None
    :param sheet_name: Sheet (tab) name
    :type sheet_name: str
    :param sheet_i: Sheet index where page is to be placed.
    :type sheet_i: int
    :param sheet_title: Title to be displayed in large font, hdr_1, at the top of the sheet
    :type sheet_title: str
    :param l_list: List of login objects (LoginObj) to display
    :type l_list: list, tuple
    :param display: List of parameters to display.
    :type display: list, tuple
    :param login_display_tbl: Display control table. See brcddb.report.report_tables.login_display_tbl
    :type login_display_tbl: dict
    :param s: If True, sorts the logins by port-id (port address where the login was found)
    :rtype: None
    """
    global login_case, fdmi_case

    # Validate the user input
    err_msg = list()
    if l_list is None:
        err_msg.append('l_list was not defined.')
    elif not isinstance(l_list, (list, tuple)):
        err_msg.append('l_list was type ' + str(type(l_list)) +
                       '. Must be a list or tuple.')
    if display is None:
        err_msg.append('display not defined.')
    if len(err_msg) > 0:
        err_msg.append('Failed to create login_page().')
        brcdapi_log.exception(err_msg, True)
        return

    # Create the worksheet, add the headers, and set up the column widths
    sheet = wb.create_sheet(index=sheet_i, title=sheet_name)
    sheet.page_setup.paperSize = sheet.PAPERSIZE_LETTER
    sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
    col = 1
    row = 1
    if isinstance(tc, str):
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].hyperlink = '#' + tc + '!A1'
        sheet[cell].font = report_fonts.font_type('link')
        sheet[cell] = 'Contents'
        col += 1
    cell = xl.get_column_letter(col) + str(row)
    sheet[cell].font = report_fonts.font_type('hdr_1')
    sheet[cell] = sheet_title
    sheet.freeze_panes = sheet['A3']
    col = 1
    row += 1
    for k in display:
        if k in login_display_tbl and 'dc' in login_display_tbl[
                k] and login_display_tbl[k]['dc'] is True:
            continue
        cell = xl.get_column_letter(col) + str(row)
        sheet[cell].font = report_fonts.font_type('bold')
        sheet[cell].border = report_fonts.border_type('thin')
        if k in login_display_tbl:
            if 'c' in login_display_tbl[k]:
                sheet.column_dimensions[xl.get_column_letter(
                    col)].width = login_display_tbl[k]['c']
            try:
                if login_display_tbl[k]['v']:
                    sheet[cell].alignment = report_fonts.align_type(
                        'wrap_vert_center')
                else:
                    sheet[cell].alignment = report_fonts.align_type('wrap')
            except:
                sheet[cell].alignment = report_fonts.align_type('wrap')
            if 'd' in login_display_tbl[k]:
                sheet[cell] = login_display_tbl[k]['d']
            else:
                sheet[cell] = k
        else:
            sheet[
                cell] = k  # This happens when a new key is introduced before updating the display table
        col += 1

    # Add a row for each login
    row += 1
    if s:
        wl = brcddb_util.sort_obj_num(l_list, 'port-id', r=False,
                                      h=True)  # Filters out anything not found
        wl.extend(list(set(l_list) - set(wl)))
    else:
        wl = l_list
    for login_obj in wl:
        if login_obj is None:
            row += 1
            continue
        col = 1
        border = report_fonts.border_type('thin')
        alignment = report_fonts.align_type('wrap')
        center_alignment = report_fonts.align_type('wrap_center')
        font = report_utils.font_type(
            report_utils.combined_login_alert_objects(login_obj))
        for k in display:
            if k in login_display_tbl and 'dc' in login_display_tbl[
                    k] and login_display_tbl[k]['dc'] is True:
                continue
            cell = xl.get_column_letter(col) + str(row)
            sheet[cell].border = border
            if k in login_display_tbl and 'm' in login_display_tbl[
                    k] and login_display_tbl[k]['m'] is True:
                sheet[cell].alignment = center_alignment
            else:
                sheet[cell].alignment = alignment
            sheet[cell].font = font
            k_list = k.split('.')
            if len(k_list) > 1:
                try:
                    sheet[cell] = fdmi_case[k_list[0]](login_obj, k_list[1])
                except:
                    sheet[cell] = ''
                    brcdapi_log.exception('Unknown key: ' + k_list[0])
            elif k in login_case:
                sheet[cell] = login_case[k](login_obj)
            elif k in login_display_tbl:
                v = login_obj.r_get(k)
                if v is None:
                    v1 = ''
                else:
                    try:
                        v1 = brcddb_common.login_conversion_tbl[k][v]
                        if v1 is None:
                            raise
                    except:
                        v1 = v
                if isinstance(v1, bool):
                    sheet[cell] = '\u221A' if v1 else ''
                else:
                    sheet[cell] = v1
            else:
                sheet[cell].font = report_fonts.font_type('std')
                sheet[cell] = '' if login_obj.r_get(k) is None else str(
                    login_obj.r_get(k))
            col += 1
        row += 1
コード例 #14
0
ファイル: fabric.py プロジェクト: jconsoli/brcddb
def _zone_configuration(fabric_obj):
    """Adds the zone configuration summary to the worksheet.

    :param fabric_obj: Fabric object
    :type fabric_obj: brcddb.classes.fabric.FabricObj
    :rtype: None
    """
    global _row, _sheet, _hdr

    border = report_fonts.border_type('thin')
    alignment = report_fonts.align_type('wrap')
    font = report_fonts.font_type('std')
    obj = fabric_obj.r_eff_zone_cfg_obj()

    # Add the Defined Configurations
    _row += 2
    col = 1
    _sheet.merge_cells(start_row=_row,
                       start_column=col,
                       end_row=_row,
                       end_column=len(_hdr) + 1)
    cell = xl.get_column_letter(col) + str(_row)
    _sheet[cell].alignment = alignment
    _sheet[cell].border = border
    _sheet[cell].font = report_fonts.font_type('bold')
    _sheet[cell] = 'Defined Configurations'
    for obj in fabric_obj.r_zonecfg_objects():
        buf = obj.r_obj_key()
        if buf == '_effective_zone_cfg':
            continue
        _row += 1
        if obj.r_is_effective():
            buf = '*' + buf
        _sheet.merge_cells(start_row=_row,
                           start_column=col,
                           end_row=_row,
                           end_column=len(_hdr))
        for col in range(1, len(_hdr) + 1):
            cell = xl.get_column_letter(col) + str(_row)
            _sheet[cell].border = border
        col = 1
        cell = xl.get_column_letter(col) + str(_row)
        _sheet[cell].alignment = alignment
        _sheet[cell].font = font
        _sheet[cell] = buf

    # Effective zone footnote
    _row += 1
    _sheet.merge_cells(start_row=_row,
                       start_column=col,
                       end_row=_row,
                       end_column=len(_hdr))
    col = 1
    cell = xl.get_column_letter(col) + str(_row)
    _sheet[cell].font = font
    _sheet[cell] = '* indicates effective zone configuration'

    # Effective zone configuration summary
    if obj is not None:
        _row += 2
        col = 1
        cell = xl.get_column_letter(col) + str(_row)
        _sheet[cell].font = report_fonts.font_type('bold')
        _sheet.merge_cells(start_row=_row,
                           start_column=col,
                           end_row=_row,
                           end_column=len(_hdr))
        _sheet[cell] = 'Effective Zone Configuration Summary'
        ec_obj = fabric_obj.r_get('brocade-zone/effective-configuration')
        if isinstance(ec_obj, dict):
            for k in ec_obj:
                _row += 1
                col = 1
                _sheet.merge_cells(start_row=_row,
                                   start_column=col,
                                   end_row=_row,
                                   end_column=col + 1)
                cell = xl.get_column_letter(col) + str(_row)
                _sheet[cell].font = font
                _sheet[cell].alignment = alignment
                # _sheet[cell].border = border
                _sheet[cell] = zone_key_conv[k] if k in zone_key_conv else k
                col += 2
                _sheet.merge_cells(start_row=_row,
                                   start_column=col,
                                   end_row=_row,
                                   end_column=len(_hdr))
                cell = xl.get_column_letter(col) + str(_row)
                _sheet[cell].font = font
                _sheet[cell].alignment = alignment
                v = ec_obj.get(k)
                try:
                    _sheet[cell] = brcddb_common.zonecfg_conversion_tbl[k][v]
                except:
                    _sheet[cell] = v
                for i in range(1, len(_hdr) + 1):
                    cell = xl.get_column_letter(i) + str(_row)
                    _sheet[cell].border = border
        else:
            _row += 1
            col = 1
            _sheet.merge_cells(start_row=_row,
                               start_column=col,
                               end_row=_row,
                               end_column=col + 1)
            cell = xl.get_column_letter(col) + str(_row)
            _sheet[cell].font = font
            _sheet[cell].alignment = alignment
            _sheet[cell] = 'No effective configuration'
コード例 #15
0
ファイル: fabric.py プロジェクト: jconsoli/brcddb
def _fabric_summary(fabric_obj):
    """Adds a fabric summary to the worksheet.

    :param fabric_obj: Fabric object
    :type fabric_obj: brcddb.classes.fabric.FabricObj
    :rtype: None
    """
    global _row, _sheet, _hdr

    border = report_fonts.border_type('thin')
    alignment = report_fonts.align_type('wrap')
    font = report_fonts.font_type('bold')

    # Add the headers
    _row += 2
    col = 1
    for k in _hdr.keys():
        cell = xl.get_column_letter(col) + str(_row)
        _sheet[cell].alignment = alignment
        _sheet[cell].border = border
        _sheet[cell].font = font
        _sheet[cell] = k
        col += 1
    _row += 1

    # Setup the common cell attributes
    font = report_fonts.font_type('std')
    switch_obj_l = fabric_obj.r_switch_objects()
    row = _row
    for switch_obj in switch_obj_l:
        for col in range(1, len(_hdr) + 1):
            cell = xl.get_column_letter(col) + str(row)
            _sheet[cell].alignment = alignment
            _sheet[cell].border = border
            _sheet[cell].font = font
        row += 1

    # Add the switch summary
    for switch_obj in switch_obj_l:
        col = 1
        # Switch name
        buf = brcddb_switch.best_switch_name(switch_obj, False)
        if switch_obj.r_is_principal():
            buf = '*' + buf
        cell = xl.get_column_letter(col) + str(_row)
        _sheet[cell] = buf
        col += 1
        # Switch WWN
        cell = xl.get_column_letter(col) + str(_row)
        _sheet[cell] = switch_obj.r_obj_key()
        col += 1
        # Switch DID
        cell = xl.get_column_letter(col) + str(_row)
        buf = switch_obj.r_get('brocade-fabric/fabric-switch/domain-id')
        _sheet[cell] = switch_obj.r_get('brocade-fibrechannel-switch/fibrechannel-switch/domain-id') if buf is None \
            else buf
        col += 1
        # Switch FID
        cell = xl.get_column_letter(col) + str(_row)
        _sheet[cell] = brcddb_switch.switch_fid(switch_obj)
        col += 1
        # Firmware version
        cell = xl.get_column_letter(col) + str(_row)
        buf = switch_obj.r_get('brocade-fabric/fabric-switch/firmware-version')
        _sheet[cell] = switch_obj.r_get('brocade-fibrechannel-switch/fibrechannel-switch/firmware-version') if \
            buf is None else buf
        _row += 1

    # Pincipal switch footnote
    col = 1
    _sheet.merge_cells(start_row=_row,
                       start_column=col,
                       end_row=_row,
                       end_column=len(_hdr))
    cell = xl.get_column_letter(col) + str(_row)
    _sheet[cell].font = font
    _sheet[cell] = '* indicates principal switch'