Merging upstream version 0.9.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
857951d9ac
commit
161de8690e
28 changed files with 1073 additions and 859 deletions
|
@ -14,13 +14,20 @@ import rich
|
|||
from loguru import logger
|
||||
from rich import console
|
||||
|
||||
from eos_downloader.models.version import BASE_BRANCH_STR, BASE_VERSION_STR, REGEX_EOS_VERSION, RTYPE_FEATURE, EosVersion
|
||||
from eos_downloader.models.version import (
|
||||
BASE_BRANCH_STR,
|
||||
BASE_VERSION_STR,
|
||||
REGEX_EOS_VERSION,
|
||||
RTYPE_FEATURE,
|
||||
EosVersion,
|
||||
)
|
||||
from eos_downloader.object_downloader import ObjectDownloader
|
||||
|
||||
# logger = logging.getLogger(__name__)
|
||||
|
||||
console = rich.get_console()
|
||||
|
||||
|
||||
class EOSDownloader(ObjectDownloader):
|
||||
"""
|
||||
EOSDownloader Object to download EOS images from Arista.com website
|
||||
|
@ -47,22 +54,27 @@ class EOSDownloader(ObjectDownloader):
|
|||
file_path : str
|
||||
Path where EOS image is located
|
||||
"""
|
||||
logger.info('Mounting volume to disable ZTP')
|
||||
console.print('🚀 Mounting volume to disable ZTP')
|
||||
logger.info("Mounting volume to disable ZTP")
|
||||
console.print("🚀 Mounting volume to disable ZTP")
|
||||
raw_folder = os.path.join(file_path, "raw")
|
||||
os.system(f"rm -rf {raw_folder}")
|
||||
os.system(f"mkdir -p {raw_folder}")
|
||||
os.system(
|
||||
f'guestmount -a {os.path.join(file_path, "hda.qcow2")} -m /dev/sda2 {os.path.join(file_path, "raw")}')
|
||||
ztp_file = os.path.join(file_path, 'raw/zerotouch-config')
|
||||
with open(ztp_file, 'w', encoding='ascii') as zfile:
|
||||
zfile.write('DISABLE=True')
|
||||
logger.info(f'Unmounting volume in {file_path}')
|
||||
f'guestmount -a {os.path.join(file_path, "hda.qcow2")} -m /dev/sda2 {os.path.join(file_path, "raw")}'
|
||||
)
|
||||
ztp_file = os.path.join(file_path, "raw/zerotouch-config")
|
||||
with open(ztp_file, "w", encoding="ascii") as zfile:
|
||||
zfile.write("DISABLE=True")
|
||||
logger.info(f"Unmounting volume in {file_path}")
|
||||
os.system(f"guestunmount {os.path.join(file_path, 'raw')}")
|
||||
os.system(f"rm -rf {os.path.join(file_path, 'raw')}")
|
||||
logger.info(f"Volume has been successfully unmounted at {file_path}")
|
||||
|
||||
def _parse_xml_for_version(self,root_xml: ET.ElementTree, xpath: str = './/dir[@label="Active Releases"]/dir/dir/[@label]') -> List[EosVersion]:
|
||||
def _parse_xml_for_version(
|
||||
self,
|
||||
root_xml: ET.ElementTree,
|
||||
xpath: str = './/dir[@label="Active Releases"]/dir/dir/[@label]',
|
||||
) -> List[EosVersion]:
|
||||
"""
|
||||
Extract list of available EOS versions from Arista.com website
|
||||
|
||||
|
@ -77,19 +89,21 @@ class EOSDownloader(ObjectDownloader):
|
|||
"""
|
||||
# XPATH: .//dir[@label="Active Releases"]/dir/dir/[@label]
|
||||
if self.eos_versions is None:
|
||||
logger.debug(f'Using xpath {xpath}')
|
||||
logger.debug(f"Using xpath {xpath}")
|
||||
eos_versions = []
|
||||
for node in root_xml.findall(xpath):
|
||||
if 'label' in node.attrib and node.get('label') is not None:
|
||||
label = node.get('label')
|
||||
if "label" in node.attrib and node.get("label") is not None:
|
||||
label = node.get("label")
|
||||
if label is not None and REGEX_EOS_VERSION.match(label):
|
||||
eos_version = EosVersion.from_str(label)
|
||||
eos_versions.append(eos_version)
|
||||
logger.debug(f"Found {label} - {eos_version}")
|
||||
logger.debug(f'List of versions found on arista.com is: {eos_versions}')
|
||||
logger.debug(f"List of versions found on arista.com is: {eos_versions}")
|
||||
self.eos_versions = eos_versions
|
||||
else:
|
||||
logger.debug('receiving instruction to download versions, but already available')
|
||||
logger.debug(
|
||||
"receiving instruction to download versions, but already available"
|
||||
)
|
||||
return self.eos_versions
|
||||
|
||||
def _get_branches(self, with_rtype: str = RTYPE_FEATURE) -> List[str]:
|
||||
|
@ -104,9 +118,11 @@ class EOSDownloader(ObjectDownloader):
|
|||
Returns:
|
||||
List[str]: A lsit of string that represent all availables EOS branches
|
||||
"""
|
||||
root = self._get_folder_tree()
|
||||
root = self.get_folder_tree()
|
||||
versions = self._parse_xml_for_version(root_xml=root)
|
||||
return list({version.branch for version in versions if version.rtype == with_rtype})
|
||||
return list(
|
||||
{version.branch for version in versions if version.rtype == with_rtype}
|
||||
)
|
||||
|
||||
def latest_branch(self, rtype: str = RTYPE_FEATURE) -> EosVersion:
|
||||
"""
|
||||
|
@ -125,7 +141,9 @@ class EOSDownloader(ObjectDownloader):
|
|||
selected_branch = branch
|
||||
return selected_branch
|
||||
|
||||
def get_eos_versions(self, branch: Union[str,None] = None, rtype: Union[str,None] = None) -> List[EosVersion]:
|
||||
def get_eos_versions(
|
||||
self, branch: Union[str, None] = None, rtype: Union[str, None] = None
|
||||
) -> List[EosVersion]:
|
||||
"""
|
||||
Get a list of available EOS version available on arista.com
|
||||
|
||||
|
@ -139,16 +157,22 @@ class EOSDownloader(ObjectDownloader):
|
|||
Returns:
|
||||
List[EosVersion]: A list of versions available
|
||||
"""
|
||||
root = self._get_folder_tree()
|
||||
root = self.get_folder_tree()
|
||||
result = []
|
||||
for version in self._parse_xml_for_version(root_xml=root):
|
||||
if branch is None and (version.rtype == rtype or rtype is None):
|
||||
result.append(version)
|
||||
elif branch is not None and version.is_in_branch(branch) and version.rtype == rtype:
|
||||
elif (
|
||||
branch is not None
|
||||
and version.is_in_branch(branch)
|
||||
and version.rtype == rtype
|
||||
):
|
||||
result.append(version)
|
||||
return result
|
||||
|
||||
def latest_eos(self, branch: Union[str,None] = None, rtype: str = RTYPE_FEATURE) -> EosVersion:
|
||||
def latest_eos(
|
||||
self, branch: Union[str, None] = None, rtype: str = RTYPE_FEATURE
|
||||
) -> EosVersion:
|
||||
"""
|
||||
Get latest version of EOS
|
||||
|
||||
|
@ -168,7 +192,9 @@ class EOSDownloader(ObjectDownloader):
|
|||
latest_branch = self.latest_branch(rtype=rtype)
|
||||
else:
|
||||
latest_branch = EosVersion.from_str(branch)
|
||||
for version in self.get_eos_versions(branch=str(latest_branch.branch), rtype=rtype):
|
||||
for version in self.get_eos_versions(
|
||||
branch=str(latest_branch.branch), rtype=rtype
|
||||
):
|
||||
if version > selected_version:
|
||||
if rtype is not None and version.rtype == rtype:
|
||||
selected_version = version
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue