Example #1
0
    def ascii_copy(self, db, switch_cons):
        """
        This method is to 
        """
        sys = ""
        founds = 0

        switch_cons.sendline('switchback')
        switch_cons.expect(defn.SWITCH_PROMPT)

        #For storing the kickstart and the system images
        switch_cons.sendline('show version | grep "image file is"')
        switch_cons.expect(defn.SWITCH_PROMPT)
        string = switch_cons.before
        if "///" in string:
            sys = string.split('///')[1]
            sys = sys.split()[0]
        if sys != "":
            switch_cons.sendline('dir')
            switch_cons.expect(defn.SWITCH_PROMPT)
            dir = switch_cons.before
            imgs = dir.split()
            if sys in imgs:
                founds = 1

        logging.info("Found sys %d", founds)
        if founds == 1:
            db.update_images(self.switch_name, "", sys)
        else:
            db.update_images(self.switch_name, "", "")

        #Now write erase and copy the running config to file
        switch_cons.sendline('delete run_power_config n')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        switch_cons.sendline('delete start_power_config n')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)

        #no boot kick and sys
        switch_cons.sendline('config t')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        switch_cons.sendline('no boot nxos')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        #write erase
        switch_cons.sendline('write erase')
        switch_cons.expect('Do you wish to proceed anyway')
        switch_cons.sendline('y')
        switch_cons.expect(defn.SWITCH_PROMPT, 120)
        #write erase boot
        switch_cons.sendline('write erase boot')
        switch_cons.expect('Do you wish to proceed anyway')
        switch_cons.sendline('y')
        switch_cons.expect(defn.SWITCH_PROMPT, 120)

        "Now copy the running config to run_power_config file"
        switch_cons.sendline('show running-config vdc-all > run_power_config')
        i = switch_cons.expect(
            [defn.SWITCH_PROMPT, r'yes/no', pexpect.TIMEOUT, pexpect.EOF])
        if i == 0:
            pass
        if i == 1:
            switch_cons.sendline('yes')
            switch_cons.expect(defn.SWITCH_PROMPT, 180)
        if i == 2 or i == 3:
            print "Something wrong with switch %s so go ahead and poweroff" % self.switch_name
            return False

        "Now copy the startup config to run_power_config file"
        switch_cons.sendline(
            'show startup-config vdc-all > start_power_config')
        i = switch_cons.expect(
            [defn.SWITCH_PROMPT, r'yes/no', pexpect.TIMEOUT, pexpect.EOF])
        if i == 0:
            pass
        if i == 1:
            switch_cons.sendline('yes')
            switch_cons.expect(defn.SWITCH_PROMPT, 180)
        if i == 2 or i == 3:
            print "Something wrong with switch %s so go ahead and poweroff" % self.switch_name
            return False

        Switch.setip(switch_cons, self.mgmt_ip)

        #Copy the kickstart and system image to server only if present
        if founds == 1:
            d_file = "%s/%s.system.gbin" % (self.switch_name, self.switch_name)
            Switch.copy_files_to_server(switch_cons=switch_cons,
                                        s_file=sys,
                                        d_file=d_file)
        d_file = "%s/%s.run_power_config" % (self.switch_name,
                                             self.switch_name)
        Switch.copy_files_to_server(switch_cons=switch_cons,
                                    s_file='run_power_config',
                                    d_file=d_file)
        d_file = "%s/%s.start_power_config" % (self.switch_name,
                                               self.switch_name)
        Switch.copy_files_to_server(switch_cons=switch_cons,
                                    s_file='start_power_config',
                                    d_file=d_file)

        return True
