Ejemplo n.º 1
0
    def create_vg_if_not_found(vgUuid, diskPaths, hostUuid, forceWipe=False):
        @linux.retry(times=5, sleep_time=random.uniform(0.1, 3))
        def find_vg(vgUuid):
            cmd = shell.ShellCmd("vgs %s -otags | grep %s" %
                                 (vgUuid, INIT_TAG))
            cmd(is_exception=False)
            if cmd.return_code != 0:
                raise RetryException("can not find vg %s with tag %s" %
                                     (vgUuid, INIT_TAG))
            return True

        try:
            find_vg(vgUuid)
        except RetryException as e:
            if forceWipe is True:
                lvm.wipe_fs(diskPaths)

            cmd = shell.ShellCmd(
                "vgcreate -qq --shared --addtag '%s::%s::%s' --metadatasize %s %s %s"
                % (INIT_TAG, hostUuid, time.time(), DEFAULT_VG_METADATA_SIZE,
                   vgUuid, " ".join(diskPaths)))
            cmd(is_exception=False)
            logger.debug("created vg %s, ret: %s, stdout: %s, stderr: %s" %
                         (vgUuid, cmd.return_code, cmd.stdout, cmd.stderr))
            if cmd.return_code == 0 and find_vg(vgUuid) is True:
                return True
            if find_vg(vgUuid) is False:
                raise Exception(
                    "can not find vg %s with disks: %s and create vg return: %s %s %s "
                    % (vgUuid, diskPaths, cmd.return_code, cmd.stdout,
                       cmd.stderr))
        except Exception as e:
            raise e

        return False
Ejemplo n.º 2
0
    def create_vg_if_not_found(vgUuid, diskPaths, hostUuid, forceWipe=False):
        @linux.retry(times=3, sleep_time=random.uniform(0.1, 3))
        def find_vg(vgUuid):
            cmd = shell.ShellCmd("vgs %s -otags | grep %s" % (vgUuid, INIT_TAG))
            cmd(is_exception=False)
            if cmd.return_code != 0:
                raise RetryException("can not find vg %s with tag %s" % (vgUuid, INIT_TAG))
            return True

        try:
            find_vg(vgUuid)
        except RetryException:
            if forceWipe is True:
                lvm.wipe_fs(diskPaths)

            r, o, e = bash.bash_roe("vgcreate --shared --addtag '%s::%s::%s' --metadatasize %s %s %s" %
                                 (INIT_TAG, hostUuid, time.time(),
                                  DEFAULT_VG_METADATA_SIZE, vgUuid, " ".join(diskPaths)))
            if r == 0:
                return True
            if find_vg(vgUuid) is False:
                raise Exception("can not find vg %s with disks: %s and create failed for %s " %
                                (vgUuid, diskPaths, e))
        except Exception as e:
            raise e

        return False
