Exemple #1
0
    def on_continue(self):
        '''Set the user's selection in the install target. If they chose
        to use the entire disk (or entire partition), define a single
        partition (or slice) to consume the whole disk (or partition)
        '''

        if self.center_win.get_active_object() is self.whole_disk_item:
            self.use_whole_segment = True
            if isinstance(self.disk, Disk):
                LOGGER.debug("Setting whole_disk for %s", self.disk)
                self.disk = self.tc.select_disk(self.disk,
                                                use_whole_disk=True)[0]
            else:
                # it's a partition, set the in_zpool attribute in the object
                # for now.  The next screen will fill in needed slices
                self.disk.in_zpool = DEFAULT_ZPOOL_NAME
        else:
            self.use_whole_segment = False
            if isinstance(self.disk, Disk):
                LOGGER.debug("Setting whole_disk to false for %s", self.disk)
                self.disk.whole_disk = False
            else:
                self.disk.in_zpool = None

        # set an attribute on the desired disk so we don't enter the
        # partition/slice edit screen.
        if isinstance(self.disk, Disk):
            self.disk.use_whole_segment = self.use_whole_segment

        dump_doc("At the end of fdisk_partitions.continue")
Exemple #2
0
    def on_continue(self):
        '''Set the user's selection in the install target. If they chose
        to use the entire disk (or entire partition), define a single
        partition (or slice) to consume the whole disk (or partition)
        
        '''

        if self.center_win.get_active_object() is self.whole_disk_item:
            self.use_whole_segment = True
            if isinstance(self.disk, Disk):
                LOGGER.debug("Setting whole_disk and creating default"
                             " layout for %s", self.disk)
                disk = self.tc.select_disk(self.disk, use_whole_disk=True)[0]
                disk.whole_disk = True
            else: 
                # it's a partition, set the in_zpool attribute in
                # the object for now.  The next screen will
                # fill in needed slices
                self.disk.in_zpool = ROOT_POOL
        else:
            self.use_whole_segment = False
            if isinstance(self.disk, Disk):
                LOGGER.debug("Setting whole_disk to false")
                self.disk.whole_disk = False
            else:
                self.disk.in_zpool = None

        dump_doc("At the end of fdisk_partitions.continue")
Exemple #3
0
    def reset(self, dummy=None):
        '''Reset ui_obj to value found from Target Discovery.
        Meaningful only for editable DiskWindows

        '''
        if not self.editable:
            return
        doc = InstallEngine.get_instance().doc

        # "reset" the desired target
        reset_obj = None
        if isinstance(self.ui_obj, UIDisk):
            reset_obj = (self.tc.reset_layout(disk=self.ui_obj.doc_obj))[0]
        else:
            # reset the partition by removing the modified Partition, and
            # resetting it with the partition found during target discovery.

            discovered_obj = self.ui_obj.discovered_doc_obj

            desired_disk = get_desired_target_disk(doc)
            desired_part = get_solaris_partition(doc)

            desired_disk.delete_partition(desired_part)
            part_copy = deepcopy(discovered_obj)
            desired_disk.insert_children(part_copy)

            # get the updated reference
            reset_obj = get_solaris_partition(doc)

        dump_doc("After doing reset")

        self.set_disk_info(disk_info=reset_obj)
        self.activate_solaris_data()
Exemple #4
0
def on_exit_edit(edit_field, disk_win=None):
    '''On exit, if the user has left the field blank, set the size to 0'''

    text = edit_field.get_text()
    if not text.strip():
        text = "0"
        enctext = text.encode(get_encoding())
        # encode per locale for floating point conversion
        edit_field.set_text("%.1f" % locale.atof(enctext))

    part_order = disk_win.ui_obj.get_parts_in_use().index(edit_field.data_obj)
    LOGGER.debug("Part being resized is at index: %s", part_order)

    new_size_text = text.strip()

    LOGGER.debug("Resizing text=%s", new_size_text)
    # encode user input per locale for floating point conversion
    enctext = new_size_text.encode(get_encoding())
    new_size = Size(str(locale.atof(enctext)) + Size.gb_units)
    old_size = edit_field.data_obj.size

    new_size_byte = new_size.get(Size.byte_units)
    old_size_byte = old_size.get(Size.byte_units)

    precision = Size(UI_PRECISION).get(Size.byte_units)

    if abs(new_size_byte - old_size_byte) > precision:
        parent_doc_obj = edit_field.data_obj.doc_obj.parent
        if isinstance(parent_doc_obj, Disk):
            if isinstance(edit_field.data_obj.doc_obj, Partition):
                resized_obj = parent_doc_obj.resize_partition(
                    edit_field.data_obj.doc_obj, new_size.get(Size.gb_units),
                    size_units=Size.gb_units)
            else:
                resized_obj = parent_doc_obj.resize_slice(
                    edit_field.data_obj.doc_obj, new_size.get(Size.gb_units),
                    size_units=Size.gb_units)
        else:
            resized_obj = parent_doc_obj.resize_slice(
                edit_field.data_obj.doc_obj, new_size.get(Size.gb_units),
                size_units=Size.gb_units)

        if isinstance(resized_obj, Partition):
            resized_obj.in_zpool = ROOT_POOL
        else:
            if resized_obj.in_zpool == ROOT_POOL:
                resized_obj.tag = V_ROOT

        if disk_win is not None:
            disk_win.set_disk_info(ui_obj=disk_win.ui_obj)
            disk_win.activate_index(part_order)

    dump_doc("After resize")
