Exemplo n.º 1
0
    def validate(self):
        '''Ensure the Solaris partition or ZFS Root exists and is large
        enough
        
        '''
        disk_info = self.disk_win.disk_info
        if self.is_x86 and not self.x86_slice_mode:
            min_size_text = _("The Solaris2 partition must be at least"
                              " %(size).1fGB")
            missing_part = _("There must be exactly one Solaris2 partition.")
        else:
            min_size_text = _("The size of %(pool)s must be at least"
                              " %(size).1fGB")
            missing_part = _("There must be one ZFS root pool, '%(pool)s.'")
        min_size = round(get_minimum_size().size_as("gb"), 1)
        format_dict = {'pool': SliceInfo.DEFAULT_POOL, 'size': min_size}

        try:
            part = disk_info.get_solaris_data(check_multiples=True)
        except ValueError:
            part = None

        if part is None:
            raise UIMessage(missing_part % format_dict)

        # When comparing sizes, check only to the first decimal place,
        # as that is all the user sees. (Rounding errors that could
        # cause the partition/slice layout to be invalid get cleaned up
        # prior to target instantiation)
        part_size = round(part.size.size_as("gb"), 1)
        if part_size < min_size:
            raise UIMessage(min_size_text % format_dict)
Exemplo n.º 2
0
def username_valid(edit_field):
    '''Ensure the username is not "root" or "jack"'''
    user_str = edit_field.get_text()
    if user_str == "root":
        raise UIMessage(_("'root' cannot be used"))
    elif user_str == "jack":
        raise UIMessage(_("'jack' cannot be used"))
    return True
Exemplo n.º 3
0
def minute_valid(minute_edit):
    '''Check validity of minute as each char entered'''
    minute_str = minute_edit.get_text()
    logging.log(LOG_LEVEL_INPUT, "validating minute, text=%s=", minute_str)
    if minute_str and not minute_str.isdigit():
        raise UIMessage(_("Minute must be numeric"))
    if len(minute_str) >= 2 and (int(minute_str) > 59):
        raise UIMessage(_("Minute out of range"))
    return True
Exemplo n.º 4
0
def hour_valid(hour_edit):
    '''Check validity of hour as each char entered'''
    hour_str = hour_edit.get_text()
    logging.log(LOG_LEVEL_INPUT, "validating hour, text=%s=", hour_str)
    if hour_str and not hour_str.isdigit():
        raise UIMessage(_("Hour must be numeric"))
    if len(hour_str) >= 2 and (int(hour_str) > 23):
        logging.debug("hour out of range, =%s", hour_str)
        raise UIMessage(_("Hour out of range"))
    return True
Exemplo n.º 5
0
def username_valid_alphanum(edit_field):
    '''Ensure username is alphanumeric, and does not start with a digit'''
    user_str = edit_field.get_text()
    if not user_str:
        return True
    if user_str[0].isalpha():
        if user_str.isalnum():
            return True
        else:
            raise UIMessage(_("Username must be alphanumeric"))
    else:
        raise UIMessage(_("First character must be a-zA-Z"))
Exemplo n.º 6
0
def be_name_valid(edit_field):
    '''Ensure BE name is valid'''

    be_name = edit_field.get_text()
    if not be_name:
        raise UIMessage(ZpoolScreen.BE_NAME_EMPTY_ERROR)

    search = re.compile(r'[^a-zA-Z0-9_\-]').search
    if bool(search(be_name)):
        raise UIMessage(ZpoolScreen.BE_NAME_UNALLOWED_ERROR)

    return True
Exemplo n.º 7
0
    def validate(self):
        if not self.pool_win:
            raise UIMessage(ZpoolScreen.NO_POOLS)
        pool_name = self.existing_pools[self.pool_win.active_object]
        be_name = self.be_name_edit.get_text()
        if not be_name:
            raise UIMessage(ZpoolScreen.BE_NAME_EMPTY_ERROR)

        be_names = get_zpool_be_names(pool_name)
        if be_name in be_names:
            filesystem_dict = {"pool_name": pool_name, "be_name": be_name}
            raise UIMessage(ZpoolScreen.FILESYSTEM_EXISTS_ERROR %
                            filesystem_dict)
