boxd 0.2.22.dev936__py3-none-any.whl → 0.3.0.dev986__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
boxd/__init__.py CHANGED
@@ -36,6 +36,7 @@ from .errors import (
36
36
  NotFoundError,
37
37
  PermissionDeniedError,
38
38
  RateLimitError,
39
+ RegionNotEnabledError,
39
40
  )
40
41
  from .models import (
41
42
  Account,
@@ -57,6 +58,7 @@ from .models import (
57
58
  DirListing,
58
59
  DiskAttachment,
59
60
  DiskStatus,
61
+ ElsewhereItem,
60
62
  EnvVar,
61
63
  FsEntry,
62
64
  FsEntryType,
@@ -100,6 +102,10 @@ from .models import (
100
102
  Proxy,
101
103
  ProxyEntry,
102
104
  ProxyPortMode,
105
+ Region,
106
+ RegionalList,
107
+ RegionCount,
108
+ RegionOrgState,
103
109
  ResizeResult,
104
110
  ResumeResult,
105
111
  Secret,
@@ -170,6 +176,7 @@ __all__ = [
170
176
  "DirListing",
171
177
  "DiskAttachment",
172
178
  "DiskStatus",
179
+ "ElsewhereItem",
173
180
  "EnvVar",
174
181
  "ExecResult",
175
182
  "FsEntry",
@@ -213,6 +220,10 @@ __all__ = [
213
220
  "Proxy",
214
221
  "ProxyEntry",
215
222
  "ProxyPortMode",
223
+ "Region",
224
+ "RegionalList",
225
+ "RegionCount",
226
+ "RegionOrgState",
216
227
  "ResizeResult",
217
228
  "ResumeResult",
218
229
  "Secret",
@@ -260,6 +271,7 @@ __all__ = [
260
271
  "NotFoundError",
261
272
  "PermissionDeniedError",
262
273
  "RateLimitError",
274
+ "RegionNotEnabledError",
263
275
  # Version
264
276
  "__version__",
265
277
  ]
boxd/_client.py CHANGED
@@ -8,6 +8,7 @@ namespace returns is plain data.
8
8
  from __future__ import annotations
9
9
 
10
10
  from ._credentials import AsyncCredentials, SyncCredentials
11
+ from ._regions import AsyncRouter, SyncRouter
11
12
  from ._transport import AsyncTransport, SyncTransport
12
13
  from ._urls import DEFAULT_BASE_URL, exchange_url_for, resolve_base_url
13
14
  from .resources.account import Account, AsyncAccount
@@ -16,6 +17,7 @@ from .resources.disks import AsyncDisks, Disks
16
17
  from .resources.domains import AsyncDomains, Domains
17
18
  from .resources.machines import AsyncMachines, Machines
18
19
  from .resources.orgs import AsyncOrgs, Orgs
20
+ from .resources.regions import AsyncRegions, Regions
19
21
  from .resources.snapshots import AsyncSnapshots, Snapshots
20
22
  from .resources.teams import AsyncTeams, Teams
21
23
  from .resources.vars import AsyncEnv, AsyncSecrets, Env, Secrets
@@ -31,6 +33,7 @@ class Boxd:
31
33
 
32
34
  boxd = Boxd() # production
33
35
  boxd = Boxd(api_key="bxd_...")
36
+ boxd = Boxd(region="nyc") # machines in New York
34
37
  boxd = Boxd(base_url="https://boxd.example.com:9443") # any other cluster
35
38
 
36
39
  Args:
@@ -40,6 +43,11 @@ class Boxd:
40
43
  base_url: The cluster to talk to. Defaults to `BOXD_BASE_URL`, then
41
44
  production. There is no `environment` argument — one URL selects
42
45
  a cluster and everything else follows from it.
46
+ region: The region machines, snapshots and disks are created in and
47
+ looked up in (``"fra"``, ``"nyc"``, ...). Defaults to
48
+ `BOXD_REGION`, then the region `base_url` serves. Account and org
49
+ calls always go to `base_url`. Every such method also takes its
50
+ own ``region=``.
43
51
  timeout: Per-request timeout in seconds.
44
52
  max_retries: Retries for connection failures, with exponential backoff.
45
53
 
@@ -53,6 +61,7 @@ class Boxd:
53
61
  api_key: str | None = None,
54
62
  token: str | None = None,
55
63
  base_url: str | None = None,
64
+ region: str | None = None,
56
65
  timeout: float = DEFAULT_TIMEOUT_SECS,
57
66
  max_retries: int = DEFAULT_MAX_RETRIES,
58
67
  ) -> None:
@@ -62,12 +71,17 @@ class Boxd:
62
71
  token=token,
63
72
  exchange_url=exchange_url_for(resolved or DEFAULT_BASE_URL),
64
73
  )
65
- self._transport = SyncTransport(
66
- base_url=resolved,
67
- credentials=credentials,
68
- timeout=timeout,
69
- max_retries=max_retries,
70
- )
74
+
75
+ def connect(url: str | None) -> SyncTransport:
76
+ # Every region's endpoint, and home's, share the one credential.
77
+ return SyncTransport(
78
+ base_url=url,
79
+ credentials=credentials,
80
+ timeout=timeout,
81
+ max_retries=max_retries,
82
+ )
83
+
84
+ self._transport = SyncRouter(connect(resolved), region=region, connect=connect)
71
85
 
72
86
  self.machines = Machines(self._transport)
73
87
  self.snapshots = Snapshots(self._transport)
@@ -79,12 +93,19 @@ class Boxd:
79
93
  self.teams = Teams(self._transport)
80
94
  self.api_keys = ApiKeys(self._transport)
81
95
  self.account = Account(self._transport)
96
+ self.regions = Regions(self._transport)
82
97
 
83
98
  @property
84
99
  def base_url(self) -> str:
85
- """The cluster this client talks to."""
100
+ """The cluster this client talks to: its home."""
86
101
  return self._transport.base_url
87
102
 
103
+ @property
104
+ def region(self) -> str | None:
105
+ """The client's region (``region=`` or `BOXD_REGION`); None = the
106
+ region `base_url` serves."""
107
+ return self._transport.region
108
+
88
109
  def close(self) -> None:
89
110
  """Close the underlying connection. Safe to call more than once."""
90
111
  self._transport.close()
@@ -111,6 +132,7 @@ class AsyncBoxd:
111
132
  api_key: str | None = None,
112
133
  token: str | None = None,
113
134
  base_url: str | None = None,
135
+ region: str | None = None,
114
136
  timeout: float = DEFAULT_TIMEOUT_SECS,
115
137
  max_retries: int = DEFAULT_MAX_RETRIES,
116
138
  ) -> None:
@@ -120,12 +142,17 @@ class AsyncBoxd:
120
142
  token=token,
121
143
  exchange_url=exchange_url_for(resolved or DEFAULT_BASE_URL),
122
144
  )
123
- self._transport = AsyncTransport(
124
- base_url=resolved,
125
- credentials=credentials,
126
- timeout=timeout,
127
- max_retries=max_retries,
128
- )
145
+
146
+ def connect(url: str | None) -> AsyncTransport:
147
+ # Every region's endpoint, and home's, share the one credential.
148
+ return AsyncTransport(
149
+ base_url=url,
150
+ credentials=credentials,
151
+ timeout=timeout,
152
+ max_retries=max_retries,
153
+ )
154
+
155
+ self._transport = AsyncRouter(connect(resolved), region=region, connect=connect)
129
156
 
130
157
  self.machines = AsyncMachines(self._transport)
131
158
  self.snapshots = AsyncSnapshots(self._transport)
@@ -137,12 +164,19 @@ class AsyncBoxd:
137
164
  self.teams = AsyncTeams(self._transport)
138
165
  self.api_keys = AsyncApiKeys(self._transport)
139
166
  self.account = AsyncAccount(self._transport)
167
+ self.regions = AsyncRegions(self._transport)
140
168
 
141
169
  @property
142
170
  def base_url(self) -> str:
143
- """The cluster this client talks to."""
171
+ """The cluster this client talks to: its home."""
144
172
  return self._transport.base_url
145
173
 
174
+ @property
175
+ def region(self) -> str | None:
176
+ """The client's region (``region=`` or `BOXD_REGION`); None = the
177
+ region `base_url` serves."""
178
+ return self._transport.region
179
+
146
180
  async def close(self) -> None:
147
181
  """Close the underlying connection. Safe to call more than once."""
148
182
  await self._transport.close()