Welcome to Infoblox NetMRI Community Sign in | Join | Help
in Search

IOS Image Upgrade 3845

Last post 08-10-2010 3:01 PM by mgriffin. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 08-10-2010 3:01 PM

    IOS Image Upgrade 3845

    ###########################################################################
    ## Export of Script: IOS Image Upgrade 3845
    ## Script-Level: 3
    ## Script-Category: Uncategorized
    ###########################################################################

    Script:
        IOS Image Upgrade 3845

    Script-Description:
         This script may be used to help automate image updates for Cisco 3845 series routers and terminal servers. It is designed to work with Cisco IOS based devices that use "flash:" as their boot storage device - with a single partition and have only one supervisor module. No attempt is made to handle multiple flash devices, partitions within flash devices, or loading images to multiple supervisor modules.

    Script-Filter:

    #    PLEASE REVIEW BEFORE USING!!!

    #

    #    This script content is provided to the user as is and is not

    #    warranted or guaranteed against specific vendor devices or user

    #    scenarios. It is provided by Netcordia to the user of this platform

    #    as an example, and should not be executed against production network

    #    devices unless the user has reviewed and/or made the proper

    #    modification to assure safe execution in specific network

    #    configurations. Please contact your Netcordia representative or

    #    Netcordia support if you have questions or concerns about how to

    #    safely use the following scripted content in your network.

    #

    #    You MUST check the "enable_changes" option for any commands to

    #    be executed. When NOT selected, the script will log the commands it

    #    would execute, but not download files or make changes to the device.

    #

    #    You may specify addtional path information in the server field when

    #    using the ftp and http protocols.

    #   

    #    If multiple protocols are selected, only one will be used. Order of

    #    preference is http, scp, ftp, then tftp.

    #

    #    The clean_flash option will attempt to free space in flash by

    #    deleting common files such as crash dumps and misc html files.

    #    If you use this option, you may want to adjust the file pattern

    #    matches in the "Delete Files" action.

    #  

    #    Use of scp requires that the device currently be running an image

    #    with crypto support (a.k.a., a "k9" image).

    #

    #    If you use scp, the password will appear in the process log of

    #    the Job details viewer. Use a dedicated, restricted account for this.

    #    In addition, the image file must exist in the user's home directory.

    #

    #    To use ftp transfer, you must first define ftp user, password, and

    #    mode settings (i.e., ip ftp username, ip ftp password, ip ftp passive)

    #

    #    The current running image AND the new image MUST end in ".bin".

    #    This means if you are currently using a running image that was not

    #    copied with its original filename intact, you must manually correct

    #    this before using this script.

    #

    #    The script will not do a force delete of the current running image

    #    from flash, if it exists. This is to help prevent leaving a device

    #    without an image if there is a problem during the file copy.

    #

    #    The download only option will copy the new file to flash if needed,

    #    but will not change the configuration or attempt to reload the device.

    #

    #    It is not necessary to specify either of the "reload_now" or

    #    "reload_cmd" options. Devices can be manually restarted later or

    #    perhaps reloaded by another script.



        $Vendor eq "Cisco"   and

        $sysDescr like /IOS/ and

        ($model like /3845/)



    Script-Timeout:

        7000



    Script-Variables:

        $use_scp        boolean

        $use_http        boolean

        $use_ftp        boolean

        $use_tftp        boolean

        $server            string        "Enter server/path info here"

        $new_image_name    string        "Enter image name here"

        $new_image_size    string        "Enter size of file in bytes"    number

        $new_image_md5    string        "Enter md5 hash here"

        $scp_username        string        "Enter username if using scp"

        $scp_password        password    "x"

        $download_only        boolean

        $clean_flash        boolean

        $reload_cmd        string        "Enter reload in command here"

        $reload_now        boolean

        $enable_changes        boolean



    #########################################################################

    Action:

        Set Variables and Download Method



    Action-Description:

        Set method of download based on above variables.

        If one of these are not set the script will fail.



    Action-Commands:

        SET: $runscript = "no"

        SET: $have_current_image = "no"

        SET: $usehttp = "no"

        SET: $useftp = "no"

        SET: $usetftp = "no"

        SET: $usescp = "no"

        SET: $spaceavailable = "no"



    Action-Commands: { $use_http eq "on" }

        SET: $usehttp = "yes"

        SET: $runscript = "yes"



    Action-Commands: { $usehttp eq "no" and $use_scp eq "on" }

        SET: $usescp = "yes"

        SET: $runscript = "yes"



    Action-Commands: { $usehttp eq "no" and $usescp eq "no" and $use_ftp eq "on" }

        SET: $useftp = "yes"

        SET: $runscript = "yes"



    Action-Commands: { $usehttp eq "no" and $usescp eq "no" and $useftp eq "no" and $use_tftp eq "on" }

        SET: $usetftp = "yes"

        SET: $runscript = "yes"



    #########################################################################

    Action:

        Delete Files



    Action-Description:

        Delete various files if selected.  This frees up space for the new file.

        This script can only handle up to a total of nine image files in flash.



        This action requires that a download protocol was selected.  If

        one of these are not set, the new file can not be downloaded.

       

        Set the terminal length to 0 so that results are not paginated.

        You may want to adjust some of the delete statements below to suit

        your site.



    Action-Filter:

        $runscript ne "no"



    Action-Commands: { $enable_changes eq "on" and $clean_flash eq "on" }

        delete /force flash:*.html

        delete /force flash:*.TXT

        delete /force flash:*.gif

        delete /force flash:*.js

        delete /force flash:*.log

        delete /force flash:*.template

        delete /force flash:*.pkg

        delete /force flash:*.sdf

        delete /force flash:*.tar

        delete /force flash:*.shtml

        delete /force flash:*.cfg

        delete /force flash:/crash*

        delete /force flash:*.zup

        delete /force flash:*.sbin

        delete /force flash:*.loads

        delete /force flash:*.sb2

        delete /force flash:*.sbn

        delete /force flash:*.cfg

        delete /force flash:*.au

        delete /force flash:crash*

        delete /force flash:P00*

        delete /force flash:S00*

        delete /force flash:cmterm*

        delete /force /rec html



    Action-Commands: { $enable_changes eq "off" and $clean_flash eq "on" }

        DEBUG:delete /force flash:*.html

        DEBUG:delete /force flash:*.TXT

        DEBUG:delete /force flash:*.gif

        DEBUG:delete /force flash:*.js

        DEBUG:delete /force flash:*.log

        DEBUG:delete /force flash:*.template

        DEBUG:delete /force flash:*.pkg

        DEBUG:delete /force flash:*.sdf

        DEBUG:delete /force flash:*.tar

        DEBUG:delete /force flash:*.shtml

        DEBUG:delete /force flash:*.cfg

        DEBUG:delete /force flash:/crash*

        DEBUG:delete /force flash:*.zup

        DEBUG:delete /force flash:*.sbin

        DEBUG:delete /force flash:*.loads

        DEBUG:delete /force flash:*.sb2

        DEBUG:delete /force flash:*.sbn

        DEBUG:delete /force flash:*.cfg

        DEBUG:delete /force flash:*.au

        DEBUG:delete /force flash:crash*

        DEBUG:delete /force flash:P00*

        DEBUG:delete /force flash:S00*

        DEBUG:delete /force flash:cmterm*

        DEBUG:delete /force /rec html



    Action-Commands:

        terminal length 0

        show ver



    Output-Triggers:

        Find Running Image

        Failed Determining Active IOS Image



    ########################################################################

    Trigger:

        Find Running Image



    Trigger-Description:

        This trigger determines the running IOS filename and calls a

        second trigger that looks for the new IOS image in flash. The

        command specifically looks only for .bin files.



    Trigger-Variables:

          $currentbootimage /\w\d{4}[\w\-\.]+\.bin/



    Trigger-Template:

          flash:.*\/?[[$currentbootimage]]



    Trigger-Filter:

        $runscript ne "no"



    Trigger-Commands:

        dir /all

        SET: $have_current_image = "yes"



    Output-Triggers:

        Check Files and Delete



    ########################################################################

    Trigger:

        Check Files and Delete



    Trigger-Description:

        This trigger looks for the user-supplied new image name in the

        output of the "dir" command in the previous trigger.



        $imagename must be a string of characters ending in ".bin".



        The $file variable is used to determine each file's position in flash.

        This allows the script to keep track of the number of image files in flash.

       

        If the .bin file is not the running image or the new image delete it

        to make room.



        $dir needs to match date strings as well as <no date> in case

        a file was uploaded to the device when the date/time was not available.

        For example, it must properly pull the file sequence and .bin file

        name from both of these:



        1  -rw-     8699556  Mar 13 2007 22:27:30 +00:00  c3660-i-mz.123-9e.bin

        3  -rw-     8477240                    <no date>  c3660-i-mz.123-3i.bin



    Trigger-Variables:

        $file       /\d+/

        $read        /\s*-\w+-\s*/

        $size        /\d+/   

        $dir         /\s*[<|>]\w+\s\w+[<|>]\s+|\s*\w*\s*\d*\s*\w+\s*\d+\s*\d+\s*\d+:\d+:\d+\s*[\+|-]\d+:\d+\s*/

        $imagename       /\w\d{4}[\w\-\.]+\.bin/



    Trigger-Template:

        [[$file]][[$read]][[$size]][[$dir]][[$imagename]]



    Trigger-Commands: { $imagename eq $new_image_name }

        verify /md5 flash:$imagename



    Trigger-Commands: { $imagename ne $currentbootimage and $imagename ne $new_image_name and $enable_changes eq "on" }

        DEBUG: del /force $imagename



    Trigger-Commands: { $imagename ne $currentbootimage and $imagename ne $new_image_name and $enable_changes eq "off" }

        DEBUG:del /force $imagename



    Output-Triggers:

        Check Image MD5 Hash



    ########################################################################

    Trigger:

        Check Image MD5 Hash



    Trigger-Description:

        Test that the calculated image MD5 hash matches the user-supplied value.



    Trigger-Variables:

        $imagemd5 /[[:xdigit:]]+/



    Trigger-Filter:

        $imagename eq $new_image_name



    Trigger-Template:

        .+Done!

        .+ = [[$imagemd5]]



    Trigger-Commands: { $imagemd5 eq $new_image_md5 }

        SET: $havenewimage = "yes"

        SET: $nofireissue = "yes"



    Trigger-Commands: { $imagemd5 ne $new_image_md5 }

        SET: $corruptnewimage = "yes"

        SET: $nofireissue = "yes"



    Output-Triggers:

        Corrupt IOS Image File



    #########################################################################

    Action:

        Squeeze



    Action-Description:

        Determine if deleted files are in flash, if so, try to squeeze the

        flash to make room. It is ran at this point in case a previous copy

        failed or we need to squeeze deleted files from the first action.



        This is an action so that it is not called after each file delete.



    Action-Filter:

        $runscript ne "no" and $have_current_image eq "yes"



    Action-Commands:

        dir /all



    Output-Triggers:

        Deleted

        Run Squeeze

       

    #########################################################################

    Trigger:

        Deleted



    Trigger-Description:

        Determine if there are deleted files still in flash. Deleted files

        will show in between brackets [.



    Trigger-Template:

        \[\S+\]



    Trigger-Commands:

        SET: $deleted = "yes"



    #########################################################################

    Trigger:

        Run Squeeze



    Trigger-Description:

        Squeeze flash if deleted files were found. Also do another dir

        command to determine free space left in flash.



    Trigger-Timeout:

        1500



    Trigger-Filter:

        $runscript ne "no"



    Trigger-Commands: { $deleted eq "yes" and $enable_changes eq "on" }

        DEBUG:squeeze flash:



    Trigger-Commands: { $deleted eq "yes" and $enable_changes eq "off" }

        DEBUG:squeeze flash:



    Trigger-Commands: { $enable_changes eq "on" }

        dir /all



    Trigger-Commands: { $enable_changes eq "off" }

        DEBUG:dir /all



    Output-Triggers:

        Check Space



    ########################################################################

    Trigger:

        Check Space



    Trigger-Description:

        This trigger determines if there is enough space in flash to load

        the new image. The dir command output from the previous trigger is

        parsed to determine free space remaining.



        If we don't already have the new image in flash, and there is not

        enough space to download it, fire an issue.



    Trigger-Variables:

            $Flash1         /\d+/ number

            $Flash2         /\d+/ number

            $FreeOrUsed     string

            $TotalOrAvail     /\w+/

            $paren        /\(/

            $paren2        /\)/



    Trigger-Template:

                    [[$Flash1]] bytes [[$TotalOrAvail]] [[$paren]][[$Flash2]] bytes [[$FreeOrUsed]][[$paren2]]





    Trigger-Commands: {$TotalOrAvail eq "available" and $Flash1 >= $new_image_size}

            SET: $spaceavailable = "yes"



    Trigger-Commands: {$FreeOrUsed eq "free" and $Flash2 >= $new_image_size}

            SET: $spaceavailable = "yes"



    Output-Triggers:

        Insufficient Space for IOS Image



    #########################################################################

    Action:

        Download IOS



    Action-Description:

        Copy the new image file to flash via SCP, TFTP, FTP or HTTP.



    Action-Timeout:

        5400



    Action-Filter:

        $runscript ne "no" and

        $havenewimage ne "yes" and

        $spaceavailable eq "yes" and

        $have_current_image eq "yes"



    Action-Commands: { $usehttp eq "yes" and $enable_changes eq "on" }

        copy http://$server/$new_image_name flash:$new_image_name n

        verify /md5 flash:$new_image_name

        SET: $havenewimage = "yes"



    Action-Commands: { $usehttp eq "yes" and $enable_changes eq "off"}

        DEBUG:copy http://$server/$new_image_name flash:$new_image_name n

        DEBUG:verify /md5 flash:$new_image_name

        SET: $havenewimage = "yes"



    Action-Commands: { $usescp eq "yes" and $enable_changes eq "on" }

        copy scp://$server/$new_image_name flash:$new_image_name $scp_username n$scp_password

        verify /md5 flash:$new_image_name

        SET: $havenewimage = "yes"



    Action-Commands: { $usescp eq "yes" and $enable_changes eq "off"}

        DEBUG:copy scp://$server/$new_image_name flash:$new_image_name $scp_username n$scp_password

        DEBUG:verify /md5 flash:$new_image_name

        SET: $havenewimage = "yes"



    Action-Commands: { $useftp eq "yes" and $enable_changes eq "on"}

        copy ftp://$server/$new_image_name flash:$new_image_name n

        verify /md5 flash:$new_image_name

        SET: $havenewimage = "yes"



    Action-Commands: {$useftp eq "yes" and $enable_changes eq "off"}

        DEBUG:copy ftp://$server/$new_image_name flash: n

        DEBUG:verify /md5 flash:$new_image_name

        SET: $havenewimage = "yes"



    Action-Commands: { $usetftp eq "yes" and $enable_changes eq "on" }

        copy tftp://$server/$new_image_name flash: n

        verify /md5 flash:$new_image_name

        SET: $havenewimage = "yes"



    Action-Commands: { $usetftp eq "yes" and $enable_changes eq "off"}

        DEBUG:copy tftp://$server/$new_image_name flash: n

        DEBUG:verify /md5 flash:$new_image_name

        SET: $havenewimage = "yes"



    Output-Triggers:

        Check Image MD5 Hash

        Check Download Complete



    ########################################################################

    Trigger:

        Check Download Complete



    Trigger-Description:

        Verify download completed successfully.



    Trigger-Template:

        %Error



    Trigger-Commands:

        SET: $copyfail = "yes"



    Output-Triggers:

        IOS Image File Copy Failed



    #########################################################################

    Action:

        Change Boot Image and Verify Changes



    Action-Description:

        Since this is a new action we need to redetermine the running version

        and change the boot system flash: commands in the following triggers.



    Action-Filter:

        $runscript ne "no" and $have_current_image eq "yes"



    Action-Commands:

        show ver

        show flash



    Output-Triggers:

        Update Boot Sequence

        IOS Upgrade Succeeded

        IOS Upgrade Failed

        Flash Squeeze Operation Failed

        Incorrect or Missing Boot Commands



    #########################################################################

    Trigger:

        Update Boot Sequence



    Trigger-Description:

        Make the new file the first boot image and the current image

        the second boot image by updating the configuration and saving

        to NVRAM.



    Trigger-Variables:

        $currentimageverify    /[\w\-\.]+\.bin/



    Trigger-Filter:

        $havenewimage eq "yes"

        and $download_only eq "off"

        and $spaceavailable eq "yes"

        and $copyfail ne "yes"



    Trigger-Template:

        flash:.*\/?[[$currentimageverify]]



    Trigger-Commands: { $havenewimage eq "yes" and $enable_changes eq "on"}

        config terminal

        no boot system

        boot system flash:$new_image_name

        end

        write memory

        show running | include boot

        SET: $bootchange = "yes"



    Trigger-Commands: { $havenewimage eq "yes" and $enable_changes eq "off"}

        DEBUG:config terminal

        DEBUG:no boot system

        DEBUG:boot system flash:$new_image_name

        DEBUG:end

        DEBUG:write memory

        show running | include boot

        SET: $bootchange = "yes"



    Output-Triggers:

        Verify Boot



    #########################################################################

    Trigger:

        Verify Boot



    Trigger-Description:

        Verify that the boot statements    exist for the new IOS image that

        was installed into flash. Then run another dir command.



    Trigger-Template:

        boot system flash:$new_image_name



    Trigger-Commands:

        SET: $bootexists = "yes"

        dir /all



    Output-Triggers:

        Verify Squeeze



    #########################################################################

    Trigger:

        Verify Squeeze



    Trigger-Description:

        Verify that the squeeze command completed by checking that no deleted

        files appear in flash.



    Trigger-Template:

        \[\S+\]



    Trigger-Commands:

        SET: $squeezefailed = "yes"



    #########################################################################

    Issue:

        Insufficient Space for IOS Image



    Issue-ID:

        IOSUpgradeNoSpace



    Issue-Severity:

        Warning



    Issue-Description:

        Insufficient storage space in flash to install the new IOS image.



    Issue-Filter:

        $spaceavailable ne "yes" and

        $nofireissue ne "yes"



    Issue-Details:

        Host        $IPAddress

        Name        $Name

        SpaceNeeded    $new_image_size

        SpaceAvailable    $freespace

        InstalledFlash    $flash



    #########################################################################

    Issue:

        IOS Image File Copy Failed



    Issue-ID:

        IOSUpgradeCopyFailed



    Issue-Severity:

        Error



    Issue-Description:

        There was an error during the IOS image copy.



    Issue-Filter:

        $copyfail eq "yes"



    Issue-Details:

        Host        $IPAddress

        Name        $Name



    #########################################################################

    Issue:

        IOS Upgrade Succeeded



    Issue-ID:

        IOSUpgradeComplete



    Issue-Severity:

        Info



    Issue-Description:

        The IOS upgrade completed successfully.



    Issue-Filter:

        $bootexists eq "yes" and

        $havenewimage eq "yes" and

        $squeezefailed ne "yes"



    Issue-Details:

        Host        $IPAddress

        Name        $Name



    #########################################################################

    Issue:

        IOS Upgrade Failed



    Issue-ID:

        IOSUpgradeFailed



    Issue-Severity:

        Error



    Issue-Description:

        The IOS upgrade failed.  The boot commands are not in the configuration,

        the new image doesn't exist in flash, or deleted files are still present

        (squeeze operation failed).



    Issue-Filter:

        ($bootexists ne "yes" and

         $download_only eq "off") or

        $havenewimage ne "yes"    or

        $squeezefailed eq "yes"   or

        $spaceavailable ne "yes"



    Issue-Details:

        Host        $IPAddress

        Name        $Name



    #########################################################################

    Issue:

        Flash Squeeze Operation Failed



    Issue-ID:

        IOSUpgradeSqueezeFailed



    Issue-Severity:

        Warning



    Issue-Description:

        Squeeze operation failed.  Deleted files still appear in flash.



    Issue-Filter:

        $squeezefailed eq "yes"



    Issue-Details:

        Host        $IPAddress

        Name        $Name



    #########################################################################

    Issue:

        Incorrect or Missing Boot Commands



    Issue-ID:

        IOSUpgradeBootIncorrect



    Issue-Severity:

        Error



    Issue-Description:

        Boot commands are incorrect or missing from the configuration.



    Issue-Filter:

        $bootexists ne "yes"    and

        $download_only eq "off" and

        $nofireissue ne "yes"



    Issue-Details:

        Host        $IPAddress

        Name        $Name



    #########################################################################

    Issue:

        Corrupt IOS Image File



    Issue-ID:

        IOSUpgradeCorruptImage



    Issue-Severity:

        Error



    Issue-Description:

        The new image file was found in flash, but the MD5 checksum didn't match.



    Issue-Filter:

        $corruptnewimage eq "yes"



    Issue-Details:

        Host        $IPAddress

        Name        $Name

        imagename    $new_image_name

        BadMD5        $imagemd5



    #########################################################################

    Issue:

        Failed Determining Active IOS Image



    Issue-ID:

        IOSUpgradeCurrentImage



    Issue-Severity:

        Error



    Issue-Description:

        Unable to determine the name of the currently active image.



    Issue-Filter:

        $have_current_image ne "yes"



    Issue-Details:

        Host        $IPAddress

        Name        $Name



    #########################################################################

    Action:

        Reload Now



    Action-Description:

        Reload the device one minute after a successful upgrade. This delay

        is necessary since NetMRI expects a response when a command is entered.



    Action-Filter:

        $reload_now eq "on"         and

        $have_current_image eq "yes"     and

        $bootexists eq "yes"        and

        $havenewimage eq "yes"      and

        $squeezefailed ne "yes"



    Action-Commands: { $enable_changes eq "on" }

        reload in 1



    Action-Commands: { $enable_changes eq "off" }

        DEBUG:reload in 1



    #########################################################################

    Action:

        Reload Later



    Action-Description:

        Reload the device at a scheduled time or a specific interval

        after a successful upgrade.



        The reload command entered at startup is directly executed.



        For example, "reload at 02:00" can be used to defer restart until

        early in the morning. Other options are available to the reload

        command.



    Action-Filter:

        $reload_cmd not like /Enter reload in command here/ and

        $have_current_image eq "yes"    and

        $bootexists eq "yes"        and

        $havenewimage eq "yes"      and

        $squeezefailed ne "yes"



    Action-Commands: { $enable_changes eq "on" }

        $reload_cmd



    Action-Commands: { $enable_changes eq "off" }

        DEBUG:$reload_cmd



    #########################################################################

    ##                            End of Script                            ##

    #########################################################################



       



    NetMRI
    Senior Escalations Engineer
    410 266 6161 option 3
Page 1 of 1 (1 items)