Exemplo n.º 8
0
def decimal_valid(edit_field, disk_win=None):
    '''Check text to see if it is a decimal number of precision no
    greater than the tenths place.
    
    '''
    text = edit_field.get_text().lstrip()
    if text.endswith(" "):
        raise UIMessage(_('Only the digits 0-9 and "." are valid.'))
    vals = text.split(".")
    if len(vals) > 2:
        raise UIMessage(_('A number can only have one "."'))
    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 "." are valid.'))
    if len(vals) > 1 and len(vals[1]) > 1:
        raise UIMessage(_("Size can be specified to only one decimal place."))
    if disk_win is not None:
        text = text.rstrip(".")
        if not text:
            text = "0"
        new_size = DiskSpace(text + "gb")
        max_size = edit_field.data_obj.get_max_size(disk_win.disk_info)

        # When comparing sizes, check only to the first decimal place,
        # as that is all the user sees. (Rounding errors that could
        # cause the partition/slice layout to be invalid get cleaned up
        # prior to target instantiation)
        new_size_rounded = round(new_size.size_as("gb"), 1)
        max_size_rounded = round(max_size, 1)
        if new_size_rounded > max_size_rounded:
            raise UIMessage(
                _("The new size (%(size).1f) is greater than "
                  "the available space (%(avail).1f)") % {
                      "size": new_size_rounded,
                      "avail": max_size_rounded
                  })
        size_diff = abs(new_size.size_as("gb") - edit_field.data_obj.orig_size)
        if size_diff > DiskWindow.SIZE_PRECISION:
            edit_field.data_obj.size = new_size
            edit_field.data_obj.adjust_offset(disk_win.disk_info)
        else:
            edit_field.data_obj.size = "%fgb" % edit_field.data_obj.orig_size
        disk_win.update_avail_space()
        disk_win.no_ut_refresh()
        part_field = disk_win.find_part_field(edit_field.data_obj)[1]
        disk_win.mark_if_destroyed(part_field)
    return True
Exemplo n.º 9
0
 def validate(self):
     '''Verify the syntactical validity of the IP Address fields'''
     ip_fields = [self.ip_field,
                  self.netmask_field,
                  self.gateway_field,
                  self.dns_field]
     for field in ip_fields:
         validate_ip(field)
     
     if not self.ip_field.get_text():
         raise UIMessage(_("IP Address must not be empty"))
     if not self.netmask_field.get_text():
         raise UIMessage(_("Netmask must not be empty"))
     if self.domain_field.get_text() and not self.dns_field.get_text():
         raise UIMessage(_("DNS server required if Domain set"))
Exemplo n.º 10
0
 def validate(self):
     '''Ensure hostname is set and a network type is chosen (unless no
     NICs are present)
     
     '''
     hostname_text = self.hostname.get_text()
     if not hostname_text:
         raise UIMessage(_("A Hostname is required."))
     if len(hostname_text) < 2:
         raise UIMessage(_("A Hostname must be at least two characters."))
     if self.have_nic:
         item_key = self.center_win.get_active_object().item_key
         if item_key not in self.net_type_dict:
             raise UIMessage(_("Select the wired network configuration: "
                                "Automatically or None."))
Exemplo n.º 11
0
 def validate(self):
     '''Verify each of the edit fields'''
     year_value = self.year_edit.get_text()
     month_value = self.month_edit.get_text()
     day_value = self.day_edit.get_text()
     hour_value = self.hour_edit.get_text()
     minute_value = self.minute_edit.get_text()
     logging.debug("year_value=%s", year_value)
     logging.debug("month_value=%s", month_value)
     logging.debug("day_value=%s", day_value)
     logging.debug("hour_value=%s", hour_value)
     logging.debug("minute_value=%s", minute_value)
     had_err = False
     if not self.year_edit.run_on_exit():
         had_err = True
     if not self.month_edit.run_on_exit():
         had_err = True
     if not self.day_edit.run_on_exit():
         had_err = True
     if not self.hour_edit.run_on_exit():
         had_err = True
     if not self.minute_edit.run_on_exit():
         had_err = True
     if had_err:
         raise UIMessage(_("Invalid date/time. See errors above."))
Exemplo n.º 12
0
    def validate(self):
        '''Validate the size of the disk.'''
        disk = self.disk_detail.disk_info
        
        warning_txt = []
        disk_selected = False
        gpt_disk_selected = False
        
        for d in self.disks:
            if d.used:
                disk_selected = True
                if DiskInfo.GPT in disk.label:
                   gpt_disk_selected = True 

        if not disk_selected:
            warning_txt.append(DiskScreen.DISK_WARNING_NEED_ONE_DISK)
        elif gpt_disk_selected:
            warning_txt.append(DiskScreen.DISK_WARNING_GPT)
        warning_txt = " ".join(warning_txt)
        
        if warning_txt:
            # warn the user and give user a chance to change
            result = self.main_win.pop_up(DiskScreen.DISK_WARNING_HEADER,
                                          warning_txt,
                                          DiskScreen.CANCEL_BUTTON,
                                          DiskScreen.CONTINUE_BUTTON)
            
            # We don't continue if user wants to change something 
            # or didn't select any disk
            if not result or not disk_selected:
                raise UIMessage() # let user select different disk
