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