def __init__(self, model, signal, iface): self.model = model self.signal = signal self.ifname = iface self.iface = self.model.get_interface(self.ifname) self.is_gateway = False self.gateway_input = StringEditor(caption="") # FIXME: ipaddr_editor self.address_input = StringEditor(caption="") # FIXME: ipaddr_editor self.subnet_input = StringEditor(caption="") # FIXME: ipaddr_editor self.error = Text("", align='center') self.nameserver_input = \ StringEditor(caption="") # FIXME: ipaddr_editor self.searchdomains_input = \ StringEditor(caption="") # FIXME: ipaddr_editor self.set_as_default_gw_button = Pile( self._build_set_as_default_gw_button()) body = [ Padding.center_79(self._build_iface_inputs()), Padding.line_break(""), Padding.center_79(self.set_as_default_gw_button), Padding.line_break(""), Padding.center_90(Color.info_error(self.error)), Padding.line_break(""), Padding.fixed_10(self._build_buttons()) ] super().__init__(ListBox(body))
def __init__(self, model, signal, selected_disk): log.debug('AddPartitionView: selected_disk=[{}]'.format(selected_disk)) self.model = model self.signal = signal self.selected_disk = selected_disk self.disk_obj = self.model.get_disk(selected_disk) self.partnum = IntegerEditor(caption="", default=self.disk_obj.lastpartnumber + 1) self.size_str = _humanize_size(self.disk_obj.freespace) self.size = StringEditor(caption="".format(self.size_str)) self.mountpoint = MountEditor(caption="", edit_text="/") self.fstype = Selector(opts=self.model.supported_filesystems) body = [ Columns([ ("weight", 0.2, Text("Adding partition to {}".format(self.disk_obj.devpath), align="right")), ("weight", 0.3, Text("")) ]), Padding.line_break(""), self._container(), Padding.line_break(""), Padding.fixed_10(self._build_buttons()) ] partition_box = Padding.center_50(ListBox(body)) super().__init__(partition_box)
def __init__(self, model, signal): self.model = model self.signal = signal self.ceph_mon = StringEditor() self.username = StringEditor() self.ceph_key = StringEditor() self.pool = [] body = [ Padding.center_50(self._build_model_inputs()), Padding.line_break(""), Padding.fixed_10(self._build_buttons()) ] super().__init__(ListBox(body))
def show_edit_default_route(self, btn): log.debug("Re-rendering specify default route") self.default_gateway_w = StringEditor( caption="Default gateway will be ") self.gateway_options.contents[-1] = (Padding.center_50( Color.string_input(self.default_gateway_w)), self.gateway_options.options())
def _make_widget(self, form): if form.ip_version == 6: return StringEditor() else: if self.has_mask: allowed = '[0-9./]' else: allowed = '[0-9.]' return RestrictedEditor(allowed)
def __init__(self, model, signal): self.model = model self.signal = signal self.iscsi_host = StringEditor() self.connect_anon = YesNo() self.connect_username = StringEditor() self.connect_password = PasswordEditor() self.server_auth = YesNo() self.server_username = StringEditor() self.server_password = PasswordEditor() body = [ Padding.center_50(self._build_model_inputs()), Padding.line_break(""), Padding.center_50(self._build_menu()), Padding.line_break(""), Padding.center_75(self._build_volume_mount_selector()) ] super().__init__(ListBox(body))
def __init__(self, model, signal, iface): self.model = model self.signal = signal self.iface = iface self.iface_obj = self.model.get_interface(iface) self.essid_input = StringEditor(caption="") self.psk_input = PasswordEditor(caption="") self.body = [ Padding.center_79(self._build_iface_inputs()), Padding.line_break(""), Padding.fixed_10(self._build_buttons()) ] super().__init__(ListBox(self.body))
def __init__(self, model, signal): self.model = model self.signal = signal self.raid_level = Selector(self.model.raid_levels) self.hot_spares = IntegerEditor() self.chunk_size = StringEditor(edit_text="4K") self.selected_disks = [] body = [ Padding.center_50(self._build_disk_selection()), Padding.line_break(""), Padding.center_50(self._build_raid_configuration()), Padding.line_break(""), Padding.fixed_10(self._build_buttons()) ] super().__init__(ListBox(body))
def __init__(self, model, signal, opts): self.model = model self.signal = signal self.opts = opts self.items = [] self.realname = RealnameEditor(caption="") self.hostname = UsernameEditor(caption="") self.username = UsernameEditor(caption="") self.password = PasswordEditor(caption="") self.ssh_import_id = StringEditor(caption="") self.ssh_import_confirmed = True self.error = Text("", align="center") self.confirm_password = PasswordEditor(caption="") body = [ Padding.center_90(self._build_model_inputs()), Padding.line_break(""), Padding.center_90(Color.info_error(self.error)), Padding.line_break(""), Padding.fixed_10(self._build_buttons()), ] super().__init__(ListBox(body))
class AddPartitionView(BaseView): def __init__(self, model, signal, selected_disk): log.debug('AddPartitionView: selected_disk=[{}]'.format(selected_disk)) self.model = model self.signal = signal self.selected_disk = selected_disk self.disk_obj = self.model.get_disk(selected_disk) self.partnum = IntegerEditor(caption="", default=self.disk_obj.lastpartnumber + 1) self.size_str = _humanize_size(self.disk_obj.freespace) self.size = StringEditor(caption="".format(self.size_str)) self.mountpoint = MountEditor(caption="", edit_text="/") self.fstype = Selector(opts=self.model.supported_filesystems) body = [ Columns([ ("weight", 0.2, Text("Adding partition to {}".format(self.disk_obj.devpath), align="right")), ("weight", 0.3, Text("")) ]), Padding.line_break(""), self._container(), Padding.line_break(""), Padding.fixed_10(self._build_buttons()) ] partition_box = Padding.center_50(ListBox(body)) super().__init__(partition_box) def _build_buttons(self): cancel = cancel_btn(on_press=self.cancel) done = done_btn(on_press=self.done) buttons = [ Color.button(done, focus_map='button focus'), Color.button(cancel, focus_map='button focus') ] return Pile(buttons) def _format_edit(self): return Pile(self.fstype.group) def _container(self): total_items = [ Columns([("weight", 0.2, Text("Partition number", align="right")), ("weight", 0.3, Color.string_input(self.partnum, focus_map="string_input focus"))], dividechars=4), Columns([ ("weight", 0.2, Text("Size (max {})".format(self.size_str), align="right")), ("weight", 0.3, Color.string_input(self.size, focus_map="string_input focus")), ], dividechars=4), Columns([("weight", 0.2, Text("Format", align="right")), ("weight", 0.3, Color.string_input(self._format_edit(), focus_map="string_input focus"))], dividechars=4), Columns([("weight", 0.2, Text("Mount", align="right")), ("weight", 0.3, Color.string_input(self.mountpoint, focus_map="string_input focs"))], dividechars=4) ] return Pile(total_items) def cancel(self, button): self.signal.prev_signal() def done(self, result): """ partition spec { 'partition_number': Int, 'size': Int(M|G), 'format' Str(ext4|btrfs.., 'mountpoint': Str } """ def __get_valid_size(size_str): r = '(\d*)(\d+[\.]?\d*)[{}]*$'.format(''.join(HUMAN_UNITS)) match = re.match(r, size_str) log.debug('valid_size: input:{} match:{}'.format(size_str, match)) if match: return match.group(0) return '' def __append_unit(input_size): ''' examine the input for a unit string. if not present, use the unit string from the displayed maximum size returns: number string with unit size ''' unit_regex = '[{}]$'.format(''.join(HUMAN_UNITS)) input_has_unit = re.findall(unit_regex, input_size) log.debug('input:{} re:{}'.format(input_size, input_has_unit)) if len(input_has_unit) == 0: # input does not have unit string displayed_unit = re.search(unit_regex, self.size_str) log.debug('input:{} re:{}'.format(self.size_str, displayed_unit)) input_size += displayed_unit.group(0) return input_size def __get_size(): log.debug('Getting partition size') log.debug('size.value={} size_str={} freespace={}'.format( self.size.value, self.size_str, self.disk_obj.freespace)) if self.size.value == '' or \ self.size.value == self.size_str: log.debug('Using default value: {}'.format( self.disk_obj.freespace)) return int(self.disk_obj.freespace) else: # 120B 120 valid_size = __get_valid_size(self.size.value) if len(valid_size) == 0: return INVALID_PARTITION_SIZE self.size.value = __append_unit(valid_size) log.debug('dehumanize_size({})'.format(self.size.value)) sz = _dehumanize_size(self.size.value) if sz > self.disk_obj.freespace: log.debug( 'Input size too big for device: ({} > {})'.format( sz, self.disk_obj.freespace)) log.warn('Capping size @ max freespace: {}'.format( self.disk_obj.freespace)) sz = self.disk_obj.freespace return sz result = { "partnum": self.partnum.value, "raw_size": self.size.value, "bytes": __get_size(), "fstype": self.fstype.value, "mountpoint": self.mountpoint.value } # Validate size (bytes) input if result['bytes'] in PARTITION_ERRORS: log.error(result['bytes']) self.size.set_error('ERROR: {}'.format(result['bytes'])) return # Validate mountpoint input try: self.model.valid_mount(result) except ValueError as e: log.exception('Invalid mount point') self.mountpoint.set_error('Error: {}'.format(str(e))) log.debug("Invalid mountpoint, try again") return log.debug("Add Partition Result: {}".format(result)) self.signal.emit_signal('filesystem:finish-add-disk-partition', self.disk_obj.devpath, result)