Exemplo n.º 13
0
def minute_on_exit(minute_edit):
    '''Check minute when exiting field'''
    minute_str = minute_edit.get_text()
    logging.debug("minute_on_exit, =%s=", minute_str)
    if not minute_str:
        raise UIMessage(_("Minute out of range"))
    minute_valid(minute_edit)
    return True
Exemplo n.º 14
0
def hour_on_exit(hour_edit):
    '''Check hour when exiting field'''
    hour_str = hour_edit.get_text()
    logging.debug("hour_on_exit, =%s=", hour_str)
    if not hour_str:
        raise UIMessage(_("Hour out of range"))
    hour_valid(hour_edit)
    return True
Exemplo n.º 15
0
def month_on_exit(month_edit):
    '''Check month when exiting field'''
    month_str = month_edit.get_text()
    logging.debug("month_on_exit, =%s=", month_str)
    month_valid(month_edit)
    if (len(month_str) == 0 or int(month_str) == 0):
        logging.debug("on exit month out of range=%s", month_str)
        raise UIMessage(_("Month out of range"))
    return True
Exemplo n.º 16
0
def hostname_is_valid(edit_field):
    '''Check hostname for characters other than a-zA-Z0-9 and hyphens'''
    user_str = edit_field.get_text()
    if not user_str:
        return True
    test_str = user_str.replace(u"-", "a")
    if not test_str.isalnum():
        raise UIMessage(_("The Hostname can only contain letters, numbers, "
                            "and minus signs (-)."))
Exemplo n.º 17
0
def pass_match(edit_field, linked_win=None):
    '''Make sure passwords match'''
    confirm_pass = edit_field.get_text()
    if linked_win is None or linked_win.get_text() == confirm_pass:
        return True
    else:
        edit_field.clear_text()
        linked_win.clear_text()
        raise UIMessage(_("Passwords don't match"))
Exemplo n.º 18
0
def day_on_exit(day_edit):
    '''Check day when exiting field'''
    day_str = day_edit.get_text()
    logging.debug("day_on_exit, =%s=", day_str)
    day_valid(day_edit)
    if (len(day_str) == 0 or int(day_str) == 0):
        logging.debug("on exit day out of range=%s", day_str)
        raise UIMessage(_("Day out of range"))
    return True
Exemplo n.º 19
0
def year_on_exit(year_edit):
    '''Check year when exiting field'''
    year_str = year_edit.get_text()
    logging.debug("year_on_exit, =%s=", year_str)
    year_valid(year_edit)
    if (len(year_str) != 4):
        logging.debug("on exit year out of range=%s", input)
        raise UIMessage(_("Year out of range"))
    return True
Exemplo n.º 20
0
    def validate(self):
        '''Check for mismatched passwords, bad login names, etc.'''

        color = self.main_win.theme.header

        if self.root_pass_edit.get_text() != self.root_confirm_edit.get_text():
            raise UIMessage(_("Root passwords don't match"))
        if not self.install_profile.install_to_pool:
            user_pass = self.user_pass_edit.get_text()
            if user_pass != self.user_confirm_edit.get_text():
                raise UIMessage(_("User passwords don't match"))
            login_name = self.username_edit.get_text()
            logging.debug("login_name=%s", login_name)
            username_valid(self.username_edit)
            real_name = self.real_name_edit.get_text()

            logging.debug("real_name=%s", real_name)
            # If password or real_name has been entered, require a login name

            if not login_name:
                if real_name or user_pass:
                    raise UIMessage(
                        _("Enter username or clear all user "
                          "account fields"))

            if login_name and not user_pass:
                continue_anyway = self.main_win.pop_up(
                    UserScreen.NO_USER_HEADER,
                    UserScreen.NO_USER_TEXT,
                    BaseScreen.CANCEL_BUTTON,
                    UserScreen.CONTINUE_BTN,
                    color=color)
                if not continue_anyway:
                    raise UIMessage()

        if not self.root_pass_edit.get_text():
            continue_anyway = self.main_win.pop_up(UserScreen.NO_ROOT_HEADER,
                                                   UserScreen.NO_ROOT_TEXT,
                                                   BaseScreen.CANCEL_BUTTON,
                                                   UserScreen.CONTINUE_BTN,
                                                   color=color)
            if not continue_anyway:
                raise UIMessage()
