Example #1
0
def generate(out, ip, switch):
  # Get Cisco model name (two tries)
  for i in xrange(2):
    var = netsnmp.Varbind('.1.3.6.1.2.1.47.1.1.1.1.13.1')
    model = netsnmp.snmpget(var, Version=2, DestHost=ip, Community='private')[0]

    if model == None:
      var = netsnmp.Varbind('.1.3.6.1.2.1.47.1.1.1.1.13.1001')
      model = netsnmp.snmpget(var, Version=2, DestHost=ip, Community='private')[0]
    
  if model == None:
    sw_reload(ip)
    error("Could not get model for switch" , ip)
    return

  if not model in config.models:
    sw_reload(ip)
    error("Template for model " + model_id + " not found")
    return

  # Throws exception if something bad happens
  try:
    txt = config.generate(switch, model)
    out.write("! Config for " + switch + "\n")
    out.write(txt)
  except:
    sw_reload(ip)
    error("Exception in generation for %s :" % switch, traceback.format_exc())
    out.close()
    return None

  return out
Example #2
0
def set_text(message):
    global text
    global messages
    text = message.text
    messages = config.generate(emoji, text)

    #Keyboard
    markup = types.InlineKeyboardMarkup()
    cp = types.InlineKeyboardButton('Переслать',
                                    switch_inline_query='\n\n' + messages)
    markup.add(cp)

    try:
        bot.send_message(message.chat.id, messages, reply_markup=markup)
    except:
        bot.send_message(message.chat.id, 'Некорректно введен текст ')
        bot.send_message(message.chat.id, 'Введите текст для обработки✍🏼:')
        bot.register_next_step_handler(message, set_text)
Example #3
0
def generate(out, ip, switch):
    model = db.get('client-{}'.format(ip)).decode()
    if model == 'cisco':
        # Get Cisco model name (two tries)
        for i in range(2):
            var = netsnmp.Varbind('.1.3.6.1.2.1.47.1.1.1.1.13.1')
            model = netsnmp.snmpget(var,
                                    Version=2,
                                    DestHost=ip,
                                    Community='private')[0]

            if model == None:
                var = netsnmp.Varbind('.1.3.6.1.2.1.47.1.1.1.1.13.1001')
                model = netsnmp.snmpget(var,
                                        Version=2,
                                        DestHost=ip,
                                        Community='private')[0]
        model = None if model is None else model.decode()

    if model == None:
        sw_reload(ip)
        error("Could not get model for switch", ip)
        return

    if not model in config.models:
        sw_reload(ip)
        error("Template for model " + model + " not found")
        return

    # Throws exception if something bad happens
    try:
        txt = config.generate(switch, model)
        out.write(txt.encode())
    except:
        sw_reload(ip)
        error("Exception in generation for %s :" % switch,
              traceback.format_exc())
        out.close()
        return None

    return out
Example #4
0
    def do_GET(self):
        db = redis.Redis()
        switch = db.get(self.client_address[0]).decode()
        model = db.get('client-{}'.format(self.client_address[0])).decode()
        if switch == None or model == None:
            log("Switch not found:", self.client_address[0])
            self.send_error(404, "File not found")
            return None
        if self.path == "/juniper-confg":
            log("Generating Juniper config for", self.client_address[0],
                "name =", switch)
            f = tempfile.TemporaryFile()
            f.write(config.generate(switch, model).encode())
            content_length = f.tell()
            f.seek(0)

            self.send_response(200)
            self.send_header("Content-type", "application/octet-stream")
            self.send_header("Content-Length", content_length)
            self.end_headers()
            self.copyfile(f, self.wfile)
            log("Config sent to", self.client_address[0], "name =", switch)

            f.close()
            return
        elif self.path == "/juniper.tgz":
            log("Sending JunOS file", config.models[model]['image'], "to",
                self.client_address[0], "name =", switch)
            if (model in config.models) and ('image' in config.models[model]):
                # All good! Overwrite the requested file path and send our own.
                self.path = config.models[model]['image']
                f = self.send_head()
                if f:
                    self.copyfile(f, self.wfile)
                    log("Sent JunOS to", self.client_address[0], "name =",
                        switch)
                    f.close()
        else:
            log("Unknown file:", self.path)
            self.send_error(404, "File not found")
Example #5
0
import netsnmp
import config
import sys

if len(sys.argv) < 3:
  print "Usage:", sys.argv[0], " D29-A WS-C2950T-24"
  sys.exit(1)

switch = sys.argv[1]
model = sys.argv[2]

print config.generate(switch, model)
Example #6
0
File: main.py Project: l3enny/rovib
if top_dir is '':
    print 'No directory provided, quitting...'
    sys.exit(0)

# Recursively find parsable files, allowed file types is currently hard-
# coded in read.py. Does not check for consistency between images.
image_paths = read.find_images(top_dir)
if image_paths is None:
    'No parsable files could be found, quitting...'
    sys.exit(0)

config_path = top_dir + '/settings.pickle'
settings = config.load(config_path)
if not settings:
    print 'Generating a configuration file...\n'
    settings = config.generate(config_path, image_paths)

if debug:
    debug_index = raw_input(
        'Type the index of the image you would like to use '
        'for debugging purposes (0-%d):' % len(image_paths))
    debug_index = int(debug_index)

times = range(0, len(image_paths))
times = [dt * i for i in times]
ctemps = []
it = 0
test_spectra = []
minerrs = []

