Пример #1
0
def main(argv):
	for mibname in argv[1:]:
		load(mibname)
	SNMP.traps.start_straps()
	scheduler.sleep(2)
	trapreceiver = SNMP.traps.TrapDispatcher(_handler)
	asyncio.register(trapreceiver)
Пример #2
0
	def __do_command(self, cmdstr, hosts):
		for host in hosts:
			if type(host) is types.ListType:
				for hle in host:
					cmdstr = cmdstr + " %s" % (str(hle))
			else:
				cmdstr = cmdstr + " %s" % (str(host))
		rqst = "-size %d -timeout %d -retries %d -delay %d %s\n" % \
					(self.size, self.timeout, self.retries, self.delay, cmdstr)
		self._write(rqst)
		# now try and get all of pyntping's output
		resstr = ''
		next = self._read(4096)
		if next:
			resstr += next
		scheduler.sleep(1)
		while self.fstat().st_size != 0:
			next = self._read(4096)
			if next:
				resstr += next
			scheduler.sleep(1)
		# we should have got a tuple of tuples
		result =  eval(resstr)
		if len(result) == 1:
			return result[0]
		else:
			return list(result)
Пример #3
0
def wait_for_port(host, port, tries=60, interval=2):
	"""Loops until a (host, port) is available to connect. Useful when waiting
for a rebooted system."""
	import scheduler
	i = 0
	while not check_port(host, port):
		assert i <= tries, "wait_for_port: max tries exceeded."
		scheduler.sleep(interval)
		i += 1
Пример #4
0
 def run_modules(self, modlist):
     """run_modules(modlist)
 Runs the run_module() function on the supplied list of modules (or module
 names).  """
     for mod in modlist:
         self.run_module(mod)
         # give things time to "settle" from previous suite. Some spawned
         # processes may delay exiting and hold open TCP ports, etc.
         scheduler.sleep(2) 
Пример #5
0
def start_slogsink(port=514):
	import scheduler
	if port != 514:
		cmd = "daemonize slogsink %d" % port
	else:
		cmd = "daemonize slogsink"
	rv =  os.system(cmd)
	scheduler.sleep(2)
	return rv
Пример #6
0
 def run(self):
     import scheduler
     import traceback
     try:
         while 1:
             scheduler.sleep(1.0)
             self.queue.insert(0, self._val)
             self._val += 1
     except KeyboardInterrupt:
         return 0 # Exit status
     except:
         traceback.print_exc()
         return 1 # Exit status
Пример #7
0
 def run(self):
     import scheduler
     import traceback
     try:
         while 1:
             try:
                 item = self.queue.pop()
             except IndexError:
                 scheduler.sleep(0.5)
     except KeyboardInterrupt:
         return 0 # Exit status
     except:
         traceback.print_exc()
         return 1 # Exit status
Пример #8
0
def fork():
    """procshare's version of os.fork().

    Use this instead of os.fork() - it does the same.
    """
    global _has_forked

    pid = _os_fork()
    _has_forked = 1 # Both processes
    if not pid:
        # Child process
        _core.init_child()
    else:
        scheduler.sleep(0.5)
    return pid
Пример #9
0
def fork():
    """procshare's version of os.fork().

    Use this instead of os.fork() - it does the same.
    """
    global _has_forked

    pid = _os_fork()
    _has_forked = 1  # Both processes
    if not pid:
        # Child process
        _core.init_child()
    else:
        scheduler.sleep(0.5)
    return pid
Пример #10
0
 def test_method(self):
     import scheduler
     p = Producer(self.q)
     #c = Consumer(self.q)
     procp = proctools.submethod(p.run)
     item = self.queue.pop()
     n = 0
     try:
         while n<10:
             try:
                 item = self.q.pop()
                 self.info("Consumer got item: %s" % (item,))
             except IndexError:
                 scheduler.sleep(0.5)
             n += 1
     finally:
         procp.kill()
         procp.wait()
Пример #11
0
def ping(host, retries=3, timeout=5, delay=1, size=64, hops=30):
	pinger = get_pinger(retries, timeout, delay, size, hops)
	sum = 0
	Nxmit = 0
	Nrecv = 0
	_min = sys.maxint
	_max = 0
	print "Pinging %s with %d bytes of data." % (host, size)
	try:
		while 1: # escape with SIGINT (^C)
			Nxmit = Nxmit + 1
			host, rttime = pinger.ping(host)
			if rttime >= 0:
				sum += rttime
				Nrecv = Nrecv + 1
				_min = min(_min, rttime)
				_max = max(_max, rttime)
				print "%-16s  %d ms" % (host, rttime)
			scheduler.sleep(pinger.delay)
	except KeyboardInterrupt:
		print "%d packets transmitted, %d packets received, %d%% packet loss" % (Nxmit, Nrecv, 100-(Nxmit/Nrecv*100))
		print "round-trip min/avg/max = %d/%d/%d ms" % (_min, sum/Nrecv, _max)
Пример #12
0
def _co_function():
	import sys, scheduler
	sys.stdout.write("hello from co_function\n")
	scheduler.sleep(5)
	return None
Пример #13
0
def _sub_function():
	import scheduler
	scheduler.sleep(5)
	return None
Пример #14
0
	def sleep(self, secs):
		"""Sleep method simply sleeps for specified number of seconds."""
		return scheduler.sleep(secs)
Пример #15
0
def _co_function():
    import sys, scheduler
    sys.stdout.write("hello from co_function\n")
    scheduler.sleep(5)
    return None
Пример #16
0
def _sub_function():
    import scheduler
    scheduler.sleep(5)
    return None