示例#1
0
 def get_volume_mbsize(self, mbsize, size_type, realpath, filesystem_name):
     """
         Implements size lookup for the given path and desired
         filesystem according to the specified size type
     """
     if size_type == 'freespace':
         # Please note for nested volumes which contains other volumes
         # the freespace calculation is not correct. Example:
         # /usr is a volume and /usr/lib is a volume. If freespace is
         # set for the /usr volume the data size calculated also
         # contains the data of the /usr/lib path which will live in
         # an extra volume later. The result will be more freespace
         # than expected ! Especially for the root volume this matters
         # most because it always nests all other volumes. Thus it is
         # better to use a fixed size for the root volume if it is not
         # configured to use all rest space
         #
         # You are invited to fix it :)
         volume_size = SystemSize(
             self.root_dir + '/' + realpath
         )
         mbsize = int(mbsize) + \
             Defaults.get_min_volume_mbytes()
         mbsize += volume_size.customize(
             volume_size.accumulate_mbyte_file_sizes(),
             filesystem_name
         )
     return mbsize
示例#2
0
文件: disk_setup.py 项目: k0da/kiwi-1
    def __accumulate_volume_size(self, root_mbytes):
        """
            calculate number of mbytes to add to the disk to allow
            the creaton of the volumes with their configured size
        """
        disk_volume_mbytes = 0

        data_volume_mbytes = self.__calculate_volume_mbytes()
        root_volume = self.__get_root_volume_configuration()

        for volume in self.volumes:
            if volume.realpath and not volume.realpath == '/' and volume.size:
                [size_type, req_size] = volume.size.split(':')
                disk_add_mbytes = 0
                if size_type == 'freespace':
                    disk_add_mbytes += int(req_size) + \
                        Defaults.get_min_volume_mbytes()
                else:
                    disk_add_mbytes += int(req_size) - \
                        data_volume_mbytes.volume[volume.realpath]
                if disk_add_mbytes > 0:
                    disk_volume_mbytes += disk_add_mbytes
                else:
                    log.warning(
                        'volume size of %s MB for %s is too small, skipped',
                        int(req_size), volume.realpath
                    )

        if root_volume:
            if root_volume.size_type == 'freespace':
                disk_add_mbytes += root_volume.req_size + \
                    Defaults.get_min_volume_mbytes()
            else:
                disk_add_mbytes = root_volume.req_size - \
                    root_mbytes + data_volume_mbytes.total

            if disk_add_mbytes > 0:
                disk_volume_mbytes += disk_add_mbytes
            else:
                log.warning(
                    'root volume size of %s MB is too small, skipped',
                    root_volume.req_size
                )

        return disk_volume_mbytes
示例#3
0
    def __accumulate_volume_size(self, root_mbytes):
        """
            calculate number of mbytes to add to the disk to allow
            the creaton of the volumes with their configured size
        """
        disk_volume_mbytes = 0

        data_volume_mbytes = self.__calculate_volume_mbytes()
        root_volume = self.__get_root_volume_configuration()

        for volume in self.volumes:
            if volume.realpath and not volume.realpath == '/' and volume.size:
                [size_type, req_size] = volume.size.split(':')
                disk_add_mbytes = 0
                if size_type == 'freespace':
                    disk_add_mbytes += int(req_size) + \
                        Defaults.get_min_volume_mbytes()
                else:
                    disk_add_mbytes += int(req_size) - \
                        data_volume_mbytes.volume[volume.realpath]
                if disk_add_mbytes > 0:
                    disk_volume_mbytes += disk_add_mbytes
                else:
                    log.warning(
                        'volume size of %s MB for %s is too small, skipped',
                        int(req_size), volume.realpath)

        if root_volume:
            if root_volume.size_type == 'freespace':
                disk_add_mbytes += root_volume.req_size + \
                    Defaults.get_min_volume_mbytes()
            else:
                disk_add_mbytes = root_volume.req_size - \
                    root_mbytes + data_volume_mbytes.total

            if disk_add_mbytes > 0:
                disk_volume_mbytes += disk_add_mbytes
            else:
                log.warning('root volume size of %s MB is too small, skipped',
                            root_volume.req_size)

        return disk_volume_mbytes
