def download(spr_client, spreadsheet): if not os.path.exists('data'): os.mkdir('data') print "downloading switches" switches = get_worksheet_data(spr_client, spreadsheet, "Switches") sws = shelve.open("data/switches") sws['list'] = switches sws.close() print "downloading port types" port_types = get_worksheet_data(spr_client, spreadsheet, "Port Types") pt = shelve.open("data/port_types") pt['list'] = port_types pt.close() print "downloading users" users = get_worksheet_data(spr_client, spreadsheet, "Users") for user in list(users): if not "IOS password" in user: users.remove(user) u = shelve.open("data/users") u["list"] = users u.close() print "downloading Addressing" addressing = get_worksheet_data(spr_client, spreadsheet, "Addressing") v4 = shelve.open("data/addressing") v4["list"] = addressing v4.close() print "downloading Links" links = get_worksheet_data(spr_client, spreadsheet, "Links") l = shelve.open("data/links") l["list"] = links l.close() print "done"
def download(spr_client, spreadsheet): if not os.path.exists('data'): os.mkdir('data') print "downloading switches" switches = get_worksheet_data(spr_client, spreadsheet, "Switches") sws = shelve.open("data/switches") sws['list'] = switches sws.close() print "downloading users" users = get_worksheet_data(spr_client, spreadsheet, "Users") for user in list(users): if not "IOS password" in user: users.remove(user) u = shelve.open("data/users") u["list"] = users u.close() print "downloading Addressing" addressing = get_worksheet_data(spr_client, spreadsheet, "Addressing") v4 = shelve.open("data/addressing") v4["list"] = addressing v4.close() print "downloading Links" links = get_worksheet_data(spr_client, spreadsheet, "Links") l = shelve.open("data/links") l["list"] = links l.close() print "done"
def dump_worksheet(spr_client, spreadsheet, wks): print get_worksheet_data(spr_client, spreadsheet, wks)
parser = argparse.ArgumentParser(description='Generate cisco IOS config files from gdocs.') parser.add_argument('--deploy', action='store_true', help='deploy zone files after generating') args = parser.parse_args() spreadsheet = config.get('gdata', 'noc_combined') spr_client = login("emfcamp DNS zone generator", config) print "downloading Addressing" addressing = get_worksheet_data(spr_client, spreadsheet, "Addressing") print "downloading codenames" codenames = get_worksheet_data(spr_client, spreadsheet, "Codenames") #for x in range(0, 2560000): # print pretty_host("gchq.org.uk", None) sshfps = get_sshfps() zones = {} for row in addressing: if "Domain" in row: fwd_zonename = row["Domain"]; else: fwd_zonename = default_domain
#!/usr/bin/python # EMF roundup user generator import ipaddr, time, os, sys, ConfigParser from nocsheet import login, get_worksheets, get_worksheet_data config = ConfigParser.ConfigParser() if not config.read("/etc/emf-gdata.conf"): print "Warning: config file /etc/emf-gdata.conf could not be found or read" spreadsheet = config.get('gdata', 'noc_combined') spr_client = login("emfcamp Roundup config generator", config) print "downloading Users" users = get_worksheet_data(spr_client, spreadsheet, "Users") for user in users: if "uid" in user and user["uid"].isdigit(): print "create user username="******"Username"] + " address=" + user["E-mail"] + " roles=Admin"
if not os.path.exists('out'): os.mkdir('out') if not os.path.exists('out/icinga'): os.mkdir('out/icinga') config = ConfigParser.ConfigParser() if not config.read("/etc/emf-gdata.conf"): print "Warning: config file /etc/emf-gdata.conf could not be found or read" spreadsheet = config.get('gdata', 'noc_combined') spr_client = login("emfcamp DHCP config generator", config) print "downloading Switches" switches = get_worksheet_data(spr_client, spreadsheet, "Switches") print "downloading Links" links = get_worksheet_data(spr_client, spreadsheet, "Links") print "downloading VMs" vms = get_worksheet_data(spr_client, spreadsheet, "VMs") po_index = {} def short_port(port): return port.replace("TenGigabitEthernet", "Te").replace("GigabitEthernet", "Gi").replace("FastEthernet", "Fa") def add_host(hostname, ip, parent): global f f.write("define host {\n")
#!/usr/bin/python # EMF roundup user generator import ipaddr, time, os, sys, ConfigParser from nocsheet import login, get_worksheets, get_worksheet_data config = ConfigParser.ConfigParser() if not config.read("/etc/emf-gdata.conf"): print "Warning: config file /etc/emf-gdata.conf could not be found or read" spreadsheet = config.get('gdata', 'noc_combined') spr_client = login("emfcamp Roundup config generator", config) print "downloading Users" users = get_worksheet_data(spr_client, spreadsheet, "Users") for user in users: if "uid" in user and user["uid"].isdigit(): print "create user username="******"Username"] + " address=" + user[ "E-mail"] + " roles=Admin"
if not os.path.exists('out'): os.mkdir('out') configfile4 = "out/dhcpd-subnets.conf" configfile6 = "out/dhcpd6-subnets.conf" config = ConfigParser.ConfigParser() if not config.read("/etc/emf-gdata.conf"): print "Warning: config file /etc/emf-gdata.conf could not be found or read" spreadsheet = config.get('gdata', 'noc_combined') spr_client = login("emfcamp DHCP config generator", config) print "downloading Addressing" ipv4 = get_worksheet_data(spr_client, spreadsheet, "Addressing") f4 = open(configfile4, "w") f6 = open(configfile6, "w") f4.write("#\n") f4.write("# generated by gen-dhcp.py from EMF2016 Google Spreadsheet\n") f4.write("# %s %s\n" % (time.strftime('%m/%d/%Y'),time.strftime('%H:%M:%S'))) f4.write("#\n") f6.write("#\n") f6.write("# generated by gen-dhcp.py from EMF2016 Google Spreadsheet\n") f6.write("# %s %s\n" % (time.strftime('%m/%d/%Y'),time.strftime('%H:%M:%S'))) f6.write("#\n") scopes = 0
if not os.path.exists('out'): os.mkdir('out') if not os.path.exists('out/icinga'): os.mkdir('out/icinga') config = ConfigParser.ConfigParser() if not config.read("/etc/emf-gdata.conf"): print "Warning: config file /etc/emf-gdata.conf could not be found or read" spreadsheet = config.get('gdata', 'noc_combined') spr_client = login("emfcamp DHCP config generator", config) print "downloading Switches" switches = get_worksheet_data(spr_client, spreadsheet, "Switches") print "downloading AP placement" aps = get_worksheet_data(spr_client, spreadsheet, "AP placement") print "downloading Links" links = get_worksheet_data(spr_client, spreadsheet, "Links") print "downloading VMs" vms = get_worksheet_data(spr_client, spreadsheet, "VMs") po_index = {} def short_port(port): return port.replace("TenGigabitEthernet",
action='store_true', help='deploy zone files after generating') parser.add_argument( '--diff', action='store_true', help='diff zone files against live versions after generating') args = parser.parse_args() spreadsheet = config.get('gdata', 'noc_combined') spr_client = login("emfcamp DNS zone generator", config) print "downloading Addressing" addressing = get_worksheet_data(spr_client, spreadsheet, "Addressing") print "downloading codenames" codenames = get_worksheet_data(spr_client, spreadsheet, "Codenames") #for x in range(0, 2560000): # print pretty_host("gchq.org.uk", None) sshfps = get_sshfps() zones = {} for row in addressing: if "Domain" in row: fwd_zonename = row["Domain"] else: fwd_zonename = default_domain
if not os.path.exists('out'): os.mkdir('out') configfile4 = "out/dhcpd-subnets.conf" configfile6 = "out/dhcpd6-subnets.conf" config = ConfigParser.ConfigParser() if not config.read("/etc/emf-gdata.conf"): print "Warning: config file /etc/emf-gdata.conf could not be found or read" spreadsheet = config.get('gdata', 'noc_combined') spr_client = login("emfcamp DHCP config generator", config) print "downloading Addressing" ipv4 = get_worksheet_data(spr_client, spreadsheet, "Addressing") f4 = open(configfile4, "w") f6 = open(configfile6, "w") f4.write("#\n") f4.write("# generated by gen-dhcp.py from EMF2018 Google Spreadsheet\n") f4.write("# %s %s\n" % (time.strftime('%m/%d/%Y'),time.strftime('%H:%M:%S'))) f4.write("#\n") f6.write("#\n") f6.write("# generated by gen-dhcp.py from EMF2018 Google Spreadsheet\n") f6.write("# %s %s\n" % (time.strftime('%m/%d/%Y'),time.strftime('%H:%M:%S'))) f6.write("#\n") scopes = 0
sipconf = '/etc/asterisk/sip.conf' if args.sipconf: sipconf = args.sipconf[0] sipconfig.read(sipconf) config = ConfigParser.ConfigParser() if not config.read("/etc/emf-gdata.conf"): print "Warning: config file /etc/emf-gdata.conf could not be found or read" spreadsheet = config.get('gdata', 'noc_combined') spr_client = login("emfcamp Cisco config generator", config, False) switches = get_worksheet_data(spr_client, spreadsheet, "Switches") returned_switches = {} for sw in switches: if 'Teardown' in sw and sw['Teardown'] == "returned": returned_switches[sw['Hostname']] = 1 phones = get_worksheet_data(spr_client, spreadsheet, "Phones") id_to_switch = {} for line in phones: if 'Phone-Name' in line: id_to_switch[line['Phone-Name']] = {"switch": line['Switch']}