def _show(self): """ create the screen for the user to select a discovery method """ y_loc = 1 y_loc += self.center_win.add_paragraph(DiscoverySelection.PARAGRAPH, y_loc) y_loc += 1 item_area = WindowArea(1, DiscoverySelection.ITEM_MAX_WIDTH, y_loc, 1) self.local = ListItem(item_area, window=self.center_win, text=DiscoverySelection.LOCAL_TEXT) self.local.item_key = "local" self.center_win.add_text(DiscoverySelection.LOCAL_DETAIL, y_loc, DiscoverySelection.ITEM_DESC_OFFSET, self.win_size_x - 3) y_loc += 2 item_area.y_loc = y_loc self.iscsi = ListItem(item_area, window=self.center_win, text=DiscoverySelection.ISCSI_TEXT) self.iscsi.item_key = "iscsi" self.center_win.add_text(DiscoverySelection.ISCSI_DETAIL, y_loc, DiscoverySelection.ITEM_DESC_OFFSET, self.win_size_x - 3) self.main_win.do_update() self.center_win.activate_object(self.current_selection)
def _show(self): # This will be used (and re-used) later. It defines a subwindow's # location at 1, 1, with width 20 and height 1 win_area = WindowArea(y_loc=1, x_loc=1, lines=1, columns=20) # Creating an empty editable field is just as simple as creating # a list item: define a location, and a parent window. field_one = EditField(win_area, window=self.center_win) # Side trick - a WindowArea can be reused. In this case, the y-coord # is updated, and then win_area is used for the next EditField. win_area.y_loc = 2 # Setting default text for a field is also simple: field_two = EditField(win_area, window=self.center_win, text="default") # For the Text Installer and SCI tool, however, an extra step must # be taken. To help with labeling and highlighting, each EditField # should be wrapped in a ListItem, like so: win_area.y_loc = 3 list_three = ListItem(win_area, window=self.center_win, text="3: ") edit_area = WindowArea(y_loc=0, x_loc=5, lines=1, columns=10) field_three = EditField(edit_area, window=list_three) # Note that the 'window' parameter for field_three is 'list_three', # and that edit_area is a position relative to list_three. win_area.y_loc = 4 list_four = ListItem(win_area, window=self.center_win, text="4: ") # Since WindowAreas are relative to their parent, edit_area can # be reused with no modifications field_four = EditField(edit_area, window=list_four, text="default") # As with lists, edit fields must be explicitly given focus. Note that # focus can be given by index, or by reference. self.center_win.activate_object(field_two)
def _show(self): # Set up the three list items... win_area = WindowArea(lines=1, columns=15, y_loc=1, x_loc=1) self.hello_item = ListItem(win_area, window=self.center_win, text="Hello World") win_area.y_loc += 1 self.list_item = ListItem(win_area, window=self.center_win, text="Lists") win_area.y_loc += 1 self.edit_item = ListItem(win_area, window=self.center_win, text="Edit Fields") self.center_win.activate_object()
def _show(self): super(NSNISAuto, self)._show() if self.nameservice.nameservice != 'NIS': raise SkipException y_loc = self._paint_opening() y_loc += self.center_win.add_paragraph(self.intro2, y_loc) y_loc += 1 ynlist = [_('Find one'), _('Specify one')] area = WindowArea(x_loc=0, y_loc=y_loc, scrollable_lines=len(ynlist) + 1) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x self.scroll_region = ScrollWindow(area, window=self.center_win) y_loc += 1 # blank line # add the entries to the screen for idx, yon in enumerate(ynlist): y_loc += 1 win_area = WindowArea(lines=1, columns=textwidth(yon) + 1, y_loc=idx, x_loc=INDENT) ListItem(win_area, window=self.scroll_region, text=yon, data_obj=yon) self.main_win.do_update() self.center_win.activate_object(self.scroll_region) self.scroll_region.activate_object_force(self.cur_nisnschoice_idx, force_to_top=True) y_loc += 1 # blank line self.center_win.add_paragraph(self.intro3, y_loc)
def _show(self): text = "List Item %s" for num in xrange(1, 10): # When adding subwindows to a screen's center_win, the location # of the subwindow needs to be specified. The location should # be relative to the parent window. y_loc = num x_loc = 1 height = 1 width = 15 win_area = WindowArea(height, width, y_loc, x_loc) # To create a list of selectable items, use ListItems. ListItem # is a thin wrapper around InnerWindow, which supports adding # text to itself in one step. The 'window' parameter specifies # the parent window item_text = text % num list_item = ListItem(win_area, window=self.center_win, text=item_text, centered=True) # After the above loop completes, 'center_win' now has 9 ListItem # 'subwindows.' By default, none are marked as 'active' (i.e., none # have focus). The activate_object() function of InnerWindow fixes # that. (With no parameter, the first ListItem is activated) self.center_win.activate_object()
def _show(self): # The _show method will not only create the four desired EditFields, # but restore saved state as well. win_area = WindowArea(lines=1, columns=40, y_loc=1, x_loc=1) edit_area = WindowArea(lines=1, columns=20, y_loc=0, x_loc=10) for field_num in range(4): win_area.y_loc += 1 field_label = "%s: " % field_num list_item = ListItem(win_area, window=self.center_win, text=field_label) # Grab the saved text for the field (assume it's been saved for # now; *how* to go about saving it is below) field_text = self.saved_text[field_num] # And then set that as the text for the field edit_field = EditField(edit_area, window=list_item, text=field_text) # Save a reference to the field so other methods can access # their data: self.fields[field_num] = edit_field # Since this series of fields also acts as a selectable list, # the current selection can be restored as well by changing which # object is active: self.center_win.activate_object(self.current_selection)
def _show(self): ''' called upon display of a screen ''' super(NSDNSChooser, self)._show() y_loc = self._paint_opening() LOGGER.debug(self.nameservice) # allow the user to choose DNS or not ynlist = [_('Configure DNS'), _('Do not configure DNS')] area = WindowArea(x_loc=0, y_loc=y_loc, scrollable_lines=len(ynlist) + 1) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x self.scroll_region_dns = ScrollWindow(area, window=self.center_win) # add the entries to the screen for idx, yon in enumerate(ynlist): win_area = WindowArea(1, textwidth(yon) + 1, idx, INDENT) ListItem(win_area, window=self.scroll_region_dns, text=yon, data_obj=yon) # finalize positioning self.main_win.do_update() self.center_win.activate_object(self.scroll_region_dns) self.scroll_region_dns.activate_object_force(self.cur_dnschoice_idx, force_to_top=True)
def _show(self): ''' called upon display of a screen ''' super(NSAltChooser, self)._show() y_loc = self._paint_opening() LOGGER.debug(self.nameservice) # allow the user to select an alternate name service area = WindowArea(x_loc=0, y_loc=y_loc, scrollable_lines=len(NameService.USER_CHOICE_LIST) + 1) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x self.scroll_region = ScrollWindow(area, window=self.center_win) # add the entries to the screen menu_item_max_width = self.win_size_x - NameService.SCROLL_SIZE for idx, nsn in enumerate(NameService.USER_CHOICE_LIST): y_loc += 1 hilite = min(menu_item_max_width, textwidth(nsn) + 1) win_area = WindowArea(1, hilite, idx, INDENT) ListItem(win_area, window=self.scroll_region, text=nsn, data_obj=nsn) # finalize positioning self.main_win.do_update() self.center_win.activate_object(self.scroll_region) self.scroll_region.activate_object_force(self.cur_nschoice_idx, force_to_top=True)
def create_list_item(self, next_part, win, list_area): '''Add an entry for next_part (a Partition or Slice) to the DiskWindow ''' list_item = ListItem(list_area, window=win, data_obj=next_part) list_item.key_dict.update(DiskWindow.ADD_KEYS) edit_field = EditField(self.edit_area, window=list_item, numeric_pad=" ", validate=decimal_valid, on_exit=on_exit_edit, error_win=self.error_win, add_obj=False, data_obj=next_part) edit_field.right_justify = True edit_field.validate_kwargs["disk_win"] = self edit_field.on_exit_kwargs["disk_win"] = self edit_field.key_dict.update(DiskWindow.ADD_KEYS) self.update_part(part_field=list_item) return list_item
def display_help_topics(self): '''Display the help topics screen.''' self.main_win.set_header_text(self.help_header) y_loc = 1 y_loc += self.center_win.add_paragraph(self.intro, y_loc, 1, max_x=(self.win_size_x - 1)) y_loc += 1 area = WindowArea(scrollable_lines=(len(self.help_info) + 1), y_loc=y_loc, x_loc=0) terminalui.LOGGER.debug("lines=%s", len(self.help_dict)) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x self.scroll_region = ScrollWindow(area, window=self.center_win) # add the entries to the screen terminalui.LOGGER.debug("range=%s", len(self.help_info)) for idx, info in enumerate(self.help_info): # create ListItem for each help topic topic_format = info[1] topic_title = self.help_dict[info[0]][1] help_topic = topic_format % topic_title hilite = min(self.win_size_x, textwidth(help_topic) + 1) list_item = ListItem(WindowArea(1, hilite, idx, 0), window=self.scroll_region, text=help_topic) terminalui.LOGGER.debug("self.screen_last=%s", self.screen_last) if self.screen_last == info[0]: terminalui.LOGGER.debug("Set cur_help_idx = %s", idx) self.cur_help_idx = idx terminalui.LOGGER.debug("beg_y=%d, beg_x=%d", *list_item.window.getbegyx()) self.center_win.activate_object(self.scroll_region) self.scroll_region.activate_object(self.cur_help_idx)
def _show(self): super(NSLDAPProxyBindChooser, self)._show() # check dictionary of screens associated with name service selections if self.nameservice.nameservice != 'LDAP': raise SkipException y_loc = self._paint_opening() ynlist = [_('No'), _('Yes')] area = WindowArea(x_loc=0, y_loc=y_loc, scrollable_lines=len(ynlist) + 1) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x self.scroll_region = ScrollWindow(area, window=self.center_win) # add the entries to the screen for idx, yon in enumerate(ynlist): win_area = WindowArea(1, textwidth(yon) + 1, idx, INDENT) ListItem(win_area, window=self.scroll_region, text=yon, data_obj=yon) self.main_win.do_update() self.center_win.activate_object(self.scroll_region) self.scroll_region.activate_object_force(self.cur_pbchoice_idx, force_to_top=True)
def make_field(self, label, description, y_loc, max_y, max_x, description_start, default_val, is_ip=True, selectable=True): '''Create a list item with 'label', add an editable field with 'default_val', and add additional 'description' text following it ''' self.list_area.y_loc = y_loc list_item = ListItem(self.list_area, text=label, data_obj=label, window=self.center_win, add_obj=selectable) if is_ip: validate = incremental_validate_ip else: validate = None edit_field = EditField(self.edit_area, window=list_item, text=default_val, validate=validate, error_win=self.main_win.error_line, data_obj=label.rstrip(":")) self.center_win.add_paragraph(description, y_loc, description_start, max_y=(y_loc + max_y), max_x=max_x) return edit_field
def pop_up(self, header, question, left_btn_txt, right_btn_txt, color=None): '''Suspend the current screen, setting the header to 'header', presenting the 'question,' and providing two 'buttons'. Returns True if the RIGHT button is selected, False if the LEFT is selected. The LEFT button is initially selected. ''' # Hide the cursor, storing its previous state (visibility) so # it can be restored when finished. Then, move the cursor # to the default position (in case this terminal type does not support # hiding the cursor entirely) try: old_cursor_state = curses.curs_set(0) except curses.error: old_cursor_state = 2 cursor_loc = curses.getsyx() curses.setsyx(self.cursor_pos[0], self.cursor_pos[1]) # Add the header, a border, and the question to the window self.popup_win.window.border() header_x = (self.popup_win.area.columns - textwidth(header)) / 2 self.popup_win.add_text(header, 0, header_x) y_loc = 2 y_loc += self.popup_win.add_paragraph(question, y_loc, 2) y_loc += 2 # Set the background color based on the parameter given, or choose # a default based on the theme. Set the highlight_color by flipping # the A_REVERSE bit of the color if color is None: color = self.popup_win.color self.popup_win.set_color(color) highlight_color = color ^ curses.A_REVERSE # Create two "buttons" of equal size by finding the larger of the # two, and centering them max_len = max(textwidth(left_btn_txt), textwidth(right_btn_txt)) left_btn_txt = " [ %s ]" % left_btn_txt.center(max_len) right_btn_txt = " [ %s ]" % right_btn_txt.center(max_len) button_len = textwidth(left_btn_txt) + 1 win_size = self.popup_win.window.getmaxyx() left_area = WindowArea(1, button_len, y_loc, (win_size[1] / 2) - (button_len + 2)) left_button = ListItem(left_area, window=self.popup_win, text=left_btn_txt, color=color, highlight_color=highlight_color) right_area = WindowArea(1, button_len, y_loc, win_size[1] / 2 + 2) right_button = ListItem(right_area, window=self.popup_win, text=right_btn_txt, color=color, highlight_color=highlight_color) # Highlight the left button, clear any errors on the screen, # and display the pop up self.popup_win.activate_object(left_button) self.popup_win.no_ut_refresh() self.error_line.clear_err() self.do_update() self._active_win = self.popup_win # Loop until the user selects an option. input_key = None while input_key != curses.KEY_ENTER: input_key = self.getch() input_key = self.popup_win.process(input_key) if input_key == curses.KEY_LEFT: self.popup_win.activate_object(left_button) elif input_key == curses.KEY_RIGHT: self.popup_win.activate_object(right_button) self.do_update() self._active_win = self.central_area user_selected = (self.popup_win.get_active_object() is right_button) # Clear the pop up and restore the previous screen, including the # cursor position and visibility self.popup_win.clear() self.central_area.redrawwin() curses.setsyx(cursor_loc[0], cursor_loc[1]) try: curses.curs_set(old_cursor_state) except curses.error: pass self.do_update() return user_selected
def _show(self): '''Display the user name, real name, and password fields''' sc_profile = solaris_install.sysconfig.profile.from_engine() # # Create UserInfo instances holding information about root and user # accounts. # if sc_profile.users is None: # # Assume root is a normal account. It will be changed to a role # if the user account is created. # root = UserInfo(login_name="root", is_role=False) # # Initialize attributes of user account which can't be configured # on screens. # user = UserInfo(gid=10, shell="/usr/bin/bash", roles="root", profiles="System Administrator", sudoers="ALL=(ALL) ALL") sc_profile.users = UserInfoContainer(root, user) self.root = sc_profile.users.root self.user = sc_profile.users.user LOGGER.debug("Root: %s", self.root) LOGGER.debug("User: %s", self.user) root_set = (self.root.passlen != 0) user_set = (self.user.passlen != 0) y_loc = 1 if self.show_user_account: intro_text = UserScreen.INTRO_SHOW_USER else: intro_text = UserScreen.INTRO_HIDE_USER self.center_win.add_paragraph(intro_text, y_loc, 1, y_loc + 2, self.win_size_x - 1) y_loc += 3 self.center_win.add_text(UserScreen.ROOT_TEXT, y_loc, 1, self.win_size_x - 1) y_loc += 2 self.error_area.y_loc = y_loc self.list_area.y_loc = y_loc self.root_pass_err = ErrorWindow(self.error_area, window=self.center_win) self.root_pass_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.ROOT_LABEL) self.root_pass_edit = PasswordField(self.edit_area, window=self.root_pass_list, error_win=self.root_pass_err, fill=root_set) y_loc += 1 self.error_area.y_loc = y_loc self.list_area.y_loc = y_loc self.root_confirm_err = ErrorWindow(self.error_area, window=self.center_win) self.root_confirm_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.CONFIRM_LABEL) self.root_confirm_edit = PasswordField(self.edit_area, window=self.root_confirm_list, fill=root_set, on_exit=pass_match, error_win=self.root_confirm_err) rc_edit_kwargs = {"linked_win": self.root_pass_edit} self.root_confirm_edit.on_exit_kwargs = rc_edit_kwargs # User account disabled, do not display related widgets. if not self.show_user_account: self.main_win.do_update() self.center_win.activate_object(self.root_pass_list) return y_loc += 2 self.center_win.add_text(UserScreen.USER_TEXT, y_loc, 1, self.win_size_x - 1) y_loc += 2 self.list_area.y_loc = y_loc self.error_area.y_loc = y_loc self.real_name_err = ErrorWindow(self.error_area, window=self.center_win) self.real_name_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.NAME_LABEL) self.real_name_edit = EditField(self.edit_area, window=self.real_name_list, error_win=self.real_name_err, text=self.user.real_name) y_loc += 1 self.list_area.y_loc = y_loc self.error_area.y_loc = y_loc self.username_err = ErrorWindow(self.error_area, window=self.center_win) self.username_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.USERNAME_LABEL) self.username_edit = EditField(self.username_edit_area, window=self.username_list, validate=username_valid, error_win=self.username_err, on_exit=login_valid, text=self.user.login_name) y_loc += 1 self.list_area.y_loc = y_loc self.error_area.y_loc = y_loc self.user_pass_err = ErrorWindow(self.error_area, window=self.center_win) self.user_pass_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.USER_PASS_LABEL) self.user_pass_edit = PasswordField(self.edit_area, window=self.user_pass_list, error_win=self.user_pass_err, fill=user_set) y_loc += 1 self.list_area.y_loc = y_loc self.error_area.y_loc = y_loc self.user_confirm_err = ErrorWindow(self.error_area, window=self.center_win) self.user_confirm_list = ListItem(self.list_area, window=self.center_win, text=UserScreen.CONFIRM_LABEL) self.user_confirm_edit = PasswordField(self.edit_area, window=self.user_confirm_list, on_exit=pass_match, error_win=self.user_confirm_err, fill=user_set) uc_edit_kwargs = {"linked_win": self.user_pass_edit} self.user_confirm_edit.on_exit_kwargs = uc_edit_kwargs self.main_win.do_update() self.center_win.activate_object(self.root_pass_list)
def _show(self): '''Create an EditField for entering hostname, and list items for each of the network types ''' sc_profile = solaris_install.sysconfig.profile.from_engine() if sc_profile.system is None: sc_profile.system = SystemInfo() self.sys_info = sc_profile.system if sc_profile.nic is None: sc_profile.nic = self.nic_info y_loc = 1 y_loc += self.center_win.add_paragraph(NetworkTypeScreen.PARAGRAPH, y_loc) y_loc += 1 self.center_win.add_text(NetworkTypeScreen.HOSTNAME_TEXT, y_loc) max_cols = self.win_size_x - self.hostfield_offset cols = min(max_cols, NetworkTypeScreen.HOSTNAME_SCREEN_LEN) scrollable_columns = SystemInfo.MAX_HOSTNAME_LEN + 1 hostname_area = WindowArea(1, cols, y_loc, self.hostfield_offset, scrollable_columns=scrollable_columns) self.hostname = EditField(hostname_area, window=self.center_win, text=self.sys_info.hostname, validate=hostname_is_valid, error_win=self.main_win.error_line) self.hostname.item_key = None # Display network configuration part of screen only if applicable. if self.configure_network: y_loc += 3 # If there are no configurable links, there is no point to let # user select type of network configuration. if not self.have_nic: # Inform user that no network interfaces were found # on the system. # If this is the case of non-global zone with all links # mandated from global zone, be more specific. if self.nic_info.type == NetworkInfo.FROMGZ: self.center_win.add_paragraph( NetworkTypeScreen.ALL_NICS_FROMGZ, y_loc, 1) else: self.center_win.add_paragraph( NetworkTypeScreen.NO_NICS_FOUND, y_loc, 1) self.main_win.do_update() activate = self.net_type_dict.get(self.nic_info.type, self.hostname) self.center_win.activate_object(activate) return y_loc += self.center_win.add_paragraph( NetworkTypeScreen.NET_TYPE_TEXT, y_loc) y_loc += 1 item_area = WindowArea(1, NetworkTypeScreen.ITEM_MAX_WIDTH, y_loc, NetworkTypeScreen.ITEM_OFFSET) self.automatic = ListItem(item_area, window=self.center_win, text=NetworkTypeScreen.AUTO_TEXT) self.automatic.item_key = NetworkInfo.AUTOMATIC self.net_type_dict[self.automatic.item_key] = self.automatic self.center_win.add_text(NetworkTypeScreen.AUTO_DETAIL, y_loc, NetworkTypeScreen.ITEM_DESC_OFFSET, self.menu_item_desc_max) y_loc += 2 item_area.y_loc = y_loc self.manual = ListItem(item_area, window=self.center_win, text=NetworkTypeScreen.MANUAL_TEXT) self.manual.item_key = NetworkInfo.MANUAL self.net_type_dict[self.manual.item_key] = self.manual self.center_win.add_text(NetworkTypeScreen.MANUAL_DETAIL, y_loc, NetworkTypeScreen.ITEM_DESC_OFFSET, self.menu_item_desc_max) y_loc += 2 item_area.y_loc = y_loc self.none_option = ListItem(item_area, window=self.center_win, text=NetworkTypeScreen.NONE_TEXT) self.none_option.item_key = NetworkInfo.NONE self.net_type_dict[self.none_option.item_key] = self.none_option self.center_win.add_text(NetworkTypeScreen.NONE_DETAIL, y_loc, NetworkTypeScreen.ITEM_DESC_OFFSET, self.menu_item_desc_max) self.main_win.do_update() activate = self.net_type_dict.get(self.nic_info.type, self.hostname) self.center_win.activate_object(activate)
def _show(self): # WindowArea boilerplate list_area = WindowArea(lines=1, columns=40, y_loc=1, x_loc=1) edit_area = WindowArea(lines=1, columns=20, y_loc=0, x_loc=15) # EditFields support per-character validation by passing in # a callback function as the "validate" keyword argument. The function # is called after each keypress with a single parameter, the EditField # in question (from which one can grab the current text). If the # current value is valid, the function should do nothing. If invalid, # a UIMessage exception should be raised. # For the sake of 'flow', the validation functions for this sample # will be defined inline; in general, they should be defined elsewhere # in the file. Finally, remember that, since these functions are # called after each keystroke, they need to be able to handle partially # correct values as well. For example, "2", "25", "255", "255.", # "255.2", "255.25", ..., "255.255.255.0" all would need to be accepted # by a netmask validation function. def digits_only(edit_field): text = edit_field.get_text() if text and not text.isdigit(): raise UIMessage("Only digits allowed!") list_area.y_loc = 1 self.char_list = ListItem(list_area, window=self.center_win, text="validate:") self.char_edit = EditField(edit_area, window=self.char_list, validate=digits_only, error_win=self.main_win.error_line) # The error_win parameter is required to make anything meaningful # display to the user; it should be a reference to an ErrorWindow # object in which to display the message. (self.main_win.error_line # is used here as filler; a more appropriate example follows) list_area.y_loc = 2 # There's nothing too special about creating an ErrorWindow; # it's much like a ListItem or EditField: error_area = WindowArea(lines=1, columns=30, y_loc=2, x_loc=40) self.char2_err = ErrorWindow(error_area, self.center_win) self.char2_list = ListItem(list_area, window=self.center_win, text="validate(2):") self.char2_edit = EditField(edit_area, window=self.char2_list, validate=digits_only, error_win=self.char2_err) # An EditField can also be checked for validity on loss of focus, # by passing a function to the "on_exit" argument # (though care must be taken to also check validity when changing # screens; screen changes don't trigger loss-of-focus checks in the # same way) # The following EditField illustrates such a thing. (An on_exit # function would be an appropriate place to ensure that a user # entered "255.255.255.0" for a netmask, and not just "255.") list_area.y_loc = 3 error_area.y_loc = 3 self.focus_err = ErrorWindow(error_area, self.center_win) self.focus_list = ListItem(list_area, window=self.center_win, text="on_exit:") self.focus_edit = EditField(edit_area, window=self.focus_list, on_exit=digits_only, error_win=self.focus_err) self.center_win.activate_object()
def _show(self): """ create the screen to collect user input """ # look in the DOC for an Iscsi object eng = InstallEngine.get_instance() iscsi_obj = eng.doc.volatile.get_children(name=ISCSI_LABEL, class_type=Iscsi) # If there's no iscsi object in the DOC, skip this screen if not iscsi_obj: raise SkipException else: self.iscsi_obj = iscsi_obj[0] LOGGER.debug("show Iscsi object: %s" % str(self.iscsi_obj)) y_loc = 1 self.center_win.add_paragraph(IscsiScreen.INTRO, start_y=y_loc) # look to see if DHCP is providing information if self.check_dhcp(): y_loc += 2 self.center_win.add_paragraph(IscsiScreen.FOUND_DHCP_LABEL, start_y=y_loc) # Target IP y_loc += 2 # Mark this field required self.center_win.window.addch(y_loc, 2, IscsiScreen.REQUIRED_MARK, self.center_win.color_theme.inactive) edit_start = textwidth(IscsiScreen.TARGET_IP_LABEL) + \ IscsiScreen.ITEM_OFFSET ip_area = WindowArea(y_loc=y_loc, x_loc=1, lines=1, columns=edit_start + IscsiScreen.MAX_IP_LEN + 1) self.target_ip_list = ListItem(ip_area, window=self.center_win, text=IscsiScreen.TARGET_IP_LABEL) self.target_ip_list.key_dict.update(self.add_keys) self.default_edit.x_loc = edit_start self.default_edit.columns = IscsiScreen.MAX_IP_LEN + 1 self.target_ip_edit = EditField(self.default_edit, window=self.target_ip_list, validate=incremental_validate_ip, error_win=self.main_win.error_line) self.target_ip_edit.key_dict.update(self.add_keys) if self.target_ip is not None: self.target_ip_edit.set_text(self.target_ip) # Target Port edit_start = ip_area.x_loc + \ textwidth(IscsiScreen.TARGET_PORT_LABEL) + \ IscsiScreen.ITEM_OFFSET port_area = WindowArea(y_loc=y_loc, x_loc=self.half_win_width + IscsiScreen.DEAD_ZONE, lines=1, columns=edit_start + IscsiScreen.MAX_PORT_LEN + 1) self.target_port_list = ListItem(port_area, window=self.center_win, text=IscsiScreen.TARGET_PORT_LABEL) self.target_port_list.key_dict.update(self.add_keys) self.right_edit.x_loc = edit_start self.right_edit.columns = IscsiScreen.MAX_PORT_LEN + 1 self.target_port_edit = EditField(self.right_edit, window=self.target_port_list, validate=incremental_validate_digits, error_win=self.main_win.error_line, text=Iscsi.ISCSI_DEFAULT_PORT) self.target_port_edit.key_dict.update(self.add_keys) if self.target_port is not None: self.target_port_edit.set_text(self.target_port) # Target LUN y_loc += 1 edit_start = textwidth(IscsiScreen.TARGET_LUN_LABEL) + \ IscsiScreen.ITEM_OFFSET lun_area = WindowArea(y_loc=y_loc, x_loc=1, lines=1, columns=edit_start + IscsiScreen.MAX_LUN_LEN + 1) self.target_lun_list = ListItem(lun_area, window=self.center_win, text=IscsiScreen.TARGET_LUN_LABEL) self.target_lun_list.key_dict.update(self.add_keys) self.default_edit.x_loc = edit_start self.default_edit.columns = IscsiScreen.MAX_LUN_LEN + 1 self.target_lun_edit = EditField(self.default_edit, window=self.target_lun_list, validate=incremental_validate_hex, error_win=self.main_win.error_line) self.target_lun_edit.key_dict.update(self.add_keys) if self.target_lun is not None: self.target_lun_edit.set_text(self.target_lun) # Target Name y_loc += 2 name_area = WindowArea(y_loc=y_loc, x_loc=1, lines=1, columns=self.full_win_width) name_area.y_loc = y_loc target_name_list = ListItem(name_area, window=self.center_win, text=IscsiScreen.TARGET_NAME_LABEL) self.name_edit.x_loc = textwidth(IscsiScreen.TARGET_NAME_LABEL) + \ IscsiScreen.ITEM_OFFSET self.name_edit.columns = self.full_win_width - \ textwidth(IscsiScreen.TARGET_NAME_LABEL) - \ IscsiScreen.ITEM_OFFSET self.target_name_edit = EditField(self.name_edit, window=target_name_list) if self.target_name is not None: self.target_name_edit.set_text(self.target_name) # Horizontal line y_loc += 1 self.center_win.window.hline(y_loc, 3, curses.ACS_HLINE, self.full_win_width) # Initiator Name y_loc += 1 if self.is_iscsiboot: # the system BIOS is configured for iSCSI boot. This means the # user will be unable to change the initiator-name. Display the # name, but don't allow it to be changed. text = "%s %s" % \ (IscsiScreen.INITIATOR_NAME_LABEL, self.initiator_name) self.center_win.add_text(text, start_y=y_loc, start_x=1) y_loc += 1 self.center_win.add_text(IscsiScreen.ISCSI_BOOT_LABEL, start_y=y_loc, start_x=1) else: # display the edit field as normal name_area.y_loc = y_loc initiator_name_list = ListItem(name_area, window=self.center_win, text=IscsiScreen.INITIATOR_NAME_LABEL) self.name_edit.x_loc = \ textwidth(IscsiScreen.INITIATOR_NAME_LABEL) + \ IscsiScreen.ITEM_OFFSET self.name_edit.columns = self.full_win_width - \ textwidth(IscsiScreen.INITIATOR_NAME_LABEL) - \ IscsiScreen.ITEM_OFFSET self.initiator_name_edit = EditField(self.name_edit, window=initiator_name_list, text=self.initiator_name) y_loc += 2 self.center_win.add_text(IscsiScreen.USE_CHAP_LABEL, y_loc, 1) # CHAP username y_loc += 1 edit_start = textwidth(IscsiScreen.CHAP_NAME_LABEL) + \ IscsiScreen.ITEM_OFFSET chapname_area = WindowArea(y_loc=y_loc, x_loc=15, lines=1, columns=edit_start + IscsiScreen.CHAP_LEN) chap_name_list = ListItem(chapname_area, window=self.center_win, text=IscsiScreen.CHAP_NAME_LABEL) self.chap_edit.x_loc = edit_start self.chap_edit.columns = IscsiScreen.CHAP_LEN + 1 self.chap_edit.scrollable_columns = IscsiScreen.MAX_NAME_LEN + 1 self.chap_name_edit = EditField(self.chap_edit, window=chap_name_list) if self.chap_name is not None: self.chap_name_edit.set_text(self.chap_name) # CHAP password y_loc += 1 edit_start = textwidth(IscsiScreen.CHAP_PASSWORD_LABEL) + \ IscsiScreen.ITEM_OFFSET chapname_area.y_loc = y_loc chap_password_list = ListItem(chapname_area, window=self.center_win, text=IscsiScreen.CHAP_PASSWORD_LABEL) self.chap_edit.x_loc = textwidth(IscsiScreen.CHAP_PASSWORD_LABEL) + \ IscsiScreen.ITEM_OFFSET self.chap_edit.scrollable_columns = None self.chap_password_edit = PasswordField(self.chap_edit, window=chap_password_list) if self.chap_password is not None: self.chap_password_edit.set_text(self.chap_password) # Legend y_loc += 2 self.center_win.window.addch(y_loc, 1, IscsiScreen.REQUIRED_MARK, self.center_win.color_theme.inactive) self.center_win.add_text(IscsiScreen.REQUIRED_FIELD_LABEL, y_loc, 1) self.main_win.do_update() self.center_win.activate_object()
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): ''' Prepare the editable fields for day, month, year, hour and minute ''' y_loc = 1 y_loc += self.center_win.add_paragraph(DateTimeScreen.PARAGRAPH, y_loc) sc_profile = solaris_install.sysconfig.profile.from_engine() os.environ["TZ"] = sc_profile.system.tz_timezone now = datetime.datetime.now() LOGGER.log( LOG_LEVEL_INPUT, "Current date (year-month-day hour:minute)" ": %s-%s-%s %s:%s", now.year, now.month, now.day, now.hour, now.minute) # Only update saved values if this is first time on screen or # if we have saved offset in profile (F2, return to screen) # update_vals = False if self.saved_year is None: update_vals = True showtime = now elif sc_profile.system.time_offset != 0: showtime = now + sc_profile.system.time_offset update_vals = True sc_profile.system.time_offset = 0 if update_vals: self.saved_year = str(showtime.year) self.saved_month = str(showtime.month) self.saved_day = str(showtime.day) self.saved_hour = str(showtime.hour) self.saved_minute = str(showtime.minute) self.saved_days_in_month = calendar.monthrange( showtime.year, showtime.month)[1] LOGGER.debug("starting year month day hour minute:_%s_%s_%s_%s_%s", self.saved_year, self.saved_month, self.saved_day, self.saved_hour, self.saved_minute) LOGGER.debug("starting days_in_month: %s", self.saved_days_in_month) y_loc += 1 self.err_area.y_loc = y_loc self.list_area.y_loc = y_loc self.year_err = ErrorWindow(self.err_area, window=self.center_win, centered=False) self.year_list = ListItem(self.list_area, window=self.center_win, text=DateTimeScreen.YEAR_TEXT) self.year_edit = EditField(self.year_edit_area, window=self.year_list, validate=year_valid, error_win=self.year_err, on_exit=year_on_exit, text=self.saved_year) self.year_edit.clear_on_enter = True self.center_win.add_text(DateTimeScreen.YEAR_FORMAT, y_loc, self.info_offset) y_loc += 1 self.err_area.y_loc = y_loc self.list_area.y_loc = y_loc self.month_err = ErrorWindow(self.err_area, window=self.center_win, centered=False) self.month_list = ListItem(self.list_area, window=self.center_win, text=DateTimeScreen.MONTH_TEXT) self.month_edit = EditField(self.edit_area, window=self.month_list, validate=month_valid, error_win=self.month_err, on_exit=month_on_exit, text=self.saved_month, numeric_pad="0") self.month_edit.clear_on_enter = True self.month_edit.right_justify = True self.center_win.add_text("(1-12)", y_loc, self.info_offset) y_loc += 1 self.err_area.y_loc = y_loc self.list_area.y_loc = y_loc self.day_err = ErrorWindow(self.err_area, window=self.center_win, centered=False) self.day_list = ListItem(self.list_area, window=self.center_win, text=DateTimeScreen.DAY_TEXT) self.day_edit = EditField(self.edit_area, window=self.day_list, validate=day_valid, error_win=self.day_err, on_exit=day_on_exit, text=self.saved_day, numeric_pad="0") self.day_edit.clear_on_enter = True self.day_edit.right_justify = True self.month_edit.validate_kwargs["date_time"] = self self.month_edit.validate_kwargs["year_edit"] = self.year_edit self.month_edit.validate_kwargs["day_edit"] = self.day_edit self.year_edit.validate_kwargs["date_time"] = self self.year_edit.validate_kwargs["month_edit"] = self.month_edit self.year_edit.validate_kwargs["day_edit"] = self.day_edit self.day_edit.validate_kwargs["date_time"] = self self.day_edit.validate_kwargs["year_edit"] = self.year_edit self.day_edit.validate_kwargs["month_edit"] = self.month_edit self.date_range_loc = (y_loc, self.info_offset) self.update_day_range(self.saved_days_in_month) y_loc += 1 self.err_area.y_loc = y_loc self.list_area.y_loc = y_loc self.hour_err = ErrorWindow(self.err_area, window=self.center_win, centered=False) self.hour_list = ListItem(self.list_area, window=self.center_win, text=DateTimeScreen.HOUR_TEXT) self.hour_edit = EditField(self.edit_area, window=self.hour_list, validate=hour_valid, error_win=self.hour_err, on_exit=hour_on_exit, text=self.saved_hour, numeric_pad="0") self.hour_edit.clear_on_enter = True self.hour_edit.right_justify = True self.center_win.add_text("(0-23)", y_loc, self.info_offset) y_loc += 1 self.err_area.y_loc = y_loc self.list_area.y_loc = y_loc self.minute_err = ErrorWindow(self.err_area, window=self.center_win, centered=False) self.minute_list = ListItem(self.list_area, window=self.center_win, text=DateTimeScreen.MINUTE_TEXT) self.minute_edit = EditField(self.edit_area, window=self.minute_list, validate=minute_valid, error_win=self.minute_err, on_exit=minute_on_exit, text=self.saved_minute, numeric_pad="0") self.minute_edit.clear_on_enter = True self.minute_edit.right_justify = True self.center_win.add_text("(0-59)", y_loc, self.info_offset) self.main_win.do_update() self.center_win.activate_object(self.year_list)
def _show(self): '''Create the list of time zones''' LOGGER.debug("self.screen %s", self.screen) sc_profile = solaris_install.sysconfig.profile.from_engine() if sc_profile.system is None: sc_profile.system = SystemInfo() self.sys_info = sc_profile.system self.cur_country = self.sys_info.tz_country self.cur_continent = self.sys_info.tz_region if self.cur_continent == SystemInfo.UTC and self.screen != "regions": raise SkipException self.center_win.border_size = TimeZone.BORDER_WIDTH if self.screen == TimeZone.LOCATIONS: self.cur_timezone_parent = self.cur_continent elif self.screen == TimeZone.TIMEZONE: self.cur_timezone_parent = self.cur_country LOGGER.debug("cur_continent %s, cur_country %s", self.cur_continent, self.cur_country) y_loc = 1 y_loc += self.center_win.add_paragraph(self.intro, y_loc) y_loc += 1 menu_item_max_width = self.win_size_x - TimeZone.SCROLL_SIZE self.center_win.add_text(self.title, y_loc, TimeZone.SCROLL_SIZE) y_loc += 1 self.center_win.window.hline(y_loc, 3, curses.ACS_HLINE, 40) y_loc += 1 tz_list = self.get_timezones(self.cur_continent, self.cur_country) area = WindowArea(x_loc=0, y_loc=y_loc, scrollable_lines=len(tz_list) + 1) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x LOGGER.debug("area.lines=%s, area.columns=%s", area.lines, area.columns) self.scroll_region = ScrollWindow(area, enable_spelldict=True, window=self.center_win) utc = 0 if self.screen == TimeZone.REGIONS: utc_area = WindowArea(1, len(TimeZone.UTC_TEXT) + 1, 0, TimeZone.SCROLL_SIZE) utc_item = ListItem(utc_area, window=self.scroll_region, text=TimeZone.UTC_TEXT, data_obj=SystemInfo.UTC) self.scroll_region.spell_dict[TimeZone.UTC_TEXT] = utc utc = 1 # add the entries to the screen for idx, timezone in enumerate(tz_list): # add this timezone to the scroll_region's spelling dict self.scroll_region.spell_dict[timezone.lower()] = idx + utc LOGGER.log(LOG_LEVEL_INPUT, "tz idx = %i name= %s", idx, tz_list[idx]) hilite = min(menu_item_max_width, len(timezone) + 1) win_area = WindowArea(1, hilite, idx + utc, TimeZone.SCROLL_SIZE) list_item = ListItem(win_area, window=self.scroll_region, text=timezone, data_obj=timezone) y_loc += 1 self.main_win.do_update() self.center_win.activate_object(self.scroll_region) LOGGER.debug("self.cur_timezone_idx=%s", self.cur_timezone_idx) self.scroll_region.activate_object_force(self.cur_timezone_idx, force_to_top=True)
def _show(self): '''Display partition data for selected disk, and present the two choices ''' doc = InstallEngine.get_instance().doc disk = get_desired_target_disk(doc) # verify the desired disk has a GPT partition table if disk.label == "VTOC": raise SkipException self.disk = disk LOGGER.debug("Working with the following disk:") LOGGER.debug(str(self.disk)) # set the header of the screen if self.disk.is_boot_disk(): bootable = GPTPart.BOOT_TEXT else: bootable = u"" disk_size_gb_str = locale.format("%.1f", self.disk.disk_prop.dev_size.get(Size.gb_units)) + LOCALIZED_GB type_bootable_str = GPTPart.HEADER_TYPE_BOOTABLE % \ {"type": self.disk.disk_prop.dev_type, "bootable": bootable} header_text = self.header_text + disk_size_gb_str + type_bootable_str self.main_win.set_header_text(header_text) if self.disk.whole_disk: LOGGER.debug("disk.whole_disk=True, skip editing") raise SkipException y_loc = 1 y_loc += self.center_win.add_paragraph(self.paragraph, start_y=y_loc) y_loc += 1 gpt_partitions = self.disk.get_children(class_type=GPTPartition) if gpt_partitions: next_line = self.found else: next_line = self.proposed y_loc += self.center_win.add_paragraph(next_line, start_y=y_loc) y_loc += 1 disk_win_area = WindowArea(6, 70, y_loc, 0) self.disk_win = DiskWindow(disk_win_area, self.disk, target_controller=self.tc, window=self.center_win) y_loc += disk_win_area.lines y_loc += 3 whole_disk_width = textwidth(self.use_whole) + 3 cols = (self.win_size_x - whole_disk_width) / 2 whole_disk_item_area = WindowArea(1, whole_disk_width, y_loc, cols) self.whole_disk_item = ListItem(whole_disk_item_area, window=self.center_win, text=self.use_whole, centered=True) y_loc += 1 partial_width = textwidth(self.use_part) + 3 cols = (self.win_size_x - partial_width) / 2 partial_item_area = WindowArea(1, partial_width, y_loc, cols) self.partial_disk_item = ListItem(partial_item_area, window=self.center_win, text=self.use_part, centered=True) self.main_win.do_update() if self.use_whole_segment: self.center_win.activate_object(self.whole_disk_item) else: self.center_win.activate_object(self.partial_disk_item)
def _show(self): '''Create a list of NICs to choose from. If more than 15 NICs are found, create a scrolling region to put them in ''' self.nic = solaris_install.sysconfig.profile.from_engine().nic if self.nic.type != NetworkInfo.MANUAL: raise SkipException if len(self.ether_nics) == 1: self.set_nic_in_profile(self.ether_nics[0]) raise SkipException if self.nic.nic_iface is None: selected_nic_name = "" else: selected_nic_name = NetworkInfo.get_nic_name(self.nic.nic_iface) y_loc = 1 y_loc += self.center_win.add_paragraph(NICSelect.PARAGRAPH, y_loc) selected_nic = 0 y_loc += 1 max_nics = min(NICSelect.MAX_NICS, self.center_win.area.lines - y_loc) if len(self.ether_nics) > max_nics: columns = self.win_size_x - NICSelect.LIST_OFFSET win_area = WindowArea(lines=max_nics, columns=columns, y_loc=y_loc, x_loc=NICSelect.LIST_OFFSET, scrollable_lines=len(self.ether_nics)) self.scroll_region = ScrollWindow(win_area, window=self.center_win) self.list_region = self.scroll_region y_loc = 0 else: self.scroll_region = None self.list_region = self.center_win for nic in self.ether_nics: self.list_area.y_loc = y_loc # # display list item in form of "NIC name (NIC device)" - # e.g. "net0 (bge0)" # If NIC device is not populated, display just NIC name. # list_item_text = NetworkInfo.get_nic_desc(nic) # list item width self.list_area.columns = len(list_item_text) + 1 list_item = ListItem(self.list_area, window=self.list_region, text=list_item_text, data_obj=nic) if NetworkInfo.get_nic_name(nic) == selected_nic_name: selected_nic = list_item y_loc += 1 self.main_win.do_update() if self.scroll_region: self.center_win.activate_object(self.scroll_region) self.scroll_region.activate_object_force(selected_nic, force_to_top=True) else: self.center_win.activate_object(selected_nic)
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): '''Display partition data for selected disk, and present the two choices ''' doc = InstallEngine.get_instance().doc disk = get_desired_target_disk(doc) if disk.label == "GPT": # this disk has GPT partitions, so skip this screen raise SkipException if self.x86_slice_mode: if disk.whole_disk: raise SkipException sol_partition = get_solaris_partition(doc) if sol_partition is None: # Must have a Solaris partition err_msg = "Critical error - no Solaris partition found" LOGGER.error(err_msg) raise ValueError(err_msg) LOGGER.debug("Working with the following partition:") LOGGER.debug(str(sol_partition)) # See if there are any slices in the partition all_slices = sol_partition.get_children(class_type=Slice) if not all_slices: LOGGER.info("No previous slices found") # Setting the in_zpool flag to indicate the whole # partition should be used. The needed underlying # slices will be created in the next step when # the in_zpool flag is detected. sol_partition.in_zpool = DEFAULT_ZPOOL_NAME raise SkipException LOGGER.debug("Preserved partition with existing slices, " "presenting option to install into a slice") self.disk = sol_partition else: self.disk = get_desired_target_disk(doc) LOGGER.debug("Working with the following disk:") LOGGER.debug(str(self.disk)) if self.disk.whole_disk: LOGGER.debug("disk.whole_disk=True, skip editing") raise SkipException if self.disk.is_boot_disk(): bootable = FDiskPart.BOOT_TEXT else: bootable = u"" disk_size_gb_str = locale.format("%.1f", self.disk.disk_prop.dev_size.get(Size.gb_units)) + LOCALIZED_GB type_bootable_str = FDiskPart.HEADER_TYPE_BOOTABLE % \ {"type": self.disk.disk_prop.dev_type, "bootable": bootable} header_text = self.header_text + disk_size_gb_str + \ type_bootable_str self.main_win.set_header_text(header_text) y_loc = 1 y_loc += self.center_win.add_paragraph(self.paragraph, start_y=y_loc) y_loc += 1 if self.is_x86 and not self.x86_slice_mode: all_parts = self.disk.get_children(class_type=Partition) else: all_parts = self.disk.get_children(class_type=Slice) found_parts = bool(all_parts) if found_parts: next_line = self.found else: next_line = self.proposed y_loc += self.center_win.add_paragraph(next_line, start_y=y_loc) y_loc += 1 disk_win_area = WindowArea(6, 70, y_loc, 0) self.disk_win = DiskWindow(disk_win_area, self.disk, target_controller=self.tc, window=self.center_win) y_loc += disk_win_area.lines y_loc += 3 whole_disk_width = textwidth(self.use_whole) + 3 cols = (self.win_size_x - whole_disk_width) / 2 whole_disk_item_area = WindowArea(1, whole_disk_width, y_loc, cols) self.whole_disk_item = ListItem(whole_disk_item_area, window=self.center_win, text=self.use_whole, centered=True) y_loc += 1 partial_width = textwidth(self.use_part) + 3 cols = (self.win_size_x - partial_width) / 2 partial_item_area = WindowArea(1, partial_width, y_loc, cols) self.partial_disk_item = ListItem(partial_item_area, window=self.center_win, text=self.use_part, centered=True) self.main_win.do_update() if self.use_whole_segment: self.center_win.activate_object(self.whole_disk_item) else: self.center_win.activate_object(self.partial_disk_item)