Show VM logs.
(self, vm_id: str, lines: int = 20, follow: bool = False)
| 611 | print(f"Resized VM {vm_id}") |
| 612 | |
| 613 | def show_logs(self, vm_id: str, lines: int = 20, follow: bool = False) -> None: |
| 614 | """Show VM logs.""" |
| 615 | path = f"/logs?id={vm_id}&follow={str(follow).lower()}&ansi=false&lines={lines}" |
| 616 | |
| 617 | status, response = self.client.request( |
| 618 | "GET", path, headers=self.headers, stream=follow |
| 619 | ) |
| 620 | |
| 621 | if status != 200: |
| 622 | if isinstance(response, str): |
| 623 | error_msg = response |
| 624 | else: |
| 625 | error_msg = str(response) |
| 626 | print(f"Failed to get logs: {error_msg}") |
| 627 | return |
| 628 | |
| 629 | if follow: |
| 630 | try: |
| 631 | # For streamed responses, response is a file-like object |
| 632 | while True: |
| 633 | line = response.readline() |
| 634 | if not line: |
| 635 | break |
| 636 | print(line.decode("utf-8").rstrip()) |
| 637 | except KeyboardInterrupt: |
| 638 | # Allow clean exit with Ctrl+C |
| 639 | return |
| 640 | finally: |
| 641 | # Close the connection when done |
| 642 | response.close() |
| 643 | else: |
| 644 | # For non-streamed responses, response is already the data |
| 645 | print(response) |
| 646 | |
| 647 | def list_images(self, json_output: bool = False) -> None: |
| 648 | """List available images.""" |