Debian Codegraph @

DOCKER-EXAMPLES.md

raw
1 # Examples of using the Docker image
2
3 ## To run interactive PyEZ (aka Junos power shell):
4
5 `docker run -it juniper/pyez python`
6
7 ```
8 $ docker run -it juniper/pyez python
9 Python 2.7.12 (default, Jun 29 2016, 08:57:23)
10 [GCC 5.3.0] on linux2
11 Type "help", "copyright", "credits" or "license" for more information.
12 >>> from jnpr.junos import Device
13 >>> import sys
14 >>> dev = Device('vmx', user='user',passwd='pass')
15 >>> dev.open()
16 >>> print dev.facts
17 {'2RE': False, 'model': 'VMX'}
18 >>> quit()
19 $
20 ```
21
22 ## As an executable package:
23
24 `docker run -it -v /some/dir:/scripts juniper/pyez python some_script.py options arguments`
25
26 ```
27 $ cd fetcher/
28 $ docker run -it -v $PWD:/scripts juniper/pyez python fetcher.py
29 Enter filename: hosts.csv
30 Username: user
31 Password:
32 ====================================================================================================
33 Inventory Report
34 ----------------------------------------------------------------------------------------------------
35 All done. Please see errors.txt for any errors.
36 ```
37
38 In this way, we can use the combination of Docker image + pyez script as an executable. Pretty neat huh? Oh, and in case you were wondering about the error logs (in this case exceptions are logged to a file, not just to stdout), they are written to the file and accessible from the host.
39
40 ```
41 $ cat fetcher/errors.txt
42 Cannot connect to device: ConnectTimeoutError(vmx.local)
43 ```
44
45 ## As a PyEZ terminal
46
47 `docker run -it juniper/pyez sh`
48
49 ```
50 $ cd fetcher/
51 $ docker run -it -v $PWD:/scripts juniper/pyez
52 /scripts # ls
53 README.md errors.txt fetcher.py hosts.csv
54 /scripts # python fetcher.py
55 Enter filename: hosts.csv
56 Username: user
57 Password:
58 ====================================================================================================
59 Inventory Report
60 ----------------------------------------------------------------------------------------------------
61 All done. Please see errors.txt for any errors.
62 ```
63
64 ## Make a bash alias to use it as an executable:
65
66 ```
67 $ alias pyez="docker run -it --rm -v $PWD:/scripts juniper/pyez python"
68 $ pyez some_script.py
69 ```