Automation & Programmability
Showing results for 
Search instead for 
Do you mean 

Python for Non-Programmers (Part 1)

by ‎11-11-2013 01:34 PM - edited ‎03-27-2014 04:33 AM

PYTHON AS A POWER TOOL

 

When I talk with Network Engineers and Operations teams about automation, often times the response is: "I am not a programmer, so I can't do this".  Worse yet are folks in the blog-o-sphere saying that if networking folks don't become a programmers, they will become obsolete.  This is all rubbish. 

 

Have you ever used Linux, and hacked out a shell "for" or "while" loop to do a quick repetitive task?  I'm sure you have, but would you call that programming?  No, of course not.  I have friends that are in different fields, like science and finance.  They use programming languages, like Python, to do numerical analysis, as a power-tool for their job.  If you ask my friend the scientist if they are a "Programmer", they would say "NO!  I am a Scientist!" 

 

So there seems to be a (self inflicted) distinction between using a programming language as a power-tool and being a programmer as a profession.  And yes, I do believe there is a distinct difference, and no, it does not mean you have a Computer Science degree.

 

So perhaps we can all agree that using a programming language does not make you a programmer.  It's just a power-tool to help you do you job. So now you can get over it, and start to have some fun and be more productive.

 

AUTOMATION IS ABOUT CONSUMPTION

 

My basic thesis is that automation is defined by the nature of the consumer, that is, the person using the automation technology.  The technology could be a purpose built tool/product, an IT framework, a set of language libraries, SDKs, or a combination of the above.  I've even tried to make this concept consumable by creating an analogy to "ice cream" - as described in this blog

 

If we treat automation as consumption, then we must consider the "digestion factor", or "how easy" can we make automation consumable by the user, you, the non-programmer.  If you are presented with an automation task that is "too hard" then it is not consumable, and thus creates "indigestion".   For example, let's say that in order to do some automation task you had to develop in Java and write over 500 lines of code. #fail.

 

My rule of thumb:  Do something useful in less than 50 lines of code, or just do it interactively.

 

THE "JUNOS EZ" LIBRARY FOR PYTHON

 

The "Junos EZ" library is a way for non-programmers to start benefiting from using automation without requiring them to be hardcore programmers.  It is not a set of APIs - APIs are for application programmers - which we've already agreed we are not.  Can Junos EZ be used by "programmers" to build tools? -- of course.  This library could also be the basis of integration with other higher-order IT frameworks (like Ansible or Salt).

 

This series of blogs "Python for Non-Programmers" will introduce the major concepts of Junos EZ.  These include:

 

  • Remote Connectivity and "Fact" Gathering
  • Configuration Management - Structured abstractions
  • Configuration Management - Unstructured snippets and templating
  • Gathering Operational (Run-State) information
  • Multipurpose Utilities (like filesystem, software-upgrade, file-copy)

 

SETUP PYTHON FOR JUNOS AUTOMATION

 

(updated: 2014-Mar-27)

 

The updated installation steps are now posted on the Juniper TechWiki here:

https://techwiki.juniper.net/Automation_Scripting/Junos_OS_PyEZ/Installation

 

TESTING "HELLO, WORLD"

 

Once everything is installed, you can do a quick check by connecting to a Junos device, and displaying the "facts" like software-version and serial-number.  I've documented this example, and others, on a previous blog here.

 

AUTOMATION IS A JOURNEY, AND SO IT BEGINS ...

 

You now have an environment and the consumable tools to begin automation efforts.  I would suggest by starting with "read-only" automation, like gathering statistical information or correlating information like the SRX example.

 

 

FURTHER READING

 

 

Comments
by MrTugs
on ‎11-25-2013 01:30 PM

I'm trying to test this with the hello world script from here (http://forums.juniper.net/t5/Network-Automaniac/Junos-NETCONF-and-SSH-tunneling-Part-2/ba-p/215307). When I do, it can't find the module 'eznc', referenced in:

 

