Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UX] sky check: show enabled clouds in a table #3160

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 39 additions & 31 deletions sky/check.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Credential checks: check cloud credentials and enable clouds."""
from typing import Dict, Iterable, Optional
from typing import Dict, Iterable, Optional, Tuple

import click
import rich

from sky import clouds
from sky import global_user_state
Expand All @@ -14,20 +15,21 @@ def check(quiet: bool = False, verbose: bool = False) -> None:
echo('Checking credentials to enable clouds for SkyPilot.')

enabled_clouds = []
for cloud in clouds.CLOUD_REGISTRY.values():

def check_one_cloud(cloud_tuple: Tuple[str, clouds.Cloud]) -> None:
cloud_repr, cloud = cloud_tuple
if not isinstance(cloud, clouds.Local):
echo(f' Checking {cloud}...', nl=False)
echo(f' Checking {cloud_repr}...', nl=False)
ok, reason = cloud.check_credentials()
echo('\r', nl=False)
status_msg = 'enabled' if ok else 'disabled'
status_color = 'green' if ok else 'red'
styles = {'fg': 'green', 'bold': False} if ok else {'dim': True}
if not isinstance(cloud, clouds.Local):
echo(' ' + click.style(
f'{cloud}: {status_msg}', fg=status_color, bold=True) +
echo(' ' + click.style(f'{cloud_repr}: {status_msg}', **styles) +
' ' * 30)
if ok:
enabled_clouds.append(str(cloud))
if verbose:
enabled_clouds.append(cloud_repr)
if verbose and cloud is not cloudflare:
activated_account = cloud.get_current_user_identity_str()
if activated_account is not None:
echo(f' Activated account: {activated_account}')
Expand All @@ -36,23 +38,15 @@ def check(quiet: bool = False, verbose: bool = False) -> None:
else:
echo(f' Reason: {reason}')

# Currently, clouds.CLOUD_REGISTRY.values() does not
# support r2 as only clouds with computing instances
# are added as 'cloud'. This will be removed when
# cloudflare/r2 is added as a 'cloud'.
cloud = 'Cloudflare (for R2 object store)'
echo(f' Checking {cloud}...', nl=False)
r2_is_enabled, reason = cloudflare.check_credentials()
echo('\r', nl=False)
status_msg = 'enabled' if r2_is_enabled else 'disabled'
status_color = 'green' if r2_is_enabled else 'red'
echo(' ' +
click.style(f'{cloud}: {status_msg}', fg=status_color, bold=True) +
' ' * 30)
if not r2_is_enabled:
echo(f' Reason: {reason}')
clouds_to_check = [
(repr(cloud), cloud) for cloud in clouds.CLOUD_REGISTRY.values()
]
clouds_to_check.append(('Cloudflare, for R2 object store', cloudflare))

for cloud_tuple in sorted(clouds_to_check):
check_one_cloud(cloud_tuple)

if len(enabled_clouds) == 0 and not r2_is_enabled:
if len(enabled_clouds) == 0:
click.echo(
click.style(
'No cloud is enabled. SkyPilot will not be able to run any '
Expand All @@ -61,14 +55,28 @@ def check(quiet: bool = False, verbose: bool = False) -> None:
bold=True))
raise SystemExit()
else:
echo('\nSkyPilot will use only the enabled clouds to run tasks. '
'To change this, configure cloud credentials, '
'and run ' + click.style('sky check', bold=True) + '.'
'\n' + click.style(
'If any problems remain, please file an issue at '
'https://github.com/skypilot-org/skypilot/issues/new',
dim=True))
echo(
click.style(
'\nTo enable a cloud, follow the hints above and rerun: ',
dim=True) + click.style('sky check', bold=True) + '\n' +
click.style(
'If any problems remain, open an issue at: '
'https://github.com/skypilot-org/skypilot/issues/new',
dim=True))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can link to the installation page in our doc, which might be easier to see for the instructions: https://skypilot.readthedocs.io/en/latest/getting-started/installation.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, done.

Could you help check if the new colors look good in light mode?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works nicely in the light mode:
image


# Pretty print for UX.
if not quiet:
enabled_clouds_str = '\n :heavy_check_mark: '.join(
[''] + sorted(enabled_clouds))
rich.print('\n[green]:tada: Enabled clouds :tada:'
f'{enabled_clouds_str}[/green]')

# Cloudflare is not a real cloud in clouds.CLOUD_REGISTRY, and should not be
# inserted into the DB (otherwise `sky launch` and other code would error
# out when it's trying to look it up in the registry).
enabled_clouds = [
cloud for cloud in enabled_clouds if not cloud.startswith('Cloudflare')
]
global_user_state.set_enabled_clouds(enabled_clouds)


Expand Down
2 changes: 1 addition & 1 deletion sky/provision/vsphere/vsphere_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def get_vsphere_credentials(name=None):
"""
credential_path = os.path.expanduser(CREDENTIALS_PATH)
assert os.path.exists(
credential_path), f' Missing credential file at {credential_path}.'
credential_path), f'Missing credential file at {credential_path}.'
with open(credential_path, 'r') as file:
credential = yaml.safe_load(file)
vcenters = credential['vcenters']
Expand Down
8 changes: 5 additions & 3 deletions sky/utils/subprocess_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ def get_parallel_threads() -> int:
def run_in_parallel(func: Callable, args: Iterable[Any]) -> List[Any]:
"""Run a function in parallel on a list of arguments.

The function should raise a CommandError if the command fails.
Returns a list of the return values of the function func, in the same order
as the arguments.
The function 'func' should raise a CommandError if the command fails.

Returns:
A list of the return values of the function func, in the same order as the
arguments.
"""
# Reference: https://stackoverflow.com/questions/25790279/python-multiprocessing-early-termination # pylint: disable=line-too-long
with pool.ThreadPool(processes=get_parallel_threads()) as p:
Expand Down
Loading