Ejemplo n.º 3
0
    def create_vg_if_not_found(vgUuid, diskPaths, hostUuid, forceWipe=False):
        @linux.retry(times=5, sleep_time=random.uniform(0.1, 3))
        def find_vg(vgUuid, raise_exception=True):
            cmd = shell.ShellCmd(
                "timeout 5 vgscan --ignorelockingfailure; vgs --nolocking %s -otags | grep %s"
                % (vgUuid, INIT_TAG))
            cmd(is_exception=False)
            if cmd.return_code != 0 and raise_exception:
                raise RetryException("can not find vg %s with tag %s" %
                                     (vgUuid, INIT_TAG))
            elif cmd.return_code != 0:
                return False
            return True

        try:
            find_vg(vgUuid)
        except RetryException as e:
            if forceWipe is True:
                running_vm = bash.bash_o(
                    "virsh list | grep running | awk '{print $2}'").strip(
                    ).split()
                if running_vm != [] and running_vm[0] != "":
                    for vm in running_vm:
                        bash.bash_r("virsh destroy %s" % vm)
                r = bash.bash_r("drbdadm down all")
                if r == 0:
                    bash.bash_r("mkdir -p %s" % BACKUP_DIR)
                    bash.bash_r("mv /etc/drbd.d/*.res %s" % BACKUP_DIR)
                lvm.wipe_fs(diskPaths, vgUuid)

            cmd = shell.ShellCmd(
                "vgcreate -qq --addtag '%s::%s::%s::%s' --metadatasize %s %s %s"
                % (INIT_TAG, hostUuid, time.time(),
                   bash.bash_o("hostname").strip(), DEFAULT_VG_METADATA_SIZE,
                   vgUuid, " ".join(diskPaths)))
            cmd(is_exception=False)
            logger.debug("created vg %s, ret: %s, stdout: %s, stderr: %s" %
                         (vgUuid, cmd.return_code, cmd.stdout, cmd.stderr))
            if cmd.return_code == 0 and find_vg(vgUuid, False) is True:
                return True
            try:
                if find_vg(vgUuid) is True:
                    return True
            except RetryException as ee:
                raise Exception(
                    "can not find vg %s with disks: %s and create vg return: %s %s %s "
                    % (vgUuid, diskPaths, cmd.return_code, cmd.stdout,
                       cmd.stderr))
            except Exception as ee:
                raise ee
        except Exception as e:
            raise e

        return False
    def add_disk(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        disk = CheckDisk(cmd.diskUuid)
        command = shell.ShellCmd("vgs --nolocking %s -otags | grep %s" % (cmd.vgUuid, INIT_TAG))
        command(is_exception=False)
        if command.return_code != 0:
            self.create_vg_if_not_found(cmd.vgUuid, [disk.get_path()], cmd.hostUuid, cmd.forceWipe)
        else:
            lvm.check_gl_lock()
            if cmd.forceWipe is True:
                lvm.wipe_fs([disk.get_path()], cmd.vgUuid)
            lvm.add_pv(cmd.vgUuid, disk.get_path(), DEFAULT_VG_METADATA_SIZE)

        rsp = AgentRsp
        rsp.totalCapacity, rsp.availableCapacity = lvm.get_vg_size(cmd.vgUuid)
        return jsonobject.dumps(rsp)
Ejemplo n.º 5
0
    def add_disk(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        disk = CheckDisk(cmd.diskUuid)
        command = shell.ShellCmd("vgs %s -otags | grep %s" % (cmd.vgUuid, INIT_TAG))
        command(is_exception=False)
        if command.return_code != 0:
            self.create_vg_if_not_found(cmd.vgUuid, [disk.get_path()], cmd.hostUuid, cmd.forceWipe)
        else:
            lvm.check_gl_lock()
            if cmd.forceWipe is True:
                lvm.wipe_fs([disk.get_path()], cmd.vgUuid)
            lvm.add_pv(cmd.vgUuid, disk.get_path(), DEFAULT_VG_METADATA_SIZE)

        rsp = AgentRsp
        rsp.totalCapacity, rsp.availableCapacity = lvm.get_vg_size(cmd.vgUuid)
        return jsonobject.dumps(rsp)
    def create_vg_if_not_found(vgUuid, diskPaths, hostUuid, forceWipe=False):
        @linux.retry(times=5, sleep_time=random.uniform(0.1, 3))
        def find_vg(vgUuid, raise_exception = True):
            cmd = shell.ShellCmd("timeout 5 vgscan --ignorelockingfailure; vgs --nolocking %s -otags | grep %s" % (vgUuid, INIT_TAG))
            cmd(is_exception=False)
            if cmd.return_code != 0 and raise_exception:
                raise RetryException("can not find vg %s with tag %s" % (vgUuid, INIT_TAG))
            elif cmd.return_code != 0:
                return False
            return True

        try:
            find_vg(vgUuid)
        except RetryException as e:
            if forceWipe is True:
                lvm.wipe_fs(diskPaths, vgUuid)

            cmd = shell.ShellCmd("vgcreate -qq --shared --addtag '%s::%s::%s::%s' --metadatasize %s %s %s" %
                                 (INIT_TAG, hostUuid, time.time(), bash.bash_o("hostname").strip(),
                                  DEFAULT_VG_METADATA_SIZE, vgUuid, " ".join(diskPaths)))
            cmd(is_exception=False)
            logger.debug("created vg %s, ret: %s, stdout: %s, stderr: %s" %
                         (vgUuid, cmd.return_code, cmd.stdout, cmd.stderr))
            if cmd.return_code == 0 and find_vg(vgUuid, False) is True:
                return True
            try:
                if find_vg(vgUuid) is True:
                    return True
            except RetryException as ee:
                raise Exception("can not find vg %s with disks: %s and create vg return: %s %s %s " %
                                (vgUuid, diskPaths, cmd.return_code, cmd.stdout, cmd.stderr))
            except Exception as ee:
                raise ee
        except Exception as e:
            raise e

        return False