Overview checks whether a Science Platform Server reports itself as
available. It inherits HTTPClient and uses the selected or explicitly supplied
credentials.
fromcanfar.overviewimportOverviewwithOverview()asoverview:ifoverview.availability():print("Science Platform Server is available")
availability() returns True only when the VOSI availability response says
the server is available. Empty or malformed availability data returns False
and is logged.
classOverview(HTTPClient):"""Overview of the CANFAR Server. This class is a subclass of the `HTTPClient` class and inherits its attributes and methods. Examples: >>> from canfar.overview import Overview >>> overview = Overview() >>> overview.availability() True """@model_validator(mode="after")def_update_base_url(self)->Self:"""Update base URL for the server. Returns: Self: The current object. """url:str=str(self.client.base_url)base:str=url.split("/v",maxsplit=1)[0]# The overview endpoint is not versioned, so need to remove itself.client.base_url=URL(base)self.asynclient.base_url=URL(base)returnselfdefavailability(self)->bool:"""Check if the server backend is available. Returns: bool: True if the server is available, False otherwise. """response:Response=self.client.get("availability")data:str=response.textifnotdata:log.error("No data returned from availability endpoint.")returnFalseroot=ElementTree.fromstring(data)available=root.find(".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}available",)availaibility:str|None=available.textifavailableisnotNoneelseNonenote=root.find(".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}note",)notify:str|None=note.textifnoteisnotNoneelseNoneifavailaibilityisNone:log.error("No availability information found in the response.")returnFalselog.info(notifyor"No additional information provided.")returnavailaibility=="true"
defavailability(self)->bool:"""Check if the server backend is available. Returns: bool: True if the server is available, False otherwise. """response:Response=self.client.get("availability")data:str=response.textifnotdata:log.error("No data returned from availability endpoint.")returnFalseroot=ElementTree.fromstring(data)available=root.find(".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}available",)availaibility:str|None=available.textifavailableisnotNoneelseNonenote=root.find(".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}note",)notify:str|None=note.textifnoteisnotNoneelseNoneifavailaibilityisNone:log.error("No availability information found in the response.")returnFalselog.info(notifyor"No additional information provided.")returnavailaibility=="true"