Example #2
0
    def ascii_copy(self, db, switch_cons):
        """
        This method is to 
        """
        sys = ""
        founds = 0
        
        switch_cons.sendline('switchback')
        switch_cons.expect(defn.SWITCH_PROMPT)

        #For storing the kickstart and the system images
        switch_cons.sendline('show version | grep "image file is"')
        switch_cons.expect(defn.SWITCH_PROMPT)
        string = switch_cons.before
        if "///" in string:
            sys = string.split('///')[1]
            sys = sys.split()[0]
        if sys != "":
            switch_cons.sendline('dir')
            switch_cons.expect(defn.SWITCH_PROMPT)
            dir = switch_cons.before
            imgs = dir.split()
            if sys in imgs:
                founds = 1

        logging.info("Found sys %d", founds)
        if founds==1:
            db.update_images(self.switch_name,"",sys)
        else:
            db.update_images(self.switch_name,"","")

        #Now write erase and copy the running config to file
        switch_cons.sendline('delete run_power_config n')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        switch_cons.sendline('delete start_power_config n')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)

        #no boot kick and sys
        switch_cons.sendline('config t')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        switch_cons.sendline('no boot nxos')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        #write erase
        switch_cons.sendline('write erase')
        switch_cons.expect('Do you wish to proceed anyway')
        switch_cons.sendline('y')
        switch_cons.expect(defn.SWITCH_PROMPT, 120)
        #write erase boot
        switch_cons.sendline('write erase boot')
        switch_cons.expect('Do you wish to proceed anyway')
        switch_cons.sendline('y')
        switch_cons.expect(defn.SWITCH_PROMPT, 120)
        
        "Now copy the running config to run_power_config file"
        switch_cons.sendline('show running-config vdc-all > run_power_config')
        i = switch_cons.expect([defn.SWITCH_PROMPT,r'yes/no',pexpect.TIMEOUT, pexpect.EOF])
        if i==0:
            pass
        if i==1:
            switch_cons.sendline('yes')
            switch_cons.expect(defn.SWITCH_PROMPT,180)
        if i==2 or i==3:
            print "Something wrong with switch %s so go ahead and poweroff" % self.switch_name
            return False
        
        "Now copy the startup config to run_power_config file"
        switch_cons.sendline('show startup-config vdc-all > start_power_config')
        i = switch_cons.expect([defn.SWITCH_PROMPT,r'yes/no',pexpect.TIMEOUT, pexpect.EOF])
        if i==0:
            pass
        if i==1:
            switch_cons.sendline('yes')
            switch_cons.expect(defn.SWITCH_PROMPT,180)
        if i==2 or i==3:
            print "Something wrong with switch %s so go ahead and poweroff" % self.switch_name
            return False
        
        Switch.setip(switch_cons,self.mgmt_ip)

        #Copy the kickstart and system image to server only if present
        if founds==1:
            d_file = "%s/%s.system.gbin"%(self.switch_name,self.switch_name)
            Switch.copy_files_to_server(switch_cons=switch_cons,s_file=sys,d_file=d_file)
        d_file = "%s/%s.run_power_config"%(self.switch_name,self.switch_name)
        Switch.copy_files_to_server(switch_cons=switch_cons,s_file='run_power_config',d_file=d_file)
        d_file = "%s/%s.start_power_config"%(self.switch_name,self.switch_name)
        Switch.copy_files_to_server(switch_cons=switch_cons,s_file='start_power_config',d_file=d_file)
        
        return True
Example #3
0
    def copy_images_to_switch(self, log):
        """
        This definition is to copy the right set of images to switch which
        has been used for sanities for other its not required so just return
        """
        dir = ''
        logging.info("Copy the sys=%s images if not available to the switch",
                     self.sys)
        console = pexpect.spawn('telnet %s %s' %
                                (self.console_ip, self.act_port))
        console.logfile = log
        time.sleep(2)
        console.sendline('')
        i = console.expect([
            pexpect.TIMEOUT, pexpect.EOF, defn.SWITCH_LOGIN,
            defn.SWITCH_PROMPT, 'loader>.*'
        ], 120)
        if i == 0 or i == 1:
            logging.debug(str(console))
            console.close()
            return
        if i == 2 or i == 3:
            if i == 2:
                console.sendline('admin')
                console.expect('assword:')
                console.sendline(self.switch_pwd)
                console.expect(defn.SWITCH_PROMPT)
            console.sendline('switchback')
            console.expect(defn.SWITCH_PROMPT)
            console.sendline('terminal length 0')
            console.expect(defn.SWITCH_PROMPT)
            console.sendline('dir')
            console.expect(defn.SWITCH_PROMPT)
            dirs = console.before
            if self.sys in dirs.split():
                logging.info("Found the System image in bootflash")
                console.close()
                return
            logging.info("Did not find System image in bootflash")
        if i == 4:
            console.sendline('')
            console.expect('loader>.*')
            console.sendline('dir')
            console.expect('loader>.*')
            dirs = console.before
            if self.sys in dirs.split():
                logging.info("Found the System image in bootflash")
                console.close()
                return
            logging.info("Did not find System image in bootflash")

        if i == 2 or i == 3:
            console.sendline('reload')
            console.expect('y/n')
            console.sendline('y')
            console.expect('loader>.*', 60)

        console.sendline('')
        i = console.expect([pexpect.TIMEOUT, pexpect.EOF, 'loader>.*'])
        if i == 0 or i == 1:
            logging.debug(str(console))
            console.close()
            return
        if i == 2:
            console.sendline('dir')
            console.expect('loader>.*')
            imgs = n9kSwitch.get_images_in_switch(console.before)
            for im in imgs:
                match = re.match(r'n9.*dk9([0-9A-Za-z\.]+)', im)
                if match:
                    break
            console.sendline('boot %s' % im)
            console.exit()
            console = self.load_or_telnet_image(log)

        Switch.setip(console, self.mgmt_ip)

        for img in imgs:
            console.sendline('delete bootflash:%s' % img)
            console.expect(defn.SWITCH_PROMPT)

        time.sleep(10)
        d_file = self.sys
        s_file = "%s/%s.system.gbin" % (self.switch_name, self.switch_name)
        Switch.copy_files_to_switch(switch_cons=console,
                                    s_file=s_file,
                                    d_file=d_file)
        d_file = "power_config"
        s_file = "%s/%s.run_power_config" % (self.switch_name,
                                             self.switch_name)
        Switch.copy_files_to_switch(switch_cons=console,
                                    s_file=s_file,
                                    d_file=d_file)
        s_file = "%s/%s.start_power_config" % (self.switch_name,
                                               self.switch_name)
        Switch.copy_files_to_switch(switch_cons=console,
                                    s_file=s_file,
                                    d_file=d_file)

        console.close()
        return
