Skip to content

Commit

Permalink
feat(cli): Implement native python cli (#21)
Browse files Browse the repository at this point in the history
* feat(cli): Implement native python cli

* feat(cli): Use a more generic entrypoint

* fix(cli): Update boolean types

* feat(cli): Implement a debug entrypoint

* feat(cli): Implement entrypoint to dl cvp

* cut(eos-download): set script as deprecated

* doc: Refactor doc with CLI

* make(docker): Refresh dockerfile with CLI
  • Loading branch information
titom73 authored Feb 3, 2023
1 parent b1ec40f commit 2155aab
Show file tree
Hide file tree
Showing 16 changed files with 488 additions and 132 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,6 @@ cython_debug/

*.tar.xz

report.html
report.html

arista.xml
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PYTHON_VER=3.8
ARG PYTHON_VER=3.10

FROM python:${PYTHON_VER}-slim

Expand All @@ -12,6 +12,7 @@ LABEL com.example.version="edge"
LABEL com.example.release-date="2022-04-05"
LABEL com.example.version.is-production="False"

RUN pip install .
ENV PYTHONPATH=/local
RUN pip --no-cache-dir install .

CMD [ "/usr/local/bin/eos-download" ]
ENTRYPOINT [ "/usr/local/bin/ardl" ]
177 changes: 52 additions & 125 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,114 +8,78 @@ Script to download Arista softwares to local folder, Cloudvision or EVE-NG.
pip install eos-downloader
```

## scripts
## CLI commands

### eos-download
A new CLI is available to execute commands. This CLI is going to replace [`eos-download`](./bin/README.md) script which is now marked as __deprecated__

```bash
usage: eos-download [-h]
--version VERSION
[--token TOKEN]
[--image IMAGE]
[--destination DESTINATION]
[--eve]
[--noztp]
[--import_docker]
[--docker_name DOCKER_NAME]
[--verbose VERBOSE]
[--log]

EOS downloader script.

optional arguments:
-h, --help show this help message and exit
--token TOKEN arista.com user API key - can use ENV:ARISTA_TOKEN
--image IMAGE Type of EOS image required
--version VERSION EOS version to download from website
--destination DESTINATION
Path where to save EOS package downloaded
--eve Option to install EOS package to EVE-NG
--noztp Option to deactivate ZTP when used with EVE-NG
--import_docker Option to import cEOS image to docker
--docker_name DOCKER_NAME
Docker image name to use
--verbose VERBOSE Script verbosity
--log Option to activate logging to eos-downloader.log file
```
ardl
Usage: ardl [OPTIONS] COMMAND [ARGS]...

Arista Network Download CLI

Options:
--token TEXT Arista Token from your customer account [env var:
ARISTA_TOKEN]
--help Show this message and exit.

- Token are read from `ENV:ARISTA_TOKEN` unless you specify a specific token with CLI.
Commands:
debug Debug commands to work with ardl
get Download Arista from Arista website
version Display version of ardl
```

- Supported platforms:
### Download EOS Package

- `INT`: International version
- `64`: 64 bits version
- `2GB` for 2GB flash platform
- `2GB-INT`: for 2GB running International
- `vEOS`: Virtual EOS image
- `vEOS-lab`: Virtual Lab EOS
- `vEOS64-lab`: Virtual Lab EOS running 64B
- `cEOS`: Docker version of EOS
- `cEOS64`: Docker version of EOS running in 64 bits

#### Examples
> Supported packages are: EOS, cEOS, vEOS-lab, cEOS64
- Download vEOS-lab image and install in EVE-NG
You can download EOS packages with following commands:

```bash
$ eos-download --image vEOS-lab --version 4.25.7M --eve --noztp
# Example for a cEOS package
$ ardl get eos --version 4.28.3M --image-type cEOS
```

- Download Docker image
Available options are :

```bash
$ eos-download --image cEOS --version 4.27.1F
🪐 eos-downloader is starting...
- Image Type: cEOS
- Version: 4.27.2F
✅ Authenticated on arista.com
🔎 Searching file cEOS-lab-4.27.2F.tar.xz
-> Found file at /support/download/EOS-USA/Active Releases/4.27/EOS-4.27.2F/cEOS-lab/cEOS-lab-4.27.2F.tar.xz
💾 Downloading cEOS-lab-4.27.2F.tar.xz ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 17.1 MB/s • 451.6/451.6 MB • 0:00:19 •
🚀 Running checksum validation
🔎 Searching file cEOS-lab-4.27.2F.tar.xz.sha512sum
-> Found file at /support/download/EOS-USA/Active
Releases/4.27/EOS-4.27.2F/cEOS-lab/cEOS-lab-4.27.2F.tar.xz.sha512sum
💾 Downloading cEOS-lab-4.27.2F.tar.xz.sha512sum ━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • ? • 154/154 bytes • 0:00:00 •
✅ Downloaded file is correct.
Options:
--image-type [64|INT|2GB-INT|cEOS|cEOS64|vEOS|vEOS-lab|EOS-2GB|default]
EOS Image type [required]
--version TEXT EOS version [required]
--docker-name TEXT Docker image name (default: arista/ceos)
[default: arista/ceos]
--output PATH Path to save image [default: .]
--log-level, --log [debug|info|warning|error|critical]
Logging level of the command
--eve-ng / --no-eve-ng Run EVE-NG vEOS provisioning (only if CLI
runs on an EVE-NG server)
--disable-ztp / --no-disable-ztp
Disable ZTP process in vEOS image (only
available with --eve-ng)
--import-docker / --no-import-docker
Import docker image (only available with
--image_type cEOSlab)
```
__Note:__ `ARISTA_TOKEN` should be set in your .profile and not set for each command. If not set, you can use `--token` knob.
### Download CVP package
> Supported packages are: OVA, KVM, RPM, Upgrade
```bash
# Export Token
export ARISTA_TOKEN="xxxxxxx"
$ ardl get cvp --format upgrade --version 2022.2.1 --log-level debug --output ~/Downloads
```
### Cloudvision Image uploader

Create an image bundle on Cloudvision.
Available options are :
```bash
cvp-upload -h
usage: cvp-upload [-h]
[--token TOKEN]
[--image IMAGE]
--cloudvision CLOUDVISION
[--create_bundle]
[--timeout TIMEOUT]
[--verbose VERBOSE]

Cloudvision Image uploader script.

optional arguments:
-h, --help show this help message and exit
--token TOKEN CVP Authentication token - can use ENV:ARISTA_AVD_CV_TOKEN
--image IMAGE Type of EOS image required
--cloudvision CLOUDVISION
Cloudvision instance where to upload image
--create_bundle Option to create image bundle with new uploaded image
--timeout TIMEOUT Timeout connection. Default is set to 1200sec
--verbose VERBOSE Script verbosity
--format [ova|rpm|kvm|upgrade] CVP Image type [required]
--version TEXT CVP version [required]
--output PATH Path to save image [default: .]
--log-level, --log [debug|info|warning|error|critical]
Logging level of the command
--help Show this message and exit.
```
## Requirements
Expand All @@ -132,46 +96,9 @@ scp
tqdm
```
## Installation

### Python PIP

```bash
# Development version from github
$ pip install git+https://github.com/titom73/eos-downloader

# Stable versions
pip install eos-downloader
```

<!-- ### Poetry
Deactivated since pyproject.toml is first source for pip and do not cover script section of setup.py
```bash
# Install dependencies
poetry install
# Run script
poetry run python <script>
``` -->
### Docker Image

A [docker image](https://hub.docker.com/repository/docker/titom73/eos-downloader/tags?page=1&ordering=last_updated) is also available when Python cannot be used.

```bash
$ docker pull titom73/eos-downloader:edge
$ docker run -it -rm -v ${PWD}:/download titom73/eos-downloader:edge bash
$ cd /download
$ eos-download --image cEOS --version 4.27.1F
```
#### Available TAGS
## Docker
- `edge`: Latest version built from the main branch
- `latest`: Latest stable Version
- `semver`: Version built from git tag
- `latest-dind`: Latest stable Version with docker CLI
- `semver-dind`: Version built from git tag with docker CLI
Please refer to [docker documentation](docs/docker.md)
## Author
Expand Down
111 changes: 111 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
## scripts

These scripts are deprecated and will be removed in a futur version. Please prefer the use of the CLI implemented in the package.

### eos-download

```bash
usage: eos-download [-h]
--version VERSION
[--token TOKEN]
[--image IMAGE]
[--destination DESTINATION]
[--eve]
[--noztp]
[--import_docker]
[--docker_name DOCKER_NAME]
[--verbose VERBOSE]
[--log]

EOS downloader script.

optional arguments:
-h, --help show this help message and exit
--token TOKEN arista.com user API key - can use ENV:ARISTA_TOKEN
--image IMAGE Type of EOS image required
--version VERSION EOS version to download from website
--destination DESTINATION
Path where to save EOS package downloaded
--eve Option to install EOS package to EVE-NG
--noztp Option to deactivate ZTP when used with EVE-NG
--import_docker Option to import cEOS image to docker
--docker_name DOCKER_NAME
Docker image name to use
--verbose VERBOSE Script verbosity
--log Option to activate logging to eos-downloader.log file
```

- Token are read from `ENV:ARISTA_TOKEN` unless you specify a specific token with CLI.

- Supported platforms:

- `INT`: International version
- `64`: 64 bits version
- `2GB` for 2GB flash platform
- `2GB-INT`: for 2GB running International
- `vEOS`: Virtual EOS image
- `vEOS-lab`: Virtual Lab EOS
- `vEOS64-lab`: Virtual Lab EOS running 64B
- `cEOS`: Docker version of EOS
- `cEOS64`: Docker version of EOS running in 64 bits

#### Examples

- Download vEOS-lab image and install in EVE-NG

```bash
$ eos-download --image vEOS-lab --version 4.25.7M --eve --noztp
```

- Download Docker image

```bash
$ eos-download --image cEOS --version 4.27.1F
🪐 eos-downloader is starting...
- Image Type: cEOS
- Version: 4.27.2F
✅ Authenticated on arista.com
🔎 Searching file cEOS-lab-4.27.2F.tar.xz
-> Found file at /support/download/EOS-USA/Active Releases/4.27/EOS-4.27.2F/cEOS-lab/cEOS-lab-4.27.2F.tar.xz
💾 Downloading cEOS-lab-4.27.2F.tar.xz ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 17.1 MB/s • 451.6/451.6 MB • 0:00:19 •
🚀 Running checksum validation
🔎 Searching file cEOS-lab-4.27.2F.tar.xz.sha512sum
-> Found file at /support/download/EOS-USA/Active
Releases/4.27/EOS-4.27.2F/cEOS-lab/cEOS-lab-4.27.2F.tar.xz.sha512sum
💾 Downloading cEOS-lab-4.27.2F.tar.xz.sha512sum ━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • ? • 154/154 bytes • 0:00:00 •
✅ Downloaded file is correct.
```

__Note:__ `ARISTA_TOKEN` should be set in your .profile and not set for each command. If not set, you can use `--token` knob.

```bash
# Export Token
export ARISTA_TOKEN="xxxxxxx"
```

### Cloudvision Image uploader

Create an image bundle on Cloudvision.

```bash
cvp-upload -h
usage: cvp-upload [-h]
[--token TOKEN]
[--image IMAGE]
--cloudvision CLOUDVISION
[--create_bundle]
[--timeout TIMEOUT]
[--verbose VERBOSE]

Cloudvision Image uploader script.

optional arguments:
-h, --help show this help message and exit
--token TOKEN CVP Authentication token - can use ENV:ARISTA_AVD_CV_TOKEN
--image IMAGE Type of EOS image required
--cloudvision CLOUDVISION
Cloudvision instance where to upload image
--create_bundle Option to create image bundle with new uploaded image
--timeout TIMEOUT Timeout connection. Default is set to 1200sec
--verbose VERBOSE Script verbosity
```
3 changes: 3 additions & 0 deletions bin/eos-download
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ if __name__ == '__main__':
cli_options = read_cli()

console = Console()

console.print('\n[red]WARNING: This script is now deprecated. Please use ardl cli instead[/red]\n\n')

if cli_options.token is None or cli_options.token == '':
console.print('\n❗ Token is unset ! Please configure ARISTA_TOKEN or use --token option', style="bold red")
sys.exit(1)
Expand Down
Loading

0 comments on commit 2155aab

Please sign in to comment.