Skip to content

Commit

Permalink
add folder methods to rh.cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
jlewitt1 committed Aug 6, 2024
1 parent 02473ff commit 4a812dd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
46 changes: 46 additions & 0 deletions runhouse/resources/hardware/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,3 +1783,49 @@ def _enable_or_update_status_check(
self.call_client_method(
"set_settings", {"status_check_interval": new_interval}
)

##############################################
# Folder Operations
##############################################
def _ls(self, path: Path, recursive: bool = False):
return self.client.folder_operation(
operation="ls", path=path, recursive=recursive
)

def _get(
self,
path: Path,
mode: str = "rb",
serialization: str = None,
):
return self.client.folder_operation(
operation="get",
path=path,
mode=mode,
serialization=serialization,
)

def _put(
self,
path: Path,
contents: Union[Dict[str, Any], Resource, List[Resource]],
mode: str = "wb",
overwrite: bool = False,
serialization: str = None,
):
return self.client.folder_operation(
operation="put",
path=path,
contents=contents,
mode=mode,
overwrite=overwrite,
serialization=serialization,
)

def _rm(self, path: Path, contents: List[str] = None, recursive: bool = False):
return self.client.folder_operation(
operation="rm", path=path, contents=contents, recursive=recursive
)

def _mkdir(self, path: Path):
return self.client.folder_operation(operation="mkdir", path=path)
6 changes: 6 additions & 0 deletions runhouse/servers/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from runhouse.servers.http.http_utils import (
CallParams,
DeleteObjectParams,
FolderMethod,
FolderParams,
GetObjectParams,
handle_response,
OutputType,
Expand Down Expand Up @@ -272,6 +274,10 @@ def status(self, resource_address: str):
# Note: Resource address must be specified in order to construct the cluster subtoken
return self.request("status", req_type="get", resource_address=resource_address)

def folder_operation(self, operation: FolderMethod, **kwargs):
folder_params = FolderParams(operation=operation, **kwargs).dict()
return self.request_json("/folder", req_type="post", json_dict=folder_params)

def get_certificate(self):
cert: bytes = self.request(
"cert",
Expand Down

0 comments on commit 4a812dd

Please sign in to comment.