

def get_port(self, ip):
    "Get forwarded ssh port for instance ip.\n\n        Ssh port forwarding is used for containers access from outside.\n        Any container is accessible by host's ip and forwarded port. E.g:\n\n         6.6.6.6:10023 -> 10.1.1.11:22\n         6.6.6.6:10024 -> 10.1.1.12:22\n         6.6.6.6:10025 -> 10.1.1.13:22\n\n        where 6.6.6.6 is host's ip.\n\n        Ip->port association is stored in self._port_cache to reduce number\n        of iptables calls.\n        "
    if (not self._port_cache):
        self._port_cache = {
            
        }
        port_re = re.compile('.+ tcp dpt:(\\d+).*to:([\\d\\.]+)\\:22')
        cmd = 'iptables -n -t nat -L PREROUTING'
        (code, out, err) = self.server.ssh.execute(cmd)
        for l in out:
            m = port_re.match(l)
            if m:
                self._port_cache[m.group(2)] = int(m.group(1))
    port = self._port_cache.get(ip)
    if (port is None):
        if self._port_cache:
            port = (max(self._port_cache.values()) + 1)
        else:
            port = 1222
    self._port_cache[ip] = port
    cmd = IPT_PORT_TEMPLATE.format(host_ip=self.server.host, ip=ip, port=port, action='I')
    self.server.ssh.run(cmd)
    return port

dataset/ETHPy150Open openstack/rally/rally/deployment/serverprovider/providers/lxc.py LxcHost.get_port/original