Beispiel #1
0
    def to_tgt(self, parent):
        '''Transfer the install profile information to tgt format'''

        if not self.modified():
            part = deepcopy(self._tgt_part)
        else:
            # Something changed, need to create a new one
            geo = tgt.Geometry(parent.cylsz, self.blocksz)

            if self.type == PartitionInfo.UNUSED:
                # Partition was deleted. Return an empty partition,
                # which will indicate to target instantiation to
                # delete this partition
                return tgt.Partition(geo,
                                     self.number,
                                     PartitionInfo.DELETED,
                                     0,
                                     0,
                                     modified=True)

            offset = int(self.offset.size_as("b") / self.blocksz)
            offset = max(PartitionInfo.MIN_OFFSET, offset)
            blocks = self.get_blocks()

            if self.is_logical() or self.is_extended():
                # Ensure that the required minimum amount of empty space
                # precedes and follows this logical partition
                offset += PartitionInfo.LOGICAL_BLOCK_PAD
                blocks -= 2 * PartitionInfo.LOGICAL_BLOCK_PAD

            # offset must be a multiple of tgt.Geometry.cylsz
            offset = round_to_multiple(offset, geo.cylsz)
            blocks = round_down(blocks, geo.cylsz)

            part = tgt.Partition(geo,
                                 self.number,
                                 self.id,
                                 offset,
                                 blocks,
                                 modified=True)

        part.use_whole = self.use_whole_segment

        child_list = ()
        if not part.use_whole:
            slices = []
            if self.boot_slice is not None:
                slices.append(self.boot_slice)
            if self.alt_slice is not None:
                slices.append(self.alt_slice)
            slices.extend(self.slices)
            for slice_info in slices:
                sl = slice_info.to_tgt(parent)
                if sl is not None:
                    child_list += (sl, )

        part.children = child_list
        return (part)
Beispiel #2
0
    def to_tgt(self, parent):
        '''Transfer the install profile information to tgt format'''
        # Create tgt.Slice object

        if self.get_type() == SliceInfo.UNUSED:
            return None

        if not self.modified():
            return self._tgt_slice

        # Don't need to include the 'backup' slice, libti will
        # automatically create one appropriately
        if self.number == SliceInfo.BACKUP_SLICE:
            return None

        # Something changed, need to create a new one
        geo = tgt.Geometry(parent.cylsz, self.blocksz)

        # offset must be a multiple of tgt.Geometry.cylsz
        off = int(self.offset.size_as("b") / self.blocksz)
        offset = round_to_multiple(off, geo.cylsz)

        blocks = round_to_multiple(self.get_blocks(), geo.cylsz)

        tag = tgt.Slice.UNASSIGNED
        slice_type = self.type[0]
        user = self.type[1]
        sl = tgt.Slice(geo,
                       self.number,
                       tag,
                       slice_type,
                       offset,
                       blocks,
                       modified=True,
                       user=str(user),
                       unmountable=self.unmountable,
                       readonly=self.readonly)
        return (sl)
Beispiel #3
0
    def to_tgt(self):
        '''Transfer the install profile information to tgt format

        ''' 
        if self._tgt_disk is not None:
            tgt_disk = self._tgt_disk
        else:
            name = self.name
            blocks = round_to_multiple(self.get_blocks(), self.cylsz)
            controller = self.controller
            boot = self.boot
            removable = self.removable
            vendor = self.vendor
            serialno = self.serialno
            geo = tgt.Geometry(cylsz=self.cylsz, blocksz=self.blocksz)
            tgt_disk = tgt.Disk(geo, name, blocks, controller=controller,
                                boot=boot, removable=removable,
                                vendor=vendor, serialno=serialno)
        
        backup_slice = None
        if self.partitions:
            sl_iter = iter(self.get_solaris_data().slices)
        else:
            sl_iter = iter(self.slices)
        for slice_ in sl_iter:
            if slice_.number == SliceInfo.BACKUP_SLICE:
                backup_slice = slice_._tgt_slice
                break
        
        tgt_disk.use_whole = self.use_whole_segment
        
        child_list = ()
        if not tgt_disk.use_whole:
            for partition in self.partitions:
                part = partition.to_tgt(self)
                if part is not None:
                    child_list += (part,)
                    tgt_disk.fdisk = True
            if not child_list:
                for slice_info in self.slices:
                    sl = slice_info.to_tgt(self)
                    if sl is not None:
                        child_list += (sl,)
                        tgt_disk.vtoc = True
        
        tgt_disk.children = child_list
        slice_parent = tgt_disk
        if child_list and isinstance(child_list[0], tgt.Partition):
            standards = []
            logicals = []
            ext_part = None
            for child in child_list:
                if child.id == PartitionInfo.DELETED:
                    continue
                if child.number > PartitionInfo.MAX_STANDARD_PARTITIONS:
                    logicals.append(child)
                else:
                    standards.append(child)
                    if child.id in PartitionInfo.EXTENDED:
                        ext_part = child
                if child.id == PartitionInfo.SOLARIS:
                    slice_parent = child
            adjust_tgt_parts(standards, tgt_parent=tgt_disk)
            if logicals:
                adjust_tgt_parts(logicals, ext_part=ext_part)
        
        slices = []
        for child in slice_parent.children:
            if child.number == SliceInfo.BACKUP_SLICE:
                continue
            slices.append(child)
        if backup_slice is not None:
            slice_parent = backup_slice
        adjust_tgt_parts(slices, tgt_parent=slice_parent)
        
        # print out the tgt_disk object for debugging
        logging.debug("%s", tgt_disk)
        
        return tgt_disk