コード例 #1
0
def Wconfd(opts, args): # pylint: disable=W0613
  """Send commands to WConfD.

  @param opts: the command line options selected by the user
  @type args: list
  @param args: the command to send, followed by the command-specific arguments
  @rtype: int
  @return: the desired exit code

  """
  if args[0] == "echo":
    if len(args) != 2:
      ToStderr("Command 'echo' takes only precisely argument.")
      return 1
    result = wconfd.Client().Echo(args[1])
    print "Answer: %s" % (result,)
  elif args[0] == "listlocks":
    if len(args) != 2:
      ToStderr("Command 'listlocks' takes precisely one argument.")
      return 1
    wconfdcontext = (int(args[1]),
                     utils.livelock.GuessLockfileFor("masterd_1"))
    result = wconfd.Client().ListLocks(wconfdcontext)
    print "Answer: %s" % (result,)
  elif args[0] == "listalllocks":
    if len(args) != 1:
      ToStderr("Command 'listalllocks' takes no arguments.")
      return 1
    result = wconfd.Client().ListAllLocks()
    print "Answer: %s" % (result,)
  elif args[0] == "listalllocksowners":
    if len(args) != 1:
      ToStderr("Command 'listalllocks' takes no arguments.")
      return 1
    result = wconfd.Client().ListAllLocksOwners()
    print "Answer: %s" % (result,)
  elif args[0] == "flushconfig":
    if len(args) != 1:
      ToStderr("Command 'flushconfig' takes no arguments.")
      return 1
    wconfd.Client().FlushConfig()
    print "Configuration flushed."
  else:
    ToStderr("Command '%s' not supported", args[0])
    return 1

  return 0
コード例 #2
0
def IsWconfdResponding():
    """Probes an echo RPC to WConfD.

  """
    probe_string = "ganeti watcher probe %d" % time.time()

    try:
        result = wconfd.Client().Echo(probe_string)
    except Exception, err:  # pylint: disable=W0703
        logging.warning("WConfd connection error: %s", err)
        return False