Example #1
0
        if sock:
            sock.close()
        return None
    lyconf.Config.local_ip = sock.getsockname()[0]
    if not lyconf.Config.local_ip:
        lyconf.Config.local_ip = b'empty'

    try:
        LOG.info("send auth request %d" % tag)
        data = struct.pack("i%ds" % lydef.LUOYUN_AUTH_DATA_LEN, tag,
                           challengestr)
        lyutil.socksend(sock, lydef.PKT_TYPE_OSM_AUTH_REQUEST, data)

        LOG.info("recv auth reply")
        recvsize = struct.calcsize("=LLi%ds" % lydef.LUOYUN_AUTH_DATA_LEN)
        result, response = lyutil.sockrecv(sock)
        if result == -1 or len(response) != recvsize:
            LOG.error("error in sockrecv")
            return None
        if result == 0:
            LOG.error("socket closed")
            return None
        t, l, rettag, answer = struct.unpack(
            "=LLi%ds" % lydef.LUOYUN_AUTH_DATA_LEN, response)
        if t != lydef.PKT_TYPE_OSM_AUTH_REPLY:
            LOG.error("wrong auth reply %d" % t)
            return None
        if rettag != tag:
            LOG.error("wrong auth reply %d %d %d" % (t, l, rettag))
            return None
        LOG.info("auth reply: %s" % answer)
Example #2
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)
Example #3
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)
Example #4
0
    LOG.warn(message)
    if sock: 
        sock.close()
    return None 
  lyconf.Config.local_ip = sock.getsockname()[0]
  if not lyconf.Config.local_ip:
    lyconf.Config.local_ip = b'empty'

  try:
    LOG.info("send auth request %d" % tag)
    data = struct.pack("i%ds" % lydef.LUOYUN_AUTH_DATA_LEN, tag, challengestr)
    lyutil.socksend(sock, lydef.PKT_TYPE_OSM_AUTH_REQUEST, data)

    LOG.info("recv auth reply")
    recvsize = struct.calcsize("=LLi%ds" % lydef.LUOYUN_AUTH_DATA_LEN);
    result, response = lyutil.sockrecv(sock)
    if result == -1 or len(response) != recvsize:
      LOG.error("error in sockrecv")
      return None 
    if result == 0:
      LOG.error("socket closed")
      return None
    t, l, rettag, answer = struct.unpack("=LLi%ds" % lydef.LUOYUN_AUTH_DATA_LEN, response)
    if t != lydef.PKT_TYPE_OSM_AUTH_REPLY:
      LOG.error("wrong auth reply %d" % t)
      return None
    if rettag != tag:
      LOG.error("wrong auth reply %d %d %d" % (t,l,rettag))
      return None
    LOG.info("auth reply: %s" % answer)
    if answer != myuuid:
Example #5
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)