Parse a group of cisco switches, compile a list of IPs and interfaces, and then point a netmiko script to that new list. Possible? - automation

I think my choice of words is correct. I want to take a group of switches and compile a list of Ip addresses and specific interfaces to have netmiko push commands to. For instance, scan all cisco switches and put together a list of all interfaces in vlan X and not being used. Can someone point me in the right direction of how to do this?

Sounds like you need to figure out the different steps to work out your solution.
Maybe something this:
Connect to switch
run show commands
config interface to vlan xx
I don't see any code or anything you have attempted so far but here is a simple flow for looping through a list of IP addresses.
#Python 3.7
from netmiko import ConnectionHandler
username = "user"
password = "password"
for ip in IPlist:
# netmiko code profiles;
cisco ={
"host":IP,
"username":username,
"password":password,
"device_type: "cisco_ios"
}
with ConnectHandler(**cisco) as ssh_conn:
print(sshcon.find_prompt())
# do stuff here.

Related

Where to put common variables for groups in Ansible

We have some scripts to help us set up VPCs with up to 6 VMs in AWS. Now I want to log in to each of these machines. For security reasons we can only access one of them via SSH and then tunnel/proxy through that to the other machines. So in our inventory we have the IP address of the SSH host (we call it Redcarpet) and some other hosts like Elasticsearch, Mongodb and Worker:
#inventory/hosts
[redcarpet]
57.44.113.25
[services]
10.0.1.2
[worker]
10.0.5.77
10.0.1.200
[elasticsearch]
10.0.5.30
[mongodb]
10.0.1.5
Now I need to tell each of the groups, EXCEPT redcarpet to use certain SSH settings. If these were applicable to all groups, I would put them in inventory/group_vars/all.yml, but now I will have to put them in:
inventory/group_vars/services.yml
inventory/group_vars/worker.yml
inventory/group_vars/elasticsearch.yml
inventory/group_vars/mongodb.yml
Which leads to duplication. Therefore I would like to use an include or include_vars to include one or two variables from a common file (e.g. inventory/common.yml). However, when I try to do this in any of the group_var files above, it does not pick up the variables. What is the best practice to use with variables that are common to multiple groups?
If you want to go with the group_vars approach, I would suggest you add another group, and add the dependent groups as children to that group.
#inventory/hosts
[redcarpet]
57.44.113.25
[services]
10.0.1.2
[worker]
10.0.5.77
10.0.1.200
[elasticsearch]
10.0.5.30
[mongodb]
10.0.1.5
[redcarpet_deps:children]
mongodb
elasticsearch
worker
services
And now you can have a group_vars file called redcarpet_deps.yml and they should pickup the vars from there.

how to set traffic statistics in mininet?

I want to make testbed for testing the my own algorithm in mininet. I want to setup link data traffic rate, control traffic rate and link processing rate. but i am not able to it. if anyone have idea how to set up all these. please help me.
thanks,
abha
TL;DR Use D-ITG to generate traffic of your choice.
To define a topology in Mininet -
You can use the MininetEdit.py application in mininet/examples/miniedit.py folder. This will create a .py file defining the topology. You could have also written the same code to create the topology, the MininetEdit application is just a GUI to make it easy.
A sample topology definition looks something like this -
(I have created a simple network with 2 hosts h1, h2 connected to a switch s1)
#!/usr/bin/python
from mininet.net import Mininet
... #More import calls
def myNetwork(net):
info( '*** Add switches\n')
s1 = net.addSwitch('s1')
info( '*** Add hosts\n')
h1 = net.addHost('h1',ip='10.0.0.1',defaultRoute=None)
h2 = net.addHost('h2',ip='10.0.0.2',defaultRoute=None)
info( '*** Add links\n')
net.addLink(h1, s1,bw=200,delay='0ms',loss=0,max_queue_size=1000)
net.addLink(h2, s1,bw=200,delay='0ms',loss=0,max_queue_size=1000)
return net
You can set the maximum link rate / bandwitdh in the MininetEdit app, or change the bw parameter in the addLink function in the code file manually.
If you want to generate some real traffic on this mininet topology, use D-ITG. This is a simple tool that will allow you to generate traffic with different distributions, inter-arrival times, packet sizes, etc.,
So if you want to generate constant rate traffic of say rate KB/s from host h1 to h2, you can follow these steps -
Run xterm h1 from mininet instance
Run the following command on the terminal of h1
ITGSend -a <ip_of_h2> -T UDP -C <rate> -c <packet_size>
You can refer the D-ITG manual for more.

