Пример #1
0
def main():
    conf_path = DEFAULT_OSM_CONF_PATH
    log_path = DEFAULT_OSM_LOG_PATH
    script_dir = DEFAULT_OSM_SCRIPT_DIR
    debug = 0

    try:
        opts, args = getopt.getopt(sys.argv[1:], "hc:l:s:", ["help", "version", "debug", "config=", "log=", "script="])
    except getopt.GetoptError:
        print "Wrong command options, use -h to list command options"
        sys.exit(1)

    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o == "--version":
            print "%s version %s" % (PROGRAM_NAME, PROGRAM_VERSION)
            sys.exit()
        if o in ("-c", "--config"):
            conf_path = a
        elif o in ("-l", "--log"):
            log_path = a
        elif o in ("-s", "--script"):
            script_dir = a
        elif o == "--debug":
            debug = 1
        else:
            print "Wrong command options"
            sys.exit(1)

    _makesure_dir_exist([os.path.dirname(log_path), script_dir])

    if debug:
        lylog.setup(debug=1)
    else:
        print "log to file %s\n" % log_path
        if os.path.exists(log_path):
            os.remove(log_path)
        lylog.setup(path=log_path)

    LOG.info("Program parameters:")
    LOG.info("  config file: %s" % conf_path)
    LOG.info("  log file: %s" % log_path)
    LOG.info("  script directory: %s" % script_dir)

    lyip.GetIp(conf_path)
    lyconf.Config(conf_path)
    lyconf.Config.script_dir = script_dir

    LOG.info("Config parameters:")
    LOG.info("  tag = %d " % lyconf.Config.tag)
    LOG.info("  clc_ip = %s " % lyconf.Config.clc_ip)
    LOG.info("  clc_port = %d " % lyconf.Config.clc_port)
    if debug:
        LOG.info("  key = %s" % lyconf.Config.key)

    for h in LOG.handlers:
        h.flush()

    signal.signal(signal.SIGTERM, myexit)
    signal.signal(signal.SIGINT, myexit)

    global osmsock
    osmsock = None
    notify = 0
    appstatus = -1
    timeout = 3600
    timenow = time.time()
    while progrun:
        # connect and register osmanager with control server
        if not osmsock:
            osmsock = lyconn.connclc()
            if not osmsock:
                LOG.error("failed connecting clc")
                time.sleep(1)
            else:
                notify = 1
        else:
            result, response = lyutil.sockrecv(osmsock)
            if result == 0:
                LOG.info("close socket")
                osmsock.close()
                osmsock = None
            elif result > 0:
                lyproc.process(osmsock, response)

        # run scripts provided by user in script_dir
        # adjust the timeout value when neccessary
        t = time.time()
        if t - timenow >= timeout or appstatus == 0 or notify:
            timenow = t
            # lyapp.run returns 0 if any of the scripts is still running
            appstatus = lyapp.run(osmsock, notify)
            if appstatus > 0 and notify:
                notify = 0

        for h in LOG.handlers:
            h.flush()

    # main() function exits
    LOG.info("%s exits" % PROGRAM_NAME)
Пример #2
0
    if clc_ip and clc_port:
        s = regclc()
    if s:
        return s
    getclcparm()
    if clc_ip == lyconf.Config.clc_ip and clc_port == lyconf.Config.clc_port:
        return None
    if lyconf.Config.clc_ip and lyconf.Config.clc_port:
        s = regclc()
    if s:
        return s
    return None


if __name__ == "__main__":
    lylog.setup()
    lyconf.Config.clc_mcast_ip = '228.0.0.1'
    lyconf.Config.clc_mcast_port = 1371
    lyconf.Config.key = b'015e33a8-787d-457e-b84d-c2a101a816e0'
    lyconf.Config.tag = 10
    lyconf.Config.status = 2
    s = connclc()
    if not s:
        LOG.error("regclc failed")
    while s:
        result, response = lyutil.sockrecv(s)
        if result <= 0:
            LOG.info("close socket")
            s.close()
            break
        print response
Пример #3
0
  if clc_ip and clc_port:
    s = regclc()
  if s:
    return s
  getclcparm()
  if clc_ip == lyconf.Config.clc_ip and clc_port == lyconf.Config.clc_port:
    return None
  if lyconf.Config.clc_ip and lyconf.Config.clc_port:
    s = regclc()
  if s:
    return s
  return None
  
    
