|
16 | 16 | PermissionMetadataDependenciesDto, |
17 | 17 | PermissionMetadataDto, |
18 | 18 | ) |
| 19 | +from pcs.common.sbd_dto import SbdCheckResultDto |
19 | 20 | from pcs.common.str_tools import format_list |
20 | 21 | from pcs.daemon import log |
21 | 22 | from pcs.daemon.app.api_v0_tools import ( |
@@ -699,6 +700,56 @@ async def _handle_request(self) -> None: |
699 | 700 | raise self._error(reports_to_str(result.reports)) |
700 | 701 |
|
701 | 702 |
|
| 703 | +class CheckSbdHandler(_BaseApiV0Handler): |
| 704 | + async def _handle_request(self) -> None: |
| 705 | + watchdog = self.get_argument("watchdog", "") |
| 706 | + device_list_json = self.get_argument("device_list", "[]") |
| 707 | + try: |
| 708 | + device_list = json.loads(device_list_json) |
| 709 | + except json.JSONDecodeError as e: |
| 710 | + raise self._error("Invalid input data format") from e |
| 711 | + if not isinstance(device_list, list) or not all( |
| 712 | + isinstance(device, str) for device in device_list |
| 713 | + ): |
| 714 | + raise self._error("Invalid input data format") |
| 715 | + |
| 716 | + result = await self._run_library_command( |
| 717 | + "sbd.check_sbd", |
| 718 | + dict(watchdog=watchdog, device_list=device_list), |
| 719 | + ) |
| 720 | + if not result.success: |
| 721 | + raise self._error(reports_to_str(result.reports)) |
| 722 | + # Not using to_dict to keep backward compatibility with older |
| 723 | + # pcs versions which don't expect watchdog and device_list keys |
| 724 | + # to be present in the response when they have no values. Also the |
| 725 | + # response was different than our DTOs so we make them into legacy |
| 726 | + # format by hand. |
| 727 | + sbd_status = cast(SbdCheckResultDto, result.result) |
| 728 | + response: dict[str, Any] = dict( |
| 729 | + sbd=dict( |
| 730 | + installed=sbd_status.sbd_service.installed, |
| 731 | + enabled=sbd_status.sbd_service.enabled, |
| 732 | + running=sbd_status.sbd_service.running, |
| 733 | + ), |
| 734 | + ) |
| 735 | + if sbd_status.watchdog is not None: |
| 736 | + response["watchdog"] = dict( |
| 737 | + path=sbd_status.watchdog.path, |
| 738 | + exist=sbd_status.watchdog.exists, |
| 739 | + is_supported=sbd_status.watchdog.is_supported, |
| 740 | + ) |
| 741 | + if sbd_status.device_list is not None: |
| 742 | + response["device_list"] = [ |
| 743 | + dict( |
| 744 | + path=device.path, |
| 745 | + exist=device.exists, |
| 746 | + block_device=device.is_block_device, |
| 747 | + ) |
| 748 | + for device in sbd_status.device_list |
| 749 | + ] |
| 750 | + self.write(json.dumps(response)) |
| 751 | + |
| 752 | + |
702 | 753 | class SetCorosyncConf(_BaseApiV0Handler): |
703 | 754 | async def _handle_request(self) -> None: |
704 | 755 | self._check_required_params({"corosync_conf"}) |
@@ -806,6 +857,7 @@ def r(url: str) -> str: |
806 | 857 | # cluster config |
807 | 858 | (r("set_corosync_conf"), SetCorosyncConf, params), |
808 | 859 | # sbd |
| 860 | + (r("check_sbd"), CheckSbdHandler, params), |
809 | 861 | (r("get_sbd_config"), GetSbdConfigHandler, params), |
810 | 862 | (r("set_sbd_config"), SetSbdConfigHandler, params), |
811 | 863 | ] |
0 commit comments