def get_ftp_dest(answers): text = "Please enter the URL for your FTP directory and, optionally, a username and password" url_field = snack.Entry(50) user_field = snack.Entry(16) passwd_field = snack.Entry(16, password=1) url_text = snack.Textbox(11, 1, "URL:") user_text = snack.Textbox(11, 1, "Username:"******"Password:"******"Specify Path", 'getftpdest', 1, 3) bb = snack.ButtonBar(tui.screen, ['Ok', 'Back']) t = snack.TextboxReflowed(50, text) entry_grid = snack.Grid(2, 3) entry_grid.setField(url_text, 0, 0) entry_grid.setField(url_field, 1, 0) entry_grid.setField(user_text, 0, 1) entry_grid.setField(user_field, 1, 1, anchorLeft=1) entry_grid.setField(passwd_text, 0, 2) entry_grid.setField(passwd_field, 1, 2, anchorLeft=1) gf.add(t, 0, 0, padding=(0, 0, 0, 1)) gf.add(entry_grid, 0, 1, padding=(0, 0, 0, 1)) gf.add(bb, 0, 2, growx=1) button = bb.buttonPressed(gf.runOnce()) if button == 'back': return uicontroller.LEFT_BACKWARDS url = url_field.value() if not url.startswith('ftp://'): url = 'ftp://' + url if user_field.value() != '': quoted_user = urllib.quote(user_field.value(), safe='') if passwd_field.value() != '': quoted_passwd = urllib.quote(passwd_field.value(), safe='') answers['dest-address'] = url.replace( '//', '//%s:%s@' % (quoted_user, quoted_passwd), 1) else: answers['dest-address'] = url.replace('//', '//%s@' % quoted_user, 1) else: answers['dest-address'] = url return uicontroller.RIGHT_FORWARDS
def __init__(self, screen, tui): self.screen = screen self.tui = tui self.tui.alreadyRegistered = 0 self.server = self.tui.serverURL size = snack._snack.size() toplevel = snack.GridForm(screen, REGISTER_WINDOW.encode('utf-8'), 1, 4) decoded_server = convert_url_from_pune(self.server) url = self.server if decoded_server != self.server: url += " (%s)" % decoded_server login_prompt = LOGIN_PROMPT % url login_label = LOGIN login_tip = LOGIN_TIP label = snack.Textbox(size[0] - 10, 3, login_prompt.encode('utf-8'), scroll=0, wrap=1) toplevel.add(label, 0, 0, anchorLeft=1) grid = snack.Grid(2, 3) label = snack.Label(login_label.encode('utf-8')) grid.setField(label, 0, 0, padding=(0, 0, 1, 0), anchorRight=1) self.userNameEntry = snack.Entry(20) self.userNameEntry.set(tui.userName) grid.setField(self.userNameEntry, 1, 0, anchorLeft=1) label = snack.Label(PASSWORD.encode('utf-8')) grid.setField(label, 0, 1, padding=(0, 0, 1, 0), anchorRight=1) try: self.passwordEntry = snack.Entry(20, password=1) except TypeError: self.passwordEntry = snack.Entry(20, hidden=1) self.passwordEntry.set(tui.password) grid.setField(self.passwordEntry, 1, 1, anchorLeft=1) toplevel.add(grid, 0, 1) label = snack.TextboxReflowed(size[0] - 10, login_tip.encode('utf-8')) toplevel.add(label, 0, 2, anchorLeft=1) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"), (BACK.encode('utf-8'), "back"), (CANCEL.encode('utf-8'), "cancel")]) toplevel.add(self.bb, 0, 3, padding=(0, 1, 0, 0), growx=1) self.g = toplevel
def __init__(self, screen, tui): self.screen = screen self.tui = tui self.tui.alreadyRegistered = 0 self.server = convert_url_from_puny(self.tui.serverURL) fixed_server_url = rhnreg.makeNiceServerUrl(self.server) #Save the config only if the url is different if fixed_server_url != self.server: self.server = fixed_server_url config.setServerURL(self.server) cfg.save() size = snack._snack.size() toplevel = snack.GridForm(screen, sstr(SATELLITE_URL_WINDOW), 1, 4) prompt_text = SATELLITE_URL_TEXT url_label = SATELLITE_URL_PROMPT ssl_label = SATELLITE_URL_PROMPT2 label = snack.Textbox(size[0] - 10, 3, sstr(prompt_text), scroll=0, wrap=1) toplevel.add(label, 0, 0, anchorLeft=1) # spacer label = snack.Label(sstr("")) toplevel.add(label, 0, 1) grid = snack.Grid(2, 3) label = snack.Label(sstr(url_label)) grid.setField(label, 0, 0, padding=(0, 0, 1, 0), anchorRight=1) self.urlEntry = snack.Entry(40) self.urlEntry.set(self.server) grid.setField(self.urlEntry, 1, 0, anchorLeft=1) label = snack.Label(sstr(ssl_label)) grid.setField(label, 0, 1, padding=(0, 0, 1, 0), anchorRight=1) self.sslEntry = snack.Entry(40) self.sslEntry.set(tui.sslCACert) grid.setField(self.sslEntry, 1, 1, anchorLeft=1) toplevel.add(grid, 0, 2) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(sstr(NEXT), "next"), (sstr(BACK), "back"), (sstr(CANCEL), "cancel")]) toplevel.add(self.bb, 0, 3, padding=(0, 1, 0, 0), growx=1) self.g = toplevel
def get_ram_and_cpu_page(self, screen): ignore = screen self.__memory = snack.Entry(10, str(self.__config.get_memory())) self.__cpus = snack.Entry(10, str(self.__config.get_cpus())) grid = snack.Grid(2, 2) grid.setField(snack.Label("Memory (RAM):"), 0, 0, anchorRight=1) grid.setField(self.__memory, 1, 0, anchorLeft=1) grid.setField(snack.Label("CPUs:"), 0, 1, anchorRight=1) grid.setField(self.__cpus, 1, 1, anchorLeft=1) return [snack.Label("Choose memory and CPU settings"), grid]
def get_network_install_page(self, screen): ignore = screen self.__install_url = snack.Entry(50, self.__config.get_install_url()) self.__kickstart_url = snack.Entry(50, self.__config.get_kickstart_url()) self.__kernel_options = snack.Entry(50, self.__config.get_kernel_options()) grid = snack.Grid(2, 3) grid.setField(snack.Label("URL:"), 0, 0, anchorRight=1) grid.setField(self.__install_url, 1, 0, anchorLeft=1) grid.setField(snack.Label("Kickstart URL:"), 0, 1, anchorRight=1) grid.setField(self.__kickstart_url, 1, 1, anchorLeft=1) grid.setField(snack.Label("Kernel Options:"), 0, 2, anchorRight=1) grid.setField(self.__kernel_options, 1, 2, anchorLeft=1) return [snack.Label("Provide the operating system URL"), grid]
def get_details_page(self, screen): if not self.__configured: self.__hypervisor = snack.RadioBar( screen, ((HYPERVISORS[HYPERVISOR_XEN], HYPERVISOR_XEN, True), (HYPERVISORS[HYPERVISOR_KVM], HYPERVISOR_KVM, False))) self.__connection = snack.RadioBar( screen, ((CONNECTIONS[CONNECTION_LOCAL], CONNECTION_LOCAL, True), (CONNECTIONS[CONNECTION_KERBEROS], CONNECTION_KERBEROS, False), (CONNECTIONS[CONNECTION_SSL], CONNECTION_SSL, False), (CONNECTIONS[CONNECTION_SSH], CONNECTION_SSH, False))) self.__hostname = snack.Entry(50, "") self.__autoconnect = snack.Checkbox("Autoconnect on Startup") self.__configured = True grid = snack.Grid(2, 4) grid.setField(snack.Label("Hypervisor:"), 0, 0, anchorRight=1, anchorTop=1) grid.setField(self.__hypervisor, 1, 0, anchorLeft=1) grid.setField(snack.Label("Connection:"), 0, 1, anchorRight=1, anchorTop=1) grid.setField(self.__connection, 1, 1, anchorLeft=1) grid.setField(snack.Label("Hostname:"), 0, 2, anchorRight=1) grid.setField(self.__hostname, 1, 2, anchorLeft=1) grid.setField(snack.Label(""), 0, 3, anchorRight=1) grid.setField(self.__autoconnect, 1, 3, anchorLeft=1) return [snack.Label("Add Connection"), grid]
def askuserIP(self, nodename): # # ask the user for an IP address # done = 0 while not done: entry = snack.Entry(15) rc, values = snack.EntryWindow( self.screen, _("IP Address Selection"), _("Enter the IP address for host %s") % (nodename), [(_("IP Address"), entry)], buttons=['Ok']) ipaddr = entry.value() try: nodeid = self.sql.getNodeId(ipaddr) if nodeid: msg = "Duplicate IP '%s' Specified" % ipaddr raise rocks.util.CommandError, msg self.setIPaddr(ipaddr) done = 1 except rocks.util.CommandError: snack.ButtonChoiceWindow(self.screen, _("Duplicate IP"), _("The IP address (%s) already exists.\n\n" \ % (ipaddr) + "Please select another."), buttons = [ _("OK") ]) return ipaddr
def get_max_capacity_page(self, screen): ignore = screen self.__capacity = snack.Entry(6, str(self.__config.get_max_capacity())) self.__allocation = snack.Entry(6, str(self.__config.get_allocation())) grid = snack.Grid(2, 2) grid.setField(snack.Label("Max. Capacity (MB):"), 0, 0, anchorRight=1) grid.setField(self.__capacity, 1, 0, anchorLeft=1) grid.setField(snack.Label("Allocation (MB):"), 0, 1, anchorRight=1) grid.setField(self.__allocation, 1, 1, anchorLeft=1) return [ snack.Label("Storage Volume Quota"), snack.Label( "%s's available space: %s" % (self.__config.get_pool().name(), utils.size_as_mb_or_gb(self.__config.get_pool().info()[3]))), grid ]
def get_select_iso_page(self, screen): ignore = screen self.__iso_path = snack.Entry(50, self.__config.get_iso_path()) grid = snack.Grid(1, 2) grid.setField(snack.Label("Enter ISO path:"), 0, 0, anchorLeft=1) grid.setField(self.__iso_path, 0, 1, anchorLeft=1) return [snack.Label("Enter the full path to an install ISO"), grid]
def get_local_storage_page(self, screen): ignore = screen self.__storage_size = snack.Entry(6, str(self.__config.get_storage_size())) self.__allocate_storage = snack.Checkbox("Allocate entire disk now", self.__config.get_allocate_storage()) grid = snack.Grid(2, 2) grid.setField(self.__allocate_storage, 0, 0, growx=1, anchorLeft=1) grid.setField(snack.Label("Storage size (GB):"), 0, 1, anchorLeft=1) grid.setField(self.__storage_size, 1, 1) return [snack.Label("Configure local storage"), grid]
def get_details_page(self, screen): ignore = screen if self.__username is None: self.__username = snack.Entry(50, "") self.__password = snack.Entry(50, "", password=1) self.__confirm = snack.Entry(50, "", password=1) self.__adminuser = snack.Checkbox("This user is an administrator", False) grid = snack.Grid(2, 4) grid.setField(snack.Label("Username:"******"Password:"******"Confirm password:"******" "), 0, 3) grid.setField(self.__adminuser, 1, 3, anchorLeft=1) return [snack.Label("Enter The User Details"), grid]
def get_bridge_page(self, screen): bridges = [] for bridge in self.get_libvirt().list_bridges(): bridges.append(["Virtual network '%s'" % bridge.name(), bridge.name(), self.__config.get_network_bridge() is bridge.name()]) self.__network_bridges = snack.RadioBar(screen, (bridges)) if self.__config.get_mac_address() is None: self.__config.set_mac_address(self.get_libvirt().generate_mac_address()) self.__mac_address = snack.Entry(20, self.__config.get_mac_address()) grid = snack.Grid(1, 1) grid.setField(self.__network_bridges, 0, 0) return [snack.Label("Select an existing bridge"), grid]
def get_volume_name_page(self, screen): ignore = screen self.__name = snack.Entry(50, self.__config.get_name()) grid = snack.Grid(2, 1) grid.setField(snack.Label("Name:"), 0, 0, anchorRight=1) grid.setField(self.__name, 1, 0, anchorLeft=1) return [ snack.Label("New Storage Volume"), grid, snack.Label( "Name of the volume to create. File extension may be appended." ) ]
def _EntryWindow(screen, header, text, entries, buttons): btns = snack.ButtonBar(screen, buttons) form = _SnackWindow(screen, header, text, 2) entries = [e if isinstance(e, tuple) else (e, "") for e in entries] entryList = [] for label, entry in entries: if label.startswith('_'): _label = snack.Label(label[1:]) _entry = snack.Entry(EDIT_WIDTH, entry, password=True) elif label.startswith('='): _label = snack.Label(label[1:]) _entry = snack.Entry(EDIT_WIDTH, entry) _entry.setFlags(snack.FLAG_DISABLED, snack.FLAGS_SET) else: _label = snack.Label(label[0:]) _entry = snack.Entry(EDIT_WIDTH, entry) entryList.append((_label, _entry)) grid = snack.Grid(2, len(entryList)) for index, (label, entry) in enumerate(entryList): grid.setField(label, 0, index, padding=(0, 0, 1, 0), anchorLeft=1) grid.setField(entry, 1, index, anchorLeft=1) form.add(grid, 0, 1, padding=(0, 0, 0, 1)) form.add(btns, 0, 2, growx=1) if buttons[1:]: form.addHotKey('ESC') result = form.runOnce() values = [entry.value() for label, entry in entryList] if result == 'F12': return values elif (btns.buttonPressed(result) == buttons[0].lower()): return values else: raise KeyboardInterrupt()
def __init__(self, dev=None): """ The constructor @screen A snack screen instance """ self.dev = dev self.name = snack.Entry(20, "") self.hwdev = snack.Entry(20, "") self.dynip = snack.Checkbox("") self.statip = snack.Entry(20, "") self.netmask = snack.Entry(20, "") self.gwy = snack.Entry(20, "") self.ioport = snack.Entry(20, "") self.ioport1 = snack.Entry(20, "") self.ioport2 = snack.Entry(20, "") self.options = snack.Entry(20, "") self.macaddr = snack.Entry(20, "") self.screen = None if dev: self.setState()
def _make_grid_input_path(insScreen, title, label, strText): l = snack.Label(label) l1 = snack.Label(" ") e = snack.Entry(50, strText) b = snack.ButtonBar(insScreen, ((" OK ", "ok"), (" Cancel ", "cancel"))) g = snack.GridForm(insScreen, title, 3, 6) g.add(l, 0, 1) g.add(l1, 0, 2) g.add(e, 0, 3) g.add(l1, 0, 4) g.add(b, 0, 5) return e, b, g
def _make_grid_search(insScreen, search_id): l = snack.Label("Search Value:") l1 = snack.Label(" ") e = snack.Entry(30, search_id) b = snack.ButtonBar(insScreen, (("Search", "search"), ("Search off", "cancel"))) g = snack.GridForm(insScreen, "Enter Search String", 3, 6) g.add(l, 0, 1) g.add(l1, 0, 2) g.add(e, 0, 3) g.add(l1, 0, 4) g.add(b, 0, 5) return e, b, g
def __init__(self, plist=None): """ The constructor """ self.hostname = snack.Entry(15, "") self.domainname = snack.Entry(15, "") self.primaryDNS = snack.Entry(15, "") self.secondaryDNS = snack.Entry(15, "") self.tertiaryDNS = snack.Entry(15, "") #self.SearchList = SearchList() self.searchList = snack.Entry(15, "") self.prof = plist.getActiveProfile()
def get_vm_details_page(self, screen): self.__guest_name = snack.Entry(50, self.__config.get_guest_name()) self.__install_type = snack.RadioBar(screen, (("Local install media (ISO image or CDROM)", DomainConfig.LOCAL_INSTALL, self.__config.is_install_type(DomainConfig.LOCAL_INSTALL)), ("Network Install (HTTP, FTP, or NFS)", DomainConfig.NETWORK_INSTALL, self.__config.is_install_type(DomainConfig.NETWORK_INSTALL)), ("Network Boot (PXE)", DomainConfig.PXE_INSTALL, self.__config.is_install_type(DomainConfig.PXE_INSTALL)))) grid = snack.Grid(2, 3) grid.setField(snack.Label("Name:"), 0, 0, anchorRight=1) grid.setField(self.__guest_name, 1, 0, anchorLeft=1) grid.setField(snack.Label("Choose how you would like to install the operating system"), 1, 1, anchorLeft=1, anchorTop=1) grid.setField(self.__install_type, 1, 2, anchorLeft=1) return [snack.Label("Enter your machine details"), grid]
def getEntriesGrid(self): ''' This function will return the entries grid built from the Entries List considering the colums ''' EntriesGrid=snack.Grid(self.columns *2,len(self.Entries)) self.Members={} k=0 # acts as X z=-1 # acts as Y for i in range(0,len(self.Entries)): if i % self.columns == 0: z=z+1 k=0 L=snack.Label(text=str(self.Entries[i][0])) E=snack.Entry(width=self.width,text=str(self.Entries[i][1])) EntriesGrid.setField(L,k+i%self.columns,z,padding=(1,0,0,0)) #Set the label EntriesGrid.setField(E,k+1+i%self.columns,z,padding=(1,0,0,0)) #Set the entry self.Members[str(self.Entries[i][0])]=E k=k+1 return EntriesGrid
def __init__(self, dev): """ The constructor @screen A snack screen instance @devicelist A NCDeviceList @dev The devernet device. If none given, the first devernetdevice in devicelist will be used. If none are there, one will be added. """ self.dev = dev self.name = snack.Entry(20, "") self.hwdev = snack.Entry(20, "") self.dynip = snack.Checkbox("") self.statip = snack.Entry(20, "") self.netmask = snack.Entry(20, "") self.dnsserver1 = snack.Entry(20, "") self.dnsserver2 = snack.Entry(20, "") self.gwy = snack.Entry(20, "") self.screen = None
def __init__(self, modem=None): """ The constructor @screen A snack screen instance @devicelist A NCDeviceList @modem The modem device. If none given, the first modem in devicelist will be used. If none are there, one will be added. """ self.name = snack.Entry(20, "") self.hwdev = snack.Entry(20, "") self.login = snack.Entry(20, "") self.phoneno = snack.Entry(20, "") self.password = snack.Entry(20, "", password=1) self.initstring = snack.Entry(20, "") self.modem = modem self.screen = None
def __init__(self, isdn=None): """ The constructor @screen A snack screen instance @devicelist A NCDeviceList @isdn The ISDN device. If none given, the first isdndevice in devicelist will be used. If none are there, one will be added. """ self.name = snack.Entry(20, "") self.hwdev = snack.Entry(20, "") self.login = snack.Entry(20, "") self.phoneno = snack.Entry(20, "") self.password = snack.Entry(20, "", password=1) self.msn = snack.Entry(20, "") self.isdn = isdn
def askuserIP(self, nodename): # # ask the user for an IP address # done = 0 while not done: entry = snack.Entry(15) rc, values = snack.EntryWindow( self.screen, _("IP Address Selection"), _("Enter the IP address for host %s") % (nodename), [(_("IP Address"), entry)], buttons=['Ok']) ipaddr = entry.value() try: query = 'select id from networks where ' +\ 'ip="%s"' % ipaddr rows = self.sql.execute(query) if rows: raise ValueError, "Duplicate IP" self.setIPaddr(ipaddr) done = 1 except ValueError: msg = _("The IP address (%s) " % ipaddr +\ "already exists.\n" ) +\ _("Please select another.") snack.ButtonChoiceWindow(self.screen, _("Duplicate IP"), msg, buttons=[_("OK")]) return ipaddr
def __init__(self, screen, tui): self.screen = screen self.tui = tui size = snack._snack.size() #get the virtualization uuid and set it to other. (virt_uuid, virt_type) = rhnreg.get_virt_info() if not virt_uuid is None: self.tui.other['virt_uuid'] = virt_uuid self.tui.other['virt_type'] = virt_type # read all hardware in tui.hardware = hardware.Hardware() toplevel = snack.GridForm(screen, HARDWARE_WINDOW.encode('utf-8'), 1, 7) text = snack.TextboxReflowed(70, HARDWARE_WINDOW_DESC1.encode('utf-8')) toplevel.add(text, 0, 0, anchorLeft=1) grid = snack.Grid(2, 2) label = snack.Label(_("Profile name:").encode('utf-8')) grid.setField(label, 0, 0, padding=(0, 0, 1, 0), anchorRight=1) self.profileEntry = snack.Entry(40) grid.setField(self.profileEntry, 1, 0, anchorLeft=1) toplevel.add(grid, 0, 1, anchorLeft=1) if tui.includeHardware: self.hardwareButton = snack.Checkbox( HARDWARE_WINDOW_CHECKBOX.encode('utf-8'), isOn=1) else: self.hardwareButton = snack.Checkbox( HARDWARE_WINDOW_CHECKBOX.encode('utf-8')) toplevel.add(self.hardwareButton, 0, 2, padding=(0, 1, 0, 0), anchorLeft=1) label = snack.Label(DESELECT.encode('utf-8')) toplevel.add(label, 0, 3, anchorLeft=1, padding=(0, 0, 0, 1)) grid = snack.Grid(4, 3) hardware_text = '' hardware_text += _("Version: ") + up2dateUtils.getVersion() + " " self.versionLabel = snack.Label(_("Version: ").encode('utf-8')) grid.setField(self.versionLabel, 0, 0, padding=(0, 0, 1, 0), anchorLeft=1) self.versionLabel2 = snack.Label(up2dateUtils.getVersion()) grid.setField(self.versionLabel2, 1, 0, anchorLeft=1) hardware_text += _("CPU model: ") for hw in tui.hardware: if hw['class'] == 'CPU': hardware_text += hw['model'] + "\n" hardware_text += _("Hostname: ") for hw in tui.hardware: if hw['class'] == 'NETINFO': unicode_hostname = idn_pune_to_unicode(hw['hostname']) hardware_text += unicode_hostname + "\n" if tui.profileName != "": self.profileEntry.set(tui.profileName) else: self.profileEntry.set(unicode_hostname.encode('utf-8')) hardware_text += _("CPU speed: ") for hw in tui.hardware: if hw['class'] == 'CPU': hardware_text += _("%d MHz") % hw['speed'] + " " hardware_text += _("IP Address: ") for hw in tui.hardware: if hw['class'] == 'NETINFO': if hw['ipaddr']: hardware_text += hw['ipaddr'] + " " elif hw['ip6addr']: hardware_text += hw['ip6addr'] + " " hardware_text += _("Memory: ") for hw in tui.hardware: if hw['class'] == 'MEMORY': hardware_text += _("%s megabytes") % hw['ram'] tb = snack.TextboxReflowed(80, hardware_text.encode('utf-8')) toplevel.add(tb, 0, 4) self.additionalHWLabel = snack.TextboxReflowed( size[0] - 10, HARDWARE_WINDOW_DESC2.encode('utf-8')) toplevel.add(self.additionalHWLabel, 0, 5, padding=(0, 1, 0, 0), anchorLeft=1) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"), (BACK.encode('utf-8'), "back"), (CANCEL.encode('utf-8'), "cancel")]) toplevel.add(self.bb, 0, 6, padding=(0, 1, 0, 0), growx=1) self.g = toplevel