示例#4
0
 def get_volume_mbsize(self, mbsize, size_type, realpath, filesystem_name):
     """
         Implements size lookup for the given path and desired
         filesystem according to the specified size type
     """
     if size_type == 'freespace':
         # Please note for nested volumes which contains other volumes
         # the freespace calculation is not correct. Example:
         # /usr is a volume and /usr/lib is a volume. If freespace is
         # set for the /usr volume the data size calculated also
         # contains the data of the /usr/lib path which will live in
         # an extra volume later. The result will be more freespace
         # than expected ! Especially for the root volume this matters
         # most because it always nests all other volumes. Thus it is
         # better to use a fixed size for the root volume if it is not
         # configured to use all rest space
         #
         # You are invited to fix it :)
         volume_size = SystemSize(self.root_dir + '/' + realpath)
         mbsize = int(mbsize) + \
             Defaults.get_min_volume_mbytes()
         mbsize += volume_size.customize(
             volume_size.accumulate_mbyte_file_sizes(), filesystem_name)
     return mbsize
示例#5
0
    def get_volumes(self):
        """
            get volumes section from systemdisk
        """
        volume_type_list = []
        systemdisk_section = self.get_build_type_system_disk_section()
        if systemdisk_section:
            volume_type = namedtuple(
                'volume_type',
                ['name', 'size', 'realpath', 'mountpoint', 'fullsize'])
            volumes = systemdisk_section.get_volume()
            have_root_volume_setup = False
            have_full_size_volume = False
            if volumes:
                for volume in volumes:
                    name = volume.get_name()
                    mountpoint = volume.get_mountpoint()
                    size = volume.get_size()
                    freespace = volume.get_freespace()
                    fullsize = False
                    realpath = None
                    if mountpoint:
                        realpath = mountpoint
                    elif '@root' not in name:
                        realpath = name

                    if '@root' in name:
                        have_root_volume_setup = True
                        name = 'Root'
                        realpath = '/'

                    if not mountpoint:
                        # if no mountpoint is specified the name attribute is
                        # both, the path information as well as the name of
                        # the volume. However turning a path value into a
                        # variable requires to introduce a directory separator
                        # different from '/'. In kiwi the '_' is used and that
                        # forbids to use this letter as part of name if no
                        # mountpoint is specified:
                        if '_' in name:
                            raise KiwiInvalidVolumeName(
                                'mountpoint attribute required for volume %s' %
                                name)
                        name = 'LV' + self.__to_volume_name(name)
                    else:
                        # if a mountpoint path is specified the value is turned
                        # into a path variable and name stays untouched. However
                        # the mountpoint path currently is not allowed to
                        # contain the directory separator '_'. In order to fix
                        # this limitation the way the kiwi initrd code handles
                        # the volume information needs to change first
                        if '_' in mountpoint:
                            raise KiwiInvalidVolumeName(
                                'mountpoint %s must not contain "_"' %
                                mountpoint)
                        mountpoint = 'LV' + self.__to_volume_name(mountpoint)

                    # the given name is used as shell variable in the kiwi boot
                    # code. Thus the name must follow the bash variable name
                    # conventions
                    if not re.match('^[a-zA-Z_]+[a-zA-Z0-9_]*$', name):
                        raise KiwiInvalidVolumeName(
                            'name %s invalid for use as shell variable' % name)

                    if size:
                        size = 'size:' + format(self.__to_mega_byte(size))
                    elif freespace:
                        size = 'freespace:' + format(
                            self.__to_mega_byte(freespace))
                    else:
                        size = 'freespace:' + format(
                            Defaults.get_min_volume_mbytes())

                    if ':all' in size:
                        size = None
                        fullsize = True
                        have_full_size_volume = True

                    volume_type_list.append(
                        volume_type(name=name,
                                    size=size,
                                    fullsize=fullsize,
                                    mountpoint=mountpoint,
                                    realpath=realpath))
            if not have_root_volume_setup:
                # There must always be a root volume setup. It will be the
                # full size volume if no other volume has this setup
                if have_full_size_volume:
                    size = 'freespace:' + format(
                        Defaults.get_min_volume_mbytes())
                    fullsize = False
                else:
                    size = None
                    fullsize = True
                volume_type_list.append(
                    volume_type(name='LVRoot',
                                size=size,
                                fullsize=fullsize,
                                mountpoint=None,
                                realpath='/'))
        return volume_type_list