Exemple #1
0
def formattedPrint(datas):
    import sys

    if sys.version_info > (2, 6) and sys.version_info < (2, 8):
        import utils2 as utils
    elif sys.version_info > (3, 0):
        import utils3 as utils

    if not datas:
        print("No data")
        exit(1)

    # get all zones
    # API /zone without :identifier
    if isinstance(datas, list):
        hr()
        print("%-20s %-8s %-12s" % ("name", "type", "notified_serial"))
        hr()
        for record in datas:
            # print 'NAME'
            utils.print_inline("%(name)-20s" % record)

            # print 'TYPE' of SOA record
            utils.print_inline("%(type)-8s" % record)

            if record.get("notified_serial"):
                print("%(notified_serial)s" % record)

        exit(0)

    elif datas.get("records"):
        print("domain: %(name)s" % datas)

        if datas.get("type") == "MASTER":
            print("serial: %(notified_serial)s" % datas)

        print("DNS   : %(type)s" % datas)

        # header
        hr()
        print("%-33s %-5s %-25s %-5s %-3s" % ("name", "type", "content", "ttl", "prio"))
        hr()

        for record in datas.get("records"):

            # print 'NAME'
            utils.print_inline("%(name)-33s" % record)

            # print 'TYPE' of SOA record
            if record.get("type") == "SOA":
                print("%(type)-5s" % record)

            # print 'TYPE' of non SOA record
            else:
                utils.print_inline("%(type)-5s" % record)

            # print 'CONTENT' of non SOA
            if record.get("type") == "SOA":
                utils.print_inline(">\t\t%(content)-25s " % record)

            # print 'CONTENT' of SOA record
            else:
                utils.print_inline("%(content)-25s" % record)

            # print TTL, and PRIORITY for MX, SRV record
            if record.get("priority"):
                utils.print_inline("%(ttl)5s" % record)
                print("%(priority)2s" % record)

            # print ttl for non SOA record
            else:
                print("%(ttl)5s " % record)

        hr()

    # for template
    elif datas.get("identifier"):
        print("identifier : %(identifier)s" % datas)
        print("description: %(description)s" % datas)
        hr()
        print("%-33s %-5s %-25s %-5s %-3s" % ("name", "type", "content", "ttl", "prio"))

        for record in datas.get("entries"):

            # print 'NAME'
            utils.print_inline("%(name)-33s" % record)

            # print 'TYPE' for SOA
            if record.get("type") == "SOA":
                print("%(type)-5s" % record)

            # print 'TYPE' for non SOA
            else:
                utils.print_inline("%(type)-5s" % record)

            # print 'CONTENT' for SOA
            if record.get("type") == "SOA":
                utils.print_inline("> %(content)-25s " % record)

            # print 'CONTENT' for non SOA
            else:
                utils.print_inline("%(content)-24s" % record)

            # print 'TTL', and 'PRIORITY'
            if record.get("priority") != None:
                utils.print_inline("%(ttl)5s" % record)
                print("%(priority)2s" % record)

            # print
            else:
                print("%(ttl)5s " % record)
        hr()
    else:
        print("No match records")
