-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to alias in the cloud registry and add k8s alias for kube…
…rnetes
- Loading branch information
Showing
18 changed files
with
60 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,53 @@ | ||
"""Clouds need to be registered in CLOUD_REGISTRY to be discovered""" | ||
|
||
import typing | ||
from typing import Optional, Type | ||
from typing import Dict, Optional, Type, List, Callable | ||
|
||
from sky.utils import ux_utils | ||
|
||
if typing.TYPE_CHECKING: | ||
from sky.clouds import cloud | ||
|
||
|
||
class _CloudRegistry(dict): | ||
class _CloudRegistry: | ||
"""Registry of clouds.""" | ||
|
||
def __init__(self): | ||
self.clouds: Dict[str, 'cloud.Cloud'] = {} | ||
self.aliases: Dict[str, str] = {} | ||
|
||
def from_str(self, name: Optional[str]) -> Optional['cloud.Cloud']: | ||
if name is None: | ||
return None | ||
if name.lower() not in self: | ||
with ux_utils.print_exception_no_traceback(): | ||
raise ValueError(f'Cloud {name!r} is not a valid cloud among ' | ||
f'{list(self.keys())}') | ||
return self.get(name.lower()) | ||
|
||
def register(self, cloud_cls: Type['cloud.Cloud']) -> Type['cloud.Cloud']: | ||
name = cloud_cls.__name__.lower() | ||
assert name not in self, f'{name} already registered' | ||
self[name] = cloud_cls() | ||
return cloud_cls | ||
search_name = name.lower() | ||
|
||
if search_name in self.clouds: | ||
return self.clouds[search_name] | ||
|
||
if search_name in self.aliases: | ||
return self.clouds[self.aliases[search_name]] | ||
|
||
with ux_utils.print_exception_no_traceback(): | ||
raise ValueError(f'Cloud {name!r} is not a valid cloud among ' | ||
f'{list(self.clouds.keys())}') | ||
|
||
def register( | ||
self, | ||
aliases: List[str] = [] | ||
) -> Callable[[Type['cloud.Cloud']], Type['cloud.Cloud']]: | ||
|
||
def _register(cloud_cls: Type['cloud.Cloud']) -> Type['cloud.Cloud']: | ||
name = cloud_cls.__name__.lower() | ||
assert name not in self.clouds, f'{name} already registered' | ||
self.clouds[name] = cloud_cls() | ||
|
||
for alias in aliases: | ||
assert alias not in self.aliases, f'alias {alias} already registered' | ||
self.aliases[alias] = name | ||
|
||
return cloud_cls | ||
|
||
return _register | ||
|
||
|
||
CLOUD_REGISTRY: _CloudRegistry = _CloudRegistry() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters