예제 #1
0
    def updateSysfsPath(self):
        """ Update this device's sysfs path. """
        if not self.parents:
            self.sysfsPath = ''

        elif self.parents[0]._devDir == "/dev/mapper":
            dm_node = devicemapper.dm_node_from_name(self.name)
            path = os.path.join("/sys", self.sysfsBlockDir, dm_node)
            self.sysfsPath = os.path.realpath(path)[4:]

        else:
            Device.updateSysfsPath(self)
예제 #2
0
파일: partition.py 프로젝트: Tayyib/uludag
    def updateSysfsPath(self):
        """ Update this device's sysfs path. """
        if not self.parents:
            self.sysfsPath = ''

        elif self.parents[0]._devDir == "/dev/mapper":
            dm_node = devicemapper.dm_node_from_name(self.name)
            path = os.path.join("/sys", self.sysfsBlockDir, dm_node)
            self.sysfsPath = os.path.realpath(path)[4:]

        else:
            Device.updateSysfsPath(self)
예제 #3
0
    def __init__(self, format=None):
        """ Create a NoDevice instance.

            Arguments:

            Keyword Arguments:

                format -- a DeviceFormat instance
        """
        if format:
            name = format.type
        else:
            name = "none"

        Device.__init__(self, name, format=format)
예제 #4
0
    def __init__(self, format=None):
        """ Create a NoDevice instance.

            Arguments:

            Keyword Arguments:

                format -- a DeviceFormat instance
        """
        if format:
            name = format.type
        else:
            name = "none"

        Device.__init__(self, name, format=format)
예제 #5
0
    def __str__(self):
        s = Device.__str__(self)
        s += (
            "  grow = %(grow)s max size = %(maxsize)s  bootable = %(bootable)s\n"
            "  part type = %(partType)s  primary = %(primary)s\n"
            "  partedPartition = %(partedPart)r  disk = %(disk)r\n"
            % {
                "grow": self.req_grow,
                "maxsize": self.req_max_size,
                "bootable": self.bootable,
                "partType": self.partType,
                "primary": self.req_primary,
                "partedPart": self.partedPartition,
                "disk": self.disk,
            }
        )

        if self.partedPartition:
            s += "  start = %(start)s  end = %(end)s  length = %(length)s\n" "  flags = %(flags)s" % {
                "length": self.partedPartition.geometry.length,
                "start": self.partedPartition.geometry.start,
                "end": self.partedPartition.geometry.end,
                "flags": self.partedPartition.getFlagsAsString(),
            }

        return s
예제 #6
0
    def __str__(self):
        s = Device.__str__(self)
        s += (
            "  grow = %(grow)s max size = %(maxsize)s  bootable = %(bootable)s\n"
            "  part type = %(partType)s  primary = %(primary)s\n"
            "  partedPartition = %(partedPart)r  disk = %(disk)r\n" % {
                "grow": self.req_grow,
                "maxsize": self.req_max_size,
                "bootable": self.bootable,
                "partType": self.partType,
                "primary": self.req_primary,
                "partedPart": self.partedPartition,
                "disk": self.disk
            })

        if self.partedPartition:
            s += ("  start = %(start)s  end = %(end)s  length = %(length)s\n"
                  "  flags = %(flags)s" % {
                      "length": self.partedPartition.geometry.length,
                      "start": self.partedPartition.geometry.start,
                      "end": self.partedPartition.geometry.end,
                      "flags": self.partedPartition.getFlagsAsString()
                  })

        return s
예제 #7
0
파일: partition.py 프로젝트: Tayyib/uludag
    def dependsOn(self, dep):
        """ Return True if this device depends on dep. """
        if isinstance(dep, Partition) and dep.isExtended and \
           self.isLogical and self.disk == dep.disk:
            return True

        return Device.dependsOn(self, dep)
예제 #8
0
    def dependsOn(self, dep):
        """ Return True if this device depends on dep. """
        if isinstance(dep, Partition) and dep.isExtended and \
           self.isLogical and self.disk == dep.disk:
            return True

        return Device.dependsOn(self, dep)
예제 #9
0
 def __str__(self):
     s = Device.__str__(self)
     s += ("  level = %(level)s  spares = %(spares)s\n"
           "  members = %(memberDevices)s\n"
           "  total devices = %(totalDevices)s" %
           {"level": self.level, "spares": self.spares,
            "memberDevices": self.memberDevices, "totalDevices": self.totalDevices})
     return s
