def __init__(self, **kw): utils.__init__(self, **kw) self.multi = False if kw.has_key('multi'): self.multi = True if self.multi: self.silent = True self.info("uploading %s to %s..." % (self.binfile, self.hostname)) self.uploadinfo = {} self.pe = pelogon(hostname=self.hostname, options=self.options, silent=self.silent) if self.multi: self.checkbinfile() if self.uploadinfo['binfilestatus'].has_key('error'): ferror = self.uploadinfo['binfilestatus']['error'] if 'local' in ferror: self.warning(ferror) else: self.warning(self.uploadinfo['binfilestatus']['error']) self.pe.scp() self.checkbinfile() self.info(self.uploadinfo['binfilestatus']) else: self.info(self.uploadinfo['binfilestatus']) else: self.pe.scp() self.checkbinfile() self.pe.exit() if self.multi: os._exit(0)
def checkMGG(self): self.getMGG() if len(self.mgg)>0: for mgg in self.mgg: self.info('checking for blocked ports on %s...' % mgg) mggpe=pelogon(hostname=mgg,options=self.options,logfile=self.peclog) mggpe.checkBlocked() mggpe.exit() if len(mggpe.errors[mgg]['critical'])>0: self.combineerrors(mggpe.errors[mgg])
def __init__(self,**kw): """ get opengear connection from mysql and test connection check that binary file is valid (on device md5 matches) run pre-checks and check for errors update the alternate boot loader and change the configuration so next reload upgrades """ utils.__init__(self,**kw) self.info("----------------\npreparing %s for upgrade..." % self.hostname,attrs='bold') self.loaddevinfo() self.bfsw='' self.mgg=None #reset log files if (self.devinfo.has_key('prepstatus') and self.devinfo['prepstatus']=='success' and self.options.noforce): self.info("Looks like this device has already been prepared, moving on...",attrs='bold') self.info("please delete %s to force!" % self.devinfofile) #self.checkOG() else: self.resetlogs() self.getOGdetails() if 'error' not in self.devinfo['oginfo']: self.checkOG() self.checkMGG() self.info('--connecting to device via ssh') self.pe=pelogon(hostname=self.hostname,options=self.options) self.pe.getbootinfo() self.devinfo['bootinfo']=self.pe.bootinfo self.checkbinfile() if self.bfsw==self.devinfo['bootinfo']['primary']['version'] and self.options.noforce: self.critical("Looks like this switch is already running %s, please check you are looking at the correct switch!" % self.bfsw) elif self.devinfo['binfilestatus'].has_key('error'): self.info(self.devinfo['binfilestatus']['error']) else: self.version=self.pe.bootinfo['primary']['version'] if self.devinfo['oginfo'].has_key('mgmtip'): if self.pe.prompt != self.og.prompt: self.critical('The prompt on the opengear (%s) does the one on the switch (%s)! Please investigate!' % (self.og.prompt,self.pe.prompt)) else: self.pe.runchecks('pre') if len(self.pe.errors[self.hostname]['critical'])<1: self.info('---updating boot info, this may take a little while...') self.updateBoot() #closing connection self.info('--exiting device...') self.pe.exit() self.combineerrors(self.pe.errors[self.hostname]) self.devinfo['errors']={'prepare':self.errors[self.hostname]} if len(self.errors[self.hostname]['critical'])>0: self.devinfo['prepstatus']='fail' self.warning('\nErrors found during preparation please check the logs!') else: self.devinfo['prepstatus']='success' self.info('\npreparation completed successfully feel free to upgrade',attrs='bold') self.writedevinfo()
def __init__(self, **kw): utils.__init__(self, **kw) self.info("backing out of %s..." % self.hostname) self.loaddevinfo() self.info('--connecting to device') self.pe = pelogon(hostname=self.hostname, options=self.options) self.info('---restoring boot config') self.pe.setBoot(self.devinfo['bootinfo']['primary']['slot'], self.devinfo['bootinfo']['secondary']['slot']) self.devinfo['prepstatus'] = 'backed out' self.writedevinfo() self.info('complete!') self.info('Please login to the switch and reload it') self.info('rtc %s should get you into the device via opengear' % self.hostname) self.pe.exit()
def checkOG(self): """ logs into opengear device and runs getbootinfo() function to assign a prompt """ self.info('--checking opengear connectivity...') if self.devinfo['oginfo'].has_key('mgmtip'): self.og=pelogon(hostname=self.hostname,options=self.options,ip=self.devinfo['oginfo']['mgmtip'],port=self.devinfo['oginfo']['interface'],og=1) self.og.remlogon() self.devinfo['oginfo']['status']=self.og.status self.devinfo['oginfo']['vendor']=self.og.vendor self.devinfo['oginfo']['message']=self.og.message if self.og.status == 'success': self.og.getbootinfo() self.info('---opengear clean, logging out...') else: self.critical(self.og.message) self.og.e.terminate()
def __init__(self,**kw): """ check if the switch is upgraded, if so re-run post tests if not login to opengear and reload check everything is reachable and run post tests """ utils.__init__(self,**kw) self.info("-------------\nupgrading %s..." % self.hostname,attrs='bold') self.curversion=None self.upgraded=False self.loaddevinfo() self.pe=pelogon(hostname=self.hostname,options=self.options) #ssh into switch, automatically retrieves bootinfo self.pe.getbootinfo() #check to see if device is already upgraded self.checkupgraded() if not self.options.notest: self.upgraded=False # if testing pretend its not upgraded already if self.upgraded: self.warning('Looks like this device was already upgraded!\nPlease make sure you are looking at the correct device!') self.info('re-running post checks') self.runpostchecks() self.checkupgraded() else: self.info('-connecting to opengear...') self.og=pelogon(hostname=self.hostname,options=self.options,ip=self.devinfo['oginfo']['mgmtip'],port=self.devinfo['oginfo']['interface'],og=1) self.og.remlogon() time.sleep(1) if self.og.status=='success' and self.og.vendor=='dell': self.info('--connected, reloading device, please be patient...') self.info('--switching output to command line...') self.og.e.logfile=sys.stdout if self.options.notest: self.og.e.sendline('reload') self.debug('sending reload command now!') resp=self.og.e.expect(['.*\[confirm yes/no\]:','Save\? \[yes/no\]:']) else: self.og.e.sendline('dir |no-more') self.og.e.expect(self.og.prompt) self.og.e.sendline('exit') self.og.e.expect('get started') self.og.e.sendline() resp=0 if resp==0: if self.options.notest: self.og.e.sendline('yes') self.devinfo['upgradestatus']='upgraded' resp=self.og.e.expect(['Login:'******'\n--reload complete, waiting for 10 seconds...') self.og.message='login' #set og message to force login if self.options.notest: time.sleep(10) #sleeping to let device recover self.info('-attempting to log on via opengear...') self.og.remlogon() if self.og.status=='success': self.info('-login successful dropping opengear connection') self.og.e.terminate() self.info('-attempting to connect via ssh to complete checks...') self.pe=pelogon(hostname=self.hostname,options=self.options) self.pe.getbootinfo() self.debug('after upgrade swversion:%s' % self.pe.bootinfo['primary']['version']) self.checkupgraded() if not self.options.notest: self.upgraded=True #added for testing self.info('--waiting for 120 seconds for interfaces to come back before running post checks...') if self.options.notest: time.sleep(120) self.runpostchecks() #checks if swversion is correct and runs post checks else: self.critical('ERROR: unable to log back into switch!') self.warning('this can usually be fixed by just re-running this script as tacacs may not be reachable...') else: self.critical('unable to catch end of reload, please attempt to login manually') self.critical(self.og.message) else: self.og.e.sendline('no') self.og.e.expect(['.*\[confirm yes/no\]:','Save\? \[yes/no\]:']) self.og.e.sendline('no') self.og.e.expect(self.og.prompt) self.critical('looks like the config has changed since being prepared, please investigate!') self.warning('this can usually be fixed by just saving the config an re-running this script...') self.devinfo['upgradestatus']='failed' else: self.critical('unable to login to opengear:%s' % self.og.message) self.devinfo['upgradestatus']='failed' self.og.e.terminate() self.checkMGG() self.combineerrors(self.pe.errors[self.hostname]) self.devinfo['errors']={'upgrade':self.errors[self.hostname]} self.info('--exiting device...') self.pe.exit() if len(self.errors[self.hostname]['critical'])>0: self.warning('attempted upgrade but found some errors!') else: self.info('upgraded successfully',attrs='bold') self.writedevinfo()