Exemplo n.º 1
0
    def _show(self):
        '''Create a list of disks to choose from and create the window
        for displaying the partition/slice information from the selected
        disk
        '''

        self.wait_for_disks()
        self.wait_for_iscsi_disk()

        discovered_target = self.doc.persistent.get_first_child( \
            name=Target.DISCOVERED)

        LOGGER.debug(discovered_target)
        if discovered_target is None:
            self.center_win.add_paragraph(DiskScreen.NO_DISKS,
                                          1,
                                          1,
                                          max_x=(self.win_size_x - 1))
            return

        self.disks = discovered_target.get_children(class_type=Disk)
        if not self.disks:
            self.center_win.add_paragraph(DiskScreen.NO_TARGETS,
                                          1,
                                          1,
                                          max_x=(self.win_size_x - 1))
            return

        if self._image_size is None:
            try:
                self._image_size = Size(str(get_image_size(LOGGER)) + \
                    Size.mb_units)
                LOGGER.debug("Image_size: %s", self._image_size)
            except:
                # Unable to get the image size for some reason, allow
                # the target controller to use it's default size.
                LOGGER.debug("Unable to get image size")
                self._image_size = FALLBACK_IMAGE_SIZE

        # initialize the target controller so the min/max size for the
        # installation can be calculated.  Explicitly do not want to select an
        # initial disk at this time in case none of the disks discovered is
        # usable.  The target controller initialization needs to be done
        # everytime we show the disk selection screen so the desired target
        # node in the DOC can be re-populated with information from target
        # discovery.
        self.tc.initialize(image_size=self._image_size, no_initial_disk=True)

        # Go through all the disks found and find ones that have enough space
        # for installation.  At the same time, see if any existing disk is the
        # boot disk.  If a boot disk is found, move it to the front of the list
        num_usable_disks = 0
        boot_disk = None
        for disk in self.disks:
            LOGGER.debug("size: %s, min: %s" % \
                         (disk.disk_prop.dev_size, self.minimum_size))
            if disk.disk_prop.dev_size >= self.minimum_size:
                if disk.is_boot_disk():
                    boot_disk = disk
                num_usable_disks += 1

        if boot_disk is not None:
            self.disks.remove(boot_disk)
            self.disks.insert(0, boot_disk)

        if num_usable_disks == 0:
            self.center_win.add_paragraph(DiskScreen.NO_DISKS,
                                          1,
                                          1,
                                          max_x=(self.win_size_x - 1))
            return

        self.main_win.reset_actions()
        self.main_win.show_actions()

        y_loc = 1
        self.center_win.add_text(DiskScreen.PARAGRAPH, y_loc, 1)

        y_loc += 1
        self.center_win.add_text(self.size_line, y_loc, 1)

        y_loc += 2
        self.center_win.add_text(self.disk_header_text, y_loc, 1)

        y_loc += 1
        self.center_win.window.hline(y_loc, self.center_win.border_size[1] + 1,
                                     curses.ACS_HLINE,
                                     textwidth(self.disk_header_text))

        y_loc += 1
        disk_win_area = WindowArea(4,
                                   textwidth(self.disk_header_text) + 2, y_loc,
                                   0)
        disk_win_area.scrollable_lines = len(self.disks) + 1
        self.disk_win = ScrollWindow(disk_win_area, window=self.center_win)

        disk_item_area = WindowArea(1, disk_win_area.columns - 2, 0, 1)
        disk_index = 0
        len_type = DiskScreen.DISK_HEADERS[0][0] - 1
        len_size = DiskScreen.DISK_HEADERS[1][0] - 1
        len_boot = DiskScreen.DISK_HEADERS[2][0] - 1
        len_dev = DiskScreen.DISK_HEADERS[3][0] - 1
        len_notes = DiskScreen.DISK_HEADERS[4][0] - 1
        for disk in self.disks:
            disk_text_fields = []
            dev_type = disk.disk_prop.dev_type
            if dev_type is not None:
                type_field = dev_type[:len_type]
                type_field = ljust_columns(type_field, len_type)
            else:
                type_field = " " * len_type
            disk_text_fields.append(type_field)
            disk_size = disk.disk_prop.dev_size.get(Size.gb_units)
            size_field = locale.format("%*.1f", (len_size, disk_size))
            disk_text_fields.append(size_field)
            if disk.is_boot_disk():
                bootable_field = "+".center(len_boot)
            else:
                bootable_field = " " * (len_boot)
            disk_text_fields.append(bootable_field)

            #
            # Information will be displayed in the device column with
            # the following priority:
            #
            # First priority is to display receptacle information,
            # if available.  If receptacle information is displayed,
            # ctd name will not be displayed.
            #
            # If receptacle information is not available, the ctd name
            # will be displayed.
            #
            # Both items above can take as much as the 44 character wide
            # column as needed.
            #
            # If the receptacle/ctd name is less than 30 characters,
            # manufacturer information will be displayed in the left
            # over space.  There won't be a column heading for the
            # manufacturer information.
            #

            device = disk.receptacle or disk.ctd
            added_device_field = False
            # is there enough room to display the manufacturer?
            if (len_dev - len(device)) >= DiskScreen.VENDOR_LEN:
                vendor = disk.disk_prop.dev_vendor
                if vendor is not None:
                    dev_display_len = len_dev - DiskScreen.VENDOR_LEN
                    device_field = ljust_columns(device, dev_display_len)
                    disk_text_fields.append(device_field)
                    vendor_field = vendor[:DiskScreen.VENDOR_LEN - 1]
                    vendor_field = ljust_columns(vendor_field,
                                                 DiskScreen.VENDOR_LEN - 1)
                    disk_text_fields.append(vendor_field)
                    added_device_field = True

            if not added_device_field:
                device_field = device[:len_dev]
                device_field = ljust_columns(device_field, len_dev)
                disk_text_fields.append(device_field)

            # display "<" or ">" if the disk is too big or too small
            selectable = True
            if disk.disk_prop.dev_size < self.minimum_size:
                selectable = False
                notes_field = DiskScreen.TOO_SMALL.center(len_notes)
                disk_text_fields.append(notes_field)
            elif disk.disk_prop.dev_size > Size(MAX_VTOC):
                notes_field = DiskScreen.TOO_BIG.center(len_notes)
                disk_text_fields.append(notes_field)

            # check the blocksize of the disk.  If it's not 512 bytes and we
            # have an EFI firmware on x86, make the disk unselectable by the
            # user.  See PSARC 2008/769
            elif platform.processor() == "i386" and \
                 disk.geometry.blocksize != 512:
                firmware = SystemFirmware.get()
                if firmware.fw_name == "uefi64":
                    selectable = False
                    notes_field = DiskScreen.INVALID_DISK.center(len_notes)
                    disk_text_fields.append(notes_field)
                    LOGGER.debug(
                        "marking disk %s unselectable as its "
                        "blocksize is not 512 bytes on an UEFI "
                        "firmware x86 system.", disk.ctd)

            disk_text = " ".join(disk_text_fields)

            disk_item_area.y_loc = disk_index
            disk_list_item = ListItem(disk_item_area,
                                      window=self.disk_win,
                                      text=disk_text,
                                      add_obj=selectable)
            disk_list_item.on_make_active = on_activate
            disk_list_item.on_make_active_kwargs["disk"] = disk
            disk_list_item.on_make_active_kwargs["disk_select"] = self
            disk_index += 1

        self.disk_win.no_ut_refresh()

        y_loc += 7
        disk_detail_area = WindowArea(6, 70, y_loc, 1)

        self.disk_detail = DiskWindow(disk_detail_area,
                                      self.disks[0],
                                      target_controller=self.tc,
                                      window=self.center_win)

        self.main_win.do_update()
        self.center_win.activate_object(self.disk_win)
        self.disk_win.activate_object(self.selected_disk_index, jump=True)
    def _show(self):
        '''Create a list of disks to choose from and create the window
        for displaying the partition/slice information from the selected
        disk
        
        '''

        self.wait_for_disks()

        discovered_target = self.doc.persistent.get_first_child( \
            name=Target.DISCOVERED)

        LOGGER.debug(discovered_target)
        if discovered_target is None:
            self.center_win.add_paragraph(DiskScreen.NO_DISKS,
                                          1,
                                          1,
                                          max_x=(self.win_size_x - 1))
            return

        self.disks = discovered_target.get_children(class_type=Disk)
        if not self.disks:
            self.center_win.add_paragraph(DiskScreen.NO_TARGETS,
                                          1,
                                          1,
                                          max_x=(self.win_size_x - 1))
            return

        if self._image_size is None:
            try:
                self._image_size = Size(str(get_image_size(LOGGER)) + \
                    Size.mb_units)
                LOGGER.debug("Image_size: %s", self._image_size)
            except:
                # Unable to get the image size for some reason, allow
                # the target controller to use it's default size.
                LOGGER.debug("Unable to get image size")
                self._image_size = FALLBACK_IMAGE_SIZE

        # initialize the target controller so the min/max size for
        # the installation can be calculated.  Explicitly do not
        # want to select an initial disk at this time in case
        # none of the disks discovered is usable.  The target controller
        # initialization needs to be done everytime we show the disk selection
        # screen so the desired target node in the DOC can be re-populated
        # with information from target discovery.
        self.tc.initialize(image_size=self._image_size, no_initial_disk=True)

        # Go through all the disks found and find ones that have
        # enough space for installation.  At the same time, see if any
        # existing disk is the boot disk.  If a boot disk is found, move
        # it to the front of the list
        num_usable_disks = 0
        boot_disk = None
        for disk in self.disks:
            LOGGER.debug("size: %s, min: %s" % \
                         (disk.disk_prop.dev_size, self.minimum_size))
            if disk.disk_prop.dev_size >= self.minimum_size:
                if disk.is_boot_disk():
                    boot_disk = disk
                num_usable_disks += 1
        if boot_disk is not None:
            self.disks.remove(boot_disk)
            self.disks.insert(0, boot_disk)

        if num_usable_disks == 0:
            self.center_win.add_paragraph(DiskScreen.NO_DISKS,
                                          1,
                                          1,
                                          max_x=(self.win_size_x - 1))
            return

        self.main_win.reset_actions()
        self.main_win.show_actions()

        y_loc = 1
        self.center_win.add_text(DiskScreen.PARAGRAPH, y_loc, 1)

        y_loc += 1
        self.center_win.add_text(self.size_line, y_loc, 1)

        y_loc += 2
        self.center_win.add_text(self.disk_header_text, y_loc, 1)

        y_loc += 1
        self.center_win.window.hline(y_loc, self.center_win.border_size[1] + 1,
                                     curses.ACS_HLINE,
                                     textwidth(self.disk_header_text))

        y_loc += 1
        disk_win_area = WindowArea(4,
                                   textwidth(self.disk_header_text) + 2, y_loc,
                                   0)
        disk_win_area.scrollable_lines = len(self.disks) + 1
        self.disk_win = ScrollWindow(disk_win_area, window=self.center_win)

        disk_item_area = WindowArea(1, disk_win_area.columns - 2, 0, 1)
        disk_index = 0
        len_type = DiskScreen.DISK_HEADERS[0][0] - 1
        len_size = DiskScreen.DISK_HEADERS[1][0] - 1
        len_boot = DiskScreen.DISK_HEADERS[2][0] - 1
        len_dev = DiskScreen.DISK_HEADERS[3][0] - 1
        len_mftr = DiskScreen.DISK_HEADERS[4][0] - 1
        for disk in self.disks:
            disk_text_fields = []
            if disk.disk_prop is None or disk.disk_prop.dev_type is None:
                continue
            type_field = disk.disk_prop.dev_type[:len_type]
            type_field = ljust_columns(type_field, len_type)
            disk_text_fields.append(type_field)
            disk_size = disk.disk_prop.dev_size.get(Size.gb_units)
            size_field = locale.format("%*.1f", (len_size, disk_size))
            disk_text_fields.append(size_field)
            if disk.is_boot_disk():
                bootable_field = "+".center(len_boot)
            else:
                bootable_field = " " * (len_boot)
            disk_text_fields.append(bootable_field)
            device_field = disk.ctd[:len_dev]
            device_field = ljust_columns(device_field, len_dev)
            disk_text_fields.append(device_field)
            vendor = disk.disk_prop.dev_vendor
            if vendor is not None:
                mftr_field = vendor[:len_mftr]
                mftr_field = ljust_columns(mftr_field, len_mftr)
            else:
                mftr_field = " " * len_mftr
            disk_text_fields.append(mftr_field)
            selectable = True
            if disk.disk_prop.dev_size < self.minimum_size:
                note_field = self.too_small_text
                selectable = False
            elif disk_size > Size(MAX_VTOC).get(Size.gb_units):
                note_field = self.too_big_warn
            else:
                note_field = ""
            disk_text_fields.append(note_field)
            disk_text = " ".join(disk_text_fields)
            disk_item_area.y_loc = disk_index
            disk_list_item = ListItem(disk_item_area,
                                      window=self.disk_win,
                                      text=disk_text,
                                      add_obj=selectable)
            disk_list_item.on_make_active = on_activate
            disk_list_item.on_make_active_kwargs["disk"] = disk
            disk_list_item.on_make_active_kwargs["disk_select"] = self
            disk_index += 1

        self.disk_win.no_ut_refresh()

        y_loc += 7
        disk_detail_area = WindowArea(6, 70, y_loc, 1)

        self.disk_detail = DiskWindow(disk_detail_area,
                                      self.disks[0],
                                      target_controller=self.tc,
                                      window=self.center_win)

        self.main_win.do_update()
        self.center_win.activate_object(self.disk_win)
        self.disk_win.activate_object(self.selected_disk_index)
    def _show(self):
        '''Create a list of disks to choose from and create the window
        for displaying the partition/slice information from the selected
        disk
        
        '''

        self.wait_for_disks()

        discovered_target = self.doc.persistent.get_first_child( \
            name=Target.DISCOVERED)

        LOGGER.debug(discovered_target)
        if discovered_target is None:
            self.center_win.add_paragraph(DiskScreen.NO_DISKS, 1, 1,
                                          max_x=(self.win_size_x - 1))
            return

        self.disks = discovered_target.get_children(class_type=Disk)
        if not self.disks:
            self.center_win.add_paragraph(DiskScreen.NO_TARGETS, 1, 1,
                                          max_x=(self.win_size_x - 1))
            return

        if self._image_size is None:
            try:
                self._image_size = Size(str(get_image_size(LOGGER)) + \
                    Size.mb_units)
                LOGGER.debug("Image_size: %s", self._image_size)
            except:
                # Unable to get the image size for some reason, allow
                # the target controller to use it's default size.
                LOGGER.debug("Unable to get image size") 
                self._image_size = FALLBACK_IMAGE_SIZE

        # initialize the target controller so the min/max size for
        # the installation can be calculated.  Explicitly do not
        # want to select an initial disk at this time in case
        # none of the disks discovered is usable.  The target controller
        # initialization needs to be done everytime we show the disk selection
        # screen so the desired target node in the DOC can be re-populated
        # with information from target discovery.
        self.tc.initialize(image_size=self._image_size, no_initial_disk=True)
         
        # Go through all the disks found and find ones that have
        # enough space for installation.  At the same time, see if any
        # existing disk is the boot disk.  If a boot disk is found, move
        # it to the front of the list
        num_usable_disks = 0
        boot_disk = None
        for disk in self.disks:
            LOGGER.debug("size: %s, min: %s" % \
                         (disk.disk_prop.dev_size, self.minimum_size))
            if disk.disk_prop.dev_size >= self.minimum_size:
                if disk.is_boot_disk():
                    boot_disk = disk
                num_usable_disks += 1
        if boot_disk is not None:
            self.disks.remove(boot_disk)
            self.disks.insert(0, boot_disk)

        if num_usable_disks == 0:
            self.center_win.add_paragraph(DiskScreen.NO_DISKS, 1, 1,
                                          max_x=(self.win_size_x - 1))
            return

        self.main_win.reset_actions()
        self.main_win.show_actions()
        
        y_loc = 1
        self.center_win.add_text(DiskScreen.PARAGRAPH, y_loc, 1)
        
        y_loc += 1
        self.center_win.add_text(self.size_line, y_loc, 1)
        
        y_loc += 2
        self.center_win.add_text(self.disk_header_text, y_loc, 1)
        
        y_loc += 1
        self.center_win.window.hline(y_loc, self.center_win.border_size[1] + 1,
                                     curses.ACS_HLINE,
                                     textwidth(self.disk_header_text))
        
        y_loc += 1
        disk_win_area = WindowArea(4, textwidth(self.disk_header_text) + 2,
                                   y_loc, 0)
        disk_win_area.scrollable_lines = len(self.disks) + 1
        self.disk_win = ScrollWindow(disk_win_area,
                                     window=self.center_win)
        
        disk_item_area = WindowArea(1, disk_win_area.columns - 2, 0, 1)
        disk_index = 0
        len_type = DiskScreen.DISK_HEADERS[0][0] - 1
        len_size = DiskScreen.DISK_HEADERS[1][0] - 1
        len_boot = DiskScreen.DISK_HEADERS[2][0] - 1
        len_dev = DiskScreen.DISK_HEADERS[3][0] - 1
        len_mftr = DiskScreen.DISK_HEADERS[4][0] - 1
        for disk in self.disks:
            disk_text_fields = []
            if disk.disk_prop is None or disk.disk_prop.dev_type is None:
                continue
            type_field = disk.disk_prop.dev_type[:len_type]
            type_field = ljust_columns(type_field, len_type)
            disk_text_fields.append(type_field)
            disk_size = disk.disk_prop.dev_size.get(Size.gb_units)
            size_field = locale.format("%*.1f", (len_size, disk_size))
            disk_text_fields.append(size_field)
            if disk.is_boot_disk():
                bootable_field = "+".center(len_boot)
            else:
                bootable_field = " " * (len_boot)
            disk_text_fields.append(bootable_field)
            device_field = disk.ctd[:len_dev]
            device_field = ljust_columns(device_field, len_dev)
            disk_text_fields.append(device_field)
            vendor = disk.disk_prop.dev_vendor
            if vendor is not None:
                mftr_field = vendor[:len_mftr]
                mftr_field = ljust_columns(mftr_field, len_mftr)
            else:
                mftr_field = " " * len_mftr
            disk_text_fields.append(mftr_field)
            selectable = True
            if disk.disk_prop.dev_size < self.minimum_size:
                note_field = self.too_small_text
                selectable = False
            elif disk_size > Size(MAX_VTOC).get(Size.gb_units):
                note_field = self.too_big_warn
            else:
                note_field = ""
            disk_text_fields.append(note_field)
            disk_text = " ".join(disk_text_fields)
            disk_item_area.y_loc = disk_index
            disk_list_item = ListItem(disk_item_area, window=self.disk_win,
                                      text=disk_text, add_obj=selectable)
            disk_list_item.on_make_active = on_activate
            disk_list_item.on_make_active_kwargs["disk"] = disk
            disk_list_item.on_make_active_kwargs["disk_select"] = self
            disk_index += 1

        self.disk_win.no_ut_refresh()
        
        y_loc += 7
        disk_detail_area = WindowArea(6, 70, y_loc, 1)

        self.disk_detail = DiskWindow(disk_detail_area, self.disks[0],
                                      target_controller=self.tc,
                                      window=self.center_win)
        
        self.main_win.do_update()
        self.center_win.activate_object(self.disk_win)
        self.disk_win.activate_object(self.selected_disk_index)