from jnpr.eznc import Netconf

 

I went to Github and tried another 'test' script which uses:

 

from jnpr.junos import Device

 

...and that worked ok. Any ideas where I screwed up? Thank you!

by
on ‎11-25-2013 02:36 PM

@MrTugs,

 

My apologies, I need to update that blog post.  The most recent version of "Junos EZ" has been migrated to a new namespace per feedback.

 

It was: "from jnpr.eznc import Netconf", and it is now "from jnpr.junos import Device".  The docs for the library have been updated on github, and I've scrubbed the "Python for Non-Programmers" series.  I'll scrub my other posts as well.  Thank you again for bringing this to my attention.

 

 

by MrTugs
on ‎11-25-2013 02:50 PM

Thanks so much for the super-fast correction! I am all set now Yeah, baby:

john@dns1:~/jnpr$ python testhw
{'2RE': False,
'RE0': {'last_reboot_reason': '0x2:watchdog ',
'mastership_state': 'master',
'model': 'EX3200-24T, 8 POE',
'status': 'OK',
'up_time': '46 days, 8 hours, 36 minutes, 48 seconds'},
'fqdn': 'noisy',
'hostname': 'noisy',
'ifd_style': 'SWITCH',
'master': 'RE0',
'model': 'EX3200-24T',
'personality': 'SWITCH',
'serialnumber': '--',
'switch_style': 'VLAN',
'vc_capable': False,
'version': '12.3R3.4',
'version_info': junos.versino_info(major=(12, 3), type=R, minor=3, build=4)}

 

Now to start playing with it more!

by
on ‎11-25-2013 03:02 PM

@MrTugs,


Excellent.  Check out the Tables and Vies under the "jnpr/junos/op" directory.  It abstracts getting operational/run-state data.  It's the topic of my next (and final) blog in this series.  You can jump directly to the docs from here.

by Maurizio Ipsale
on ‎12-17-2013 06:42 AM

Hi,

when I try installing the NETCONF 'ncclient library' I get a lot of errors:


src/lxml/lxml.etree.c:175069: error: ‘findChildBackwards’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175070: error: ‘nextElement’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175071: error: ‘previousElement’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175073: error: ‘pyunicode’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175077: error: ‘namespacedName’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175078: error: ‘namespacedNameFromNsName’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175081: error: ‘findOrBuildNodeNsPrefix’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175087: error: expected declaration specifiers or ‘...’ before ‘xmlParserCtxt’

src/lxml/lxml.etree.c:175088: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseParser’ has no member named ‘_newParserCtxt’

src/lxml/lxml.etree.c:175088: error: ‘xmlParserCtxt’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175088: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175088: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_11_BaseParser__newParserCtxt’

src/lxml/lxml.etree.c:175089: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseParser’ has no member named ‘_newPushParserCtxt’

src/lxml/lxml.etree.c:175089: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175089: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_11_BaseParser__newPushParserCtxt’

src/lxml/lxml.etree.c:175090: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseParser’ has no member named ‘_copy’

src/lxml/lxml.etree.c:175091: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseParser’ has no member named ‘_parseUnicodeDoc’

src/lxml/lxml.etree.c:175091: error: ‘xmlDoc’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175091: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175091: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_11_BaseParser__parseUnicodeDoc’

src/lxml/lxml.etree.c:175092: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseParser’ has no member named ‘_parseDoc’

src/lxml/lxml.etree.c:175092: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175092: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_11_BaseParser__parseDoc’

src/lxml/lxml.etree.c:175093: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseParser’ has no member named ‘_parseDocFromFile’

src/lxml/lxml.etree.c:175093: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175093: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_11_BaseParser__parseDocFromFile’

src/lxml/lxml.etree.c:175094: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseParser’ has no member named ‘_parseDocFromFilelike’

src/lxml/lxml.etree.c:175094: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175094: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_11_BaseParser__parseDocFromFilelike’

src/lxml/lxml.etree.c:175271: error: ‘struct __pyx_vtabstruct_4lxml_5etree__FileReaderContext’ has no member named ‘_createParserInputBuffer’

src/lxml/lxml.etree.c:175271: error: ‘xmlParserInputBuffer’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175271: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175271: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_18_FileReaderContext__createParserInputBuffer’

src/lxml/lxml.etree.c:175272: error: ‘struct __pyx_vtabstruct_4lxml_5etree__FileReaderContext’ has no member named ‘_createParserInput’

src/lxml/lxml.etree.c:175272: error: ‘xmlParserInput’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175272: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175272: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_18_FileReaderContext__createParserInput’

src/lxml/lxml.etree.c:175273: error: ‘struct __pyx_vtabstruct_4lxml_5etree__FileReaderContext’ has no member named ‘_readDtd’

src/lxml/lxml.etree.c:175273: error: ‘xmlDtd’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175273: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175273: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_18_FileReaderContext__readDtd’

src/lxml/lxml.etree.c:175274: error: ‘struct __pyx_vtabstruct_4lxml_5etree__FileReaderContext’ has no member named ‘_readDoc’

src/lxml/lxml.etree.c:175274: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175274: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_18_FileReaderContext__readDoc’

src/lxml/lxml.etree.c:175275: error: ‘struct __pyx_vtabstruct_4lxml_5etree__FileReaderContext’ has no member named ‘copyToBuffer’

src/lxml/lxml.etree.c:175282: error: expected declaration specifiers or ‘...’ before ‘xmlError’

src/lxml/lxml.etree.c:175297: error: ‘struct __pyx_vtabstruct_4lxml_5etree_XSLT’ has no member named ‘_run_transform’

src/lxml/lxml.etree.c:175297: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175297: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_4XSLT__run_transform’

src/lxml/lxml.etree.c:175313: error: ‘struct __pyx_vtabstruct_4lxml_5etree_ElementDepthFirstIterator’ has no member named ‘_nextNodeAnyTag’

src/lxml/lxml.etree.c:175313: error: ‘xmlNode’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175313: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175313: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_25ElementDepthFirstIterator__nextNodeAnyTag’

src/lxml/lxml.etree.c:175314: error: ‘struct __pyx_vtabstruct_4lxml_5etree_ElementDepthFirstIterator’ has no member named ‘_nextNodeMatchTag’

src/lxml/lxml.etree.c:175314: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175314: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_25ElementDepthFirstIterator__nextNodeMatchTag’

src/lxml/lxml.etree.c:175352: error: expected declaration specifiers or ‘...’ before ‘xmlXPathContext’

src/lxml/lxml.etree.c:175358: error: expected declaration specifiers or ‘...’ before ‘xmlXPathObject’

src/lxml/lxml.etree.c:175414: error: expected declaration specifiers or ‘...’ before ‘xmlNode’

src/lxml/lxml.etree.c:175415: error: expected declaration specifiers or ‘...’ before ‘xmlAttr’

src/lxml/lxml.etree.c:175518: error: expected declaration specifiers or ‘...’ before ‘xmlXPathContext’

src/lxml/lxml.etree.c:175533: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseContext’ has no member named ‘_find_cached_function’

src/lxml/lxml.etree.c:175533: warning: type defaults to ‘int’ in declaration of ‘xmlChar’

src/lxml/lxml.etree.c:175533: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token

src/lxml/lxml.etree.c:175533: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_12_BaseContext__find_cached_function’

src/lxml/lxml.etree.c:175534: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseContext’ has no member named ‘_release_temp_refs’

src/lxml/lxml.etree.c:175535: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseContext’ has no member named ‘_hold’

src/lxml/lxml.etree.c:175536: error: ‘struct __pyx_vtabstruct_4lxml_5etree__BaseContext’ has no member named ‘_findDocumentForNode’

