-
Notifications
You must be signed in to change notification settings - Fork 142
/
client.py
109 lines (89 loc) · 3.26 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#
# Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
#
from __future__ import annotations # pylint: disable=unused-variable
from aistore.sdk.bucket import Bucket
from aistore.sdk.const import (
PROVIDER_AIS,
)
from aistore.sdk.cluster import Cluster
from aistore.sdk.dsort import Dsort
from aistore.sdk.request_client import RequestClient
from aistore.sdk.types import Namespace
from aistore.sdk.job import Job
from aistore.sdk.etl import Etl
# pylint: disable=unused-variable, duplicate-code
class Client:
"""
AIStore client for managing buckets, objects, ETL jobs
Args:
endpoint (str): AIStore endpoint
"""
def __init__(
self,
endpoint: str,
skip_verify: bool = False,
ca_cert: str = None,
timeout: float | tuple[float, float] | None = None,
):
self._request_client = RequestClient(endpoint, skip_verify, ca_cert, timeout)
def bucket(
self, bck_name: str, provider: str = PROVIDER_AIS, namespace: Namespace = None
):
"""
Factory constructor for bucket object.
Does not make any HTTP request, only instantiates a bucket object.
Args:
bck_name (str): Name of bucket
provider (str): Provider of bucket, one of "ais", "aws", "gcp", ... (optional, defaults to ais)
namespace (Namespace): Namespace of bucket (optional, defaults to None)
Returns:
The bucket object created.
"""
return Bucket(
client=self._request_client,
name=bck_name,
provider=provider,
namespace=namespace,
)
def cluster(self):
"""
Factory constructor for cluster object.
Does not make any HTTP request, only instantiates a cluster object.
Returns:
The cluster object created.
"""
return Cluster(client=self._request_client)
def job(self, job_id: str = "", job_kind: str = ""):
"""
Factory constructor for job object, which contains job-related functions.
Does not make any HTTP request, only instantiates a job object.
Args:
job_id (str, optional): Optional ID for interacting with a specific job
job_kind (str, optional): Optional specific type of job empty for all kinds
Returns:
The job object created.
"""
return Job(client=self._request_client, job_id=job_id, job_kind=job_kind)
def etl(self, etl_name: str):
"""
Factory constructor for ETL object.
Contains APIs related to AIStore ETL operations.
Does not make any HTTP request, only instantiates an ETL object.
Args:
etl_name (str): Name of the ETL
Returns:
The ETL object created.
"""
return Etl(client=self._request_client, name=etl_name)
def dsort(self, dsort_id: str = ""):
"""
Factory constructor for dSort object.
Contains APIs related to AIStore dSort operations.
Does not make any HTTP request, only instantiates a dSort object.
Args:
dsort_id: ID of the dSort job
Returns:
dSort object created
"""
return Dsort(client=self._request_client, dsort_id=dsort_id)