Esempio n. 1
0
 def get_hosts(cls, hosts, **kwargs):
     key = (frozenset(hosts), frozenset(kwargs.items()))
     cache = cls._hosts_cache
     if key not in cache:
         cache[key] = []
         for backend in testinfra.backend.get_backends(hosts, **kwargs):
             host = cls(backend)
             backend.set_host(host)
             cache[key].append(host)
     return cache[key]
Esempio n. 2
0
 def get_hosts(cls, hosts, **kwargs):
     key = (frozenset(hosts), frozenset(kwargs.items()))
     cache = cls._hosts_cache
     if key not in cache:
         cache[key] = []
         for backend in testinfra.backend.get_backends(hosts, **kwargs):
             host = cls(backend)
             backend.set_host(host)
             cache[key].append(host)
     return cache[key]
Esempio n. 3
0
    def get_host(cls, hostspec, **kwargs):
        """Return a Host instance from `hostspec`

        `hostspec` should be like
        `<backend_type>://<name>?param1=value1&param2=value2`

        Params can also be passed in `**kwargs` (eg. get_host("local://",
        sudo=True) is equivalent to get_host("local://?sudo=true"))

        Examples::

        >>> get_host("local://", sudo=True)
        >>> get_host("paramiko://user@host", ssh_config="/path/my_ssh_config")
        >>> get_host("ansible://all?ansible_inventory=/etc/ansible/inventory")
        """
        key = (hostspec, frozenset(kwargs.items()))
        cache = cls._host_cache
        if key not in cache:
            backend = testinfra.backend.get_backend(hostspec, **kwargs)
            cache[key] = host = cls(backend)
            backend.set_host(host)
        return cache[key]
Esempio n. 4
0
    def get_host(cls, hostspec, **kwargs):
        """Return a Host instance from `hostspec`

        `hostspec` should be like
        `<backend_type>://<name>?param1=value1&param2=value2`

        Params can also be passed in `**kwargs` (eg. get_host("local://",
        sudo=True) is equivalent to get_host("local://?sudo=true"))

        Examples::

        >>> get_host("local://", sudo=True)
        >>> get_host("paramiko://user@host", ssh_config="/path/my_ssh_config")
        >>> get_host("ansible://all?ansible_inventory=/etc/ansible/inventory")
        """
        key = (hostspec, frozenset(kwargs.items()))
        cache = cls._host_cache
        if key not in cache:
            backend = testinfra.backend.get_backend(hostspec, **kwargs)
            cache[key] = host = cls(backend)
            backend.set_host(host)
        return cache[key]