Skip to content

Arista XML API

arista_xml_server

This module provides classes for managing and querying Arista XML data.

Classes: AristaXmlBase: Base class for Arista XML data management. AristaXmlQuerier: Class to query Arista XML data for Software versions. AristaXmlObject: Base class for Arista XML data management with specific software and version. EosXmlObject: Class to query Arista XML data for EOS versions.

AristaXmlBase

AristaXmlBase(
    token: Union[str, None] = None,
    xml_path: Union[str, None] = None,
)

Base class for Arista XML data management.

Parameters:

Name Type Description Default
token Union[str, None]

Authentication token. Defaults to None.

None
xml_path Union[str, None]

Path to the XML file. Defaults to None.

None

Returns:

Type Description
None
Source code in eos_downloader/logics/arista_xml_server.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def __init__(
    self, token: Union[str, None] = None, xml_path: Union[str, None] = None
) -> None:
    """
    Initialize the AristaXmlBase class.

    Parameters
    ----------
    token : Union[str, None], optional
        Authentication token. Defaults to None.
    xml_path : Union[str, None], optional
        Path to the XML file. Defaults to None.

    Returns
    -------
    None
    """
    logging.info("Initializing AristXmlBase.")
    self.server = eos_downloader.logics.arista_server.AristaServer(token=token)
    if xml_path is not None:
        try:
            self.xml_data = ET.parse(xml_path)
        except ET.ParseError as error:
            logging.error(f"Error while parsing XML data: {error}")
    else:
        if self.server.authenticate():
            data = self._get_xml_root()
            if data is None:
                logging.error("Unable to get XML data from Arista server")
                raise ValueError("Unable to get XML data from Arista server")
            self.xml_data = data
        else:
            logging.error("Unable to authenticate to Arista server")
            raise ValueError("Unable to authenticate to Arista server")

AristaXmlObject

AristaXmlObject(
    searched_version: str,
    image_type: str,
    token: Union[str, None] = None,
    xml_path: Union[str, None] = None,
)

Bases: AristaXmlBase

Base class for Arista XML data management.

Parameters:

Name Type Description Default
searched_version str

The version of the software to search for.

required
image_type str

The type of image to download.

required
token Union[str, None]

Authentication token. Defaults to None.

None
xml_path Union[str, None]

Path to the XML file. Defaults to None.

None

Returns:

Type Description
None
Source code in eos_downloader/logics/arista_xml_server.py
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
def __init__(
    self,
    searched_version: str,
    image_type: str,
    token: Union[str, None] = None,
    xml_path: Union[str, None] = None,
) -> None:
    """
    Initialize the AristaXmlObject class.

    Parameters
    ----------
    searched_version : str
        The version of the software to search for.
    image_type : str
        The type of image to download.
    token : Union[str, None], optional
        Authentication token. Defaults to None.
    xml_path : Union[str, None], optional
        Path to the XML file. Defaults to None.

    Returns
    -------
    None
    """
    self.search_version = searched_version
    self.image_type = image_type
    super().__init__(token=token, xml_path=xml_path)

filename property

filename: Union[str, None]

Helper to build filename to search on arista.com.

Returns:

Type Description
Union[str, None]

Filename to search for on Arista.com.

urls property

urls: Dict[str, Union[str, None]]

Get URLs to download files from Arista server for given software and version.

This method will return a dictionary with file type as key and URL as value. It returns URL for the following items: ‘image’, ‘md5sum’, and ‘sha512sum’.

Returns:

Type Description
Dict[str, Union[str, None]]

Dictionary with file type as key and URL as value.

Raises:

Type Description
ValueError

If filename or hash file is not found.

hash_filename

hash_filename() -> Union[str, None]

Helper to build filename for checksum to search on arista.com.

Returns:

Type Description
Union[str, None]

Filename to search for on Arista.com.

Source code in eos_downloader/logics/arista_xml_server.py
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
def hash_filename(self) -> Union[str, None]:
    """
    Helper to build filename for checksum to search on arista.com.

    Returns
    -------
    Union[str, None]
        Filename to search for on Arista.com.
    """

    logging.info(f"Building hash filename for {self.software} package.")

    if self.filename is not None:
        return f"{self.filename}.{self.checksum_file_extension}"
    return None

