예제 #1
0
    def info(self, name='all'):

        volumes = {}
        program = [
            "/usr/sbin/gluster",
            "--remote-host=%s" % self.__remote_host, "volume", "info", name
        ]
        try:
            response = subprocess.check_output(
                program, stderr=subprocess.STDOUT).split("\n")
        except subprocess.CalledProcessError, e:
            raise ExceptionGluster(e.output)
예제 #2
0
    def create(self,
               name,
               list_bricks,
               transport='tcp',
               stripe=None,
               replica=None,
               quota=None):
        brickdiv = 1

        if name is None or name == "":
            raise KeyError("Volume must have a name")
        if list_bricks is None or len(list_bricks) == 0:
            raise KeyError("Volume must have bricks")

        program = [
            "/usr/sbin/gluster",
            "volume",
            "create",
            name,
        ]

        if stripe is not None:
            stripe = int(stripe)
            program.append("stripe")
            program.append(str(stripe))
            brickdiv = stripe
        if replica is not None:
            replica = int(replica)
            program.append("replica")
            program.append(str(replica))
            brickdiv = brickdiv * replica
        if transport is not None:
            transport = transport if transport in ("tcp", "rdma", "tcp,rdma",
                                                   "rdma,tcp") else "tcp"
            program.append("transport")
            program.append(transport)
        if len(list_bricks) % brickdiv:
            raise KeyError(
                "Invalid brick count. Bricks must be in multiples of %d" %
                brickdiv)
        [program.append(x) for x in list_bricks]

        try:
            response = subprocess.check_output(program).split("\n")
            success = "volume create: %s: success: please start the volume to access data" % name
            if not success in response:
                raise ExceptionVolumeCreate(response)
        except subprocess.CalledProcessError, e:
            raise ExceptionGluster(e.output)
예제 #3
0
    def probe(self, peer):

        if peer is None or peer == '':
            raise KeyError("You must set the peer to probe")

        try:
            response = subprocess.check_output(
                ["/usr/sbin/gluster", "peer", "probe", peer])
            if response == "peer probe: success. Probe on localhost not needed":
                raise ExceptionProbeLocalhost(response)
            if response[:13] == "Probe on host":
                raise ExceptionProbeWarning(response)
            if response[:33] == "Probe returned with unknown errno":
                raise ExceptionProbeError(response)
            return True
        except subprocess.CalledProcessError, e:
            raise ExceptionGluster(e.output)
예제 #4
0
 def __status(self, remote_host=None, recursion=False):
     if remote_host is None:
         remote_host = self.__remote_host
     peerstatus = {
         "host": {},
     }
     program = [
         "/usr/sbin/gluster",
         "--remote-host=%s" % remote_host, "peer", "status"
     ]
     try:
         response = subprocess.check_output(
             program, stderr=subprocess.STDOUT).split("\n")
     except subprocess.CalledProcessError, e:
         if recursion is False:
             raise ExceptionGluster(e.output)
         else:
             print("Remote host '" + remote_host + "' seems offline")
예제 #5
0
    def detach(self, peer):

        if peer is None or peer == '':
            raise KeyError("You must set the peer to detach")

        try:
            response = subprocess.check_output(
                ["/usr/sbin/gluster", "peer", "detach", peer])
        except subprocess.CalledProcessError, e:
            response = e.output
            if response[-14:] == " is localhost\n":
                raise ExceptionDetachLocalhost(response)
            if response[-24:] == " is not part of cluster\n":
                raise ExceptionDetachNotInCluster(response)
            if response[:23] == "Brick(s) with the peer ":
                raise ExceptionDetachWarning(response)
            if response[:36] == "Detach unsuccessful\nDetach returned ":
                raise ExceptionDetachNotInCluster(response)

            raise ExceptionGluster(e.output)
예제 #6
0
    def extend(self, name, list_bricks, replica=None):
        if name is None or name == "":
            raise KeyError("Volume must have a name")
        if list_bricks is None or len(list_bricks) == 0:
            raise KeyError("Volume must have bricks")

        program = ["/usr/sbin/gluster", "volume", "add-brick", name]

        if replica is not None and replica > 0:
            program.append("replica")
            program.append(str(replica))

        for brick in list_bricks:
            program.append(brick)

        try:
            response = subprocess.check_output(program).split("\n")
            success = "volume add-brick: success"
            if not success in response:
                raise ExceptionVolumeExtend(response)
        except subprocess.CalledProcessError, e:
            raise ExceptionGluster(e.output)
예제 #7
0
            if not success in response:
                raise ExceptionVolumeStart(response)
        except subprocess.CalledProcessError, e:
            raise ExceptionGluster(e.output)

        #We enable quota if needed
        time.sleep(1)
        if quota is not None:
            program = ["/usr/sbin/gluster", "volume", "quota", name, "enable"]
            try:
                response = subprocess.check_output(program).split("\n")
                success = "volume quota : success" % name
                if not success in response:
                    raise ExceptionVolumeQuotaEnable(response)
            except subprocess.CalledProcessError, e:
                raise ExceptionGluster(e.output)

            # We set the quota
            program = [
                "/usr/sbin/gluster", "volume", "quota", name, "limit-usage",
                "/", quota, "90%"
            ]
            try:
                response = subprocess.check_output(program).split("\n")
                success = "volume quota : success" % name
                if not success in response:
                    raise ExceptionVolumeQuotaSet(response)
            except subprocess.CalledProcessError, e:
                raise ExceptionGluster(e.output)

        return True