Skip to content

Commit 7b9a8f3

Browse files
authored
Merge pull request #63 from Serverless-Devs/sandbox-delete-stop-headers
fix(sandbox): add sandbox delete/stop/get passthrough config
2 parents a5ae5f9 + 2a6d32a commit 7b9a8f3

File tree

3 files changed

+363
-33
lines changed

3 files changed

+363
-33
lines changed

agentrun/sandbox/__sandbox_async_template.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ async def create_async(
187187
nas_config=nas_config,
188188
oss_mount_config=oss_mount_config,
189189
polar_fs_config=polar_fs_config,
190+
config=config,
190191
)
191192

192193
# 根据 template 类型转换为对应的子类实例
@@ -216,35 +217,42 @@ async def create_async(
216217
return sandbox
217218

218219
@classmethod
219-
async def stop_by_id_async(cls, sandbox_id: str):
220+
async def stop_by_id_async(
221+
cls, sandbox_id: str, config: Optional[Config] = None
222+
):
220223
"""通过 ID 停止 Sandbox(异步)
221224
222225
Args:
223226
sandbox_id: Sandbox ID
224-
config: 配置对象
227+
config: 配置对象 / Config object
225228
226229
Returns:
227230
Sandbox: Sandbox 对象
228231
"""
229232
if sandbox_id is None:
230233
raise ValueError("sandbox_id is required")
231-
# todo 后续适配后使用 stop()
232-
return await cls.__get_client().stop_sandbox_async(sandbox_id)
234+
return await cls.__get_client().stop_sandbox_async(
235+
sandbox_id, config=config
236+
)
233237

234238
@classmethod
235-
async def delete_by_id_async(cls, sandbox_id: str):
239+
async def delete_by_id_async(
240+
cls, sandbox_id: str, config: Optional[Config] = None
241+
):
236242
"""通过 ID 删除 Sandbox(异步)
237243
238244
Args:
239245
sandbox_id: Sandbox ID
240-
config: 配置对象
246+
config: 配置对象 / Config object
241247
242248
Returns:
243249
Sandbox: Sandbox 对象
244250
"""
245251
if sandbox_id is None:
246252
raise ValueError("sandbox_id is required")
247-
return await cls.__get_client().delete_sandbox_async(sandbox_id)
253+
return await cls.__get_client().delete_sandbox_async(
254+
sandbox_id, config=config
255+
)
248256

249257
@classmethod
250258
async def list_async(
@@ -476,16 +484,17 @@ async def get_async(self):
476484
if self.sandbox_id is None:
477485
raise ValueError("sandbox_id is required to get a Sandbox")
478486

479-
return await self.connect_async(self.sandbox_id)
487+
return await self.connect_async(self.sandbox_id, config=self._config)
480488

481489
async def delete_async(self):
482490
if self.sandbox_id is None:
483491
raise ValueError("sandbox_id is required to delete a Sandbox")
484492

485-
return await self.delete_by_id_async(self.sandbox_id)
493+
return await self.delete_by_id_async(
494+
self.sandbox_id, config=self._config
495+
)
486496

487497
async def stop_async(self):
488498
if self.sandbox_id is None:
489499
raise ValueError("sandbox_id is required to stop a Sandbox")
490-
# todo 后续适配后使用 stop()
491-
return await self.stop_by_id_async(self.sandbox_id)
500+
return await self.stop_by_id_async(self.sandbox_id, config=self._config)

agentrun/sandbox/sandbox.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ async def create_async(
257257
nas_config=nas_config,
258258
oss_mount_config=oss_mount_config,
259259
polar_fs_config=polar_fs_config,
260+
config=config,
260261
)
261262

262263
# 根据 template 类型转换为对应的子类实例
@@ -332,6 +333,7 @@ def create(
332333
nas_config=nas_config,
333334
oss_mount_config=oss_mount_config,
334335
polar_fs_config=polar_fs_config,
336+
config=config,
335337
)
336338

337339
# 根据 template 类型转换为对应的子类实例
@@ -361,66 +363,72 @@ def create(
361363
return sandbox
362364

363365
@classmethod
364-
async def stop_by_id_async(cls, sandbox_id: str):
366+
async def stop_by_id_async(
367+
cls, sandbox_id: str, config: Optional[Config] = None
368+
):
365369
"""通过 ID 停止 Sandbox(异步)
366370
367371
Args:
368372
sandbox_id: Sandbox ID
369-
config: 配置对象
373+
config: 配置对象 / Config object
370374
371375
Returns:
372376
Sandbox: Sandbox 对象
373377
"""
374378
if sandbox_id is None:
375379
raise ValueError("sandbox_id is required")
376-
# todo 后续适配后使用 stop()
377-
return await cls.__get_client().stop_sandbox_async(sandbox_id)
380+
return await cls.__get_client().stop_sandbox_async(
381+
sandbox_id, config=config
382+
)
378383

379384
@classmethod
380-
def stop_by_id(cls, sandbox_id: str):
385+
def stop_by_id(cls, sandbox_id: str, config: Optional[Config] = None):
381386
"""通过 ID 停止 Sandbox(同步)
382387
383388
Args:
384389
sandbox_id: Sandbox ID
385-
config: 配置对象
390+
config: 配置对象 / Config object
386391
387392
Returns:
388393
Sandbox: Sandbox 对象
389394
"""
390395
if sandbox_id is None:
391396
raise ValueError("sandbox_id is required")
392-
# todo 后续适配后使用 stop()
393-
return cls.__get_client().stop_sandbox(sandbox_id)
397+
return cls.__get_client().stop_sandbox(sandbox_id, config=config)
394398

395399
@classmethod
396-
async def delete_by_id_async(cls, sandbox_id: str):
400+
async def delete_by_id_async(
401+
cls, sandbox_id: str, config: Optional[Config] = None
402+
):
397403
"""通过 ID 删除 Sandbox(异步)
398404
399405
Args:
400406
sandbox_id: Sandbox ID
401-
config: 配置对象
407+
config: 配置对象 / Config object
402408
403409
Returns:
404410
Sandbox: Sandbox 对象
405411
"""
406412
if sandbox_id is None:
407413
raise ValueError("sandbox_id is required")
408-
return await cls.__get_client().delete_sandbox_async(sandbox_id)
414+
return await cls.__get_client().delete_sandbox_async(
415+
sandbox_id, config=config
416+
)
409417

410418
@classmethod
411-
def delete_by_id(cls, sandbox_id: str):
419+
def delete_by_id(cls, sandbox_id: str, config: Optional[Config] = None):
412420
"""通过 ID 删除 Sandbox(同步)
413421
414422
Args:
415423
sandbox_id: Sandbox ID
416-
config: 配置对象
424+
config: 配置对象 / Config object
417425
418426
Returns:
419427
Sandbox: Sandbox 对象
420428
"""
421429
if sandbox_id is None:
422430
raise ValueError("sandbox_id is required")
423-
return cls.__get_client().delete_sandbox(sandbox_id)
431+
return cls.__get_client().delete_sandbox(sandbox_id, config=config)
424432

425433
@classmethod
426434
async def list_async(
@@ -866,34 +874,34 @@ async def get_async(self):
866874
if self.sandbox_id is None:
867875
raise ValueError("sandbox_id is required to get a Sandbox")
868876

869-
return await self.connect_async(self.sandbox_id)
877+
return await self.connect_async(self.sandbox_id, config=self._config)
870878

871879
def get(self):
872880
if self.sandbox_id is None:
873881
raise ValueError("sandbox_id is required to get a Sandbox")
874882

875-
return self.connect(self.sandbox_id)
883+
return self.connect(self.sandbox_id, config=self._config)
876884

877885
async def delete_async(self):
878886
if self.sandbox_id is None:
879887
raise ValueError("sandbox_id is required to delete a Sandbox")
880888

881-
return await self.delete_by_id_async(self.sandbox_id)
889+
return await self.delete_by_id_async(
890+
self.sandbox_id, config=self._config
891+
)
882892

883893
def delete(self):
884894
if self.sandbox_id is None:
885895
raise ValueError("sandbox_id is required to delete a Sandbox")
886896

887-
return self.delete_by_id(self.sandbox_id)
897+
return self.delete_by_id(self.sandbox_id, config=self._config)
888898

889899
async def stop_async(self):
890900
if self.sandbox_id is None:
891901
raise ValueError("sandbox_id is required to stop a Sandbox")
892-
# todo 后续适配后使用 stop()
893-
return await self.stop_by_id_async(self.sandbox_id)
902+
return await self.stop_by_id_async(self.sandbox_id, config=self._config)
894903

895904
def stop(self):
896905
if self.sandbox_id is None:
897906
raise ValueError("sandbox_id is required to stop a Sandbox")
898-
# todo 后续适配后使用 stop()
899-
return self.stop_by_id(self.sandbox_id)
907+
return self.stop_by_id(self.sandbox_id, config=self._config)

0 commit comments

Comments
 (0)