path_from_xml

path_from_xml(search_file: str) -> Union[str, None]

Parse XML to find path for a given file.

Parameters:

Name Type Description Default
search_file str

File to search for.

required

Returns:

Type Description
Union[str, None]

Path from XML if found, None otherwise.

Source code in eos_downloader/logics/arista_xml_server.py
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
def path_from_xml(self, search_file: str) -> Union[str, None]:
    """
    Parse XML to find path for a given file.

    Parameters
    ----------
    search_file : str
        File to search for.

    Returns
    -------
    Union[str, None]
        Path from XML if found, None otherwise.
    """

    logging.info(f"Building path from XML for {search_file}.")

    # Build xpath with provided file
    xpath_query = self.base_xpath_filepath.format(search_file)
    # Find the element using XPath
    path_element = self.xml_data.find(xpath_query)

    if path_element is not None:
        logging.debug(f'found path: {path_element.get("path")} for {search_file}')

    # Return the path if found, otherwise return None
    return path_element.get("path") if path_element is not None else None

AristaXmlQuerier

AristaXmlQuerier(
    token: Union[str, None] = None,
    xml_path: Union[str, None] = None,
)

Bases: AristaXmlBase

Class to query Arista XML data for Software versions.

Parameters:

Name Type Description Default
token Union[str, None]

Authentication token. Defaults to None.

None
xml_path Union[str, None]

Path to the XML file. Defaults to None.

None

Returns:

Type Description
None
Source code in eos_downloader/logics/arista_xml_server.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def __init__(
    self, token: Union[str, None] = None, xml_path: Union[str, None] = None
) -> None:
    """
    Initialize the AristaXmlBase class.

    Parameters
    ----------
    token : Union[str, None], optional
        Authentication token. Defaults to None.
    xml_path : Union[str, None], optional
        Path to the XML file. Defaults to None.

    Returns
    -------
    None
    """
    logging.info("Initializing AristXmlBase.")
    self.server = eos_downloader.logics.arista_server.AristaServer(token=token)
    if xml_path is not None:
        try:
            self.xml_data = ET.parse(xml_path)
        except ET.ParseError as error:
            logging.error(f"Error while parsing XML data: {error}")
    else:
        if self.server.authenticate():
            data = self._get_xml_root()
            if data is None:
                logging.error("Unable to get XML data from Arista server")
                raise ValueError("Unable to get XML data from Arista server")
            self.xml_data = data
        else:
            logging.error("Unable to authenticate to Arista server")
            raise ValueError("Unable to authenticate to Arista server")

available_public_versions

available_public_versions(
    branch: Union[str, None] = None,
    rtype: Union[str, None] = None,
    package: AristaPackage = "eos",
) -> List[AristaVersions]

Get list of available public EOS versions from Arista website.

This method parses XML data to extract available EOS or CVP versions based on specified criteria.

Parameters:

Name Type Description Default
branch Union[str, None]

Branch number to filter versions (e.g. “4.29”). Defaults to None.

None
rtype Union[str, None]

Release type to filter versions. Must be one of the valid release types defined in RTYPES. Defaults to None.

None
package AristaPackage

Type of package to look for - either ‘eos’ or ‘cvp’. Defaults to ‘eos’.

'eos'

Returns:

Type Description
List[AristaVersions]

List of version objects (EosVersion or CvpVersion) matching the criteria.

Raises:

Type Description
ValueError

If provided rtype is not in the list of valid release types.

Examples:

