Esempio n. 1
0
File: dyn.py Progetto: intgr/lemur
def get_zones(account_number):
    get_dynect_session()
    zones = get_all_zones()
    zone_list = []
    for zone in zones:
        zone_list.append(zone.name)
    return zone_list
Esempio n. 2
0
def get_zones(account_number):
    get_dynect_session()
    zones = get_all_zones()
    zone_list = []
    for zone in zones:
        zone_list.append(zone.name)
    return zone_list
Esempio n. 3
0
def list_dyn_domains():
    args = docopt.docopt(__doc__)
    with DynectSession(os.environ["DYN_CUSTOMER"], os.environ["DYN_USERNAME"],
                       os.environ["DYN_PASSWORD"]) as session:
        zones = get_all_zones()
        for zone in zones:
            records = zone.get_all_records()
            for name, value in records.items():
                print(f"Zone {zone} has {name} with {value}")
Esempio n. 4
0
def _get_dyn_node(name: str) -> Node:
    """Retrieve a Dyn DNS Node using the Dyn API

    NOTE: A Dyn Session (dyn.tm.session.DynectSession) must have been
          initialized prior to using this method. DynectSession is a singleton
          that does not require to be passed around to call APIs
    """
    zones = dyn_zones.get_all_zones()
    for z in zones:
        for n in z.get_all_nodes():
            if n.fqdn == name:
                return n

    raise DynResourceNotFound(f"could not find a DNS node named {name}")
Esempio n. 5
0
def list_zone(zone_name):
    """
    Print names of a zone or all zones
    """
    try:
        if zone_name == None:
            zones = get_all_zones()
        else:
            zones = [Zone(zone_name)]
    except Exception as e:
        errordie("failed to get zone(s): {}".format(e))

    for zone in zones:
        print(zone.name)
Esempio n. 6
0
def get_zone_name(domain):
    zones = get_all_zones()

    zone_name = ""

    for z in zones:
        if domain.endswith(z.name):
            # Find the most specific zone possible for the domain
            # Ex: If fqdn is a.b.c.com, there is a zone for c.com,
            # and a zone for b.c.com, we want to use b.c.com.
            if z.name.count(".") > zone_name.count("."):
                zone_name = z.name
    if not zone_name:
        raise Exception("No Dyn zone found for domain: {}".format(domain))
    return zone_name
Esempio n. 7
0
File: dyn.py Progetto: intgr/lemur
def get_zone_name(domain):
    zones = get_all_zones()

    zone_name = ""

    for z in zones:
        if domain.endswith(z.name):
            # Find the most specific zone possible for the domain
            # Ex: If fqdn is a.b.c.com, there is a zone for c.com,
            # and a zone for b.c.com, we want to use b.c.com.
            if z.name.count(".") > zone_name.count("."):
                zone_name = z.name
    if not zone_name:
        raise Exception("No Dyn zone found for domain: {}".format(domain))
    return zone_name
Esempio n. 8
0
import csv
from datetime import date
from datetime import timedelta
from dyn.tm.session import DynectSession
from dyn.tm.zones import get_all_zones
from dyn.tm.errors import DynectGetError

config = configparser.ConfigParser()
config.read('dynfetch.ini')

session = DynectSession(config['dyn']['accountname'],
                        config['dyn']['username'],
                        config['dyn']['password']
                        )

zonelist = get_all_zones()

sum_records = 0
sum_requests = 0

start = date.today() - timedelta(days=30)

zones = dict()

def csvsum(csvvar):
    """
    cumulates the second column in the csv and returns it
    """
    sum = 0
    intread = csv.reader(csvvar.splitlines())
    next(intread)  # to skip the first line
Esempio n. 9
0
def main():

    # Get config file
    conf = Config()
    conf.open_file(get_config_file())

    directory = os.path.abspath(os.path.dirname(__file__)) + "/../tmp"
    if not os.path.exists(directory):
        os.makedirs(directory)

    # MD5 file
    md5_file = os.path.abspath(os.path.dirname(__file__)) + "/../tmp/md5.txt"

    # Get  details from cconfig file
    my_session = DynectSession(conf.get_item('dynapi', 'username'), 'API',
                               conf.get_item('dynapi', 'password'))

    # Checking if any zones have been found if none exits
    my_zones = get_all_zones()
    if my_zones == None:
        print "HELP! We have no data"
        sys.exit(1)

    # Get each zone and add to a string ( used to create & record a hash )
    hashable_zones = ""
    for zone in my_zones:
        hashable_zones = hashable_zones + str(zone).split()[1]
    hashed_zones = hashlib.md5(hashable_zones).hexdigest()

    #open md5.txt and checks if the new md5 is same as old md5
    if os.path.isfile(md5_file):
        f = open(os.path.abspath(md5_file))
        if hashed_zones == f.readline():
            print "No change"
            sys.exit()
        f.close()

    # Writing bind config
    mytemplate = Template(filename=os.path.abspath(os.path.dirname(__file__)) +
                          '/../docs/mytmpl.txt',
                          module_directory=os.path.abspath(
                              os.path.dirname(__file__) +
                              "/../tmp/makotemplate"))
    f = open(conf.get_item('dynapi', 'bind_file'), 'w')

    # Write bind config
    for zone in my_zones:
        zone = str(zone).split()[1]
        f.write(
            mytemplate.render(zone=zone,
                              cache_dir=conf.get_item('dynapi', 'cache_dir'),
                              master_ip=conf.get_item('dynapi', 'master_ip')))

    f.close()

    # Reload config
    status, message = commands.getstatusoutput(
        conf.get_item('dynapi', 'rndc') + " reconfig")
    if status > 0:
        print message
        sys.exit(status)

    # Update new md5hash, reconfigure was successful
    f = open(md5_file, 'w')
    f.write(hashed_zones)
Esempio n. 10
0
 def get_zones(self):
     self.start_session()            
     zones = get_all_zones()
     self.close_session()
     return zones