if __name__ == "__main__":
  lylog.setup()
  lyconf.Config.clc_mcast_ip = '228.0.0.1'
  lyconf.Config.clc_mcast_port = 1371
  lyconf.Config.key = b'015e33a8-787d-457e-b84d-c2a101a816e0'
  lyconf.Config.tag = 10
  lyconf.Config.status = 2
  s = connclc()
  if not s:
    LOG.error("regclc failed")
  while s:
    result, response = lyutil.sockrecv(s)
    if result <= 0:
      LOG.info("close socket")
      s.close()
      break
    print response
Пример #4
0
            sys.exit()
        if o in ("-c", "--config"):
            confpath = a
        elif o in ("-l", "--log"):
            logpath = a
        elif o in ("-p", "--port"):
            webport = int(a)
        elif o in ("-w", "--web"):
            webdir = a
        else:
            print "Wrong command options"
            sys.exit(1)

    if os.path.exists(logpath):
        os.remove(logpath)
    lylog.setup(path=logpath)

    jsonstr = ""
    try:
        f = open(confpath, "r")
        for l in f.readlines():
            if l[:5] == "JSON=":
                jsonstr = l[5:]
                jsonstr.strip()
                break
        f.close()
    except IOError:
        print "IOError: processing %s" % (confpath)
        sys.exit(1)

    if jsonstr:
Пример #5
0
def main():
  conf_path = DEFAULT_OSM_CONF_PATH
  key_path = DEFAULT_OSM_KEY_PATH
  log_path = DEFAULT_OSM_LOG_PATH
  script_dir = DEFAULT_OSM_SCRIPT_DIR
  debug = 0
  try:
    opts, args = getopt.getopt(sys.argv[1:], "hc:k:l:s:", ["help", "version", "debug", "config=", "key=", "log=", "script="])
  except getopt.GetoptError:
    print 'Wrong command options, use -h to list command options'
    sys.exit(1)
  for o, a in opts:
    if o in ("-h", "--help"):
      usage()
      sys.exit()
    if o == "--version":
      print "%s version %s" % (PROGRAM_NAME, PROGRAM_VERSION)
      sys.exit()
    if o in ("-c", "--config"):
      conf_path = a
    elif o in ("-k", "--key"):
      key_path = a
    elif o in ("-l", "--log"):
      log_path = a
    elif o in ("-s", "--script"):
      script_dir = a
    elif o == "--debug":
      debug = 1
    else:
      print 'Wrong command options'
      sys.exit(1)
  if debug:
    lylog.setup(debug = 1)
  else:
    print "log to file %s" % log_path
    lylog.setup(path = log_path)
  LOG.info('Program parameters:')
  LOG.info('  config file: %s' % conf_path)
  LOG.info('  key file: %s' % key_path)
  LOG.info('  log file: %s' % log_path)
  LOG.info('  script directory: %s' % script_dir)

  lyconf.Config(conf_path, key_path)
  lyconf.Config.script_dir = script_dir
  LOG.info('Config parameters:')
  LOG.info('  tag = %d ' % lyconf.Config.tag)
  LOG.info('  clc_ip = %s ' % lyconf.Config.clc_ip)
  LOG.info('  clc_port = %d ' % lyconf.Config.clc_port)
  LOG.info('  clc_mcast_ip = %s ' % lyconf.Config.clc_mcast_ip)
  LOG.info('  clc_mcast_port = %d ' % lyconf.Config.clc_mcast_port)
  if debug:
    LOG.info('  key = %s' % lyconf.Config.key)

  signal.signal(signal.SIGTERM, myexit)
  signal.signal(signal.SIGINT, myexit)

  sock = None
  timenow = time.time()
  timeout = 5
  while True:
    if not sock:
      sock = lyconn.connclc()
      if not sock:
        LOG.error("failed connecting clc")
        time.sleep(1)
    else:
      result, response = lyutil.sockrecv(sock)
      if result == 0:
        LOG.info("close socket")
        sock.close()
      elif result > 0:
        lyproc.process(sock, response)
    t = time.time()
    if t - timenow >= timeout:
      timenow = t
      lyapp.run(sock)
