Skip to content

Commit 7d978c6

Browse files
chore: format
1 parent 92783c8 commit 7d978c6

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

morphcloud/api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,18 @@ async def astop(self, instance_id: str) -> None:
15751575
)
15761576
response.raise_for_status()
15771577

1578+
def reboot(self, instance_id: str) -> None:
1579+
"""Reboot an instance by its ID."""
1580+
response = self._client._http_client.post(f"/instance/{instance_id}/reboot")
1581+
response.raise_for_status()
1582+
1583+
async def areboot(self, instance_id: str) -> None:
1584+
"""Reboot an instance by its ID."""
1585+
response = await self._client._async_http_client.post(
1586+
f"/instance/{instance_id}/reboot"
1587+
)
1588+
response.raise_for_status()
1589+
15781590
def boot(
15791591
self,
15801592
snapshot_id: str,

morphcloud/cli.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,35 @@ def resume_instance(instance_id):
13081308
handle_api_error(e)
13091309

13101310

1311+
@instance.command("reboot")
1312+
@click.argument("instance_id")
1313+
def reboot_instance(instance_id):
1314+
"""Reboot a running instance."""
1315+
client = get_client()
1316+
try:
1317+
instance_obj = client.instances.get(instance_id)
1318+
with Spinner(
1319+
text=f"Rebooting instance {instance_id}...",
1320+
success_text=f"Instance rebooted: {instance_id}",
1321+
success_emoji="🔄",
1322+
):
1323+
instance_obj.reboot()
1324+
except api.ApiError as e:
1325+
if e.status_code == 404:
1326+
click.echo(f"Error: Instance '{instance_id}' not found.", err=True)
1327+
sys.exit(1)
1328+
elif e.status_code == 409:
1329+
click.echo(
1330+
f"Error: Instance '{instance_id}' cannot be rebooted ({e.response_body}).",
1331+
err=True,
1332+
)
1333+
sys.exit(1)
1334+
else:
1335+
handle_api_error(e)
1336+
except Exception as e:
1337+
handle_api_error(e)
1338+
1339+
13111340
@instance.command("get")
13121341
@click.argument("instance_id")
13131342
def get_instance(instance_id):

0 commit comments

Comments
 (0)