예제 #1
0
 def get_db(self, ip='1.1.1.1'):
     h = Host(ip)
     h.add_user(User('root', '34546'))
     return Database(
         h,
         self.db_name,
         User(self.db_user, self.db_pass),
     )
예제 #2
0
def provision_host(request):
    """
    Provisions a mock host.
    """
    ip = getattr(request.cls, "host_ip")
    root_password = getattr(request.cls, "root_password")
    data = getattr(request.cls, "data")

    mock = Host(ip=ip)
    mock.add_user(RootUser(password=root_password))
    mock.executor_factory = FakeExecutorFactory(cmd_to_data=data,
                                                files_content=None)
    return mock
예제 #3
0
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
예제 #4
0
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
예제 #5
0
def get_host(ip='1.1.1.1'):
    h = Host(ip)
    h.users.append(RootUser('123456'))
    return h
 def fake_host(cls):
     fh = Host('1.1.1.1')
     fh.add_user(User('root', '11111'))
     fh.executor_factory = FakeExecutorFactory(cls.data, cls.files)
     return fh
 def get_host(self, ip='1.1.1.1'):
     return Host(ip)
예제 #8
0
 def get_host(self, ip='1.1.1.1'):
     h = Host(ip)
     h.add_user(User('root', '11111'))
     return h
예제 #9
0
 def test_host_fqdn(self):
     h = Host('localhost')
     assert h.ip == '127.0.0.1'
     assert 'localhost' in h.fqdn
예제 #10
0
 def get_db(self, ip='1.1.1.1'):
     return Database(
         Host(ip),
         self.db_name,
         User(self.db_user, self.db_pass),
     )
예제 #11
0
def get_host(ip='1.1.1.1'):
    h = Host(ip)
    h.add_user(User('root', 'fakepasswd'))
    return h
예제 #12
0
 def get_host(ip='1.1.1.1'):
     h = Host(ip)
     h.add_user(User('root', '123456'))
     return h
예제 #13
0
 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
예제 #14
0
 def __init__(self, config, server):
     self.config = config
     self.host = Host(server)
     self.host.users.append(
         User(config["ssh"]["USER"], config["ssh"]["PASSWORD"]))