├── .devcontainer ├── .devcontainer.json └── Dockerfile.standalone ├── .dockerignore ├── .gitignore ├── Makefile ├── README.md └── requirements.txt /.devcontainer/.devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "py-network-automation-env", 3 | "context": ".", 4 | "dockerFile": "Dockerfile", 5 | "mounts": ["source=${localEnv:HOME}${localEnv:USERPROFILE}/.ssh,target=/root/.ssh,type=bind,consistency=cached"], 6 | "extensions": [ 7 | "ms-python.python", 8 | "vscoss.vscode-ansible", 9 | "bungcip.better-toml", 10 | "davidanson.vscode-markdownlint", 11 | "redhat.vscode-yaml", 12 | "samuelcolvin.jinjahtml", 13 | "eamodio.gitlens", 14 | "oderwat.indent-rainbow", 15 | "hediet.vscode-drawio", 16 | "usernamehw.errorlens" 17 | ], 18 | "settings": { 19 | "python.pythonPath": "/opt/conda/bin/python", 20 | "python.linting.flake8Enabled": true, 21 | "python.linting.enabled": true, 22 | "python.linting.flake8Args": [ 23 | "--max-line-length=88" 24 | ], 25 | "python.formatting.provider": "black", 26 | "python.linting.pylintEnabled": false 27 | }, 28 | "postCreateCommand": "apt-get update -y && apt-get install -y iputils-ping git gcc make vim wget tcpdump curl wget && pip install -r requirements.txt" 29 | } 30 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile.standalone: -------------------------------------------------------------------------------- 1 | FROM python:3.8 2 | 3 | LABEL version="0.0.1" 4 | LABEL description="Network Automation Development Environment" 5 | LABEL maintainer="Rick Donato" 6 | 7 | WORKDIR /workspace 8 | COPY . /workspace 9 | 10 | # Below lines will not be run when using integrated VSCode/Docker. 11 | RUN apt-get update -y 12 | RUN apt-get install -y vim tcpdump curl wget gcc procps net-tools 13 | RUN pip install -r requirements.txt 14 | 15 | CMD ["/bin/bash"] 16 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.git 2 | **/.gitignore 3 | **/.vscode 4 | README.md 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # virl directory 2 | .virl/* 3 | 4 | # ansible directories/files 5 | *.retry 6 | 7 | # Byte-compiled / optimized / DLL files 8 | __pycache__/ 9 | *.py[cod] 10 | *$py.class 11 | 12 | # C extensions 13 | *.so 14 | 15 | # Distribution / packaging 16 | .Python 17 | build/ 18 | develop-eggs/ 19 | dist/ 20 | downloads/ 21 | eggs/ 22 | .eggs/ 23 | lib/ 24 | lib64/ 25 | parts/ 26 | sdist/ 27 | var/ 28 | wheels/ 29 | pip-wheel-metadata/ 30 | share/python-wheels/ 31 | *.egg-info/ 32 | .installed.cfg 33 | *.egg 34 | MANIFEST 35 | 36 | # PyInstaller 37 | # Usually these files are written by a python script from a template 38 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 39 | *.manifest 40 | *.spec 41 | 42 | # Installer logs 43 | pip-log.txt 44 | pip-delete-this-directory.txt 45 | 46 | # Unit test / coverage reports 47 | htmlcov/ 48 | .tox/ 49 | .nox/ 50 | .coverage 51 | .coverage.* 52 | .cache 53 | nosetests.xml 54 | coverage.xml 55 | *.cover 56 | .hypothesis/ 57 | .pytest_cache/ 58 | 59 | # Translations 60 | *.mo 61 | *.pot 62 | 63 | # Django stuff: 64 | *.log 65 | local_settings.py 66 | db.sqlite3 67 | db.sqlite3-journal 68 | 69 | # Flask stuff: 70 | instance/ 71 | .webassets-cache 72 | 73 | # Scrapy stuff: 74 | .scrapy 75 | 76 | # Sphinx documentation 77 | docs/_build/ 78 | 79 | # PyBuilder 80 | target/ 81 | 82 | # Jupyter Notebook 83 | .ipynb_checkpoints 84 | 85 | # IPython 86 | profile_default/ 87 | ipython_config.py 88 | 89 | # pyenv 90 | .python-version 91 | 92 | # pipenv 93 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 94 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 95 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 96 | # install all needed dependencies. 97 | #Pipfile.lock 98 | 99 | # celery beat schedule file 100 | celerybeat-schedule 101 | 102 | # SageMath parsed files 103 | *.sage.py 104 | 105 | # Environments 106 | .env 107 | .venv 108 | env/ 109 | venv*/ 110 | ENV/ 111 | env.bak/ 112 | venv.bak/ 113 | 114 | # Spyder project settings 115 | .spyderproject 116 | .spyproject 117 | 118 | # Rope project settings 119 | .ropeproject 120 | 121 | # mkdocs documentation 122 | /site 123 | 124 | # mypy 125 | .mypy_cache/ 126 | .dmypy.json 127 | dmypy.json 128 | 129 | # Pyre type checker 130 | .pyre/ 131 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL := help 2 | 3 | DOCKER_IMG = rickdonato/netdev 4 | DOCKER_TAG = latest 5 | export PYROOT=. 6 | export ANSIBLEROOT=./ansible/ 7 | 8 | .PHONY: help 9 | help: 10 | @grep '^[a-zA-Z]' $(MAKEFILE_LIST) | \ 11 | sort | \ 12 | awk -F ':.*?## ' 'NF==2 {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}' 13 | 14 | ### ------------------------------------------------- 15 | ### FORMAT 16 | ### ------------------------------------------------- 17 | 18 | .PHONY: remove-yml-eol-spaces 19 | remove-yml-eol-spaces: ## Remove end of line spaces from yaml files 20 | @echo "[*] Removing EOL YAML spaces." 21 | @find ./ \( -name *.yaml -o -name *.yml \) | xargs sed -i "s/\s *$$//g" 22 | 23 | .PHONY: black-check 24 | black-check: ## Perform Black formatting against py files. Check ONLY. 25 | @echo "[*] Performing Black (Check)." 26 | @. ./venv/bin/activate 27 | @find $$PYROOT -name venv -prune -o -name '*.py' -exec black -v --check {} + 28 | 29 | .PHONY: black-diff 30 | black-diff: ## Perform formatting against py files. Diff ONLY. 31 | @echo "[*] Performing Black (Diff)." 32 | @. ./venv/bin/activate 33 | @find $$PYROOT -name venv -prune -o -name '*.py' -exec black --diff {} + 34 | 35 | .PHONY: black 36 | black: ## Perform formatting against py files. 37 | @echo "[*] Performing Black." 38 | @. ./venv/bin/activate 39 | @find $$PYROOT -name venv -prune -o -name '*.py' -exec black {} + 40 | 41 | ### ------------------------------------------------- 42 | ### LINT 43 | ### ------------------------------------------------- 44 | 45 | .PHONY: ansible-lint 46 | lint-ansible: ## Perform linting against ansible yaml files 47 | @echo "[*] Performing YAML Lint." 48 | @. ./venv/bin/activate 49 | @find $$ANSIBLEROOT \( -name *.yaml -o -name *.yml \) -exec ansible-lint {} + 50 | 51 | .PHONY: pylint 52 | lint-py: ## Perform linting against py files 53 | @echo "[*] Performing PyLint." 54 | @. ./venv/bin/activate 55 | @find $$PYROOT -name venv -prune -o -name '*.py' -exec pylint {} + 56 | 57 | ### ------------------------------------------------- 58 | ### OTHER 59 | ### ------------------------------------------------- 60 | 61 | .PHONY: requirements 62 | update: ## Update pip requirements.txt 63 | @echo "[*] Updating pip requirements.txt" 64 | pip freeze > requirements.txt 65 | 66 | ### ------------------------------------------------- 67 | ### VIRTUALENV 68 | ### ------------------------------------------------- 69 | 70 | .PHONY: venv 71 | venv: ## Install virtualenv, create virtualenv, install requirements 72 | @echo "[*] Create virtual environment and install deps (Python3.x)" 73 | virtualenv --python=`which python3` venv 74 | . ./venv/bin/activate 75 | pip install -r ./requirements.txt 76 | 77 | ### ------------------------------------------------- 78 | ### DOCKER 79 | ### ------------------------------------------------- 80 | 81 | build: ## build docker container. 82 | docker build -t $(DOCKER_IMG):$(DOCKER_TAG) . 83 | 84 | run: ## run docker container 85 | docker run -d -t \ 86 | $(DOCKER_IMG):$(DOCKER_TAG) 87 | 88 | # :%s/^[ ]\+/\t/g - automatically replace all tabs with spaces 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Network Automation Python Environment 2 | 3 | This repo is WIP... 4 | 5 | ## Docker 6 | ``` 7 | git clone https://github.com/rickdonato/network-automation-py-dev 8 | docker build --tag network-automation-dev:standalone --file Dockerfile.standalone . 9 | docker run --rm -it network-automation-dev:standalone 10 | ``` 11 | 12 | ## VSCode 13 | * `git clone https://github.com/rickdonato/network-automation-py-dev` 14 | * Open `network-automation-py-dev` folder in VSCode. 15 | * VSCode will detect `devcontainer.json` file and create container. 16 | * Your dev envrionment will be ready using this container environment. 17 | For full details around environment checkout `devcontainer.json`. 18 | 19 | ## Makefile 20 | Various tasks can be run via the `Makefile`. 21 | 22 | ## Tools 23 | The following tools are installed: 24 | * Chromaterm - Colorize network output - `cat running-config.txt | ct` 25 | 26 | ## VSCode Extenstions 27 | * alefragnani.bookmarks 28 | * usernamehw.errorlens 29 | * eamodio.gitlens 30 | * oderwat.indent-rainbow 31 | * rubymaniac.vscode-paste-and-indent 32 | * ms-python.python 33 | * visualstudioexptteam.vscodeintellicode 34 | 35 | 36 | ## To Do 37 | poetery 38 | 39 | * Shell - https://ohmyz.sh/ 40 | 41 | * pylint - Linter 42 | * Black - code formatters 43 | * vulture - find unused code. 44 | 45 | * pylint 46 | 47 | * saftey 48 | * Bandit - Security Checker 49 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | chromaterm 2 | black 3 | --------------------------------------------------------------------------------