Exemplo n.º 1
0
 def get_disks(disks, pools):
     '''
     Call into target discovery and get disk data. The disks found are
     added to the list passed in by the 'disks' argument
     
     '''
     try:
         td_disks = tgt.discover_target_data()
         for disk in td_disks:
             disks.append(DiskInfo(tgt_disk=disk))
         pools.extend(get_zpool_list())
     # If an exception occurs, regardless of type, log it, add it as the
     # first item in the disk list, and consume it (an uncaught Exception
     # in this threaded code would distort the display).
     # During the call to _show, if an exception occurred, the program
     # aborts gracefully
     # pylint: disable-msg=W0703
     except BaseException, err:
         logging.exception(traceback.format_exc())
         disks.insert(0, err)
Exemplo n.º 2
0
 def get_disks(disks, pools):
     '''
     Call into target discovery and get disk data. The disks found are
     added to the list passed in by the 'disks' argument
     
     '''
     try:
         td_disks = tgt.discover_target_data()
         for disk in td_disks:
             disks.append(DiskInfo(tgt_disk=disk))
         pools.extend(get_zpool_list())
     # If an exception occurs, regardless of type, log it, add it as the
     # first item in the disk list, and consume it (an uncaught Exception
     # in this threaded code would distort the display).
     # During the call to _show, if an exception occurred, the program
     # aborts gracefully
     # pylint: disable-msg=W0703
     except BaseException, err:
         logging.exception(traceback.format_exc())
         disks.insert(0, err)
Exemplo n.º 3
0
    def _show(self):
        '''Create a list of pools to choose from, ask user to select BE
        name and if we should overwrite pool's boot configuration
        
        '''
        if not self.install_profile.install_to_pool:
            raise SkipException

        if len(self.existing_pools) == 0:
            self.existing_pools.extend(get_zpool_list())
        self.num_targets = 0

        if len(self.existing_pools) == 0:
            self.center_win.add_paragraph(ZpoolScreen.NO_POOLS,
                                          1,
                                          1,
                                          max_x=(self.win_size_x - 1))
            return

        for pool in self.existing_pools:
            free_gb = get_zpool_free_size(pool) / 1024 / 1024 / 1024
            if (get_zpool_free_size(pool) / 1024 / 1024 / 1024 >
                    self.minimum_size):
                self.num_targets += 1
            else:
                logging.info("Skipping pool %s: need %d GB, free %d GB" %
                             (pool, self.minimum_size, free_gb))

        if self.num_targets == 0:
            self.center_win.add_paragraph(ZpoolScreen.NO_TARGETS,
                                          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(ZpoolScreen.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.pool_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.pool_header_text))

        y_loc += 1
        pool_win_area = WindowArea(4,
                                   textwidth(self.pool_header_text) + 2, y_loc,
                                   0)
        pool_win_area.scrollable_lines = len(self.existing_pools) + 1
        self.pool_win = ScrollWindow(pool_win_area, window=self.center_win)

        pool_item_area = WindowArea(1, pool_win_area.columns - 2, 0, 1)
        pool_index = 0
        len_name = ZpoolScreen.POOL_HEADERS[0][0] - 1
        len_size = ZpoolScreen.POOL_HEADERS[2][0] - 1
        for pool in self.existing_pools:
            pool_text_fields = []
            name_field = pool[:len_name]
            name_field = ljust_columns(name_field, len_name)
            pool_text_fields.append(name_field)
            pool_size = get_zpool_free_size(pool) / 1024 / 1024 / 1024
            size_field = "%*.1f" % (len_size, pool_size)
            pool_text_fields.append(size_field)
            selectable = True
            if pool_size < self.minimum_size:
                note_field = self.too_small_text
                selectable = False
            else:
                note_field = ""
            pool_text_fields.append(note_field)
            pool_text = " ".join(pool_text_fields)
            pool_item_area.y_loc = pool_index
            pool_list_item = ListItem(pool_item_area,
                                      window=self.pool_win,
                                      text=pool_text,
                                      add_obj=selectable)
            pool_list_item.on_make_active = on_activate
            pool_list_item.on_make_active_kwargs["pool_select"] = self

            pool_index += 1
        self.pool_win.no_ut_refresh()

        y_loc += 7
        self.list_area.y_loc = y_loc
        y_loc += 2
        self.error_area.y_loc = y_loc
        self.be_name_err = ErrorWindow(self.error_area, window=self.center_win)
        self.be_name_list = ListItem(self.list_area,
                                     window=self.center_win,
                                     text=ZpoolScreen.BE_LABEL)
        self.be_name_edit = EditField(self.edit_area,
                                      window=self.be_name_list,
                                      validate=be_name_valid,
                                      error_win=self.be_name_err,
                                      text=self.install_profile.be_name)

        y_loc += 2
        boot_configuration_width = textwidth(
            ZpoolScreen.OVERWRITE_BOOT_CONFIGURATION_LABEL) + 5
        cols = int((self.win_size_x - boot_configuration_width) / 2)
        boot_configuration_area = WindowArea(1, boot_configuration_width,
                                             y_loc, cols)

        self.boot_configuration_item = MultiListItem(
            boot_configuration_area,
            window=self.center_win,
            text=ZpoolScreen.OVERWRITE_BOOT_CONFIGURATION_LABEL,
            used=self.install_profile.overwrite_boot_configuration)

        self.boot_configuration_item.on_select = on_select_obc
        self.boot_configuration_item.on_select_kwargs["pool_select"] = self

        self.main_win.do_update()
        self.center_win.activate_object(self.pool_win)
        self.pool_win.activate_object(self.selected_pool)
        # Set the flag so that the pool is not copied by on_change_screen,
        # unless on_activate gets called as a result of the user changing
        # the selected pool.
        self.do_copy = False