예제 #10
0
 def __str__(self):
     s = Device.__str__(self)
     s += ("  level = %(level)s  spares = %(spares)s\n"
           "  members = %(memberDevices)s\n"
           "  total devices = %(totalDevices)s" %
           {"level": self.level, "spares": self.spares,
            "memberDevices": self.memberDevices, "totalDevices": self.totalDevices})
     return s
예제 #11
0
파일: partition.py 프로젝트: Tayyib/uludag
    def teardown(self, recursive=None):
        """ Close, or tear down, a device. """
        if not self.exists and not recursive:
            raise PartitionError("device has not been created", self.name)

        if self.status:
            if self.originalFormat.exists:
                self.originalFormat.teardown()
            if self.format.exists:
                self.format.teardown()
            if self.parents[0].type == 'dm-multipath':
                devmap = block.getMap(major=self.major, minor=self.minor)
                if devmap:
                    try:
                        block.removeDeviceMap(devmap)
                    except Exception as e:
                        raise PartitionTeardownError("failed to tear down device-mapper partition %s: %s" % (self.name, e))
                yali.baseudev.udev_settle()

        Device.teardown(self, recursive=recursive)
예제 #12
0
    def teardown(self, recursive=None):
        """ Close, or tear down, a device. """
        if not self.exists and not recursive:
            raise PartitionError("device has not been created", self.name)

        if self.status:
            if self.originalFormat.exists:
                self.originalFormat.teardown()
            if self.format.exists:
                self.format.teardown()
            if self.parents[0].type == 'dm-multipath':
                devmap = block.getMap(major=self.major, minor=self.minor)
                if devmap:
                    try:
                        block.removeDeviceMap(devmap)
                    except Exception as e:
                        raise PartitionError("failed to tear down device-mapper partition %s: %s" % (self.name, e))
                yali.baseudev.udev_settle()

        Device.teardown(self, recursive=recursive)
예제 #13
0
파일: partition.py 프로젝트: Tayyib/uludag
    def __init__(self, name, format=None,
             size=None, grow=False, maxsize=None,
             major=None, minor=None, bootable=None,
             sysfsPath='', parents=None, exists=None,
             partType=None, primary=False, weight=0):

        """ Create a Partition instance.

            Arguments:

                name -- the device name (generally a device node's basename)

            Keyword Arguments:

                exists -- indicates whether this is an existing device
                format -- the device's format (DeviceFormat instance)

                For existing partitions:

                    parents -- the disk that contains this partition
                    major -- the device major
                    minor -- the device minor
                    sysfsPath -- sysfs device path

                For new partitions:

                    partType -- primary,extended,&c (as parted constant)
                    grow -- whether or not to grow the partition
                    maxsize -- max size for growable partitions (in MB)
                    size -- the device's size (in MB)
                    bootable -- whether the partition is bootable
                    parents -- a list of potential containing disks
                    weight -- an initial sorting weight to assign
        """
        self.req_disks = []
        self.req_partType = None
        self.req_primary = None
        self.req_grow = None
        self.req_bootable = None
        self.req_size = 0
        self.req_base_size = 0
        self.req_max_size = 0
        self.req_base_weight = 0

        self._bootable = False

        Device.__init__(self, name, format=format, size=size,
                        major=major, minor=minor, exists=exists,
                        sysfsPath=sysfsPath, parents=parents)
        if not exists:
            # this is a request, not a partition -- it has no parents
            self.req_disks = self.parents[:]
            for dev in self.parents:
                dev.removeChild()
            self.parents = []

        # FIXME: Validate partType, but only if this is a new partition
        #        Otherwise, overwrite it with the partition's type.
        self._partType = None
        self.partedFlags = {}
        self._partedPartition = None
        self._origPath = None
        self._currentSize = 0

        # FIXME: Validate size, but only if this is a new partition.
        #        For existing partitions we will get the size from
        #        parted.

        if self.exists:
            ctx.logger.debug("looking up parted Partition: %s" % self.path)
            self._partedPartition = self.disk.format.partedDisk.getPartitionByPath(self.path)
            if not self._partedPartition:
                raise PartitionError("cannot find parted partition instance", self.name)

            self._origPath = self.path
            self.probe()
            if self.getFlag(parted.PARTITION_PREP):
                # the only way to identify a PPC PReP Boot partition is to
                # check the partition type/flags, so do it here.
                self.format = getFormat("prepboot", device=self.path, exists=True)
        else:
            # XXX It might be worthwhile to create a shit-simple
            #     PartitionRequest class and pass one to this constructor
            #     for new partitions.
            if not self._size:
                # default size for new partition requests
                self._size = self.defaultSize
            self.req_name = name
            self.req_partType = partType
            self.req_primary = primary
            self.req_max_size = numeric_type(maxsize)
            self.req_grow = grow
            self.req_bootable = bootable

            # req_size may be manipulated in the course of partitioning
            self.req_size = self._size

            # req_base_size will always remain constant
            self.req_base_size = self._size

            self.req_base_weight = weight