Пример #6
0
def main():
    conf_path = DEFAULT_OSM_CONF_PATH
    log_path = DEFAULT_OSM_LOG_PATH
    script_dir = DEFAULT_OSM_SCRIPT_DIR
    debug = 0

    try:
        opts, args = getopt.getopt(
            sys.argv[1:], "hc:l:s:",
            ["help", "version", "debug", "config=", "log=", "script="])
    except getopt.GetoptError:
        print 'Wrong command options, use -h to list command options'
        sys.exit(1)

    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o == "--version":
            print "%s version %s" % (PROGRAM_NAME, PROGRAM_VERSION)
            sys.exit()
        if o in ("-c", "--config"):
            conf_path = a
        elif o in ("-l", "--log"):
            log_path = a
        elif o in ("-s", "--script"):
            script_dir = a
        elif o == "--debug":
            debug = 1
        else:
            print 'Wrong command options'
            sys.exit(1)

    _makesure_dir_exist([os.path.dirname(log_path), script_dir])

    if debug:
        lylog.setup(debug=1)
    else:
        print "log to file %s\n" % log_path
        if os.path.exists(log_path):
            os.remove(log_path)
        lylog.setup(path=log_path)

    LOG.info('Program parameters:')
    LOG.info('  config file: %s' % conf_path)
    LOG.info('  log file: %s' % log_path)
    LOG.info('  script directory: %s' % script_dir)

    lyip.GetIp(conf_path)
    lyconf.Config(conf_path)
    lyconf.Config.script_dir = script_dir

    LOG.info('Config parameters:')
    LOG.info('  tag = %d ' % lyconf.Config.tag)
    LOG.info('  clc_ip = %s ' % lyconf.Config.clc_ip)
    LOG.info('  clc_port = %d ' % lyconf.Config.clc_port)
    if debug:
        LOG.info('  key = %s' % lyconf.Config.key)

    for h in LOG.handlers:
        h.flush()

    signal.signal(signal.SIGTERM, myexit)
    signal.signal(signal.SIGINT, myexit)

    global osmsock
    osmsock = None
    notify = 0
    appstatus = -1
    timeout = 3600
    timenow = time.time()
    while progrun:
        # connect and register osmanager with control server
        if not osmsock:
            osmsock = lyconn.connclc()
            if not osmsock:
                LOG.error("failed connecting clc")
                time.sleep(1)
            else:
                notify = 1
        else:
            result, response = lyutil.sockrecv(osmsock)
            if result == 0:
                LOG.info("close socket")
                osmsock.close()
                osmsock = None
            elif result > 0:
                lyproc.process(osmsock, response)

        # run scripts provided by user in script_dir
        # adjust the timeout value when neccessary
        t = time.time()
        if t - timenow >= timeout or appstatus == 0 or notify:
            timenow = t
            # lyapp.run returns 0 if any of the scripts is still running
            appstatus = lyapp.run(osmsock, notify)
            if appstatus > 0 and notify:
                notify = 0

        for h in LOG.handlers:
            h.flush()

    # main() function exits
    LOG.info('%s exits' % PROGRAM_NAME)
Пример #7
0
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o in ("-c", "--config"):
            confpath = a
        elif o in ("-l", "--log"):
            logpath = a
        elif o in ("-p", "--port"):
            webport = int(a)
        elif o in ("-w", "--web"):
            webdir = a
        else:
            print 'Wrong command options'
            sys.exit(1)

    lylog.setup(logpath)

    jsonstr = ""
    try:
        f = open(confpath, "r")
        for l in f.readlines():
            if l[:5] == 'JSON=':
                jsonstr = l[5:]
                jsonstr.strip()
                break
        f.close()
    except IOError:
        print "IOError: processing %s" % (confpath)
        sys.exit(1)

    if jsonstr:
Пример #8
0
            sys.exit()
        if o in ("-c", "--config"):
            confpath = a
        elif o in ("-l", "--log"):
            logpath = a
        elif o in ("-p", "--port"):
            webport = int(a)
        elif o in ("-w", "--web"):
            webdir = a
        else:
            print 'Wrong command options'
            sys.exit(1)

    if os.path.exists(logpath):
      os.remove(logpath)
    lylog.setup(path = logpath)

    jsonstr = ""
    try:
        f = open(confpath, "r")
        for l in f.readlines():
            if l[:5] == 'JSON=':
                jsonstr = l[5:]
                jsonstr.strip()
                break
        f.close()
    except IOError:
        print "IOError: processing %s" % (confpath)
        sys.exit(1)

    if jsonstr:
Пример #9
0
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o in ("-c", "--config"):
            confpath = a
        elif o in ("-l", "--log"):
            logpath = a
        elif o in ("-p", "--port"):
            webport = int(a)
        elif o in ("-w", "--web"):
            webdir = a
        else:
            print 'Wrong command options'
            sys.exit(1)

    lylog.setup(logpath)

    jsonstr = ""
    try:
        f = open(confpath, "r")
        for l in f.readlines():
            if l[:5] == 'JSON=':
                jsonstr = l[5:]
                jsonstr.strip()
                break
        f.close()
    except IOError:
        print "IOError: processing %s" % (confpath)
        sys.exit(1)

    if jsonstr: