Python Script to convert firewall rules

Kashif Rana kashifrana84 at gmail.com
Sat Dec 13 12:41:45 EST 2014


On Saturday, December 13, 2014 6:31:34 AM UTC+4, Jason Friedman wrote:
> Thanks for the reply. Yes I can make the all possible keywords/values for both formate. But after that what gonna be the logic to convert one format to other format. Like to convert one line below are the keywords:
> 
> 
> 
> set interface ethernet2/5 ip 10.17.10.1/24 (format 1)
> 
> set interfaces ge-0/0/0 unit 0 family inet address 10.17.10.1/24 (format 2)
> 
> 
> 
> (set, interface, ip) = (set, interfaces, family inet address)
> 
> 
> 
> But some values are variable and should ask the user to convert manually like ethernet2/5 equal to ge-0/0/0 or ge-0/0/1 or ge-0/0/2
> 
> 
> 
> And some values keep as it is like 10.17.10.1/24
> 
> 
> 
> Also then format 2 can be converted int o format 3 (as below) for more readability of format 2. This is just optional.
> 
> 
> 
> interfaces {
> 
>     ge-2/0/5 {
> 
>         unit 0 {
> 
>             family inet {
> 
>                 address 10.17.10.1/24;
> 
>             }
> 
>         }
> 
>     }
> 
> }
> 
> 
> 
> 
> Note that the practice on this list is to put your response after the (edited) portion of the previous posts.
> 
> 
> Are you willing to learn some Python, if someone gets you started?
> 
> Would it be helpful if someone provided Python code to convert this:
> 
> set interfaces ge-0/0/0 unit 0 family inet address 10.17.10.1/24
> 
> 
> to this:
> 
> 
> interfaces {
> 
>     ge-2/0/5 {
> 
>         unit 0 {
> 
>             family inet {
> 
>                 address 10.17.10.1/24;
> 
>             }
> 
>         }
> 
>     }
> 
> }
> 
> 
> ?

Hello

Thanks for the reply. I am learning python using CBT nuggets for python. But If you can refer me some good course, that should be practical then it would be great. 

For my requirement, if you can give me the best approach to start with or high level steps or give me some sample cod, I really appreciate that.

Regards,

Kashif



More information about the Python-list mailing list