Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82493
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <kashifrana84@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.013 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'python.': 0.02; 'interfaces': 0.04; 'subject:Python': 0.06; '"""': 0.07; 'great.': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'def': 0.12; 'address)': 0.16; 'address):': 0.16; 'family,': 0.16; 'indent': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; '>': 0.26; 'appreciated': 0.26; 'skip:" 20': 0.27; 'values': 0.27; 'header :In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'reply.': 0.31; 'that.': 0.31; '"': 0.31; 'indentation': 0.31; 'class': 0.32; 'interface': 0.32; 'text': 0.33; 'url:python': 0.33; 'skip:& 30': 0.33; 'sources': 0.33; 'skip:_ 10': 0.34; 'convert': 0.35; 'equal': 0.35; 'requirement': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; '14,': 0.36; 'interface,': 0.36; 'much.': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'unit': 0.37; 'level': 0.37; 'skip:& 10': 0.38; 'thank': 0.38; 'jason': 0.38; 'skip:& 20': 0.39; 'skip:p 20': 0.39; 'manually': 0.60; 'url:3': 0.61; 'first': 0.61; 'address': 0.63; 'high': 0.63; 'refer': 0.63; 'to:addr:gmail.com': 0.65; 'sample': 0.67; 'url:11': 0.68; 'url:17': 0.68; 'url:18': 0.68; 'below:': 0.68; 'skip:r 30': 0.69; 'family': 0.73; 'url:self': 0.84; 'good,': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=iU6Z0EIZ6GGTDVRlcachHVRdMoizxRKbH4MyRlSe2J4=; b=H9BkPm8fIu6XFUOXWWB1UZHG2FNDbdo8CHe4vtpfJjY4wOZ7zTcsA3rZSOoPDGZTL/ mQ4aJAMH3OpU2zZ4mYdzo8WHeEQTa309qqk800NrXnbNliWlUJX1E2atvOdd5w+vFs7r zkwKnPq4D3Qg5SEVJMnV7TATrS8GDF13WgIp1SCJeqh6hwRcfliYFJFP/tSAyMdATs7D bQQCKCSIHvQrutA9pj9tFV3+Qy1B1uRlU9FmTVHadYmGD9KOEROEElc6lATEWPyDKLXG hUmPb5YpAOUA7H78EHDmhKj81hXymG4NOV2m26hfnC05h2jiWAd+Zxi3yukiUug8T49d oQqA== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.13.205 with SMTP id 196mr15168822ion.15.1418539867457; Sat, 13 Dec 2014 22:51:07 -0800 (PST) |
| In-Reply-To | <CANy1k1jZ=XPh_hDhe9UpFWwUuJGT-p9q6qBgJv-oggNpq9CwrA@mail.gmail.com> |
| References | <b23872cc-7b5c-4e38-96c1-ac907b6df7f1@googlegroups.com> <mailman.16883.1418348704.18130.python-list@python.org> <e0d8dd24-2256-4b89-972e-c1ebe82f72a9@googlegroups.com> <mailman.16931.1418437882.18130.python-list@python.org> <c89c75f8-190d-4678-b575-b92db5c38983@googlegroups.com> <CANy1k1jZ=XPh_hDhe9UpFWwUuJGT-p9q6qBgJv-oggNpq9CwrA@mail.gmail.com> |
| Date | Sun, 14 Dec 2014 10:51:07 +0400 |
| Subject | Re: Python Script to convert firewall rules |
| From | Kashif Rana <kashifrana84@gmail.com> |
| To | Jason Friedman <jsf80238@gmail.com> |
| Content-Type | multipart/alternative; boundary=001a113feec4e67ac3050a278cc0 |
| Cc | python-list <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16940.1418539876.18130.python-list@python.org> (permalink) |
| Lines | 154 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1418539876 news.xs4all.nl 2831 [2001:888:2000:d::a6]:46665 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:82493 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Hi Jason
Thank you very much. Appreciated ! But the first requirement was to convert
format1 to format2 as below:
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
Thanks and Regards,
Kashif
On Sun, Dec 14, 2014 at 5:35 AM, Jason Friedman <jsf80238@gmail.com> wrote:
>
> > 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.
> >
> Good, some other sources for learning:
> https://docs.python.org/3/tutorial/
> http://learnpythonthehardway.org/
>
> Here's some code to get you started (version 3.4.0):
>
> """
> convert
>
> set interfaces ge-0/0/0 unit 0 family inet address 10.17.10.1/24
>
> to
>
> interfaces {
> ge-2/0/5 {
> unit 0 {
> family inet {
> address 10.17.10.1/24;
> }
> }
> }
> }
> """
>
> class interface():
> attribute_name_list = ("ge", "unit", "family", "address")
> def __init__(self, ge, unit, family, address):
> self.ge = ge
> self.unit = unit
> self.family = family
> self.address = address
>
> def convert(interface_list, indent=4):
> indentation = 0
> return_list = list()
> return_list.append(" " * indentation + "interfaces {")
> for interface in interface_list:
> for attribute_name in interface.attribute_name_list:
> indentation += indent
> text = "%s %s {" % (attribute_name, getattr(interface,
> attribute_name))
> return_list.append(" " * indentation + text)
> while indentation > indent:
> indentation -= indent
> return_list.append(" " * indentation + "}")
> indentation -= indent
> return_list.append("}")
> return "\n".join(return_list)
>
> if __name__ == "__main__":
> interface1 = interface("0/0/0", "0", "inet", "10.17.10.1/24")
> interface2 = interface("2/0/5", "0", "inet", "11.18.10.1/24")
> print(convert((interface1, interface2, )))
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python Script to convert firewall rules Kashif Rana <kashifrana84@gmail.com> - 2014-12-10 10:51 -0800
Re: Python Script to convert firewall rules Jason Friedman <jsf80238@gmail.com> - 2014-12-11 18:44 -0700
Re: Python Script to convert firewall rules Kashif Rana <kashifrana84@gmail.com> - 2014-12-11 23:54 -0800
Re: Python Script to convert firewall rules Jason Friedman <jsf80238@gmail.com> - 2014-12-12 19:31 -0700
Re: Python Script to convert firewall rules Kashif Rana <kashifrana84@gmail.com> - 2014-12-13 09:41 -0800
Re: Python Script to convert firewall rules Jason Friedman <jsf80238@gmail.com> - 2014-12-13 18:35 -0700
Re: Python Script to convert firewall rules Kashif Rana <kashifrana84@gmail.com> - 2014-12-14 10:51 +0400
Re: Python Script to convert firewall rules Jason Friedman <jsf80238@gmail.com> - 2014-12-14 22:07 -0700
csiph-web