def formattedPrint(datas):
    import sys
    if sys.version_info > (2, 6) and sys.version_info < (2, 8):
        import utils2 as utils
    elif sys.version_info > (3, 0):
        import utils3 as utils
    if not datas:
        print("No data")
        exit(1)
    if datas.get('records'):
        print("domain: %(name)s" % datas)
        if datas.get('type') == 'MASTER':
            print("serial: %(notified_serial)s" % datas)
        print("DNS   : %(type)s" % datas)
        hr()
        print('%-33s %-5s %-25s %-5s %-3s'
              % ('name', 'type', 'content', 'ttl', 'prio'))
        hr()
        for record in datas.get('records'):
            utils.print_inline("%(name)-33s" % record)
            if record.get('type') == 'SOA':
                print("%(type)-5s" % record)
            else:
                utils.print_inline("%(type)-5s" % record)
            if record.get('type') == 'SOA':
                utils.print_inline(">\t\t%(content)-25s " % record)
            else:
                utils.print_inline("%(content)-25s" % record)
            if record.get('priority'):
                utils.print_inline("%(ttl)5s" % record)
                print("%(priority)2s" % record)
            else:
                print("%(ttl)5s " % record)
        hr()
    elif datas.get('identifier'):
        print("identifier : %(identifier)s" % datas)
        print("description: %(description)s" % datas)
        hr()
        print('%-33s %-5s %-25s %-5s %-3s'
              % ('name', 'type', 'content', 'ttl', 'prio'))
        for record in datas.get('entries'):
            utils.print_inline("%(name)-33s" % record)
            if record.get('type') == 'SOA':
                print("%(type)-5s" % record)
            else:
                utils.print_inline("%(type)-5s" % record)
            if record.get('type') == 'SOA':
                utils.print_inline("> %(content)-25s " % record)
            else:
                utils.print_inline("%(content)-24s" % record)
            if record.get('priority') != None:
                utils.print_inline("%(ttl)5s" % record)
                print("%(priority)2s" % record)
            else:
                print("%(ttl)5s " % record)
        hr()
    else:
        print("No match records")
Exemple #3
0
def formattedPrint(datas):
    import sys
    if sys.version_info > (2, 6) and sys.version_info < (2, 8):
        import utils2 as utils
    elif sys.version_info > (3, 0):
        import utils3 as utils

    if not datas:
        print("No data")
        exit(1)

    if datas.get('records'):
        print("domain: %(name)s" % datas)

        if datas.get('type') == 'MASTER':
            print("serial: %(notified_serial)s" % datas)

        print("DNS   : %(type)s" % datas)

        # header
        hr()
        print('%-33s %-5s %-25s %-5s %-3s'
              % ('name', 'type', 'content', 'ttl', 'prio'))
        hr()

        for record in datas.get('records'):

            # print 'NAME'
            utils.print_inline("%(name)-33s" % record)

            # print 'TYPE' of SOA record
            if record.get('type') == 'SOA':
                print("%(type)-5s" % record)

            # print 'TYPE' of non SOA record
            else:
                utils.print_inline("%(type)-5s" % record)

            # print 'CONTENT' of non SOA
            if record.get('type') == 'SOA':
                utils.print_inline(">\t\t%(content)-25s " % record)

            # print 'CONTENT' of SOA record
            else:
                utils.print_inline("%(content)-25s" % record)

            # print TTL, and PRIORITY for MX, SRV record
            if record.get('priority'):
                utils.print_inline("%(ttl)5s" % record)
                print("%(priority)2s" % record)

            # print ttl for non SOA record
            else:
                print("%(ttl)5s " % record)

        hr()

    # for template
    elif datas.get('identifier'):
        print("identifier : %(identifier)s" % datas)
        print("description: %(description)s" % datas)
        hr()
        print('%-33s %-5s %-25s %-5s %-3s'
              % ('name', 'type', 'content', 'ttl', 'prio'))

        for record in datas.get('entries'):

            # print 'NAME'
            utils.print_inline("%(name)-33s" % record)

            # print 'TYPE' for SOA
            if record.get('type') == 'SOA':
                print("%(type)-5s" % record)

            # print 'TYPE' for non SOA
            else:
                utils.print_inline("%(type)-5s" % record)

            # print 'CONTENT' for SOA
            if record.get('type') == 'SOA':
                utils.print_inline("> %(content)-25s " % record)

            # print 'CONTENT' for non SOA
            else:
                utils.print_inline("%(content)-24s" % record)

            # print 'TTL', and 'PRIORITY'
            if record.get('priority') != None:
                utils.print_inline("%(ttl)5s" % record)
                print("%(priority)2s" % record)

            # print
            else:
                print("%(ttl)5s " % record)
        hr()
    else:
        print("No match records")