src/lxml/lxml.etree.c:175536: error: expected declaration specifiers or ‘...’ before ‘xmlNode’

src/lxml/lxml.etree.c:175543: error: expected declaration specifiers or ‘...’ before ‘xsltTransformContext’

src/lxml/lxml.etree.c:175552: error: expected declaration specifiers or ‘...’ before ‘xmlNode’

src/lxml/lxml.etree.c:175576: error: expected declaration specifiers or ‘...’ before ‘xmlParserCtxt’

src/lxml/lxml.etree.c:175580: error: expected declaration specifiers or ‘...’ before ‘xmlDoc’

src/lxml/lxml.etree.c:175581: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserContext’ has no member named ‘_handleParseResultDoc’

src/lxml/lxml.etree.c:175581: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175581: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_14_ParserContext__handleParseResultDoc’

src/lxml/lxml.etree.c:175588: error: expected declaration specifiers or ‘...’ before ‘xmlParserCtxt’

src/lxml/lxml.etree.c:175590: error: expected declaration specifiers or ‘...’ before ‘xmlParserCtxt’

src/lxml/lxml.etree.c:175598: error: expected declaration specifiers or ‘...’ before ‘xmlDoc’

src/lxml/lxml.etree.c:175599: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserContext’ has no member named ‘_handleParseResultDoc’

src/lxml/lxml.etree.c:175599: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175599: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_20_TargetParserContext__handleParseResultDoc’

src/lxml/lxml.etree.c:175601: error: expected declaration specifiers or ‘...’ before ‘xmlDoc’

src/lxml/lxml.etree.c:175611: error: expected declaration specifiers or ‘...’ before ‘xmlXPathContext’

src/lxml/lxml.etree.c:175656: error: ‘struct __pyx_vtabstruct_4lxml_5etree__Document’ has no member named ‘_findOrBuildNodeNs’

src/lxml/lxml.etree.c:175656: error: ‘xmlNs’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175656: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175656: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_9_Document__findOrBuildNodeNs’

src/lxml/lxml.etree.c:175657: error: ‘struct __pyx_vtabstruct_4lxml_5etree__Document’ has no member named ‘_setNodeNs’

src/lxml/lxml.etree.c:175657: error: expected declaration specifiers or ‘...’ before ‘xmlNode’

src/lxml/lxml.etree.c:175657: warning: type defaults to ‘int’ in declaration of ‘xmlChar’

src/lxml/lxml.etree.c:175657: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token

src/lxml/lxml.etree.c:175657: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_9_Document__setNodeNs’

src/lxml/lxml.etree.c:175708: error: expected declaration specifiers or ‘...’ before ‘xmlError’

src/lxml/lxml.etree.c:175736: error: expected declaration specifiers or ‘...’ before ‘xmlParserCtxt’

src/lxml/lxml.etree.c:175738: error: expected declaration specifiers or ‘...’ before ‘xmlDoc’

src/lxml/lxml.etree.c:175739: error: expected declaration specifiers or ‘...’ before ‘xmlNode’

src/lxml/lxml.etree.c:175740: error: expected declaration specifiers or ‘...’ before ‘xmlNode’

src/lxml/lxml.etree.c:175741: error: expected declaration specifiers or ‘...’ before ‘xmlNode’

src/lxml/lxml.etree.c:175776: error: expected declaration specifiers or ‘...’ before ‘xmlChar’

src/lxml/lxml.etree.c:175857: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserDictionaryContext’ has no member named ‘_getThreadDict’

src/lxml/lxml.etree.c:175857: error: ‘xmlDict’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175857: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175857: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_24_ParserDictionaryContext__getThreadDict’

src/lxml/lxml.etree.c:175858: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserDictionaryContext’ has no member named ‘initThreadDictRef’

src/lxml/lxml.etree.c:175858: error: expected declaration specifiers or ‘...’ before ‘xmlDict’

src/lxml/lxml.etree.c:175859: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserDictionaryContext’ has no member named ‘initParserDict’

src/lxml/lxml.etree.c:175859: error: expected declaration specifiers or ‘...’ before ‘xmlParserCtxt’

src/lxml/lxml.etree.c:175860: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserDictionaryContext’ has no member named ‘initXPathParserDict’

src/lxml/lxml.etree.c:175860: error: expected declaration specifiers or ‘...’ before ‘xmlXPathContext’

src/lxml/lxml.etree.c:175861: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserDictionaryContext’ has no member named ‘initDocDict’

src/lxml/lxml.etree.c:175861: error: expected declaration specifiers or ‘...’ before ‘xmlDoc’

src/lxml/lxml.etree.c:175862: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserDictionaryContext’ has no member named ‘findImpliedContext’

src/lxml/lxml.etree.c:175863: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserDictionaryContext’ has no member named ‘pushImpliedContextFromParser’

src/lxml/lxml.etree.c:175864: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserDictionaryContext’ has no member named ‘pushImpliedContext’

src/lxml/lxml.etree.c:175865: error: ‘struct __pyx_vtabstruct_4lxml_5etree__ParserDictionaryContext’ has no member named ‘popImpliedContext’

src/lxml/lxml.etree.c:175997: error: ‘struct __pyx_vtabstruct_4lxml_5etree__FilelikeWriter’ has no member named ‘_createOutputBuffer’

src/lxml/lxml.etree.c:175997: error: ‘xmlOutputBuffer’ undeclared (first use in this function)

src/lxml/lxml.etree.c:175997: error: expected expression before ‘)’ token

src/lxml/lxml.etree.c:175997: error: expected ‘;’ before ‘__pyx_f_4lxml_5etree_15_FilelikeWriter__createOutputBuffer’

src/lxml/lxml.etree.c:175998: error: ‘struct __pyx_vtabstruct_4lxml_5etree__FilelikeWriter’ has no member named ‘write’

src/lxml/lxml.etree.c:175999: error: ‘struct __pyx_vtabstruct_4lxml_5etree__FilelikeWriter’ has no member named ‘close’

src/lxml/lxml.etree.c:176030: error: expected declaration specifiers or ‘...’ before ‘xsltSecurityOption’

src/lxml/lxml.etree.c:176031: error: expected declaration specifiers or ‘...’ before ‘xsltTransformContext’

src/lxml/lxml.etree.c:176032: error: expected declaration specifiers or ‘...’ before ‘xsltSecurityOption’

src/lxml/lxml.etree.c:176065: error: expected declaration specifiers or ‘...’ before ‘xmlDoc’

src/lxml/lxml.etree.c:176066: error: expected declaration specifiers or ‘...’ before ‘xmlParserCtxt’

src/lxml/lxml.etree.c:176884: warning: implicit declaration of function ‘xmlThrDefIndentTreeOutput’

src/lxml/lxml.etree.c:176893: warning: implicit declaration of function ‘xmlThrDefLineNumbersDefaultValue’

src/lxml/lxml.etree.c:176911: warning: implicit declaration of function ‘xmlInitParser’

src/lxml/lxml.etree.c:177212: error: ‘xmlParserVersion’ undeclared (first use in this function)

src/lxml/lxml.etree.c:177334: error: ‘LIBXML_VERSION’ undeclared (first use in this function)

src/lxml/lxml.etree.c:178335: error: ‘__pyx_v_4lxml_5etree___DEFAULT_ENTITY_LOADER’ undeclared (first use in this function)

src/lxml/lxml.etree.c:178335: warning: implicit declaration of function ‘xmlGetExternalEntityLoader’

src/lxml/lxml.etree.c:178344: warning: implicit declaration of function ‘xmlSetExternalEntityLoader’

src/lxml/lxml.etree.c:178344: error: ‘xmlExternalEntityLoader’ undeclared (first use in this function)

src/lxml/lxml.etree.c:178344: error: expected ‘)’ before ‘__pyx_f_4lxml_5etree__local_resolver’

src/lxml/lxml.etree.c:178353: error: ‘XML_PARSE_NOENT’ undeclared (first use in this function)

src/lxml/lxml.etree.c:178353: error: ‘XML_PARSE_NOCDATA’ undeclared (first use in this function)

src/lxml/lxml.etree.c:178353: error: ‘XML_PARSE_NONET’ undeclared (first use in this function)

src/lxml/lxml.etree.c:178647: error: ‘XML_PARSE_RECOVER’ undeclared (first use in this function)

src/lxml/lxml.etree.c:178647: error: ‘HTML_PARSE_NONET’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179321: error: ‘XML_XPATH_NUMBER_ERROR’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179331: error: ‘XML_XPATH_UNFINISHED_LITERAL_ERROR’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179341: error: ‘XML_XPATH_VARIABLE_REF_ERROR’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179351: error: ‘XML_XPATH_INVALID_PREDICATE_ERROR’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179361: error: ‘XML_XPATH_UNCLOSED_ERROR’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179371: error: ‘XML_XPATH_INVALID_CHAR_ERROR’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179405: error: ‘XML_XPATH_UNDEF_VARIABLE_ERROR’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179415: error: ‘XML_XPATH_UNDEF_PREFIX_ERROR’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179425: error: ‘XML_XPATH_UNKNOWN_FUNC_ERROR’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179435: error: ‘XML_XPATH_INVALID_OPERAND’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179445: error: ‘XML_XPATH_INVALID_TYPE’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179455: error: ‘XML_XPATH_INVALID_ARITY’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179465: error: ‘XML_XPATH_INVALID_CTXT_SIZE’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179475: error: ‘XML_XPATH_INVALID_CTXT_POSITION’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179818: error: ‘LIBXSLT_VERSION’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179830: error: ‘xsltLibxsltVersion’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179842: error: ‘__pyx_v_4lxml_5etree_XSLT_DOC_DEFAULT_LOADER’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179842: error: ‘xsltDocDefaultLoader’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179851: warning: implicit declaration of function ‘xsltSetLoaderFunc’

src/lxml/lxml.etree.c:179851: error: ‘xsltDocLoaderFunc’ undeclared (first use in this function)

src/lxml/lxml.etree.c:179851: error: expected ‘)’ before ‘__pyx_f_4lxml_5etree__xslt_doc_loader’

src/lxml/lxml.etree.c:180101: warning: implicit declaration of function ‘xsltRegisterAllExtras’

src/lxml/lxml.etree.c:180110: warning: implicit declaration of function ‘exsltRegisterAll’

error: command 'gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/local/bin/python2.7 -c "import setuptools;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-FuoZyY-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip_build_root/lxml
Traceback (most recent call last):
File "/usr/local/bin/pip-2.7", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip-2.7')()
File "/usr/local/lib/python2.7/site-packages/pip/__init__.py", line 148, in main
return command.main(args[1:], options)
File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 169, in main
text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 81: ordinal not in range(128)

by
on ‎12-17-2013 08:08 AM

@Maurizio,

 

What Linux distro/version are you using?  Did you download ncclient from the Juniper github?  It appears that you might not have the right libraries installed.  You many need to manually install the "libxslt" and "libxml2" libraries.  There is a good post here on how that's done:

 

http://lamejournal.com/2013/12/02/installing-junos-ez-library-easy-sdn-part-1/

by musa
on ‎03-06-2014 04:55 AM

I'm getting the same error above,

i'm using Centos and tried to get the libraires manully but didn't succeed even;

 

Cleaning up...
Command /usr/local/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-08NOEd-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/lxml
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
  File "/usr/local/lib/python2.7/site-packages/pip/__init__.py", line 185, in main
    return command.main(cmd_args)
  File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 81: ordinal not in range(128)

by aeroplane
on ‎03-09-2014 10:23 PM

Hi Jeremy

 

Could you please refer me any good book for network automation/scripting using python on amazon store?

 

Thanks

by
on ‎03-16-2014 08:20 AM

@aeroplane - I would suggest "The Quick Python Book" as a good start.

by kalsoup
on ‎04-14-2014 07:47 AM

Hello Jeremy,

 

I am running Python 2.7.5 on Ubuntu 13.10.

I installed: python-pip, python-dev, libxml2-dev and libxslt-dev prior to installing ncclient 0.4.1 (https://pypi.python.org/pypi/ncclient) using  "sudo python setup.py install" from the ncclient directory.

 

After this, I attempt install junos-eznc using "pip install junos-eznc" , but get the following error:

 

"ser@wt-ubuntu:~$ sudo pip install junos-eznc
Downloading/unpacking junos-eznc
  Downloading junos-eznc-0.0.5.tar.gz (81kB): 81kB downloaded
  Running setup.py egg_info for package junos-eznc
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'namespace_packages'
      warnings.warn(msg)
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
      warnings.warn(msg)
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help
    
    error: invalid command 'egg_info'
    Complete output from command python setup.py egg_info:
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'namespace_packages'

  warnings.warn(msg)

/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires'

  warnings.warn(msg)

usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]

   or: -c --help [cmd1 cmd2 ...]

   or: -c --help-commands

   or: -c cmd --help



error: invalid command 'egg_info'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/junos-eznc"

 

Could you please tell me if I'm missing/doing something wrong?

I'm no expert at Linux/Ubuntu and would greatly appreciate your help!

 

Best Regards

by
‎04-15-2014 04:22 AM - edited ‎04-15-2014 04:23 AM

@kalsoup,

 

Thank you for your inquiry.  I haven't personally tested the install process on Ubuntu 13.10, but there are install instructions for on the github repo, here. Please review those instructions and let us know if you have any issues.


Thank you!

by Juniper Employee
‎04-15-2014 06:30 AM - edited ‎04-15-2014 06:30 AM

@kalsoup, This appears to be a system related issue.

 

Please update your system packages and setuptools

 

sudo apt-get update
sudo apt-get upgrade
sudo pip install --upgrade setuptools

 

 

http://stackoverflow.com/questions/11425106/python-pip-install-fails-invalid-command-egg-info

by kalsoup
‎04-15-2014 08:44 AM - edited ‎04-15-2014 02:12 PM

Hello @Jeremy, @rsherman,

 

Thank you both for your quick response!

Looks like I was missing setuptools and Paramiko 1.7+. I installed both of them and junoz-eznc is intalled (I think), but it doesn't look "clean":

 

"Cleaning up...
Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-OTKKcB-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip_build_root/lxml
Storing complete log in /home/.pip/pip.log"

Junos-eznc however does show up as installed

 

$ pip list
junos-eznc (0.0.5)
ncclient (0.4.1)

 

When I try to run a test script from Jeremy's examples (inventory.py), I get :

 

Traceback (most recent call last):
  File "inventory.py", line 4, in <module>
    jdev.open()
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 242, in open
    hostkey_verify=False, device_params={'name':'junos'} )
  File "build/bdist.linux-x86_64/egg/ncclient/manager.py", line 96, in connect_ssh
  File "build/bdist.linux-x86_64/egg/ncclient/transport/ssh.py", line 188, in connect
ncclient.transport.errors.SSHError: Could not open socket to 172.27.12.1:830


Netconf has been enabled on the Junos device.

 

