-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Host class added for easier config management. * Documentation and new test cases have been added.
- Loading branch information
1 parent
a50073f
commit e5f76bb
Showing
15 changed files
with
470 additions
and
184 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""CLI command implementation for deleting a Host.""" | ||
# dem/cli/command/del_host_cmd.py | ||
|
||
from dem.core.platform import Platform | ||
from dem.cli.console import stdout, stderr | ||
|
||
def execute(platform: Platform, host_name: str) -> None: | ||
""" Delete the Host. | ||
Args: | ||
host_name -- name of the host to delete | ||
""" | ||
for host_config in platform.hosts.list_host_configs(): | ||
if host_config["name"] == host_name: | ||
platform.hosts.delete_host(host_config) | ||
stdout.print("[green]Host deleted successfully![/]") | ||
break | ||
else: | ||
stderr.print("[red]Error: The input Host does not exist.[/]") |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Hosts.""" | ||
# dem/core/hosts.py | ||
|
||
from dem.core.data_management import ConfigFile | ||
from dem.core.core import Core | ||
|
||
class Host(): | ||
""" A Host. """ | ||
def __init__(self, host_config: dict) -> None: | ||
""" Init the class with the host config. | ||
Args: | ||
host_config -- the host config | ||
""" | ||
self.config: dict = host_config | ||
self.name: str = host_config["name"] | ||
self.address: str = host_config["address"] | ||
|
||
class Hosts(Core): | ||
""" List of the available Hosts. """ | ||
def __init__(self, config_file: ConfigFile) -> None: | ||
""" Init the class with the host configurations. | ||
Args: | ||
config_file -- contains the host configurations | ||
""" | ||
self._config_file: ConfigFile = config_file | ||
self.hosts: list[Host] = [] | ||
for host_config in config_file.hosts: | ||
self._try_to_add_host(host_config) | ||
|
||
def _try_to_add_host(self, host_config: dict) -> bool: | ||
try: | ||
self.hosts.append(Host(host_config)) | ||
except Exception as e: | ||
self.user_output.error(str(e)) | ||
self.user_output.error("Error: Couldn't add this Host.") | ||
return False | ||
else: | ||
return True | ||
|
||
def add_host(self, host_config: dict) -> None: | ||
""" Add a new host. | ||
Args: | ||
catalog_config -- the new catalog to add | ||
""" | ||
if self._try_to_add_host(host_config): | ||
self._config_file.hosts.append(host_config) | ||
self._config_file.flush() | ||
|
||
def list_host_configs(self) -> list[dict]: | ||
""" List the host configs. (As stored in the config file.) | ||
Return with the list of the available host configurations. | ||
""" | ||
return self._config_file.hosts | ||
|
||
def delete_host(self, host_config: dict) -> None: | ||
""" Delete the host. | ||
Args: | ||
host_config -- config of the host to delete | ||
""" | ||
for host in self.hosts.copy(): | ||
if host.config == host_config: | ||
self.hosts.remove(host) | ||
|
||
self._config_file.hosts.remove(host_config) | ||
self._config_file.flush() |
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
Oops, something went wrong.