Exemplo n.º 1
0
def GetClient():
    """Connects to the a luxi socket and returns a client.

  """
    try:
        client = luxi.Client(address=pathutils.QUERY_SOCKET)
    except NoMasterError:
        ss = ssconf.SimpleStore()

        # Try to read ssconf file
        try:
            ss.GetMasterNode()
        except errors.ConfigurationError:
            raise errors.OpPrereqError(
                "Cluster not initialized or this machine is"
                " not part of a cluster", errors.ECODE_INVAL)

        master, myself = ssconf.GetMasterAndMyself(ss=ss)
        if master != myself:
            raise errors.OpPrereqError(
                "This is not the master node, please connect"
                " to node '%s' and rerun the command" % master,
                errors.ECODE_INVAL)
        raise
    return client
Exemplo n.º 2
0
    def _CheckMasterDaemon():
        try:
            cl = luxi.Client()
            (cluster_name, ) = cl.QueryConfigValues(["cluster_name"])
        except Exception:
            raise utils.RetryAgain()

        logging.debug("Received cluster name %s from master", cluster_name)
Exemplo n.º 3
0
    def __call__(self, address=None):
        """Creates an instrumented LUXI client.

    The LUXI client will record all method calls (use L{CalledNames} to
    retrieve them).

    """
        return luxi.Client(transport=compat.partial(_TestLuxiTransport,
                                                    self.Record),
                           address=address)
Exemplo n.º 4
0
def GetClient(query=True):
    """Connects to the a luxi socket and returns a client.

  @type query: boolean
  @param query: this signifies that the client will only be
      used for queries; if the build-time parameter
      enable-split-queries is enabled, then the client will be
      connected to the query socket instead of the masterd socket

  """
    override_socket = os.getenv(constants.LUXI_OVERRIDE, "")
    if override_socket:
        if override_socket == constants.LUXI_OVERRIDE_MASTER:
            address = pathutils.MASTER_SOCKET
        elif override_socket == constants.LUXI_OVERRIDE_QUERY:
            address = pathutils.QUERY_SOCKET
        else:
            address = override_socket
    elif query:
        address = pathutils.QUERY_SOCKET
    else:
        address = None
    # TODO: Cache object?
    try:
        client = luxi.Client(address=address)
    except NoMasterError:
        ss = ssconf.SimpleStore()

        # Try to read ssconf file
        try:
            ss.GetMasterNode()
        except errors.ConfigurationError:
            raise errors.OpPrereqError(
                "Cluster not initialized or this machine is"
                " not part of a cluster", errors.ECODE_INVAL)

        master, myself = ssconf.GetMasterAndMyself(ss=ss)
        if master != myself:
            raise errors.OpPrereqError(
                "This is not the master node, please connect"
                " to node '%s' and rerun the command" % master,
                errors.ECODE_INVAL)
        raise
    return client