Psychopy and pylink example

I'm working on integrating an experiment in psychopy with the eyelink eyetracking system. The way to do this seems to be through pylink. Unfortunately I'm really unfamiliar with pylink and I was hoping there was a sample of an experiment that combines the two. I haven't been able to find one. If anyone would be able to share an example or point me towards a more accessible manual than the pylink api that sr-research provides I'd be really grateful.
Thanks!
I am glad you found your solution. I have not used iohub, but we do use psychopy and an eyelink and therefore some of the following code may be of use to others who wish to invoke more direct communication. Note that our computers use Archlinux. If none of the following makes any sense to you, don't worry about it, but maybe it will help others who are stumbling along the same path we are.
Communication between experimental machine and eye tracker machine
First, you have to establish communication with the eyelink. If your experimental machine is turned on and plugged into a live Eyelink computer then on linux you have to first set your ethernet card up, and then set the default address that Eyelink uses (this also works for the Eyelink 1000 - they kept the same address). Note your ethernet will probably have a different name than enp4s0. Try simply with ip link and look for something similar. NB: these commands are being typed into a terminal.
#To set up connection with Eyelink II computer:
#ip link set enp4s0 up
#ip addr add 100.1.1.2/24 dev enp4s0
Eyetracker functions
We have found it convenient to write some functions for talking to the Eyelink computer. For example:
Initialize Eyetracker
sp refers to the tuple of screenx, screeny sizes.
def eyeTrkInit (sp):
el = pl.EyeLink()
el.sendCommand("screen_pixel_coords = 0 0 %d %d" %sp)
el.sendMessage("DISPLAY_COORDS 0 0 %d %d" %sp)
el.sendCommand("select_parser_configuration 0")
el.sendCommand("scene_camera_gazemap = NO")
el.sendCommand("pupil_size_diameter = %s"%("YES"))
return(el)
NB: the pl function comes from import pylink as pl. Also, note that there is another python library called pylink that you can find on line. It is probably not the one you want. Go through the Eyelink forum and get pylink from there. It is old, but it still works.
Calibrate Eyetracker
el is the name of the eyetracker object initialized above. sp screen size, and cd is color depth, e.g. 32.
def eyeTrkCalib (el,sp,cd):
pl.openGraphics(sp,cd)
pl.setCalibrationColors((255,255,255),(0,0,0))
pl.setTargetSize(int(sp[0]/70), int(sp[1]/300))
pl.setCalibrationSounds("","","")
pl.setDriftCorrectSounds("","off","off")
el.doTrackerSetup()
pl.closeGraphics()
#el.setOfflineMode()
Open datafile
You can talk to the eye tracker and do things like opening a file
def eyeTrkOpenEDF (dfn,el):
el.openDataFile(dfn + '.EDF')
Drift correction
Or drift correct
def driftCor(el,sp,cd):
blockLabel=psychopy.visual.TextStim(expWin,text="Press the space bar to begin drift correction",pos=[0,0], color="white", bold=True,alignHoriz="center",height=0.5)
notdone=True
while notdone:
blockLabel.draw()
expWin.flip()
if keyState[key.SPACE] == True:
eyeTrkCalib(el,sp,cd)
expWin.winHandle.activate()
keyState[key.SPACE] = False
notdone=False
Sending and getting messages.
There are a number of built-in variables you can set, or you can add your own. Here is an example of sending a message from your python program to the eyelink
eyelink.sendMessage("TRIALID "+str(trialnum))
eyelink.startRecording(1,1,1,1)
eyelink.sendMessage("FIX1")
tFix1On=expClock.getTime()
Gaze contingent programming
Here is a portion of some code that uses the eyelink's most recent sample in the logic of the experimental program.
while notdone:
if recalib==True:
dict['recalib']=True
eyelink.sendMessage("RECALIB END")
eyelink.startRecording(1,1,1,1)
recalib=False
eventType=eyelink.getNextData()
if eventType==pl.STARTFIX or eventType==pl.FIXUPDATE or eventType==pl.ENDFIX:
sample=eyelink.getNewestSample()
if sample != None:
if sample.isRightSample():
gazePos = sample.getRightEye().getGaze()
if sample.isLeftSample():
gazePos = sample.getLeftEye().getGaze()
gazePosCorFix = [gazePos[0]-scrx/2,-(gazePos[1]-scry/2)]
posPix = posToPix(fixation)
eucDistFix = sqrt((gazePosCorFix[0]-posPix[0])**2+(gazePosCorFix[1]-posPix[1])**2)
if eucDistFix < tolFix:
core.wait(timeFix1)
notdone=False
eyelink.resetData()
break
Happy Hacking.
rather than PyLink, you might want to look into using the ioHub system within PsychoPy. This is a more general-purpose eye tracking system that also allows for saving data in a common format (integrated with PsychoPy events), and provides tools for data analysis and visualisation.
ioHUb is built to be agnostic to the particular eye tracker you are using. You just need to create a configuration file specific to your EyeLink system, and thereafter use the generic functions ioHiv provides for calibration, accessing gaze data in real-time, and so on.
There are some teaching resources accessible here: http://www.psychopy.org/resources/ECEM_Python_materials.zip
For future readers, I wanted to share my library for combining pylink and psychopy. I've recently updated it to work with python 3. It provides simple to use, high level functions.
https://github.com/colinquirk/templateexperiments/tree/master/eyelinker
You could also work at a lower level with the PsychoPyCustomDisplay class (see the pylink docs for more info about EyeLinkCustomDisplay).
For an example of it in use, see:
https://github.com/colinquirk/ChangeDetectionEyeTracking
(At the time of writing, this experiment code is not yet python 3 ready, but it should still be a useful example.)
The repo also includes other modules for creating experiments and recording EEG data, but they are not necessary if you are just interested in the eyelinker code.

