Coverage for /home/fedora/jumpstarter/packages/jumpstarter-driver-http/jumpstarter_driver_http/client.py: 65%
20 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-05 20:29 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-05 20:29 +0000
1from dataclasses import dataclass
3from jumpstarter_driver_composite.client import CompositeClient
4from jumpstarter_driver_opendal.common import PathBuf
5from opendal import Operator
6from yarl import URL
9@dataclass(kw_only=True)
10class HttpServerClient(CompositeClient):
11 """Client for the HTTP server driver"""
13 def start(self):
14 """
15 Start the HTTP server.
17 Initializes and starts the HTTP server if it's not already running.
18 The server will listen on the configured host and port.
19 """
20 self.call("start")
22 def stop(self):
23 """
24 Stop the HTTP server.
26 Stops the running HTTP server and releases associated resources.
27 Raises:
28 ServerNotRunning: If the server is not currently running
29 """
30 self.call("stop")
32 def get_host(self) -> str:
33 """
34 Get the host IP address the HTTP server is listening on.
36 Returns:
37 str: The IP address or hostname the server is bound to
38 """
39 return self.call("get_host")
41 def get_port(self) -> int:
42 """
43 Get the port number the HTTP server is listening on.
45 Returns:
46 int: The port number (default is 8080)
47 """
48 return self.call("get_port")
50 def get_url(self) -> str:
51 """
52 Get the base URL of the HTTP server.
54 Returns:
55 str: The base URL of the server
56 """
57 return self.call("get_url")
59 def put_file(self, dst: PathBuf, src: PathBuf, operator: Operator | None = None) -> str:
60 """
61 Upload a file to the HTTP server using a opendal operator as source.
63 Args:
64 dst (PathBuf): Name to save the file as on the server.
65 src (PathBuf): Name to read the file from opendal operator.
66 operator (Operator): opendal operator to read the file from, defaults to local fs.
68 Returns:
69 str: URL of the uploaded file
70 """
71 self.storage.write_from_path(dst, src, operator)
73 return str(URL(self.get_url()).joinpath(dst))