root@wt-ubuntu:/home/projects/Juniper/Scripts# ssh -s 172.27.12.1 netconf
root@172.27.12.1's password:
<!-- No zombies were killed during the creation of this user interface -->
<!-- user root, class super-user -->
<hello>
  <capabilities>
    <capability>urn:ietf params:xml:ns:netconf:base:1.0</capability>
    <capability>urn:ietf params:xml:ns:netconf:capability:candidate:1.0</capability>
    <capability>urn:ietf params:xml:ns:netconf:capability:confirmed-commit:1.0</capability>
    <capability>urn:ietf params:xml:ns:netconf:capability:validate:1.0</capability>
    <capability>urn:ietf params:xml:ns:netconf:capability:url:1.0?protocol=http,ftp,file</capability>
    <capability>http://xml.juniper.net/netconf/junos/1.0</capability>
    <capability>http://xml.juniper.net/dmi/system/1.0</capability>
  </capabilities>
  <session-id>99021</session-id>
</hello>
]]>]]>

 

I will do some more testing and make sure I have all the dependencies and maybe even try a fresh install of Ubuntu.

 

Do you see anything else that might be amiss?

I downloaded ncclient from https://pypi.python.org/pypi/ncclient/0.4.1 and installed it in my "home" projectc directory. Can this directory path be an issue?

 

Thanks again and much appreciate your help!

 

 Edit:

 

It worked!!!

 

root@wt-ubuntu:/home/projects/Juniper/Scripts# python inventory.py
model: SRX210HE2
serial-number: CD3813AK0157

 

To summarize:

1. I was missing Setuptools and Paramiko

2. Netconf has to be opened under the 'edit system services' heierarchy AND 'edit security zones security-zone <your-zone>' heirarchy.

 

I'm super excited to get started with JunOS_PyEZ.

 

Thanks a lot @Jermey and @rsherman for you help!!

 

 

 

Announcements
Juniper Networks Technical Books
About the Author
  • Ben has been working with service providers around the world for the last 15 years developing business cases for a variety of product concepts and new ventures. Ben holds an MBA from MIT and a BS & MS in Mechanical Engineering from Johns Hopkins University.
  • Part of Juniper PS EMEA since 2005 Primarily interested in making technology do the boring repetitive work so I can do fun new work.
  • Donyel Jones-Williams is the Director of Service Provider Product Marketing Management overseeing all of Juniper's Service Provider Products for Juniper Networks. In this role, he leads all of the internal and external marketing activities for Juniper with respect to routing, automation, SDN and NFV. Prior to joining Juniper Networks in January 2014, Donyel was a Senior Product Line Manager for Cisco Systems with in the High End Optical Routing Group managing product lifecycle for multiple products lines helping telecom providers operate efficiently and effectively including; ONS 155xx Product Family, ONS 15216, ONS 15454 MSTP, Carrier Packet Transport Product Family, ME 2600x, & ASR 9000v. He also negotiated favorable agreements with 3rd-party vendors furnishing components and parts and conducted both outbound and inbound marketing (webinars, case study-development, developed and delivered both business & technical at Cisco Live 2005-2012). Donyel graduated from California Polytechnic State University-San Luis Obispo with a Bachelor of Science in Computer Science. While attending Cal Poly SLO he was a collegiate student athlete playing football as a wide receiver and a key member of the National Society of Black Engineers. Donyel is now an active volunteer for V Foundation.
  • Dwayne loves everything related to automation and enjoys talking about it: Automation benefits outweigh any associated disruption.
  • Ebben Aries is a Principal Engineer for Junos Manageability in the Juniper Development and Innovation Division.
  • Michael Pergament, JNCIE-SP #510, JNCIE-ENT #23, JNCIE-DC #3
  • Marcel Wiget is a member of the Routing TME team. His career within Juniper started back in 2009 as a Senior Systems Engineer driving one of the first MX based Broadband Edge deployment to success. Prior to Juniper, Marcel held various positions in pre-sales, professional services and development at Chantry Networks, Spring Tide, Nortel Networks and Wellfleet.
  • Surya Nimmagadda is a Distinguished Engineer working on packet forwarding software for Juniper Networks routing and switching platforms.
  • Pallavi Mahajan is Vice President Engineering, Junos Engineering, and leads the Junos Programmability & Automation teams
  • Product Manager, JUNOS Automation