Custom External Ports not showing on custom IP Core - Zedboard

I am trying to build a custom IP peripheral (my_perph). I have used the CIP tool to generate the basic perph and now want to add my custom external port (my_port).
Basically I followed this tutorial http://www.programmableplanet.com/author.asp?section_id=2142&doc_id=264841.
I have added the external port definitions to the top source vhdl my_perph.vhdl .
i.e
Port(
---Add user defined ports here----
MY_PORT : out std_logic;
I then added the port to the MPD file with the syntax:
PORT MY_PORT = "", DIR = O, IO_IF = MY_PORT_0, IO_IS = MY_PORT
This didn't work so I tried losing the 0 to match the name of the VHDL declared port so:
PORT MY_PORT = "", DIR = O, IO_IF = MY_PORT, IO_IS = MY_PORT
The issue is that once I have re-scanned the IP library I get the error saying there is
NO IO_INTERFACE MATCHING MY_PORT
It seems that my custom external port MY_PORT is not being recognised in the IP design although it exists in the HDL of the included IP entity.
And even when I go to add the perph I find that this port does not show up in the info. I am totally lost as I have followed all tutorials and tired every possible thing I can think of!
Read the Platform Specification Format guide. You need to understand all of the MPD file, before just copy and pasting lines within it. The line you have needs to have a matching IO_INTERFACE section (as the error message tells you)
If your IO is not part of a "standard" IO port (see the IO_INTERFACE section of the PSF) you should be able to use simply:
PORT MY_PORT = "", DIR = O

VB.NET : Grabbing and Tieing IP Addresses to Interfaces

I would like to find a way to grab the assigned IPv4 and IPv6 addresses to different interfaces and being able to determine which interface they're tied to.
Currently I am looping ' System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces ' and able to grab interface specific information:
For Each nic As System.Net.NetworkInformation.NetworkInterface In System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
myarr(count2, 0) = (String.Format("{0}", nic.Description))
myarr(count2, 1) = (String.Format("{0}", nic.GetPhysicalAddress))
myarr(count2, 2) = (String.Format("{0}", nic.OperationalStatus))
myarr(count2, 3) = (String.Format("{0}", nic.Speed))
count2 += 1
Next
Through this method I can't determine a simple method to grab assigned IP Addresses unfortunately.
The most common method that I can easily find with google-foo is to find your IP via going through something like the following:
Dim ipAdd As IPAddress = Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.First(Function(f) f.AddressFamily = Sockets.AddressFamily.InterNetwork)
Which is fine and dandy but I can't determine which interface is being used nor can it determine an assigned IP Address that's not going through DNS or mulitple NICS.
I can possibly do some ghetto method of issuing a command-line command and parsing all the information out of ipconfig or getting a GUID and running through the registry but I feel like there should be an easier more effecient method.
A good example of what I want is the ability to produce a list like IPCONFIG where it has interface information and their designated IP Addresess, etc...
in you for-loop try
Dim ip = nic.GetIPProperties().UnicastAddresses(0).Address;