예제 #14
0
파일: partition.py 프로젝트: Tayyib/uludag
 def _setFormat(self, format):
     """ Set the Device's format. """
     Device._setFormat(self, format)
예제 #15
0
 def setup(self, orig=False):
     """ Open, or set up, a device. """
     Device.setup(self, orig=orig)
     self.activate()
예제 #16
0
    def __init__(self,
                 name,
                 format=None,
                 size=None,
                 grow=False,
                 maxsize=None,
                 major=None,
                 minor=None,
                 bootable=None,
                 sysfsPath='',
                 parents=None,
                 exists=None,
                 partType=None,
                 primary=False,
                 weight=0):
        """ Create a Partition instance.

            Arguments:

                name -- the device name (generally a device node's basename)

            Keyword Arguments:

                exists -- indicates whether this is an existing device
                format -- the device's format (DeviceFormat instance)

                For existing partitions:

                    parents -- the disk that contains this partition
                    major -- the device major
                    minor -- the device minor
                    sysfsPath -- sysfs device path

                For new partitions:

                    partType -- primary,extended,&c (as parted constant)
                    grow -- whether or not to grow the partition
                    maxsize -- max size for growable partitions (in MB)
                    size -- the device's size (in MB)
                    bootable -- whether the partition is bootable
                    parents -- a list of potential containing disks
                    weight -- an initial sorting weight to assign
        """
        self.req_disks = []
        self.req_partType = None
        self.req_primary = None
        self.req_grow = None
        self.req_bootable = None
        self.req_size = 0
        self.req_base_size = 0
        self.req_max_size = 0
        self.req_base_weight = 0

        self._bootable = False

        Device.__init__(self,
                        name,
                        format=format,
                        size=size,
                        major=major,
                        minor=minor,
                        exists=exists,
                        sysfsPath=sysfsPath,
                        parents=parents)
        if not exists:
            # this is a request, not a partition -- it has no parents
            self.req_disks = self.parents[:]
            for dev in self.parents:
                dev.removeChild()
            self.parents = []

        # FIXME: Validate partType, but only if this is a new partition
        #        Otherwise, overwrite it with the partition's type.
        self._partType = None
        self.partedFlags = {}
        self._partedPartition = None
        self._origPath = None
        self._currentSize = 0

        # FIXME: Validate size, but only if this is a new partition.
        #        For existing partitions we will get the size from
        #        parted.

        if self.exists:
            ctx.logger.debug("looking up parted Partition: %s" % self.path)
            self._partedPartition = self.disk.format.partedDisk.getPartitionByPath(
                self.path)
            if not self._partedPartition:
                raise PartitionError("cannot find parted partition instance",
                                     self.name)

            self._origPath = self.path
            self.probe()
            if self.getFlag(parted.PARTITION_PREP):
                # the only way to identify a PPC PReP Boot partition is to
                # check the partition type/flags, so do it here.
                self.format = getFormat("prepboot",
                                        device=self.path,
                                        exists=True)
        else:
            # XXX It might be worthwhile to create a shit-simple
            #     PartitionRequest class and pass one to this constructor
            #     for new partitions.
            if not self._size:
                # default size for new partition requests
                self._size = self.defaultSize
            self.req_name = name
            self.req_partType = partType
            self.req_primary = primary
            self.req_max_size = numeric_type(maxsize)
            self.req_grow = grow
            self.req_bootable = bootable

            # req_size may be manipulated in the course of partitioning
            self.req_size = self._size

            # req_base_size will always remain constant
            self.req_base_size = self._size

            self.req_base_weight = weight
예제 #17
0
 def _setFormat(self, format):
     """ Set the Device's format. """
     Device._setFormat(self, format)
