示例#1
0
 def stop(self):
     if not self.active:
         return 1
     command = "%s --stop '%s'" % (RAID.prog, self.device)
     if run_script(command, self.chroot) != 0:
         log.error("Deactivation of raid '%s' failed: %s", self.name, msg)
         return 0
     self.active = False
     return 1
示例#2
0
文件: raid.py 项目: kholia/pyrpm
 def stop(self):
     if not self.active:
         return 1
     command = "%s --stop '%s'" % (RAID.prog, self.device)
     if run_script(command, self.chroot) != 0:
         log.error("Deactivation of raid '%s' failed: %s", self.name, msg)
         return 0
     self.active = False
     return 1
示例#3
0
    def info(device, chroot=None):
        command = "%s --detail '%s'" % (RAID.prog, device)
        if run_script(command, chroot) != 0:
            log.error("Failed to get details for '%s'.", device)
            return None

        dict = {}
        for line in msg.split("\n"):
            line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            if line.find(":") == -1:
                continue
            (key, value) = line.split(":", 1)
            key = key.strip()
            value = value.strip()
            try:
                if key == "Raid Level":
                    dict["level"] = long(value[4:])
                elif key == "Array Size":
                    dict["size"] = 1024L * long(value.split()[0])
                elif key == "Total Devices":
                    dict["total-devices"] = long(value)
                elif key == "Active Devices":
                    dict["active-devices"] = long(value)
                elif key == "Working Devices":
                    dict["working-devices"] = long(value)
                elif key == "Spare Devices":
                    dict["spare-devices"] = long(value)
                elif key == "Preferred Minor":
                    dict["preferred-minor"] = long(value)
                elif key == "Failed Devices":
                    dict["failed-devices"] = long(value)
                elif key == "State":
                    dict["state"] = value
                elif key == "Layout":
                    dict["layout"] = value
                elif key == "Chunk Size":
                    dict["chunk-size"] = value
                elif key == "UUID":
                    dict["uuid"] = value

                # uuid is not usable, because it changes with device names
                # /dev/loopX is not good to get an uuid
            except:
                log.error("mdadm output malformed.")
                return None
        dict["device"] = device
        return dict
示例#4
0
文件: raid.py 项目: kholia/pyrpm
    def info(device, chroot=None):
        command = "%s --detail '%s'" % (RAID.prog, device)
        if run_script(command, chroot) != 0:
            log.error("Failed to get details for '%s'.", device)
            return None

        dict = { }
        for line in msg.split("\n"):
            line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            if line.find(":") == -1:
                continue
            (key, value) = line.split(":", 1)
            key = key.strip()
            value = value.strip()
            try:
                if key == "Raid Level":
                    dict["level"] = long(value[4:])
                elif key == "Array Size":
                    dict["size"] = 1024L * long(value.split()[0])
                elif key == "Total Devices":
                    dict["total-devices"] = long(value)
                elif key == "Active Devices":
                    dict["active-devices"] = long(value)
                elif key == "Working Devices":
                    dict["working-devices"] = long(value)
                elif key == "Spare Devices":
                    dict["spare-devices"] = long(value)
                elif key == "Preferred Minor":
                    dict["preferred-minor"] = long(value)
                elif key == "Failed Devices":
                    dict["failed-devices"] = long(value)
                elif key == "State":
                    dict["state"] = value
                elif key == "Layout":
                    dict["layout"] = value
                elif key == "Chunk Size":
                    dict["chunk-size"] = value
                elif key == "UUID":
                    dict["uuid"] = value

                # uuid is not usable, because it changes with device names
                # /dev/loopX is not good to get an uuid
            except:
                log.error("mdadm output malformed.")
                return None
        dict["device"] = device
        return dict
示例#5
0
    def assemble(self):
        command = "%s --assemble '%s'" % (RAID.prog, self.device) + \
                  " %s" % (" ".join(self.devices))
        status = run_script(command, self.chroot)
        if status != 0:
            log.error("mdadm failed on '%s' with error code %d", self.name,
                      status)
            return 1
        self.active = True

        dict = self.info(self.device, self.chroot)
        if not dict:
            self.stop()
            return 0
        self.level = dict["level"]
        self.spares = dict["spare-devices"]
        self.preferred_minor = dict["preferred-minor"]
        self.size = dict["size"]
        return 0
示例#6
0
文件: raid.py 项目: kholia/pyrpm
    def assemble(self):
        command = "%s --assemble '%s'" % (RAID.prog, self.device) + \
                  " %s" % (" ".join(self.devices))
        status = run_script(command, self.chroot)
        if status != 0:
            log.error("mdadm failed on '%s' with error code %d", self.name,
                      status)
            return 1
        self.active = True

        dict = self.info(self.device, self.chroot)
        if not dict:
            self.stop()
            return 0
        self.level = dict["level"]
        self.spares = dict["spare-devices"]
        self.preferred_minor = dict["preferred-minor"]
        self.size = dict["size"]
        return 0
