Followers

Thursday, April 12, 2018

Build your Network programmability Environement in your Labtop via Pycharm to Automate your Network via Python


Always Network Engineers in a dilemma of How to build their Network Programmable Environment :

They read a lot but few who take steps towards the Hands-on.

That Article will decrease that gap.

- How to start write Python Code on your Windows machine ?
- What are the Tools you need to start developing your scripts ?
- How to Create your first project in that tool ?

Your Labtop or PC should be like the below one





1. Python either 2 or 3 .
2. Python interpreter (I am using Pycharm) 
3. If your Labtop has connection to real Network so it's ok. 
    if you need to connect to your Simulated Environment
    So you will need to go for either
    - EVE-NG 
    - GNS3

  and both of GNS3 or EVE-NG will be hosted as VMs on either VMware workstation,     
    Vmware vSphere or virtual box.


 1) Python

Python 2 is installed by default on most of the OSs now 
you can open your command prompt and check that by typing python.




if Not , go for the that URL to download Python 


Python interpreter Installation and let's Open the First Project

Let's begin with Python interpreter at Which we will write over it our Python Code .
1.     How to download the Python Interpreter jetbrains Pycharm ? 
         click on the below hyperlink to download it's community edition

      2. How to Create project on Pycharm.

- Open Pycharm  , you will see a page like the below
click on create New project






 - choose the directory that you will host your Project  and give your project a name and    
     choose the interpreter either  python 2 or 3
    here i choose python 2  and my project name is  : MyfirstPythonproject

finally click Create





 - your project appear now at the environment





- Right Click on the project itself then choose New > Python file



- Assign for your file a name and click ok
   No need here to write the .py extension of the file as it is already by choosing the file          type.



- Congrats 😉 you can type python right now.

   let's type your first Code




This code to print the GigabitEthernet interfaces with no shutdown below it to open all the interfaces inside my  Network Device.

here i  make a simple for loop to iterate from 0 to 9
to open the first ten interfaces at my line card at slot 0  
so i wll print the string "GigabitEthernet0/"  and the variable will be after the   /
 but because we are iterating over integer number , so in the print we can't add string to integer.
so we will change the type of the variable i firstly , and the variable becomes y now .


Now let's run the script ,




- After running the Code the output will appear in the below half of the Screen from the Run tab

  to adust that we can right click on Run and choose Windowed mode 

the output will appear in another Screen

For sure you can copy it and paste it directly to your Network device 😉




In the Coming blog post i will show you how to run from Pycharm a python Code towards The Network Devices Topology inside the EVE-NG simulator.

Be ready and download the EVE-NG from the below link 😉

Happy labbing and keep tuned.

Regards,
Mostafa Hassan Ahmed

3 comments:

  1. Hello, Great job!!! Please share (In the Coming blog post i will show you how to run from Pycharm a python Code towards The Network Devices Topology inside the EVE-NG simulator.) as promised.
    I look forward to the piece. Thanks man. Keep the great job up

    ReplyDelete
  2. I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more. hire automation professional

    ReplyDelete
  3. Iron Tooth Dog | T-Shirt
    Buy T-Shirt apple watch stainless steel vs titanium with Steel titanium ranger Tooth Dogs | T-Shirt | T-Shirt Online | ford fiesta titanium T-Shirt by T-Shirt | T-Shirt | apple watch stainless steel vs titanium T-Shirt | T-Shirt | T-Shirt | T-Shirt | T-Shirt. Rating: 4 · ‎22 votes · ‎$23.99 · ‎Out titanium money clip of stock

    ReplyDelete