Example #1
0
def execute_host(args):
    if not args.subcommand == 'list' and not args.host:
        puts(red('--host is required'))
        return
    ssh_config = Storm()
    if args.subcommand == 'list':
        for entry in ssh_config.list_entries():
            puts(green(entry['host']))
    elif args.subcommand == 'add':
        result = parse(args.connection_url)
        puts(result)
        ssh_config.add_entry(args.host,
                             host=result[1],
                             user=result[0],
                             port=result[2],
                             id_file=args.id_file)
        for entry in ssh_config.list_entries():
            puts(green(entry['host']))
    elif args.subcommand == 'delete':
        ssh_config.delete_entry(args.host)
        for entry in ssh_config.list_entries():
            puts(green(entry['host']))
Example #2
0
    def __init__(self) -> None:
        """Initialization method.

        Raises:
            NoRuntimeDetectedError: If no `Runtime` could be automatically detected.
        """
        # Create the Logger
        self.log = logging.getLogger(__name__)

        runtimes = {}
        self.inactive_hosts = []

        # Iterate over ssh configuration entries and look for valid RemoteRuntimes
        ssh_util = Storm()
        self.log.debug(
            "RuntimeManager starts looking for Runtimes based on ssh configuration."
        )

        for ssh_entry in ssh_util.list_entries(only_servers=True):
            if ssh_entry["host"] in runtimes:
                continue
            if (ssh_entry["host"] == "localhost" and "127.0.0.1"
                    in runtimes) or (ssh_entry["host"] == "127.0.0.1"
                                     and "localhost" in runtimes):
                continue
            try:
                self.log.debug(
                    f'RuntimeManager tries to instantiate host {ssh_entry["host"]} as Runtime.'
                )
                runtime = Runtime(ssh_entry["host"])
            except InvalidRuntimeError:
                self.inactive_hosts.append(ssh_entry["host"])
                self.log.debug(
                    f'RuntimeManager detected host config for {ssh_entry["host"]}, that could NOT be '
                    f"instantiated  as a valid Runtime.")
                continue
            runtimes.update({runtime.host: runtime})
            self.log.info(runtime.host +
                          " detected as valid Runtime by the RuntimeManager.")

        try:
            self._group = RuntimeGroup(list(runtimes.values()))
            self.log.info(
                f"RuntimeManager detected {len(runtimes)} valid Runtime(s).")
        except ValueError as err:
            raise NoRuntimesDetectedError(err)

        self.log.debug("RuntimeManager initialized.")