Arista Server
arista_server ¶
Server module for handling interactions with Arista software download portal.
This module provides the AristaServer class which manages authentication and file retrieval operations with the Arista software download portal. It handles session management, XML data retrieval, and download URL generation.
Classes:
Name | Description |
---|---|
AristaServer |
Main class for interacting with the Arista software portal. |
Dependencies
- base64: For encoding authentication tokens
- json: For handling JSON data in requests
- xml.etree.ElementTree: For parsing XML responses
- loguru: For logging
- requests: For making HTTP requests
Example
>>> from eos_downloader.logics.server import AristaServer
>>> server = AristaServer(token='my_auth_token')
>>> server.authenticate()
>>> xml_data = server.get_xml_data()
>>> download_url = server.get_url('/path/to/file')
Notes
The module requires valid authentication credentials to interact with the Arista portal. All server interactions are performed over HTTPS and follow Arista’s API specifications.
AristaServer ¶
AristaServer(
token: Union[str, None] = None,
timeout: int = 5,
session_server: str = eos_downloader.defaults.DEFAULT_SERVER_SESSION,
headers: Dict[
str, Any
] = eos_downloader.defaults.DEFAULT_REQUEST_HEADERS,
xml_url: str = eos_downloader.defaults.DEFAULT_SOFTWARE_FOLDER_TREE,
download_server: str = eos_downloader.defaults.DEFAULT_DOWNLOAD_URL,
)
AristaServer class to handle authentication and interactions with Arista software download portal.
This class provides methods to authenticate with the Arista software portal, retrieve XML data containing available software packages, and generate download URLs for specific files.
Attributes:
Name | Type | Description |
---|---|---|
token |
(str, optional)
|
Authentication token for Arista portal access |
timeout |
int, default=5
|
Timeout in seconds for HTTP requests |
session_server |
str
|
URL of the authentication server |
headers |
Dict[str, any]
|
HTTP headers to use in requests |
xml_url |
str
|
URL to retrieve software package XML data |
download_server |
str
|
Base URL for file downloads |
_session_id |
str
|
Session ID obtained after authentication |
Methods:
Name | Description |
---|---|
authenticate |
Authenticates with the Arista portal using provided or stored token |
get_xml_data |
Retrieves XML data containing available software packages |
get_url |
Generates download URL for a specific file path |
Raises:
Type | Description |
---|---|
AuthenticationError
|
When authentication fails due to invalid or expired token |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
Union[str, None]
|
Authentication token. Defaults to None. |
None
|
timeout
|
int
|
Request timeout in seconds. Defaults to 5. |
5
|
session_server
|
str
|
URL of the session server. Defaults to DEFAULT_SERVER_SESSION. |
DEFAULT_SERVER_SESSION
|
headers
|
Dict[str, any]
|
HTTP headers for requests. Defaults to DEFAULT_REQUEST_HEADERS. |
DEFAULT_REQUEST_HEADERS
|
xml_url
|
str
|
URL of the software folder tree XML. Defaults to DEFAULT_SOFTWARE_FOLDER_TREE. |
DEFAULT_SOFTWARE_FOLDER_TREE
|
download_server
|
str
|
Base URL for downloads. Defaults to DEFAULT_DOWNLOAD_URL. |
DEFAULT_DOWNLOAD_URL
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in eos_downloader/logics/arista_server.py
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 |
|
authenticate ¶
authenticate(token: Union[str, None] = None) -> bool
Authenticate to the API server using access token.
The token is encoded in base64 and sent to the server for authentication. A session ID is retrieved from the server response if authentication is successful.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
Union[str, None]
|
Access token for authentication. If None, uses existing token stored in instance. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if authentication successful, False otherwise |
Raises:
Type | Description |
---|---|
AuthenticationError
|
If access token is invalid or expired |
Source code in eos_downloader/logics/arista_server.py
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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
get_url ¶
get_url(remote_file_path: str) -> Union[str, None]
Get download URL for a remote file from server.
This method retrieves the download URL for a specified remote file by making a POST request to the server. If not authenticated, it will first authenticate before making the request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remote_file_path
|
str
|
Path to the remote file on server to get download URL for |
required |
Returns:
Type | Description |
---|---|
Union[str, None]
|
The download URL if successful, None if request fails or URL not found in response |
Raises:
Type | Description |
---|---|
RequestException
|
If the request to server fails |
JSONDecodeError
|
If server response is not valid JSON |
Timeout
|
If server request times out |
Source code in eos_downloader/logics/arista_server.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
get_xml_data ¶
get_xml_data() -> Union[ET.ElementTree, None]
Retrieves XML data from the server.
This method fetches XML data by making a POST request to the server’s XML endpoint. If not already authenticated, it will initiate the authentication process first.
Returns:
Type | Description |
---|---|
ElementTree
|
An ElementTree object containing the parsed XML data from the server response. |
Raises:
Type | Description |
---|---|
KeyError
|
If the server response doesn’t contain the expected data structure. |
Notes
The method requires a valid session ID which is obtained through authentication. The XML data is expected to be in the response JSON under data.xml path.
Source code in eos_downloader/logics/arista_server.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|