response
scrapli.response
MultiResponse
¶
Bases: ScrapliMultiResponse
Source code in scrapli/response.py
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 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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
__init__(initlist: Optional[Iterable[Any]] = None) -> None
¶
Initialize list of responses
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initlist |
Optional[Iterable[Any]]
|
initial list seed data, if any |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in scrapli/response.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
__str__() -> str
¶
Magic str method for MultiResponse class
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
str for class object |
Source code in scrapli/response.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
failed() -> bool
property
¶
Determine if any elements of MultiResponse are failed
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True for failed |
Source code in scrapli/response.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
host() -> str
property
¶
Return the host of the multiresponse
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The host of the associated responses |
Source code in scrapli/response.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
raise_for_status() -> None
¶
Raise a ScrapliCommandFailure
if any elements are failed
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ScrapliCommandFailure
|
if any elements are failed |
Source code in scrapli/response.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
result() -> str
property
¶
Build a unified result from all elements of MultiResponse
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Unified result by combining results of all elements of MultiResponse |
Source code in scrapli/response.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
Response
¶
Source code in scrapli/response.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 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 188 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 229 230 231 |
|
__bool__() -> bool
¶
Magic bool method based on channel_input being failed or not
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True/False if channel_input failed |
Source code in scrapli/response.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
__init__(host: str, channel_input: str, textfsm_platform: str = '', genie_platform: str = '', failed_when_contains: Optional[Union[str, List[str]]] = None)
¶
Scrapli Response
Store channel_input, resulting output, and start/end/elapsed time information. Attempt to determine if command was successful or not and reflect that in a failed attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
str
|
host that was operated on |
required |
channel_input |
str
|
input that got sent down the channel |
required |
textfsm_platform |
str
|
ntc-templates friendly platform type |
''
|
genie_platform |
str
|
cisco pyats/genie friendly platform type |
''
|
failed_when_contains |
Optional[Union[str, List[str]]]
|
list of strings that, if present in final output, represent a failed command/interaction |
None
|
Returns:
Type | Description |
---|---|
None |
Source code in scrapli/response.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
__repr__() -> str
¶
Magic repr method for Response class
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
repr for class object |
Source code in scrapli/response.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
__str__() -> str
¶
Magic str method for Response class
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
str for class object |
Source code in scrapli/response.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
genie_parse_output() -> Union[Dict[str, Any], List[Any]]
¶
Parse results with genie, always return structured data
Returns an empty list if parsing fails!
Returns:
Name | Type | Description |
---|---|---|
structured_result |
Union[Dict[str, Any], List[Any]]
|
empty list or parsed data from genie |
Source code in scrapli/response.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
raise_for_status() -> None
¶
Raise a ScrapliCommandFailure
if command/config failed
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ScrapliCommandFailure
|
if command/config failed |
Source code in scrapli/response.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
record_response(result: bytes) -> None
¶
Record channel_input results and elapsed time of channel input/reading output
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result |
bytes
|
string result of channel_input |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in scrapli/response.py
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 |
|
textfsm_parse_output(template: Union[str, TextIO, None] = None, to_dict: bool = True) -> Union[Dict[str, Any], List[Any]]
¶
Parse results with textfsm, always return structured data
Returns an empty list if parsing fails!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template |
Union[str, TextIO, None]
|
string path to textfsm template or opened textfsm template file |
None
|
to_dict |
bool
|
convert textfsm output from list of lists to list of dicts -- basically create dict from header and row data so it is easier to read/parse the output |
True
|
Returns:
Name | Type | Description |
---|---|---|
structured_result |
Union[Dict[str, Any], List[Any]]
|
empty list or parsed data from textfsm |
Source code in scrapli/response.py
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 |
|
ttp_parse_output(template: Union[str, TextIOWrapper]) -> Union[Dict[str, Any], List[Any]]
¶
Parse results with ttp, always return structured data
Returns an empty list if parsing fails!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template |
Union[str, TextIOWrapper]
|
string path to ttp template or opened ttp template file |
required |
Returns:
Name | Type | Description |
---|---|---|
structured_result |
Union[Dict[str, Any], List[Any]]
|
empty list or parsed data from ttp |
Source code in scrapli/response.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|