nebu 0.1.3__py3-none-any.whl → 0.1.5__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.
@@ -10,6 +10,7 @@ from nebu.containers.models import (
10
10
  V1ContainerRequest,
11
11
  V1ContainerResources,
12
12
  V1Containers,
13
+ V1ContainerSearch,
13
14
  V1EnvVar,
14
15
  V1Meter,
15
16
  V1PortRequest,
@@ -17,15 +18,16 @@ from nebu.containers.models import (
17
18
  V1SSHKey,
18
19
  V1VolumePath,
19
20
  )
21
+ from nebu.meta import V1ResourceReference
20
22
 
21
23
 
22
24
  class Container:
23
25
  def __init__(
24
26
  self,
25
27
  name: str,
28
+ image: str,
26
29
  namespace: str = "default",
27
30
  platform: Optional[str] = None,
28
- image: str = "",
29
31
  env: Optional[List[V1EnvVar]] = None,
30
32
  command: Optional[str] = None,
31
33
  volumes: Optional[List[V1VolumePath]] = None,
@@ -48,6 +50,7 @@ class Container:
48
50
  raise ValueError("No current server config found")
49
51
  self.api_key = current_server.api_key
50
52
  self.nebu_host = current_server.server
53
+ self.config = config
51
54
 
52
55
  # print(f"nebu_host: {self.nebu_host}")
53
56
  # print(f"api_key: {self.api_key}")
@@ -240,3 +243,130 @@ class Container:
240
243
  )
241
244
  response.raise_for_status()
242
245
  print(f"Deleted container {self.name} in namespace {self.namespace}")
246
+
247
+ @classmethod
248
+ def get(
249
+ cls,
250
+ name: Optional[str] = None,
251
+ namespace: Optional[str] = None,
252
+ config: Optional[GlobalConfig] = None,
253
+ ) -> List[V1Container]:
254
+ """
255
+ Get a list of containers that match the optional name and/or namespace filters.
256
+ """
257
+ config = config or GlobalConfig.read()
258
+ current_server = config.get_current_server_config()
259
+ if not current_server:
260
+ raise ValueError("No current server config found")
261
+ api_key = current_server.api_key
262
+ nebu_host = current_server.server
263
+
264
+ containers_url = f"{nebu_host}/v1/containers"
265
+
266
+ response = requests.get(
267
+ containers_url, headers={"Authorization": f"Bearer {api_key}"}
268
+ )
269
+ response.raise_for_status()
270
+
271
+ containers_response = V1Containers.model_validate(response.json())
272
+ filtered_containers = containers_response.containers
273
+
274
+ if name:
275
+ filtered_containers = [
276
+ container
277
+ for container in filtered_containers
278
+ if container.metadata.name == name
279
+ ]
280
+ if namespace:
281
+ filtered_containers = [
282
+ container
283
+ for container in filtered_containers
284
+ if container.metadata.namespace == namespace
285
+ ]
286
+
287
+ return filtered_containers
288
+
289
+ @classmethod
290
+ def load(
291
+ cls,
292
+ name: str,
293
+ namespace: str = "default",
294
+ config: Optional[GlobalConfig] = None,
295
+ ):
296
+ """
297
+ Get a container from the remote server.
298
+ """
299
+ containers = cls.get(namespace=namespace, name=name, config=config)
300
+ if not containers:
301
+ raise ValueError("Container not found")
302
+ container_v1 = containers[0]
303
+
304
+ out = cls.__new__(cls)
305
+ out.container = container_v1
306
+ out.config = config or GlobalConfig.read()
307
+ current_server = out.config.get_current_server_config()
308
+ if not current_server:
309
+ raise ValueError("No current server config found")
310
+ out.api_key = current_server.api_key
311
+ out.nebu_host = current_server.server
312
+ out.containers_url = f"{out.nebu_host}/v1/containers"
313
+
314
+ out = cls.from_v1(container_v1)
315
+ return out
316
+
317
+ @classmethod
318
+ def from_v1(cls, v1: V1Container) -> "Container":
319
+ out = cls.__new__(cls)
320
+ out.name = v1.metadata.name
321
+ out.namespace = v1.metadata.namespace
322
+ out.status = v1.status
323
+ out.kind = v1.kind
324
+ out.platform = v1.platform
325
+ out.metadata = v1.metadata
326
+ out.image = v1.image
327
+ out.env = v1.env
328
+ out.command = v1.command
329
+ out.volumes = v1.volumes
330
+ out.accelerators = v1.accelerators
331
+ out.resources = v1.resources
332
+ out.meters = v1.meters
333
+ out.restart = v1.restart
334
+ out.queue = v1.queue
335
+ out.timeout = v1.timeout
336
+ out.ssh_keys = v1.ssh_keys
337
+ return out
338
+
339
+ @classmethod
340
+ def search(
341
+ cls,
342
+ params: V1ContainerSearch,
343
+ config: Optional[GlobalConfig] = None,
344
+ ) -> List[V1Container]:
345
+ """
346
+ Search for containers on the remote server.
347
+ """
348
+ config = config or GlobalConfig.read()
349
+ current_server = config.get_current_server_config()
350
+ if not current_server:
351
+ raise ValueError("No current server config found")
352
+ api_key = current_server.api_key
353
+ nebu_host = current_server.server
354
+
355
+ search_url = f"{nebu_host}/v1/containers/search"
356
+
357
+ response = requests.post(
358
+ search_url,
359
+ headers={"Authorization": f"Bearer {api_key}"},
360
+ json=params.model_dump(),
361
+ )
362
+ response.raise_for_status()
363
+
364
+ containers_response = V1Containers.model_validate(response.json())
365
+ return containers_response.containers
366
+
367
+ def ref(self) -> V1ResourceReference:
368
+ return V1ResourceReference(
369
+ kind="Container",
370
+ name=self.name,
371
+ namespace=self.namespace,
372
+ )
nebu/containers/models.py CHANGED
@@ -212,3 +212,27 @@ class V1Containers(BaseModel):
212
212
  containers: List[V1Container]
213
213
 
214
214
  model_config = ConfigDict(use_enum_values=True)
215
+
216
+
217
+ class V1ContainerSearch(BaseModel):
218
+ namespace: Optional[str] = None
219
+ image: Optional[str] = None
220
+ env: Optional[List[V1EnvVar]] = None
221
+ command: Optional[str] = None
222
+ args: Optional[str] = None
223
+ volumes: Optional[List[V1VolumePath]] = None
224
+ accelerators: Optional[List[str]] = None
225
+ labels: Optional[Dict[str, str]] = None
226
+ cpu_request: Optional[str] = None
227
+ memory_request: Optional[str] = None
228
+ platform: Optional[str] = None
229
+ health_check: Optional[V1ContainerHealthCheck] = None
230
+ meters: Optional[List[V1Meter]] = None
231
+ restart: Optional[str] = None
232
+ queue: Optional[str] = None
233
+ timeout: Optional[str] = None
234
+ resources: Optional[V1ContainerResources] = None
235
+ proxy_port: Optional[int] = None
236
+ authz: Optional[V1AuthzConfig] = None
237
+
238
+ model_config = ConfigDict(use_enum_values=True)
nebu/meta.py CHANGED
@@ -22,3 +22,12 @@ class V1ResourceMeta(BaseModel):
22
22
  created_by: str
23
23
  owner_ref: Optional[str] = None
24
24
  labels: Optional[Dict[str, str]] = None
25
+
26
+
27
+ class V1ResourceReference(BaseModel):
28
+ kind: str
29
+ name: str
30
+ namespace: str
31
+
32
+ def to_string(self) -> str:
33
+ return f"{self.name}.{self.namespace}.{self.kind}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nebu
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: A globally distributed container runtime
5
5
  Requires-Python: >=3.10.14
6
6
  Description-Content-Type: text/markdown
@@ -1,16 +1,16 @@
1
1
  nebu/__init__.py,sha256=EbdC8ZKnRTt6jkX0WN0p1pnaDEzb2InqZ1r8QZWzph0,195
2
2
  nebu/config.py,sha256=XBY7uKgcJX9d1HGxqqpx87o_9DuF3maUlUnKkcpUrKU,4565
3
- nebu/meta.py,sha256=AnvrtP0mc7a-YP4zVhErHPsU0FSmwMejYgKWnV8wqqE,566
4
- nebu/containers/container.py,sha256=WCXBadAHhvkFQdpDjHu7nh6NjLlMxRsJbMbLXH8zaCs,9283
3
+ nebu/meta.py,sha256=CzFHMND9seuewzq9zNNx9WTr6JvrCBExe7BLqDSr7lM,745
4
+ nebu/containers/container.py,sha256=JbqdzjsagdlPmB8J_IueVqWuLixPAQ6RW9PRVlnRiqE,13444
5
5
  nebu/containers/decorator.py,sha256=sZQ4ZwqQk_jLDJ-n9P6N0MlxvWL9Ac7eCPIHVxYq58c,5576
6
- nebu/containers/models.py,sha256=o4jHBiXpcnxdxvUSR4q38ctHdL0w6M0uRj4DD-5B0o8,5932
6
+ nebu/containers/models.py,sha256=_d6BS6puoVWvyHhWX-74WFHJSOE8WJaFt2zGMTm9EEA,6782
7
7
  nebu/containers/server.py,sha256=yFa2Y9PzBn59E1HftKiv0iapPonli2rbGAiU6r-wwe0,2513
8
8
  nebu/processors/models.py,sha256=6XSw4iM77XYJf6utm8QReN9fyMS0dK40a5sVwsC7RRA,1970
9
9
  nebu/processors/processor.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  nebu/redis/models.py,sha256=coPovAcVXnOU1Xh_fpJL4PO3QctgK9nBe5QYoqEcnxg,1230
11
11
  nebu/services/service.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- nebu-0.1.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
13
- nebu-0.1.3.dist-info/METADATA,sha256=QAQ6mgaNa41T-MxXPykyYFibeki6AUZw1kNPoWQHPHo,1587
14
- nebu-0.1.3.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
15
- nebu-0.1.3.dist-info/top_level.txt,sha256=uLIbEKJeGSHWOAJN5S0i5XBGwybALlF9bYoB1UhdEgQ,5
16
- nebu-0.1.3.dist-info/RECORD,,
12
+ nebu-0.1.5.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
13
+ nebu-0.1.5.dist-info/METADATA,sha256=YI3zEPhY_Fit5ErIMM0I0mBpgAxx0L63Rm2yn_cx-gw,1587
14
+ nebu-0.1.5.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
15
+ nebu-0.1.5.dist-info/top_level.txt,sha256=uLIbEKJeGSHWOAJN5S0i5XBGwybALlF9bYoB1UhdEgQ,5
16
+ nebu-0.1.5.dist-info/RECORD,,
File without changes