Esempio n. 1
0
def main():
    global opt, debug, verbose

    # most cli optnios available in global hash opt; e.g., opt['hostname']
    get_options()

    wapi = InfobloxAPI(gridmgr, opt['uid'], opt['passwd'], 
                       debug=debug, verbose=verbose, verify=False)

    r = { }  # r will hold response from wapi calls

    if not opt['noaction']:
        r = wapi.rh_add( opt['iprange'],
                         wapi.next_available_ip(opt['iprange']),
                         opt['hostname'] )
    else:
        print "Bailing due to noaction flag."
        return 1

    if not r:
        print "Unknown error in WAPI call."
        return 0
    

    r['iprange'] = opt['iprange']
    return print_output(r)
Esempio n. 2
0
def main():
    global opt, debug, verbose

    # most cli optnios available in global hash opt; e.g., opt['hostname']
    get_options()

    wapi = InfobloxAPI(gridmgr,
                       opt['uid'],
                       opt['passwd'],
                       debug=debug,
                       verbose=verbose,
                       verify=False)

    r = {}  # r will hold response from wapi calls

    if not opt['noaction']:
        r = wapi.rh_add(opt['iprange'], wapi.next_available_ip(opt['iprange']),
                        opt['hostname'])
    else:
        print "Bailing due to noaction flag."
        return 1

    if not r:
        print "Unknown error in WAPI call."
        return 0

    r['iprange'] = opt['iprange']
    return print_output(r)
Esempio n. 3
0
def main():
    get_options()

    if debug:
        print "prefix: " + opt['prefix']
        print "count:  " + str(opt['count_start'])
        print "digits: " + str(opt['digits'])
        print "domains:"
        for i in opt['domain']:
            print '  ' + i

    i = InfobloxAPI(
        '10.69.15.170',
        opt['uid'],
        opt['passwd'],
        # verbose=verbose, debug=debug, verify=False)
        verify=False)

    cnt = opt['count_start']
    end = 10**opt['digits']
    while cnt < end:
        hostname = "{0:s}{1:s}".format(opt['prefix'],
                                       str(cnt).zfill(opt['digits']))
        if verbose:
            print "Checking {0:s}".format(hostname),
        available = True
        for d in opt['domain']:
            fqdn = hostname + '.' + d
            if verbose:
                print " .{0:s}".format(d),

            # Test DNS
            try:
                socket.gethostbyname(fqdn)
                available = False
                break
            except:
                pass

            # Test record:a
            if i.ra_exists(fqdn):
                if verbose:
                    print "Infoblox record:a"
                available = False
                break

            # Test record:host
            if i.rh_exists(fqdn):
                if verbose:
                    print "Infoblox record:host"
                available = False
                break

        if verbose:
            print ""

        if available:
            if verbose:
                print "Available!"
            print hostname
            return 0

        cnt += 1

    return 1
Esempio n. 4
0
def main():
    get_options()

    if debug:
        print "prefix: " + opt["prefix"]
        print "count:  " + str(opt["count_start"])
        print "digits: " + str(opt["digits"])
        print "domains:"
        for i in opt["domain"]:
            print "  " + i

    i = InfobloxAPI(
        "10.69.15.170",
        opt["uid"],
        opt["passwd"],
        # verbose=verbose, debug=debug, verify=False)
        verify=False,
    )

    cnt = opt["count_start"]
    end = 10 ** opt["digits"]
    while cnt < end:
        hostname = "{0:s}{1:s}".format(opt["prefix"], str(cnt).zfill(opt["digits"]))
        if verbose:
            print "Checking {0:s}".format(hostname),
        available = True
        for d in opt["domain"]:
            fqdn = hostname + "." + d
            if verbose:
                print " .{0:s}".format(d),

            # Test DNS
            try:
                socket.gethostbyname(fqdn)
                available = False
                break
            except:
                pass

            # Test record:a
            if i.ra_exists(fqdn):
                if verbose:
                    print "Infoblox record:a"
                available = False
                break

            # Test record:host
            if i.rh_exists(fqdn):
                if verbose:
                    print "Infoblox record:host"
                available = False
                break

        if verbose:
            print ""

        if available:
            if verbose:
                print "Available!"
            print hostname
            return 0

        cnt += 1

    return 1