network: add network/has_network endpoint to check if we have network

Many views provide a different display based on whether the network is
available. Up to now, it was up to the controller corresponding to the
view to return the value of has_network.

We now have a dedicated /network/has_network endpoint that clients can
lean on.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2023-01-19 16:33:31 +01:00
parent 35db182e89
commit 3824734916
2 changed files with 6 additions and 0 deletions

View File

@ -172,6 +172,9 @@ class API:
def GET() -> NetworkStatus: ... def GET() -> NetworkStatus: ...
def POST() -> None: ... def POST() -> None: ...
class has_network:
def GET() -> bool: ...
class global_addresses: class global_addresses:
def GET() -> List[str]: def GET() -> List[str]:
"""Return the global IP addresses the system currently has.""" """Return the global IP addresses the system currently has."""

View File

@ -406,3 +406,6 @@ class NetworkController(BaseNetworkController, SubiquityController):
async def info_GET(self, dev_name: str) -> str: async def info_GET(self, dev_name: str) -> str:
return await self.get_info_for_netdev(dev_name) return await self.get_info_for_netdev(dev_name)
async def has_network_GET(self) -> bool:
return self.model.has_network