Skip to content

Commit

Permalink
Fix fleet re-creation (#1462)
Browse files Browse the repository at this point in the history
* Make CLI wait for fleet to be deleted

* Improve apply confirm messages
  • Loading branch information
r4victor authored Jul 29, 2024
1 parent c4853b4 commit 6319a31
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
28 changes: 25 additions & 3 deletions src/dstack/_internal/cli/services/configurators/fleet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import time
from pathlib import Path
from typing import List, Optional

Expand Down Expand Up @@ -62,10 +63,23 @@ def apply_configuration(
confirmed = True
with console.status("Deleting fleet..."):
self.api.client.fleets.delete(project_name=self.api.project, names=[conf.name])
# Fleet deletion is async. Wait for fleet to be deleted.
while True:
try:
self.api.client.fleets.get(
project_name=self.api.project, name=conf.name
)
except ResourceNotExistsError:
break
else:
time.sleep(1)
if not confirmed and not command_args.yes:
if not confirm_ask(
f"Fleet [code]{conf.name}[/] does not exist yet. Create the fleet?"
):
confirm_message = "Configuration does not specify the fleet name. Create a new fleet?"
if conf.name is not None:
confirm_message = (
f"Fleet [code]{conf.name}[/] does not exist yet. Create the fleet?"
)
if not confirm_ask(confirm_message):
console.print("\nExiting...")
return
with console.status("Creating fleet..."):
Expand Down Expand Up @@ -100,6 +114,14 @@ def delete_configuration(

with console.status("Deleting fleet..."):
self.api.client.fleets.delete(project_name=self.api.project, names=[conf.name])
# Fleet deletion is async. Wait for fleet to be deleted.
while True:
try:
self.api.client.fleets.get(project_name=self.api.project, name=conf.name)
except ResourceNotExistsError:
break
else:
time.sleep(1)

console.print(f"Fleet [code]{conf.name}[/] deleted")

Expand Down
11 changes: 8 additions & 3 deletions src/dstack/_internal/cli/services/configurators/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ def apply_configuration(
project_name=self.api.project, gateways_names=[conf.name]
)
if not confirmed and not command_args.yes:
if not confirm_ask(
f"Gateway [code]{conf.name}[/] does not exist yet. Create the gateway?"
):
confirm_message = (
"Configuration does not specify the gateway name. Create a new gateway?"
)
if conf.name is not None:
confirm_message = (
f"Gateway [code]{conf.name}[/] does not exist yet. Create the gateway?"
)
if not confirm_ask(confirm_message):
console.print("\nExiting...")
return
with console.status("Creating gateway..."):
Expand Down
16 changes: 8 additions & 8 deletions src/dstack/_internal/cli/services/configurators/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ def apply_configuration(
)

print_run_plan(run_plan, offers_limit=configurator_args.max_offers)
if not command_args.yes and not confirm_ask("Continue?"):
console.print("\nExiting...")
return

confirm_message = "Submit a new run?"
if conf.name:
old_run = self.api.runs.get(run_name=conf.name)
if old_run is not None:
if not command_args.yes and not confirm_ask(
f"Run [code]{configurator_args.run_name}[/] already exists. Override the run?"
):
console.print("\nExiting...")
return
confirm_message = f"Run [code]{conf.name}[/] already exists. Override the run?"
else:
confirm_message = f"Submit the run [code]{conf.name}[/]?"

if not command_args.yes and not confirm_ask(confirm_message):
console.print("\nExiting...")
return

try:
with console.status("Submitting run..."):
Expand Down
11 changes: 8 additions & 3 deletions src/dstack/_internal/cli/services/configurators/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ def apply_configuration(
project_name=self.api.project, names=[conf.name]
)
if not confirmed and not command_args.yes:
if not confirm_ask(
f"Volume [code]{conf.name}[/] does not exist yet. Create the volume?"
):
confirm_message = (
"Configuration does not specify the volume name. Create a new volume?"
)
if conf.name is not None:
confirm_message = (
f"Volume [code]{conf.name}[/] does not exist yet. Create the volume?"
)
if not confirm_ask(confirm_message):
console.print("\nExiting...")
return
with console.status("Creating volume..."):
Expand Down

0 comments on commit 6319a31

Please sign in to comment.