Skip to content

Commit

Permalink
Travel the path to find the vineyard socket in the vineyard.csi.read/…
Browse files Browse the repository at this point in the history
…write API. (#1577)

Fixes part of #1568

Signed-off-by: Ye Cao <[email protected]>
  • Loading branch information
dashanji authored Sep 21, 2023
1 parent 646c7ce commit c10d4b4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions python/vineyard/csi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
import vineyard


def _find_vineyard_socket(path):
current_dir = path
while current_dir != "/":
socket_path = os.path.join(current_dir, "vineyard.sock")
if os.path.exists(socket_path):
return socket_path
current_dir = os.path.dirname(current_dir)
return None


def write(
value: Any,
path: str,
Expand All @@ -31,19 +41,17 @@ def write(
Notice, the API is only used for CSI driver.
Parameters:
client: IPCClient
The vineyard client to use.
path: str
The path that represents a vineyard object.
.. code:: python
>>> arr = np.arange(8)
>>> client.write(arr)
>>> vineyard.write(arr)
"""
socket_path = os.path.join(path, "vineyard.sock")
socket_path = _find_vineyard_socket(path)

if not os.path.exists(path):
if socket_path is None:
raise FileNotFoundError(
f"The given path is not generated by vineyard CSI driver: {path}"
)
Expand Down Expand Up @@ -72,9 +80,9 @@ def read(
Returns:
A python object that return by the resolver, by resolving an vineyard object.
"""
socket_path = os.path.join(path, "vineyard.sock")
socket_path = _find_vineyard_socket(path)

if not os.path.exists(path):
if socket_path is None:
raise FileNotFoundError(
f"The given path is not generated by vineyard CSI driver: {path}"
)
Expand Down

0 comments on commit c10d4b4

Please sign in to comment.