diff --git a/nanokvm/client.py b/nanokvm/client.py index 356a957..0224252 100644 --- a/nanokvm/client.py +++ b/nanokvm/client.py @@ -28,6 +28,7 @@ GetHardwareRsp, GetHdmiStateRsp, GetHidModeRsp, + GetHostnameRsp, GetImagesRsp, GetInfoRsp, GetMdnsStateRsp, @@ -54,6 +55,7 @@ PasteReq, SetGpioReq, SetHidModeReq, + SetHostnameReq, SetMemoryLimitReq, SetMouseJigglerReq, SetOledReq, @@ -323,6 +325,22 @@ async def get_hardware(self) -> GetHardwareRsp: response_model=GetHardwareRsp, ) + async def get_hostname(self) -> GetHostnameRsp: + """Get the configured hostname.""" + return await self._api_request_json( + hdrs.METH_GET, + "/vm/hostname", + response_model=GetHostnameRsp, + ) + + async def set_hostname(self, hostname: str) -> None: + """Set the device hostname (applies after reboot).""" + await self._api_request_json( + hdrs.METH_POST, + "/vm/hostname", + data=SetHostnameReq(hostname=hostname), + ) + async def get_gpio(self) -> GetGpioRsp: """Get GPIO LED status.""" return await self._api_request_json( diff --git a/nanokvm/models.py b/nanokvm/models.py index 35f4458..9a42c1f 100644 --- a/nanokvm/models.py +++ b/nanokvm/models.py @@ -160,6 +160,14 @@ class GetInfoRsp(BaseModel): device_key: str = Field(alias="deviceKey") +class GetHostnameRsp(BaseModel): + hostname: str + + +class SetHostnameReq(BaseModel): + hostname: str # Applies after reboot + + class GetHardwareRsp(BaseModel): version: HWVersion