def provisioned_hosts(docker_ip, docker_services): hosts = {} for h in ('ubuntu',): host = Host(docker_ip) host.add_user(User("root", "docker.io")) host.executor_factory = RemoteExecutorFactory( port=docker_services.port_for(h, 22)) executor = host.executor() docker_services.wait_until_responsive( timeout=30.0, pause=1, check=lambda: executor.is_connective, ) hosts[h] = host return hosts
class Engine: """ Class that gets informations and runs ssh commands on engine """ config = None host = None def __init__(self, config, server): self.config = config self.host = Host(server) self.host.users.append( User(config["ssh"]["USER"], config["ssh"]["PASSWORD"])) def run(self, command): """ Run command via ssh on the server Arguments: command (list): command to run, parsed with shlex Returns: (list) lines of command output Raises: (EngineException) In case running command failed """ result, out, err = self.host.executor().run_cmd(command) if result == 0 and out: return out.split("\n") else: if not err and not out: err = "No output" raise EngineException("command `{cmd}`: {err}".format( cmd=" ".join(command), err=err)) def get_hostname(self): """ Get engine's fqdn """ for hostname in self.host.network.hostname.split("\n"): if "localhost" not in hostname: return hostname def get_release_info(self): """ Get engine's OS info """ return self.host.os.release_info
def get_host(self, ip='1.1.1.1', sudo=False): h = Host(ip) h.add_user(User('root', '11111')) h.executor(sudo=sudo) return h