Best Python code snippet using lisa_python
confconsole.py
Source:confconsole.py
...100 ifnames.append(ifname)101 ifnames.sort()102 return ifnames103 @classmethod104 def _get_default_nic(cls):105 def _validip(ifname):106 ip = ifutil.get_ipconf(ifname)[0]107 if ip and not ip.startswith('169'):108 return True109 return False110 ifname = conf.Conf().default_nic111 if ifname and _validip(ifname):112 return ifname113 for ifname in cls._get_filtered_ifnames():114 if _validip(ifname):115 return ifname116 return None117 def _get_advmenu(self):118 items = []119 items.append(("Networking", "Configure appliance networking"))120 if self.installer.available:121 items.append(("Install", "Install to hard disk"))122 items.append(("Reboot", "Reboot the appliance"))123 items.append(("Shutdown", "Shutdown the appliance"))124 #items.append(("Quit", "Quit the configuration console"))125 return items126 def _get_netmenu(self):127 menu = []128 for ifname in self._get_filtered_ifnames():129 addr = ifutil.get_ipconf(ifname)[0]130 ifmethod = ifutil.get_ifmethod(ifname)131 if addr:132 desc = addr133 if ifmethod:134 desc += " (%s)" % ifmethod135 if ifname == self._get_default_nic():136 desc += " [*]"137 else:138 desc = "not configured"139 menu.append((ifname, desc))140 return menu141 def _get_ifconfmenu(self, ifname):142 menu = []143 menu.append(("DHCP", "Configure networking automatically"))144 menu.append(("StaticIP", "Configure networking manually"))145 if not ifname == self._get_default_nic() and \146 len(self._get_filtered_ifnames()) > 1 and \147 ifutil.get_ipconf(ifname)[0] is not None:148 menu.append(("Default", "Show this adapter's IP address in Usage"))149 return menu150 def _get_ifconftext(self, ifname):151 addr, netmask, gateway, nameservers = ifutil.get_ipconf(ifname)152 if addr is None:153 return "Network adapter is not configured\n"154 155 text = "IP Address: %s\n" % addr156 text += "Netmask: %s\n" % netmask157 text += "Default Gateway: %s\n" % gateway158 text += "Name Server(s): %s\n\n" % " ".join(nameservers)159 ifmethod = ifutil.get_ifmethod(ifname)160 if ifmethod:161 text += "Networking configuration method: %s\n" % ifmethod162 if len(self._get_filtered_ifnames()) > 1:163 text += "Is this adapter's IP address displayed in Usage: "164 if ifname == self._get_default_nic():165 text += "yes\n"166 else:167 text += "no\n"168 return text169 def usage(self):170 #if no interfaces at all - display error and go to advanced171 if len(self._get_filtered_ifnames()) == 0:172 self.console.msgbox("Error", "No network adapters detected")173 return "advanced"174 #if interfaces but no default - display error and go to networking175 ifname = self._get_default_nic()176 if not ifname:177 self.console.msgbox("Error", "Networking is not yet configured")178 return "networking"179 #tklbam integration180 try:181 tklbam_status = executil.getoutput("tklbam-status --short")182 except executil.ExecError, e:183 if e.exitcode in (10, 11): #not initialized, no backups184 tklbam_status = e.output185 else:186 tklbam_status = ''187 #display usage188 ipaddr = ifutil.get_ipconf(ifname)[0]189 #hostname = netinfo.get_hostname().upper()190 hostname = netinfo.get_hostname()191 try:192 #backwards compatible - use usage.txt if it exists193 t = file(conf.path("usage.txt"), 'r').read()194 text = Template(t).substitute(hostname=hostname, ipaddr=ipaddr)195 retcode = self.console.msgbox("Usage", text,196 button_label="Advanced Menu")197 except conf.Error:198 t = file(conf.path("services.txt"), 'r').read().rstrip()199 text = Template(t).substitute(ipaddr=ipaddr)200 text += "\n\n%s\n\n" % tklbam_status201 text += "\n" * (self.height - len(text.splitlines()) - 7)202 #text += " TurnKey Backups and Cloud Deployment\n"203 #text += " https://hub.turnkeylinux.org"204 retcode = self.console.msgbox("%s services" % hostname,205 text, button_label="Advanced Menu")206 if retcode is not self.OK:207 self.running = False208 return "advanced"209 def advanced(self):210 #dont display cancel button when no interfaces at all211 no_cancel = False212 if len(self._get_filtered_ifnames()) == 0:213 no_cancel = True214 retcode, choice = self.console.menu("Advanced Menu",215 self.appname + " Advanced Menu\n",216 self._get_advmenu(),217 no_cancel=no_cancel)218 if retcode is not self.OK:219 return "usage"220 return "_adv_" + choice.lower()221 def networking(self):222 ifnames = self._get_filtered_ifnames()223 #if no interfaces at all - display error and go to advanced224 if len(ifnames) == 0:225 self.console.msgbox("Error", "No network adapters detected")226 return "advanced"227 # if only 1 interface, dont display menu - just configure it228 if len(ifnames) == 1:229 self.ifname = ifnames[0]230 return "ifconf"231 # display networking232 text = "Choose network adapter to configure\n"233 if self._get_default_nic():234 text += "[*] This adapter's IP address is displayed in Usage"235 retcode, self.ifname = self.console.menu("Networking configuration",236 text, self._get_netmenu())237 if retcode is not self.OK:238 return "advanced"239 return "ifconf"240 def ifconf(self):241 retcode, choice = self.console.menu("%s configuration" % self.ifname,242 self._get_ifconftext(self.ifname),243 self._get_ifconfmenu(self.ifname))244 if retcode is not self.OK:245 # if multiple interfaces go back to networking246 if len(self._get_filtered_ifnames()) > 1:247 return "networking"...
confconsole
Source:confconsole
...98 ifnames.append(ifname)99 ifnames.sort()100 return ifnames101 @classmethod102 def _get_default_nic(cls):103 def _validip(ifname):104 ip = ifutil.get_ipconf(ifname)[0]105 if ip and not ip.startswith('169'):106 return True107 return False108 ifname = conf.Conf().default_nic109 if ifname and _validip(ifname):110 return ifname111 for ifname in cls._get_filtered_ifnames():112 if _validip(ifname):113 return ifname114 return None115 def _get_advmenu(self):116 items = []117 items.append(("Networking", "Configure appliance networking"))118 if self.installer.available:119 items.append(("Install", "Install to hard disk"))120 items.append(("Reboot", "Reboot the appliance"))121 items.append(("Shutdown", "Shutdown the appliance"))122 items.append(("Quit", "Quit the configuration console"))123 return items124 def _get_netmenu(self):125 menu = []126 for ifname in self._get_filtered_ifnames():127 addr = ifutil.get_ipconf(ifname)[0]128 ifmethod = ifutil.get_ifmethod(ifname)129 if addr:130 desc = addr131 if ifmethod:132 desc += " (%s)" % ifmethod133 if ifname == self._get_default_nic():134 desc += " [*]"135 else:136 desc = "not configured"137 menu.append((ifname, desc))138 return menu139 def _get_ifconfmenu(self, ifname):140 menu = []141 menu.append(("DHCP", "Configure networking automatically"))142 menu.append(("StaticIP", "Configure networking manually"))143 if not ifname == self._get_default_nic() and \144 len(self._get_filtered_ifnames()) > 1 and \145 ifutil.get_ipconf(ifname)[0] is not None:146 menu.append(("Default", "Show this adapter's IP address in Usage"))147 return menu148 def _get_ifconftext(self, ifname):149 addr, netmask, gateway, nameservers = ifutil.get_ipconf(ifname)150 if addr is None:151 return "Network adapter is not configured\n"152 153 text = "IP Address: %s\n" % addr154 text += "Netmask: %s\n" % netmask155 text += "Default Gateway: %s\n" % gateway156 text += "Name Server(s): %s\n\n" % " ".join(nameservers)157 ifmethod = ifutil.get_ifmethod(ifname)158 if ifmethod:159 text += "Networking configuration method: %s\n" % ifmethod160 if len(self._get_filtered_ifnames()) > 1:161 text += "Is this adapter's IP address displayed in Usage: "162 if ifname == self._get_default_nic():163 text += "yes\n"164 else:165 text += "no\n"166 return text167 def usage(self):168 #if no interfaces at all - display error and go to advanced169 if len(self._get_filtered_ifnames()) == 0:170 self.console.msgbox("Error", "No network adapters detected")171 return "advanced"172 #if interfaces but no default - display error and go to networking173 ifname = self._get_default_nic()174 if not ifname:175 self.console.msgbox("Error", "Networking is not yet configured")176 return "networking"177 #tklbam integration178 try:179 tklbam_status = executil.getoutput("tklbam-status --short")180 except executil.ExecError, e:181 if e.exitcode in (10, 11): #not initialized, no backups182 tklbam_status = e.output183 else:184 tklbam_status = ''185 #display usage186 ipaddr = ifutil.get_ipconf(ifname)[0]187 hostname = netinfo.get_hostname().upper()188 try:189 #backwards compatible - use usage.txt if it exists190 t = file(conf.path("usage.txt"), 'r').read()191 text = Template(t).substitute(hostname=hostname, ipaddr=ipaddr)192 retcode = self.console.msgbox("Usage", text,193 button_label="Advanced Menu")194 except conf.Error:195 t = file(conf.path("services.txt"), 'r').read().rstrip()196 text = Template(t).substitute(ipaddr=ipaddr)197 text += "\n\n%s\n\n" % tklbam_status198 text += "\n" * (self.height - len(text.splitlines()) - 7)199 text += " TurnKey Backups and Cloud Deployment\n"200 text += " https://hub.turnkeylinux.org"201 retcode = self.console.msgbox("%s appliance services" % hostname,202 text, button_label="Advanced Menu")203 if retcode is not self.OK:204 self.running = False205 return "advanced"206 def advanced(self):207 #dont display cancel button when no interfaces at all208 no_cancel = False209 if len(self._get_filtered_ifnames()) == 0:210 no_cancel = True211 retcode, choice = self.console.menu("Advanced Menu",212 self.appname + " Advanced Menu\n",213 self._get_advmenu(),214 no_cancel=no_cancel)215 if retcode is not self.OK:216 return "usage"217 return "_adv_" + choice.lower()218 def networking(self):219 ifnames = self._get_filtered_ifnames()220 #if no interfaces at all - display error and go to advanced221 if len(ifnames) == 0:222 self.console.msgbox("Error", "No network adapters detected")223 return "advanced"224 # if only 1 interface, dont display menu - just configure it225 if len(ifnames) == 1:226 self.ifname = ifnames[0]227 return "ifconf"228 # display networking229 text = "Choose network adapter to configure\n"230 if self._get_default_nic():231 text += "[*] This adapter's IP address is displayed in Usage"232 retcode, self.ifname = self.console.menu("Networking configuration",233 text, self._get_netmenu())234 if retcode is not self.OK:235 return "advanced"236 return "ifconf"237 def ifconf(self):238 retcode, choice = self.console.menu("%s configuration" % self.ifname,239 self._get_ifconftext(self.ifname),240 self._get_ifconfmenu(self.ifname))241 if retcode is not self.OK:242 # if multiple interfaces go back to networking243 if len(self._get_filtered_ifnames()) > 1:244 return "networking"...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!