cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1804
Views
5
Helpful
4
Replies

ZTP Cat9K - Python Guestshell - Clean Software Packages

mgns
Level 1
Level 1

Hello,
I'm trying to clean old software packages on Cat9300 Switch during ZTP.
The command "request platform software package clean switch all" shows following confirmation prompt "Do you want to proceed? [y/n]".

I tried to use an EEM script with Action 3.0 as confirmation:
cli.configurep([
"event manager applet clean" ,
"event none maxrun 300" ,
"action 1.0 cli command \"enable\"" ,
"action 2.0 cli command \"request platform software package clean switch all\",
"action 3.0 cli command \"y\" "
])
and then cli.execute("event manager run clean")
But it is not working.

An other idea: Can I modify the prompt for which the method cli.execute is waiting?

Thanks and best regards,
Magnus

1 Accepted Solution

Accepted Solutions

Hi Seb,

Thanks for your hint. I found the following variable $(SWITCHNAME), so action 2.0 looks like this:

"action 2.0 cli command \"request platform software package clean switch all\" pattern \"proceed|$(SWITCHNAME)#\" "

Finally, it works.

 

View solution in original post

4 Replies 4

Seb Rupik
VIP Alumni
VIP Alumni

HI there,

For interactive CLI prompts use the pattern command. Try replacing action 2.0 with:

"action 2.0 cli command \"request platform software package clean switch all\" pattern \"proceed\",

 

cheers,

Seb.

 

Thanks, Sep. It works!

 

But there is one problem: If there are no old packages, the pattern is never true. (see output below)

 

host#request platform software package clean switch all
This operation may take several minutes...
Running command on switch 1
Cleaning up unnecessary package files
No path specified, will use booted path flash:packages.conf
Cleaning flash:
Scanning boot directory for packages ... done.
Preparing packages list to delete ...
cat9k-cc_srdriver.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-espbase.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-guestshell.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-rpbase.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-rpboot.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-sipbase.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-sipspa.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-srdriver.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-webui.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-wlc.16.12.01.SPA.pkg
File is in use, will not delete.
packages.conf
File is in use, will not delete.
done.

SUCCESS: No extra package or provisioning files found on media. Nothing to clean.
host#

 

Can I run a cli command only for a specified pattern? Like if pattern "proceed" then "y" else if pattern "host#" then "do nothing"?

 

Regards,

Magnus

hmmm I suppose it doesn't matter it you type 'y' in EXEC mode, so you could change the pattern to regex logical OR:

"action 2.0 cli command \"request platform software package clean switch all\" pattern \"proceed|<host_name>\",

...I am sure there is a built-in EEM variable representing hostname but I can't recall what it is. In which case you will need to substitute <host_name> on each EEM script instance.

 

cheers,

Seb.

Hi Seb,

Thanks for your hint. I found the following variable $(SWITCHNAME), so action 2.0 looks like this:

"action 2.0 cli command \"request platform software package clean switch all\" pattern \"proceed|$(SWITCHNAME)#\" "

Finally, it works.

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: