Reply

Identifying the deviceID of a device entered as a Script variable in Perl

Guru
Posts: 50
3298     0

Hi,

I am writing a Perl script to issue configuration commands on a Cisco 6509 but in the script I need to find out the DeviceID of a neighbour (remote) device based on the Hostname of the remote device entered as variable name.

 

At the end of the script, I need to open an SSH session to the attached device (using $easy->device_session(<remotedeviceID>).

 

How can I easily get the remotedeviceID from within this script as this is what I am missing.

 

Hope Im making myself clear.

 

Thanks

 

Russ

 

Re: Identifying the deviceID of a device entered as a Script variable in Perl

Adviser
Posts: 452
3298     0

This is a smart to open 2 sessions

 

https://community.infoblox.com/t5/Network-Change-Configuration/How-do-you-run-a-script-through-route...

 

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: Identifying the deviceID of a device entered as a Script variable in Perl

Guru
Posts: 50
3298     0

Hi Sif,

 

Ouch. Not sure which part you are referring to in the linked article.

I am fairly new to the Perl programming in NetMRI, so is it possible to point in the right direction.

Also, might not have made it clear in that I am trying to write an internal Perl script using NetMRI_Easy - i.e. not using the API interface from a remote site.

 

Thanks

Russ

 

 

Re: Identifying the deviceID of a device entered as a Script variable in Perl

Adviser
Posts: 452
3298     0

How are your Python skills, in the latest version of NetMRI we included Phyton for you to use instead of PERL Smiley Happy

 

 

What are you trying to accomplish with the script, you can post it as if you were doing it from the CLI

 

 

Thanks,

Sif

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: Identifying the deviceID of a device entered as a Script variable in Perl

Guru
Posts: 50
3298     0

Hi Sif, Due to upgrade to 7.2.1 this weekend. I am more familiar with Perl (but most of the methods I use were based on the old AlterPoint - which NetMRI replaces at our site). We may have someone who is able to assist on the Python side but the main Perl script has been completed as described below.

 

Basically, the purpose of the script is to add a VLAN to a port channel on a C6509. We prune out all unnecessary VLANs from a port channel and then add individual VLANs as required on the access switch on the other side of the port channel.

So the script accepts the Script Variables valid name of the Access switch AND the VLAN it requires to add.

The 1st stage is to find out a bit more about the connections by sending the command "show CDP neig" and then finding the attached physical (Gig or TenGig) interface that is associated with the entered switch (from the Script Variable).

Once the interfaces associated with the Access switch have been identified (there will usually be 2 interfaces) , we send the command "show etherchannel summary" which gives all port channels and their associated physical interfaces.

We then use the interface to match the correct port channel. 

After that, we pull the config for that interface and determine if the VLAN is already assigned. If it exists on the interface, then we ignore and end the script (At the moment, the script exits with a value 1 causing the job to display an error - would be good if we could issue a warning instead of an error - not sure if this is possible).

 

 

If the VLAN doesnt exist, then we add the VLAN to the port channel using the command "switchport trunk allowed vlan add $vlanid" - obviously with the usual Cisco interface commands surrounding this.

Up to here, this script works perfectly.

 

The bit I am struggling with is understanding how I can create a new session within the same script. I understand that this is possible, but I need to specify the DeviceID of the access switch (from the Script Variable) in order to do this and I am not sure how to get this DeviceID. The things I tried simply brought back the same DeviceID of the selected device that the script runs against and not that of the Access Switch.

Why I need to do this is to login to the access switch to confirm that the VLAN has already been configured on the access switch. If not, I will need the script to exit with error. 

 

This part will probably need to appear early in the script before the VLAN is configured on the port channel. I have mentioned it at the end to make it easier to read my reasonings.

 

 

Hope this makes my objective a bit clearer.

 

Thanks

 

Russ

 

 

Showing results for 
Search instead for 
Did you mean: 

Recommended for You