if debug:
Example #7
0
    print 'Reading edges...'
    edges = graph.read_edges(options.prefix + '.net.xml')
    print 'Success.'

    print 'Reading edge connections...'
    connections = graph.read_connections(options.prefix + '.net.xml')
    print 'Success.'

    if not options.nogen:
        print 'Generating route...'
        subprocess.Popen(['python', os.path.join(os.environ['SUMO_HOME'], 'tools/trip/randomTrips.py'), '-e', '1', '-n', options.prefix+'.net.xml', '-r', options.prefix+'.rou.xml', '-o', options.prefix+'.trips.xml', '--fringe-factor', '1000000'], stdout=sys.stdout, stderr=sys.stderr).wait()
        print 'Success.'

        print 'Writing configuration...'
        config.generate(options.prefix)
        print 'Success.'

    speedChanges = []
    sumoProcess = subprocess.Popen([sumoBinary, '-c', options.prefix + '.sumocfg'], stdout=sys.stdout, stderr=sys.stderr)
    optTime = run(edges, connections, speedChanges, True, options.nogui)
    sumoProcess.wait()

    speedChanges.reverse()
    sumoProcess = subprocess.Popen([sumoBinary, '-c', options.prefix + '.sumocfg'], stdout=sys.stdout, stderr=sys.stderr)
    noOptTime = run(edges, connections, speedChanges, False, options.nogui)
    sumoProcess.wait()

    print '\nSimulation time with optimalization: {0}'.format(optTime / 1000.)
    print 'Simulation time without optimalization: {0}'.format(noOptTime / 1000.)
Example #8
0
    if not options.nogen:
        print 'Generating route...'
        subprocess.Popen([
            'python',
            os.path.join(os.environ['SUMO_HOME'],
                         'tools/trip/randomTrips.py'), '-e', '1', '-n',
            options.prefix + '.net.xml', '-r', options.prefix + '.rou.xml',
            '-o', options.prefix + '.trips.xml', '--fringe-factor', '1000000'
        ],
                         stdout=sys.stdout,
                         stderr=sys.stderr).wait()
        print 'Success.'

        print 'Writing configuration...'
        config.generate(options.prefix)
        print 'Success.'

    speedChanges = []
    sumoProcess = subprocess.Popen(
        [sumoBinary, '-c', options.prefix + '.sumocfg'],
        stdout=sys.stdout,
        stderr=sys.stderr)
    optTime = run(edges, connections, speedChanges, True, options.nogui)
    sumoProcess.wait()

    speedChanges.reverse()
    sumoProcess = subprocess.Popen(
        [sumoBinary, '-c', options.prefix + '.sumocfg'],
        stdout=sys.stdout,
        stderr=sys.stderr)
Example #9
0
def process(container, event):
    global instances, containers

    # Process instance event
    if "bunkerized-nginx.AUTOCONF" in container.labels:
        if event == "create":
            instances[container.id] = container
            utils.log("[*] bunkerized-nginx instance created : " +
                      container.name + " / " + container.id)
        elif event == "start":
            instances[container.id].reload()
            utils.log("[*] bunkerized-nginx instance started : " +
                      container.name + " / " + container.id)
        elif event == "die":
            instances[container.id].reload()
            utils.log("[*] bunkerized-nginx instance stopped : " +
                      container.name + " / " + container.id)
        elif event == "destroy":
            del instances[container.id]
            utils.log("[*] bunkerized-nginx instance removed : " +
                      container.name + " / " + container.id)

    # Process container event
    elif "bunkerized-nginx.SERVER_NAME" in container.labels:
        # Convert labels to env vars
        vars = {
            k.replace("bunkerized-nginx.", "", 1): v
            for k, v in container.labels.items()
            if k.startswith("bunkerized-nginx.")
        }
        if event == "create":
            if config.generate(instances, vars):
                utils.log("[*] Generated config for " + vars["SERVER_NAME"])
                containers[container.id] = container
            else:
                utils.log("[!] Can't generate config for " +
                          vars["SERVER_NAME"])
        elif event == "start":
            if container.id in containers:
                containers[container.id].reload()
                if config.activate(instances, vars):
                    utils.log("[*] Activated config for " +
                              vars["SERVER_NAME"])
                else:
                    utils.log("[!] Can't activate config for " +
                              vars["SERVER_NAME"])
        elif event == "die":
            if container.id in containers:
                containers[container.id].reload()
                if config.deactivate(instances, vars):
                    utils.log("[*] Deactivated config for " +
                              vars["SERVER_NAME"])
                else:
                    utils.log("[!] Can't deactivate config for " +
                              vars["SERVER_NAME"])
        elif event == "destroy":
            if container.id in containers:
                del containers[container.id]
                if config.remove(vars):
                    utils.log("[*] Removed config for " + vars["SERVER_NAME"])
                else:
                    utils.log("[!] Can't remove config for " +
                              vars["SERVER_NAME"])
Example #10
0
File: main.py Project: l3enny/rovib
if top_dir is '':
    print 'No directory provided, quitting...'
    sys.exit(0)

# Recursively find parsable files, allowed file types is currently hard-
# coded in read.py. Does not check for consistency between images.
image_paths = read.find_images(top_dir)
if image_paths is None:
    'No parsable files could be found, quitting...'
    sys.exit(0)

config_path = top_dir + '/settings.pickle'
settings = config.load(config_path)
if not settings:
    print 'Generating a configuration file...\n'
    settings = config.generate(config_path, image_paths)

if debug:
    debug_index = raw_input('Type the index of the image you would like to use '
                            'for debugging purposes (0-%d):' % len(image_paths))
    debug_index = int(debug_index)


times = range(0, len(image_paths))
times = [dt * i for i in times]
ctemps = []
it = 0
test_spectra = []
minerrs = []

if debug:
Example #11
0
import netsnmp
import config
import sys

if len(sys.argv) < 3:
  print("Usage:", sys.argv[0], " D29-A WS-C2950T-24")
  sys.exit(1)

switch = sys.argv[1]
model = sys.argv[2]

print(config.generate(switch, model))