summaryrefslogtreecommitdiffstats
path: root/eos_downloader/cli/info
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-11 09:25:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-12 05:31:22 +0000
commit7ad1d0e0af695fa7f872b740a1bb7b2897eb41bd (patch)
tree13dd59a8ea98206a8c56ffd466f59c146f9f19c7 /eos_downloader/cli/info
parentInitial commit. (diff)
downloadeos-downloader-upstream/0.8.1.tar.xz
eos-downloader-upstream/0.8.1.zip
Adding upstream version 0.8.1.upstream/0.8.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'eos_downloader/cli/info')
-rw-r--r--eos_downloader/cli/info/__init__.py0
-rw-r--r--eos_downloader/cli/info/commands.py87
2 files changed, 87 insertions, 0 deletions
diff --git a/eos_downloader/cli/info/__init__.py b/eos_downloader/cli/info/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/eos_downloader/cli/info/__init__.py
diff --git a/eos_downloader/cli/info/commands.py b/eos_downloader/cli/info/commands.py
new file mode 100644
index 0000000..b51003b
--- /dev/null
+++ b/eos_downloader/cli/info/commands.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+# coding: utf-8 -*-
+# pylint: disable=no-value-for-parameter
+# pylint: disable=too-many-arguments
+# pylint: disable=line-too-long
+# pylint: disable=redefined-builtin
+# flake8: noqa E501
+
+"""
+Commands for ARDL CLI to list data.
+"""
+
+import sys
+from typing import Union
+
+import click
+from loguru import logger
+from rich.console import Console
+from rich.pretty import pprint
+
+import eos_downloader.eos
+from eos_downloader.models.version import BASE_VERSION_STR, RTYPE_FEATURE, RTYPES
+
+
+@click.command(no_args_is_help=True)
+@click.pass_context
+@click.option('--latest', '-l', is_flag=True, type=click.BOOL, default=False, help='Get latest version in given branch. If --branch is not use, get the latest branch with specific release type')
+@click.option('--release-type', '-rtype', type=click.Choice(RTYPES, case_sensitive=False), default=RTYPE_FEATURE, help='EOS release type to search')
+@click.option('--branch', '-b', type=click.STRING, default=None, help='EOS Branch to list releases')
+@click.option('--verbose', '-v', is_flag=True, type=click.BOOL, default=False, help='Human readable output. Default is none to use output in script)')
+@click.option('--log-level', '--log', help='Logging level of the command', default='warning', type=click.Choice(['debug', 'info', 'warning', 'error', 'critical'], case_sensitive=False))
+def eos_versions(ctx: click.Context, log_level: str, branch: Union[str,None] = None, release_type: str = RTYPE_FEATURE, latest: bool = False, verbose: bool = False) -> None:
+ # pylint: disable = too-many-branches
+ """
+ List Available EOS version on Arista.com website.
+
+ Comes with some filters to get latest release (F or M) as well as branch filtering
+
+ - To get latest M release available (without any branch): ardl info eos-versions --latest -rtype m
+
+ - To get latest F release available: ardl info eos-versions --latest -rtype F
+ """
+ console = Console()
+ # Get from Context
+ token = ctx.obj['token']
+
+ logger.remove()
+ if log_level is not None:
+ logger.add("eos-downloader.log", rotation="10 MB", level=log_level.upper())
+
+ my_download = eos_downloader.eos.EOSDownloader(
+ image='unset',
+ software='EOS',
+ version='unset',
+ token=token,
+ hash_method='sha512sum')
+
+ auth = my_download.authenticate()
+ if verbose and auth:
+ console.print('✅ Authenticated on arista.com')
+
+ if release_type is not None:
+ release_type = release_type.upper()
+
+ if latest:
+ if branch is None:
+ branch = str(my_download.latest_branch(rtype=release_type).branch)
+ latest_version = my_download.latest_eos(branch, rtype=release_type)
+ if str(latest_version) == BASE_VERSION_STR:
+ console.print(f'[red]Error[/red], cannot find any version in {branch} for {release_type} release type')
+ sys.exit(1)
+ if verbose:
+ console.print(f'Branch {branch} has been selected with release type {release_type}')
+ if branch is not None:
+ console.print(f'Latest release for {branch}: {latest_version}')
+ else:
+ console.print(f'Latest EOS release: {latest_version}')
+ else:
+ console.print(f'{ latest_version }')
+ else:
+ versions = my_download.get_eos_versions(branch=branch, rtype=release_type)
+ if verbose:
+ console.print(f'List of available versions for {branch if branch is not None else "all branches"}')
+ for version in versions:
+ console.print(f' → {str(version)}')
+ else:
+ pprint([str(version) for version in versions])