예제 #18
0
    def __init__(self,
                 name,
                 level=None,
                 major=None,
                 minor=None,
                 size=None,
                 memberDevices=None,
                 totalDevices=None,
                 uuid=None,
                 format=None,
                 exists=None,
                 parents=None,
                 sysfsPath=''):
        """ Create a RaidArray instance.

            Arguments:

                name -- the device name (generally a device node's basename)

            Keyword Arguments:

                level -- the device's RAID level (a string, eg: '1' or 'raid1')
                parents -- list of member devices (Device instances)
                size -- the device's size (units/format TBD)
                uuid -- the device's UUID
                minor -- the device minor
                sysfsPath -- sysfs device path
                format -- a DeviceFormat instance
                exists -- indicates whether this is an existing device
        """
        Device.__init__(self,
                        name,
                        format=format,
                        exists=exists,
                        major=major,
                        minor=minor,
                        size=size,
                        parents=parents,
                        sysfsPath=sysfsPath)

        self.level = level
        if level == "container":
            self._type = "mdcontainer"
        elif level is not None:
            self.level = raid.raidLevel(level)

        # For new arrays check if we have enough members
        if (not exists and parents
                and len(parents) < raid.get_raid_min_members(self.level)):
            raise ValueError, _("A RAID%(level)d set requires at least %(min_member)d member") % \
                                {"level":self.level, "min_member":raid.get_raid_min_members(self.level)}

        self.uuid = uuid
        self._totalDevices = numeric_type(totalDevices)
        self._memberDevices = numeric_type(memberDevices)
        self.sysfsPath = "/devices/virtual/block/%s" % name
        self.chunkSize = 512.0 / 1024.0  # chunk size in MB
        self.superBlockSize = 2.0  # superblock size in MB

        self.createMetadataVer = "1.1"
        # bitmaps are not meaningful on raid0 according to mdadm-3.0.3
        self.createBitmap = self.level != 0

        # For container members probe size now, as we cannot determine it
        # when teared down.
        if self.parents and self.parents[0].type == "mdcontainer":
            self._size = self.currentSize
            self._type = "mdbiosraidarray"

        self.formatClass = get_device_format("mdmember")
        if not self.formatClass:
            raise RaidArrayError("cannot find class for 'mdmember'", self.name)

        if self.exists and self.uuid:
            # this is a hack to work around mdadm's insistence on giving
            # really high minors to arrays it has no config entry for
            open("/etc/mdadm.conf",
                 "a").write("ARRAY %s UUID=%s\n" % (self.path, self.uuid))
예제 #19
0
    def __init__(self, name, level=None, major=None, minor=None, size=None,
                 memberDevices=None, totalDevices=None,
                 uuid=None, format=None, exists=None,
                 parents=None, sysfsPath=''):
        """ Create a RaidArray instance.

            Arguments:

                name -- the device name (generally a device node's basename)

            Keyword Arguments:

                level -- the device's RAID level (a string, eg: '1' or 'raid1')
                parents -- list of member devices (Device instances)
                size -- the device's size (units/format TBD)
                uuid -- the device's UUID
                minor -- the device minor
                sysfsPath -- sysfs device path
                format -- a DeviceFormat instance
                exists -- indicates whether this is an existing device
        """
        Device.__init__(self, name, format=format, exists=exists,
                               major=major, minor=minor, size=size,
                               parents=parents, sysfsPath=sysfsPath)

        self.level = level
        if level == "container":
            self._type = "mdcontainer"
        elif level is not None:
            self.level = raid.raidLevel(level)

        # For new arrays check if we have enough members
        if (not exists and parents and
                len(parents) < raid.get_raid_min_members(self.level)):
            raise ValueError, _("A RAID%(level)d set requires at least %(min_member)d member") % \
                                {"level":self.level, "min_member":raid.get_raid_min_members(self.level)}

        self.uuid = uuid
        self._totalDevices = numeric_type(totalDevices)
        self._memberDevices = numeric_type(memberDevices)
        self.sysfsPath = "/devices/virtual/block/%s" % name
        self.chunkSize = 512.0 / 1024.0         # chunk size in MB
        self.superBlockSize = 2.0               # superblock size in MB

        self.createMetadataVer = "1.1"
        # bitmaps are not meaningful on raid0 according to mdadm-3.0.3
        self.createBitmap = self.level != 0

        # For container members probe size now, as we cannot determine it
        # when teared down.
        if self.parents and self.parents[0].type == "mdcontainer":
            self._size = self.currentSize
            self._type = "mdbiosraidarray"

        self.formatClass = get_device_format("mdmember")
        if not self.formatClass:
            raise RaidArrayError("cannot find class for 'mdmember'", self.name)

        if self.exists and self.uuid:
            # this is a hack to work around mdadm's insistence on giving
            # really high minors to arrays it has no config entry for
            open("/etc/mdadm.conf", "a").write("ARRAY %s UUID=%s\n"
                                                % (self.path, self.uuid))
예제 #20
0
 def setup(self, intf=None, orig=False):
     """ Open, or set up, a device. """
     Device.setup(self, intf=None, orig=orig)
     self.activate()