Execute a CLI, calling the before/after hooks appropriately. :param cli: CLI to execute :param strip_ansi_escapes: If true, remove ansi escape sequences from output :returns: CLI output
(self, cli, strip_ansi_escapes: bool = True)
| 461 | return r |
| 462 | |
| 463 | def cli(self, cli, strip_ansi_escapes: bool = True): |
| 464 | """Execute a CLI, calling the before/after hooks appropriately. |
| 465 | |
| 466 | :param cli: CLI to execute |
| 467 | :param strip_ansi_escapes: If true, remove ansi escape sequences from output |
| 468 | :returns: CLI output |
| 469 | |
| 470 | """ |
| 471 | r = self.cli_return_response(cli) |
| 472 | if r.retval == -156: |
| 473 | raise CliSyntaxError(r.reply) |
| 474 | if r.retval != 0: |
| 475 | raise CliFailedCommandError(r.reply) |
| 476 | if hasattr(r, "reply"): |
| 477 | if strip_ansi_escapes: |
| 478 | return self.ansi_escape.sub("", r.reply) |
| 479 | return r.reply |
| 480 | |
| 481 | def ppcli(self, cli): |
| 482 | """Helper method to print CLI command in case of info logging level. |