Exemplo n.º 21
0
def incremental_validate_IP(edit_field):
    '''Incrementally validate the IP Address as the user enters it'''
    ip_address = edit_field.get_text()
    if not ip_address:
        return True
    try:
        IPAddress.incremental_check(ip_address)
    except ValueError:
        raise UIMessage(_("%s must be of the form xxx.xxx.xxx.xxx") %
                        edit_field.data_obj)
    return True
Exemplo n.º 22
0
def day_valid(day_edit, month_edit=None, year_edit=None, date_time=None):
    '''Check validity of day as each char entered'''
    day_str = day_edit.get_text()
    logging.log(LOG_LEVEL_INPUT, "validating day, text=%s=", day_str)
    if not day_str:
        return True
    if not day_str.isdigit():
        raise UIMessage(_("Day must be numeric"))
    logging.log(LOG_LEVEL_INPUT, "len = %s, text=%s ", len(day_str), day_str)

    # When screen first comes up, there is no month/year_edit
    if (month_edit is None or year_edit is None):
        return True

    days_in_month = get_days_in_month(month_edit, year_edit, date_time)
    if (len(day_str) >= 2):
        if (int(day_str) > days_in_month or int(day_str) == 0):
            logging.debug("day out of range, =%s", day_str)
            raise UIMessage(_("Day out of range"))
    return True
Exemplo n.º 23
0
def month_valid(month_edit, day_edit=None, year_edit=None, date_time=None):
    '''Check validity of month as each char entered'''
    if date_time:
        date_time.month_is_valid = False
    month_str = month_edit.get_text()
    logging.log(LOG_LEVEL_INPUT, "validating month, text=%s=", month_str)
    if not month_str:
        return True
    if not month_str.isdigit():
        raise UIMessage(_("Month must be numeric"))
    logging.debug("len = %s, text=%s ", len(month_str), month_str)
    if len(month_str) >= 2:
        if (int(month_str) > 12 or int(month_str) == 0):
            logging.log(LOG_LEVEL_INPUT, "month out of range, =%s", month_str)
            raise UIMessage(_("Month out of range"))
    if date_time:
        date_time.month_is_valid = True
        if int(month_str) > 0:
            check_day_range(month_edit, day_edit, year_edit, date_time)
    return True
Exemplo n.º 24
0
def year_valid(year_edit, month_edit=None, day_edit=None, date_time=None):
    '''Check validity of year as each char entered'''
    if date_time:
        date_time.year_is_valid = False
    year_str = year_edit.get_text()
    if not year_str:
        return True
    now = datetime.datetime.now()
    logging.log(LOG_LEVEL_INPUT, "validating year, text=%s=", year_str)
    if not year_str.isdigit():
        raise UIMessage(_("Year must be numeric"))
    if year_str[0] != now.strftime("%Y")[0]:
        logging.debug("year doesn't start with 2, text=%s", year_str)
        raise UIMessage(_("Year out of range"))
    if len(year_str) > 1 and year_str[1] != now.strftime("%Y")[1]:
        logging.debug("year out of range=%s", year_str)
        raise UIMessage(_("Year out of range"))
    if date_time:
        date_time.year_is_valid = True
        if len(year_str) == 4:
            check_day_range(month_edit, day_edit, year_edit, date_time)
    return True
Exemplo n.º 25
0
def validate_ip(edit_field):
    '''Wrap a call to IPAddress.check_address and raise a UIMessage with
    appropriate message text
    
    '''
    ip_address = edit_field.get_text()
    if not ip_address:
        return True
    try:
        IPAddress.convert_address(ip_address)
    except ValueError:
        raise UIMessage(_("%s must be of the form xxx.xxx.xxx.xxx") %
                        edit_field.data_obj)
    return True
Exemplo n.º 26
0
    def validate(self):
        '''Validate the size of the disk.'''
        disk = self.disk_detail.disk_info

        warning_txt = []
        if DiskInfo.GPT in disk.label:
            warning_txt.append(DiskScreen.DISK_WARNING_GPT)
        if disk.size > SliceInfo.MAX_VTOC:
            warning_txt.append(self.disk_warning_too_big)
        warning_txt = " ".join(warning_txt)

        if warning_txt:
            # warn the user and give user a chance to change
            result = self.main_win.pop_up(DiskScreen.DISK_WARNING_HEADER,
                                          warning_txt,
                                          DiskScreen.CANCEL_BUTTON,
                                          DiskScreen.CONTINUE_BUTTON)

            if not result:
                raise UIMessage()  # let user select different disk