def start(self, **kwargs): # Get the session host = kwargs['session'] if kwargs['options'].device: dev_string = kwargs['options'].device.replace(" ", "_") else: name = kwargs['session'].name dev_string = ".".join( re.findall(r"[\w']+", "_".join(name.split(" ")[1:]))) CFG_BKP_FILE = dev_string + ".cfg_bkup" aulog.debug("Backing up configurations in file %s..." % (CFG_BKP_FILE)) try: host.expect_exact("#", timeout=15) except: pass try: # Set terminal length host.sendline("terminal length 0") host.expect_exact("#") # Pass CLI's to box host.sendline("show running") status = host.expect_exact(["end\r\n", INVALID_INPUT, EOF], timeout=tout_cmd) self.save_configs(host.before, CFG_BKP_FILE) if status != 0: aulog.info("Unxpected statements") return -1 status = host.expect_exact("#", timeout=tout_cmd) except Exception as e: aulog.debug( "Command: Timed out, before considering this as failure") aulog.debug(str(e)) aulog.debug(host.before) return -1 # reset terminal length host.sendline("terminal length 100") try: host.expect_exact("#") except: aulog.debug(host.before) aulog.debug( "Command: Timed out, before considering this as failure") return -1 return 0
def start(self, **kwargs): # Get the session host = kwargs['session'] if kwargs['options'].device : dev_string = kwargs['options'].device.replace(" ","_") else : name = kwargs['session'].name dev_string = ".".join(re.findall(r"[\w']+","_".join(name.split(" ")[1:]))) CFG_BKP_FILE = dev_string + ".cfg_bkup" aulog.debug("Backing up configurations in file %s..."%(CFG_BKP_FILE)) try : host.expect_exact("#", timeout = 15) except: pass try: # Set terminal length host.sendline("terminal length 0") host.expect_exact("#") # Pass CLI's to box host.sendline("show running") status = host.expect_exact( ["end\r\n", INVALID_INPUT, EOF], timeout = tout_cmd) self.save_configs(host.before, CFG_BKP_FILE) if status != 0: aulog.info("Unxpected statements") return -1 status = host.expect_exact( "#", timeout = tout_cmd) except Exception as e: aulog.debug("Command: Timed out, before considering this as failure") aulog.debug(str(e)) aulog.debug(host.before) return -1 # reset terminal length host.sendline("terminal length 100") try: host.expect_exact("#") except : aulog.debug(host.before) aulog.debug("Command: Timed out, before considering this as failure") return -1 return 0
def start(self, **kwargs): """ Start the plugin Return -1 if the plugin has found a fatal error, 0 otherwise. """ host = kwargs['session'] pkg_path = kwargs['repository'] if (not pkg_path): aulog.error( "Couldn't ping, package repository path is not provided") return -1 try: host.expect_exact("#", timeout=30) except: pass pat = re.compile('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') ipaddr = re.findall(pat, pkg_path) protocol = ['tftp:', 'sftp:', 'ftp:'] list = [' '] list = pkg_path.split('/') if not len(ipaddr): aulog.error("Invalid TFTP address ") return -1 if (len(list[0]) if list[0] else list[1] in protocol): cmd = "ping " + ipaddr[0] aulog.info(cmd) host.sendline(cmd) try: status = host.expect_exact( [INVALID_INPUT, MORE, "#", PROMPT, EOF], timeout=tout_cmd) except: aulog.warning( """Command: Timed out, before considering this as failure. Please check consolelog file for details""") return 0 out = host.before if (out.find('Success rate is 0') != -1 or out.find('Bad hostname or protocol not running') != -1 or out.find('UUUUU') != -1): aulog.warning("TFTP server %s is not reachable from device" % (ipaddr)) return 0 return 0
def start(self, **kwargs): """ Start the plugin Return -1 if the plugin has found a fatal error, 0 otherwise. """ host = kwargs['session'] pkg_path = kwargs['repository'] if (not pkg_path): aulog.error("Couldn't ping, package repository path is not provided") return -1 try : host.expect_exact("#", timeout=30) except : pass pat = re.compile('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') ipaddr = re.findall(pat, pkg_path) protocol =['tftp:', 'sftp:', 'ftp:'] list = [' ']; list = pkg_path.split('/') if not len(ipaddr) : aulog.error("Invalid TFTP address ") return -1 if ( len(list[0]) if list[0] else list[1] in protocol): cmd = "ping "+ipaddr[0] aulog.info(cmd) host.sendline(cmd) try : status = host.expect_exact( [INVALID_INPUT, MORE, "#", PROMPT, EOF], timeout = tout_cmd) except : aulog.warning("""Command: Timed out, before considering this as failure. Please check consolelog file for details""") return 0 out = host.before if (out.find('Success rate is 0') != -1 or out.find('Bad hostname or protocol not running') != -1 or out.find('UUUUU') != -1): aulog.warning("TFTP server %s is not reachable from device"%(ipaddr)) return 0 return 0
def print_success(str): aulog.info(str)
def start(self, **kwargs): """ Starts all the plugins in order @throw PluginError when a plugin could not be initialized """ # holds status of all plugins we run results={} # common parameters we pass to all plugins host = kwargs['session'] option = kwargs['options'] kwargs['results']= results plugin_type ="" if len(self.plugins) != 0: self.sequence_plugins(option) #self.load_plugins() if option.preupgradeset: plugin_type = "PreUpgrade" if option.upgradeset: plugin_type ="" elif option.postupgradeset: plugin_type="PostUpgrade" elif option.upgradeset: plugin_type="Upgrade" host.sendline("terminal len 0") try : status = host.expect_exact( [INVALID_INPUT, MORE, "#", LOGIN_PROMPT_ERR, EOF], timeout=20) except: pass try : status=1 status = host.expect_exact( ['#'], timeout=20) except: pass #print "Setting term len to zero", status pno = 1; for (name, i) in self.plugins: aulog.info("++++"*5+ bcolors.HEADER +" (%d) (%s) Check "%(pno, i.plugin_type)+ bcolors.ENDC+"++++"*5) aulog.info("\nStarting => %s...."%(i.plugin_name)) status = i.start(**kwargs) return_status = {i.plugin_name:status} results.update(return_status) if status == SUCCESS or status == SYSTEM_RELOADED or status == INSTALL_METHOD_PROCESS_RESTART : aulog.info(bcolors.OKGREEN +"\nPassed => %s\n"%(i.plugin_name)+ bcolors.ENDC) elif status == IGNORE: aulog.info(bcolors.WARNING +"\nIgnoring => %s\n"%(i.plugin_name)+ bcolors.ENDC) else : if not option.ignore_fail: aulog.error(bcolors.FAIL+"\nFailed => %s\n"%(i.plugin_name)+ bcolors.ENDC) else : aulog.ignore_error(bcolors.FAIL+"\nFailed => %s\n"%(i.plugin_name)+ bcolors.ENDC) self.active.append((name, i)) pno = pno + 1 sleep(1) if pno == 1: aulog.info(bcolors.HEADER + "++++"*5+" Notice "+"++++"*5 + bcolors.ENDC) aulog.info(bcolors.WARNING +"Didn't find any plugins of type ** %s **"%(plugin_type)) aulog.info(bcolors.HEADER + "++++"*5+" Done "+"++++"*5 + bcolors.ENDC) return status