Exemple #5
0
    def on_continue(self):
        '''Set the user's selection in the install target.
        '''

        active_object = self.center_win.get_active_object()
        if active_object is self.whole_disk_item:
            LOGGER.debug("Setting whole_disk for %s", self.disk)
            self.use_whole_segment = True
            self.disk = self.tc.select_disk(self.disk, use_whole_disk=True)[0]
        else:
            LOGGER.debug("Setting whole_disk to false")
            self.use_whole_segment = False
            self.disk.whole_disk = False

        dump_doc("At the end of gpt_partitions.continue")
Exemple #6
0
def resize_validate(edit_field, disk_win=None):
    '''Check text to see if it is a decimal number of precision no greater
       than the tenths place. Resize the partition if everything checks
       out.
    '''

    LOGGER.debug("in resize_validate()")
    text = edit_field.get_text().lstrip()
    radixchar = locale.localeconv()['decimal_point']
    if text.endswith(" "):
        raise UIMessage(
            _('Only the digits 0-9 and "%s" are valid.') % radixchar)
    vals = text.split(radixchar)
    if len(vals) > 2:
        raise UIMessage(_('A number can only have one "%s"') % radixchar)
    try:
        if len(vals[0]) > 0:
            int(vals[0])
        if len(vals) > 1 and len(vals[1]) > 0:
            int(vals[1])
    except ValueError:
        raise UIMessage(
            _('Only the digits 0-9 and "%s" are valid.') % radixchar)
    if len(vals) > 1 and len(vals[1]) > 1:
        raise UIMessage(_("Size can be specified to only one decimal place."))

    if disk_win is None:
        return True

    text = text.rstrip(radixchar)
    # If the user deleted all digits, leave partition size alone until user
    # inputs new digits
    if not text:
        LOGGER.debug("No size value digits, skipping resize")
        return True

    part_order = disk_win.ui_obj.get_parts_in_use().index(edit_field.data_obj)
    LOGGER.debug("Part being resized is at index: %s", part_order)

    # encode user input per locale for floating point conversion
    text = text.encode(get_encoding())
    new_size = Size(str(locale.atof(text)) + Size.gb_units)
    max_size = edit_field.data_obj.get_max_size()

    # When comparing user input and display sizes, check only to the first
    # decimal place as that is all the user sees.
    new_size_rounded = round(new_size.get(Size.gb_units), 1)
    max_size_rounded = round(max_size.get(Size.gb_units), 1)
    if new_size_rounded > max_size_rounded:
        locale_new_size = locale.format("%.1f", new_size_rounded)
        locale_max_size = locale.format("%.1f", max_size_rounded)
        msg = _("The new size %(size)s is greater than "
                "the available space %(avail)s") % \
                {"size": locale_new_size,
                 "avail": locale_max_size}
        raise UIMessage(msg)

    new_size_text = text.strip()
    LOGGER.debug("New size text=%s", new_size_text)

    old_size = edit_field.data_obj.size
    new_size_byte = new_size.get(Size.byte_units)

    # Filter out edits that would result in resizing a partition to zero
    if new_size_byte == 0:
        return True

    old_size_byte = old_size.get(Size.byte_units)
    precision_bytes = Size(UI_PRECISION).get(Size.byte_units)

    # Ignore potential rounding artifacts.
    if abs(new_size_byte - old_size_byte) <= precision_bytes:
        return True

    max_size_byte = max_size.get(Size.byte_units)

    if new_size_byte > max_size_byte:
        # Allow for loss of precision from rounding errors, but no greater
        if (new_size_byte - max_size_byte) > precision_bytes:
            raise RuntimeError("Requested partition resize to %d bytes "
                               "exceeds maximum size available: %d" %
                               (new_size_byte, max_size_byte))

        # Clamp the new size at max size otherwise the resize will throw
        # an InsufficientSpaceError.
        LOGGER.debug(
            "Requested partition resize exceeds maximum size: "
            "Clamping %d bytes to %d bytes", new_size_byte, max_size_byte)
        new_size = max_size
    parent_doc_obj = edit_field.data_obj.doc_obj.parent
    if isinstance(parent_doc_obj, Disk):
        if isinstance(edit_field.data_obj.doc_obj, GPTPartition):
            resized_obj = parent_doc_obj.resize_gptpartition(
                edit_field.data_obj.doc_obj,
                new_size.get(Size.gb_units),
                size_units=Size.gb_units)
        elif isinstance(edit_field.data_obj.doc_obj, Partition):
            resized_obj = parent_doc_obj.resize_partition(
                edit_field.data_obj.doc_obj,
                new_size.get(Size.gb_units),
                size_units=Size.gb_units)
        else:
            resized_obj = parent_doc_obj.resize_slice(
                edit_field.data_obj.doc_obj,
                new_size.get(Size.gb_units),
                size_units=Size.gb_units)
    else:
        resized_obj = parent_doc_obj.resize_slice(edit_field.data_obj.doc_obj,
                                                  new_size.get(Size.gb_units),
                                                  size_units=Size.gb_units)

    if isinstance(resized_obj, Partition):
        # Don't do this for GPTPartition because there is no guarantee this
        # will be the installation target partition if there is more than
        # 1 Solaris partition
        resized_obj.in_zpool = ROOT_POOL
    elif isinstance(resized_obj, Slice):
        if resized_obj.in_zpool == ROOT_POOL:
            resized_obj.tag = V_ROOT

    disk_win.set_disk_info(ui_obj=disk_win.ui_obj)
    disk_win.activate_index(part_order)

    dump_doc("After resize")

    return True