示例#7
0
    def create(self, level, spares=0):
        num = len(self.devices) - spares
        self.level = level
        self.spares = spares
        command = "%s --create '%s' --run" % (RAID.prog, self.device) + \
                " --raid-devices=%d" % (num) + \
                " --spare-devices=%d" % (self.spares) + \
                " --level=%d" % (self.level) + \
                " %s" % (" ".join(self.devices))
        if run_script(command, self.chroot) != 0:
            log.error("Failed to create raid '%s'.", self.name)
            return 0
        self.active = True

        dict = self.info(self.device, self.chroot)
        if not dict:
            self.stop()
            return 0
        self.preferred_minor = dict["preferred-minor"]
        self.size = dict["size"]
        return 1
示例#8
0
文件: raid.py 项目: kholia/pyrpm
    def create(self, level, spares=0):
        num = len(self.devices) - spares
        self.level = level
        self.spares = spares
        command = "%s --create '%s' --run" % (RAID.prog, self.device) + \
                " --raid-devices=%d" % (num) + \
                " --spare-devices=%d" % (self.spares) + \
                " --level=%d" % (self.level) + \
                " %s" % (" ".join(self.devices))
        if run_script(command, self.chroot) != 0:
            log.error("Failed to create raid '%s'.", self.name)
            return 0
        self.active = True

        dict = self.info(self.device, self.chroot)
        if not dict:
            self.stop()
            return 0
        self.preferred_minor = dict["preferred-minor"]
        self.size = dict["size"]
        return 1
示例#9
0
    def examine(device, chroot=None):
        command = "%s -E '%s'" % (RAID.prog, device)
        if run_script(command, chroot) != 0:
            log.error("Unable to get raid information for '%s'.", device)
            return None

        dict = {}
        for line in msg.split("\n"):
            line.strip()
            if not line or len(line) < 1:
                continue
            if line.find(":") != -1:
                (key, value) = line.split(":", 1)
                key = key.strip()
                value = value.strip()
                try:
                    if key == "Magic":
                        dict["magic"] = value
                    elif key == "UUID":
                        dict["uuid"] = value
                    elif key == "Raid Level":
                        dict["level"] = long(value[4:])
                    elif key == "Raid Devices":
                        dict["raid-devices"] = long(value)
                    elif key == "Total Devices":
                        dict["total-devices"] = long(value)
                    elif key == "Preferred Minor":
                        dict["preferred-minor"] = long(value)
                    elif key == "State":
                        dict["state"] = value
                    elif key == "Active Devices":
                        dict["active-devices"] = long(value)
                    elif key == "Working Devices":
                        dict["working-devices"] = long(value)
                    elif key == "Failed Devices":
                        dict["failed-devices"] = long(value)
                    elif key == "Spare Devices":
                        dict["spare-devices"] = long(value)
                    elif key == "Layout":
                        dict["layout"] = value
                    elif key == "Chunk Size":
                        dict["chunk-size"] = value
                except:
                    log.error("mdadm output malformed.")
                    return None
            else:
                splits = line.split()
                try:
                    if splits[0] == "this":
                        dict["device-number"] = long(splits[1])
                except:
                    log.error("mdadm output malformed.")
                    return None

        for key in [
                "magic", "uuid", "level", "raid-devices", "total-devices",
                "preferred-minor", "state", "active-devices", "failed-devices",
                "device-number"
        ]:
            if not dict.has_key(key):
                log.warning("Raid information for '%s' is incomplete: %s",
                            device, key)
                return None
        dict["device"] = device
        return dict
示例#10
0
文件: raid.py 项目: kholia/pyrpm
    def examine(device, chroot=None):
        command = "%s -E '%s'" % (RAID.prog, device)
        if run_script(command, chroot) != 0:
            log.error("Unable to get raid information for '%s'.", device)
            return None

        dict = { }
        for line in msg.split("\n"):
            line.strip()
            if not line or len(line) < 1:
                continue
            if line.find(":") != -1:
                (key, value) = line.split(":", 1)
                key = key.strip()
                value = value.strip()
                try:
                    if key == "Magic":
                        dict["magic"] = value
                    elif key == "UUID":
                        dict["uuid"] = value
                    elif key == "Raid Level":
                        dict["level"] = long(value[4:])
                    elif key == "Raid Devices":
                        dict["raid-devices"] = long(value)
                    elif key == "Total Devices":
                        dict["total-devices"] = long(value)
                    elif key == "Preferred Minor":
                        dict["preferred-minor"] = long(value)
                    elif key == "State":
                        dict["state"] = value
                    elif key == "Active Devices":
                        dict["active-devices"] = long(value)
                    elif key == "Working Devices":
                        dict["working-devices"] = long(value)
                    elif key == "Failed Devices":
                        dict["failed-devices"] = long(value)
                    elif key == "Spare Devices":
                        dict["spare-devices"] = long(value)
                    elif key == "Layout":
                        dict["layout"] = value
                    elif key == "Chunk Size":
                        dict["chunk-size"] = value
                except:
                    log.error("mdadm output malformed.")
                    return None
            else:
                splits = line.split()
                try:
                    if splits[0] == "this":
                        dict["device-number"] = long(splits[1])
                except:
                    log.error("mdadm output malformed.")
                    return None

        for key in [ "magic", "uuid", "level", "raid-devices", "total-devices",
                     "preferred-minor", "state", "active-devices",
                     "failed-devices", "device-number" ]:
            if not dict.has_key(key):
                log.warning("Raid information for '%s' is incomplete: %s",
                            device, key)
                return None
        dict["device"] = device
        return dict