Skip to content

Commit

Permalink
wrap rename
Browse files Browse the repository at this point in the history
  • Loading branch information
asaiacai committed Sep 29, 2024
1 parent 8056bc8 commit 9bdf9df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 3 additions & 7 deletions sky/provision/do/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@ def run_instances(region: str, cluster_name_on_cloud: str,
if to_start_count == 0:
if head_instance is None:
head_instance = list(exist_instances.values())[0]
utils.client().droplet_actions.rename(
droplet=head_instance['id'],
body={
'type': 'rename',
'name': f'{cluster_name_on_cloud}-'
f'{uuid.uuid4().hex[:4]}-head'
})
utils.rename_instance(
head_instance,
f'{cluster_name_on_cloud}-{uuid.uuid4().hex[:4]}-head')
assert head_instance is not None, ('`head_instance` should not be None')
logger.info(f'Cluster {cluster_name_on_cloud} already has '
f'{len(exist_instances)} nodes, no need to start more.')
Expand Down
11 changes: 9 additions & 2 deletions sky/provision/do/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def _init_client():
'no credentials file found from '
f'the following paths {POSSIBLE_CREDENTIALS_PATHS}')

auth_contexts = common_utils.read_yaml(
CREDENTIALS_PATH)['auth-contexts']
auth_contexts = common_utils.read_yaml(CREDENTIALS_PATH)['auth-contexts']
for context, api_token in auth_contexts.items():
try:
test_client = do.pydo.Client(token=api_token)
Expand Down Expand Up @@ -204,6 +203,14 @@ def down_instance(instance: Dict[str, Any]):
droplet_id=instance['id'], x_dangerous=True)


def rename_instance(instance: Dict[str, Any], new_name: str):
client().droplet_actions.rename(droplet=instance['id'],
body={
'type': 'rename',
'name': new_name
})


def filter_instances(
cluster_name_on_cloud: str,
status_filters: Optional[List[str]] = None) -> Dict[str, Any]:
Expand Down

0 comments on commit 9bdf9df

Please sign in to comment.