>>> server.available_public_eos_version(branch="4.29", rtype="INT", package="eos")
[EosVersion('4.29.0F-INT'), EosVersion('4.29.1F-INT'), ...]
Source code in eos_downloader/logics/arista_xml_server.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
def available_public_versions(
    self,
    branch: Union[str, None] = None,
    rtype: Union[str, None] = None,
    package: AristaPackage = "eos",
) -> List[AristaVersions]:
    """
    Get list of available public EOS versions from Arista website.

    This method parses XML data to extract available EOS or CVP versions based on specified criteria.

    Parameters
    ----------
    branch : Union[str, None], optional
        Branch number to filter versions (e.g. "4.29"). Defaults to None.
    rtype : Union[str, None], optional
        Release type to filter versions. Must be one of the valid release types defined in RTYPES. Defaults to None.
    package : AristaPackage, optional
        Type of package to look for - either 'eos' or 'cvp'. Defaults to 'eos'.

    Returns
    -------
    List[AristaVersions]
        List of version objects (EosVersion or CvpVersion) matching the criteria.

    Raises
    ------
    ValueError
        If provided rtype is not in the list of valid release types.

    Examples
    --------
    >>> server.available_public_eos_version(branch="4.29", rtype="INT", package="eos")
    [EosVersion('4.29.0F-INT'), EosVersion('4.29.1F-INT'), ...]
    """

    logging.info(f"Getting available versions for {package} package")

    xpath_query = './/dir[@label="Active Releases"]//dir[@label]'
    regexp = eos_downloader.models.version.EosVersion.regex_version

    if package == "cvp":
        xpath_query = './/dir[@label="Active Releases"]//dir[@label]'
        regexp = eos_downloader.models.version.CvpVersion.regex_version

    package_versions = []

    if rtype is not None and rtype not in eos_downloader.models.data.RTYPES:
        raise ValueError(
            f"Invalid release type: {rtype}. Expected one of {eos_downloader.models.data.RTYPES}"
        )
    nodes = self.xml_data.findall(xpath_query)
    for node in nodes:
        if "label" in node.attrib and node.get("label") is not None:
            label = node.get("label")
            if label is not None and regexp.match(label):
                package_version = None
                if package == "eos":
                    package_version = (
                        eos_downloader.models.version.EosVersion.from_str(label)
                    )
                elif package == "cvp":
                    package_version = (
                        eos_downloader.models.version.CvpVersion.from_str(label)
                    )
                package_versions.append(package_version)
    if rtype is not None or branch is not None:
        package_versions = [
            version
            for version in package_versions
            if version is not None
            and (rtype is None or version.rtype == rtype)
            and (branch is None or str(version.branch) == branch)
        ]

    return package_versions

branches

branches(
    package: eos_downloader.models.types.AristaPackage = "eos",
    latest: bool = False,
) -> List[str]

Returns a list of valid EOS version branches.

The branches are determined based on the available public EOS versions. When latest=True, only the most recent branch is returned.

Parameters:

Name Type Description Default
package AristaPackage

Type of package to look for - either ‘eos’ or ‘cvp’. Defaults to ‘eos’.

'eos'
latest bool

If True, returns only the latest branch version. Defaults to False.

False

Returns:

Type Description
List[str]

A list of branch version strings. Contains single latest version if latest=True, otherwise all available versions sorted descendingly.

Source code in eos_downloader/logics/arista_xml_server.py
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
def branches(
    self,
    package: eos_downloader.models.types.AristaPackage = "eos",
    latest: bool = False,
) -> List[str]:
    """
    Returns a list of valid EOS version branches.

    The branches are determined based on the available public EOS versions.
    When latest=True, only the most recent branch is returned.

    Parameters
    ----------
    package : eos_downloader.models.types.AristaPackage, optional
        Type of package to look for - either 'eos' or 'cvp'. Defaults to 'eos'.
    latest : bool, optional
        If True, returns only the latest branch version. Defaults to False.

    Returns
    -------
    List[str]
        A list of branch version strings. Contains single latest version if latest=True,
        otherwise all available versions sorted descendingly.
    """
    if latest:
        latest_branch = max(
            self._get_branches(self.available_public_versions(package=package))
        )
        return [str(latest_branch)]
    return sorted(
        self._get_branches(self.available_public_versions(package=package)),
        reverse=True,
    )

latest

latest(
    package: eos_downloader.models.types.AristaPackage = "eos",
    branch: Union[str, None] = None,
    rtype: Union[
        eos_downloader.models.types.ReleaseType, None
    ] = None,
) -> AristaVersions

Get latest branch from semver standpoint.

Parameters:

Name Type Description Default
package AristaPackage

Type of package to look for - either ‘eos’ or ‘cvp’. Defaults to ‘eos’.

'eos'
branch Union[str, None]

Branch to search for. Defaults to None.

None
rtype Union[ReleaseType, None]

Release type to search for. Defaults to None.

None

Returns:

