def get_html()

in classic-load-balancer-consolelink-utility/consolelink_classic_load_balancer.py [0:0]


def get_html(elb_data):
    '''
    Generate a html file with Classic Load Balancers' Attributes and ConsoleLink
    '''
    html = """<html><body><title>Classic Load Balancer Console Link</title><table border="1"><tr>"""
    colunm_names = sorted(list(set(k for d in elb_data for k in d)))
    for colunm in colunm_names:
        html += "<th>{}</th>".format(colunm)
    html += "</tr><tr>"
    for lb in elb_data:
        for attribute in ([lb.get(col, None) for col in colunm_names]):
            if isinstance(attribute,str):
                if CONSOLE_PREFIX in attribute:
                    html+='''<td><a href="{}">{}</a></td>'''.format(attribute,attribute.split('=')[-1])
                else:
                    html += "<td>{}</td>".format(attribute)
    html = """<!DOCTYPE html><html><title>Classic Load Balancer Console Link</title><body><table border="1"><tr>"""
    column_names = sorted(list(set(k for d in elb_data for k in d)))
    for column in column_names:
        html += "<th>{}</th>".format(column)
    html += "</tr>"
    for lb in elb_data:
        html += "<tr>"
        for attribute in ([lb.get(col, None) for col in column_names]):
            if isinstance(attribute, str) and (CONSOLE_PREFIX in attribute):
                html+='''<td><a href="{}">{}</a></td>'''.format(attribute, attribute.split('=')[-1])
            else:
                html += "<td>{}</td>".format(attribute)
        html += "</tr>"
    html += "</table></body></html>"
    with open('CLBConsoleLink.html', 'wb') as html_file:
        html_file.write(html)