Example #4
0
    def copy_images_to_switch(self, log):
        """
        This definition is to copy the right set of images to switch which
        has been used for sanities for other its not required so just return
        """
        dir = ''
        logging.info("Copy the sys=%s images if not available to the switch", self.sys)
        console = pexpect.spawn('telnet %s %s'%(self.console_ip,self.act_port))
        console.logfile = log
        time.sleep(2)
        console.sendline('')
        i = console.expect([pexpect.TIMEOUT, pexpect.EOF, defn.SWITCH_LOGIN, defn.SWITCH_PROMPT, 'loader>.*'], 120)
        if i==0 or i==1:
            logging.debug(str(console))
            console.close()
            return
        if i==2 or i==3:
            if i==2:
                console.sendline('admin')
                console.expect('assword:')
                console.sendline(self.switch_pwd)
                console.expect(defn.SWITCH_PROMPT)
            console.sendline('switchback')
            console.expect(defn.SWITCH_PROMPT)
            console.sendline('terminal length 0')
            console.expect(defn.SWITCH_PROMPT)
            console.sendline('dir')
            console.expect(defn.SWITCH_PROMPT)
            dirs = console.before
            if self.sys in dirs.split():
                logging.info("Found the System image in bootflash")
                console.close()
                return
            logging.info("Did not find System image in bootflash")
        if i==4:
            console.sendline('')
            console.expect('loader>.*')
            console.sendline('dir')
            console.expect('loader>.*')
            dirs = console.before
            if self.sys in dirs.split():
                logging.info("Found the System image in bootflash")
                console.close()
                return
            logging.info("Did not find System image in bootflash")
        
        if i==2 or i==3:
            console.sendline('reload')
            console.expect('y/n')
            console.sendline('y')
            console.expect('loader>.*', 60)
        
        console.sendline('')
        i = console.expect([pexpect.TIMEOUT, pexpect.EOF, 'loader>.*'])
        if i==0 or i==1:
            logging.debug(str(console))
            console.close()
            return
        if i==2:
            console.sendline('dir')
            console.expect('loader>.*')
            imgs = n9kSwitch.get_images_in_switch(console.before)
            for im in imgs:
                match = re.match(r'n9.*dk9([0-9A-Za-z\.]+)', im)
                if match:
                    break
            console.sendline('boot %s' % im)
            console.exit()
            console = self.load_or_telnet_image(log)

        Switch.setip(console,self.mgmt_ip)
        
        for img in imgs:
            console.sendline('delete bootflash:%s' % img)
            console.expect(defn.SWITCH_PROMPT)
        
        time.sleep(10)
        d_file = self.sys
        s_file = "%s/%s.system.gbin"%(self.switch_name,self.switch_name)
        Switch.copy_files_to_switch(switch_cons=console, s_file=s_file, d_file=d_file)
        d_file = "power_config"
        s_file = "%s/%s.run_power_config"%(self.switch_name,self.switch_name)
        Switch.copy_files_to_switch(switch_cons=console, s_file=s_file, d_file=d_file)
        s_file = "%s/%s.start_power_config"%(self.switch_name,self.switch_name)
        Switch.copy_files_to_switch(switch_cons=console, s_file=s_file, d_file=d_file)
        
        console.close()
        return