Type Description
AristaVersions

Latest version found.

Raises:

Type Description
ValueError

If no versions are found to run the max() function.

Source code in eos_downloader/logics/arista_xml_server.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
def latest(
    self,
    package: eos_downloader.models.types.AristaPackage = "eos",
    branch: Union[str, None] = None,
    rtype: Union[eos_downloader.models.types.ReleaseType, None] = None,
) -> AristaVersions:
    """
    Get latest branch from semver standpoint.

    Parameters
    ----------
    package : eos_downloader.models.types.AristaPackage, optional
        Type of package to look for - either 'eos' or 'cvp'. Defaults to 'eos'.
    branch : Union[str, None], optional
        Branch to search for. Defaults to None.
    rtype : Union[eos_downloader.models.types.ReleaseType, None], optional
        Release type to search for. Defaults to None.

    Returns
    -------
    AristaVersions
        Latest version found.

    Raises
    ------
    ValueError
        If no versions are found to run the max() function.
    """
    if package == "eos":
        if rtype is not None and rtype not in eos_downloader.models.data.RTYPES:
            raise ValueError(
                f"Invalid release type: {rtype}. Expected {eos_downloader.models.data.RTYPES}"
            )

    versions = self.available_public_versions(
        package=package, branch=branch, rtype=rtype
    )
    if len(versions) == 0:
        raise ValueError("No versions found to run the max() function")
    return max(versions)

CvpXmlObject

CvpXmlObject(
    searched_version: str,
    image_type: str,
    token: Union[str, None] = None,
    xml_path: Union[str, None] = None,
)

Bases: AristaXmlObject

Class to query Arista XML data for CVP versions.

Parameters:

Name Type Description Default
searched_version str

The version of the software to search for.

required
image_type str

The type of image to download.

required
token Union[str, None]

The authentication token. Defaults to None.

None
xml_path Union[str, None]

The path to the XML file. Defaults to None.

None

Returns:

Type Description
None
Source code in eos_downloader/logics/arista_xml_server.py
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
def __init__(
    self,
    searched_version: str,
    image_type: str,
    token: Union[str, None] = None,
    xml_path: Union[str, None] = None,
) -> None:
    """
    Initialize an instance of the CvpXmlObject class.

    Parameters
    ----------
    searched_version : str
        The version of the software to search for.
    image_type : str
        The type of image to download.
    token : Union[str, None], optional
        The authentication token. Defaults to None.
    xml_path : Union[str, None], optional
        The path to the XML file. Defaults to None.

    Returns
    -------
    None
    """

    self.search_version = searched_version
    self.image_type = image_type
    self.version = eos_downloader.models.version.CvpVersion().from_str(
        searched_version
    )

    super().__init__(
        searched_version=searched_version,
        image_type=image_type,
        token=token,
        xml_path=xml_path,
    )

EosXmlObject

EosXmlObject(
    searched_version: str,
    image_type: str,
    token: Union[str, None] = None,
    xml_path: Union[str, None] = None,
)

Bases: AristaXmlObject

Class to query Arista XML data for EOS versions.

Parameters:

Name Type Description Default
searched_version str

The version of the software to search for.

required
image_type str

The type of image to download.

required
token Union[str, None]

The authentication token. Defaults to None.

None
xml_path Union[str, None]

The path to the XML file. Defaults to None.

None

Returns:

Type Description
None
Source code in eos_downloader/logics/arista_xml_server.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
def __init__(
    self,
    searched_version: str,
    image_type: str,
    token: Union[str, None] = None,
    xml_path: Union[str, None] = None,
) -> None:
    """
    Initialize an instance of the EosXmlObject class.

    Parameters
    ----------
    searched_version : str
        The version of the software to search for.
    image_type : str
        The type of image to download.
    token : Union[str, None], optional
        The authentication token. Defaults to None.
    xml_path : Union[str, None], optional
        The path to the XML file. Defaults to None.

    Returns
    -------
    None
    """

    self.search_version = searched_version
    self.image_type = image_type
    self.version = eos_downloader.models.version.EosVersion().from_str(
        searched_version
    )

    super().__init__(
        searched_version=searched_version,
        image_type=image_type,
        token=token,
        xml_path=xml_path,
    )