Ejemplo n.º 1
0
   def get_nodebyname(self,nodename):
      """Get specified node from current replica group.
      
      Parameters:
         Name         Type     Info:
         nodename     str      The host name of the node.
      Return values:
         a replicanode object of query
      Exceptions:
         pysequoiadb.error.SDBTypeError
         pysequoiadb.error.SDBBaseError
      """
      if not isintance(nodename, basestring):
         raise SDBTypeError("nodename must be an instance of basestring")

      try:
         node = replicanode(self._client)
         rc = sdb.gp_get_nodebyname(self._group, node._node, nodename)
         pysequoiadb._raise_if_error("Failed to get node", rc)
      except SDBBaseError:
         del node
         node = None
         raise

      return node
Ejemplo n.º 2
0
    def get_nodebyendpoint(self, hostname, servicename):
        """Get specified node from current replica group.

        Parameters:
           Name         Type     Info:
           hostname     str      The host name of the node.
           servicename  str      The service name of the node.
        Return values:
           a replicanode object of query
        Exceptions:
           pysequoiadb.error.SDBBaseError
        """
        if not isinstance(hostname, str_type):
            raise SDBTypeError("hostname must be an instance of str_type")
        if not isinstance(servicename, str_type):
            raise SDBTypeError("servicename must be an instance of str_type")

        node = replicanode(self._client)
        try:
            rc = sdb.gp_get_nodebyendpoint(self._group, node._node, hostname,
                                           servicename)
            raise_if_error(rc, "Failed to get node")
        except SDBBaseError:
            del node
            raise

        return node
Ejemplo n.º 3
0
    def get_slave(self, *positions):
        """Get one of slave node of the current replica group, if no slave exists
           then get master.

        Parameters:
           Name         Type                  Info:
           positions    int           The positions of nodes.
        Return values:
           a replicanode object of query
        Exceptions:
           pysequoiadb.error.SDBBaseError
        """
        for i in range(len(positions)):
            if not isinstance(positions[i], int):
                raise SDBTypeError(
                    "elements of positions should be instance of int")

        node = replicanode(self._client)

        try:
            rc = sdb.gp_get_slave(self._group, node._node, positions)
            raise_if_error(rc, "Failed to get slave")
        except SDBBaseError:
            del node
            raise

        return node
Ejemplo n.º 4
0
    def get_master(self):
        """Get the master node of the current replica group.

        Return values:
           a replica node object of query
        Exceptions:
           pysequoiadb.error.SDBBaseError
        """
        node = replicanode(self._client)
        try:
            rc = sdb.gp_get_master(self._group, node._node)
            raise_if_error(rc, "Failed to get master")
        except SDBBaseError:
            del node
            raise

        return node
Ejemplo n.º 5
0
   def get_master(self):
      """Get the master node of the current replica group.

      Return values:
         a replicanode object of query
      Exceptions:
         pysequoiadb.error.SDBBaseError
      """
      try:
         node = replicanode(self._client)
         rc = sdb.gp_get_master(self._group, node._node)
         pysequoiadb._raise_if_error("Failed to get master", rc)
      except SDBBaseError:
         del node
         node = None
         raise

      return node
Ejemplo n.º 6
0
    def get_slave(self):
        """Get one of slave node of the current replica group, if no slave exists
           then get master.

        Return values:
           a replicanode object of query
        Exceptions:
           pysequoiadb.error.SDBBaseError
        """
        node = replicanode(self._client)
        try:
            rc = sdb.gp_get_slave(self._group, node._node)
            raise_if_error(rc, "Failed to get slave")
        except SDBBaseError:
            del node
            raise

        return node