Left: | ||
Right: |
OLD | NEW |
---|---|
1 import random | 1 import random |
2 | 2 |
3 from twisted.internet.defer import inlineCallbacks, returnValue | 3 from twisted.internet.defer import inlineCallbacks, returnValue |
4 | 4 |
5 from txzookeeper.client import ConnectionTimeoutException | 5 from txzookeeper.client import ConnectionTimeoutException |
6 | 6 |
7 from juju.errors import EnvironmentNotFound, EnvironmentPending, NoConnection | 7 from juju.errors import EnvironmentNotFound, EnvironmentPending, NoConnection |
8 from juju.lib.twistutils import sleep | 8 from juju.lib.twistutils import sleep |
9 from juju.state.sshclient import SSHClient | 9 from juju.state.sshclient import SSHClient |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 """Attempt connection to one of the ZK nodes.""" | 57 """Attempt connection to one of the ZK nodes.""" |
58 candidates = yield self._provider.get_zookeeper_machines() | 58 candidates = yield self._provider.get_zookeeper_machines() |
59 assigned = [machine for machine in candidates if machine.dns_name] | 59 assigned = [machine for machine in candidates if machine.dns_name] |
60 if not assigned: | 60 if not assigned: |
61 yield sleep(1) # Momentarily backoff | 61 yield sleep(1) # Momentarily backoff |
62 raise EnvironmentPending("No machines have assigned addresses") | 62 raise EnvironmentPending("No machines have assigned addresses") |
63 | 63 |
64 chosen = random.choice(assigned) | 64 chosen = random.choice(assigned) |
65 log.debug("Connecting to environment using %s...", chosen.dns_name) | 65 log.debug("Connecting to environment using %s...", chosen.dns_name) |
66 try: | 66 try: |
67 client = yield SSHClient().connect( | 67 client = yield SSHClient(session_timeout=20000).connect( |
bcsaller
2013/02/01 17:12:20
Should this be the default in SSHClient.__init__?
hazmat
2013/02/01 17:50:14
sshclient doesn't define that, changed to use the
| |
68 chosen.dns_name + ":2181", timeout=30, share=share) | 68 chosen.dns_name + ":2181", timeout=30, share=share) |
69 except (NoConnection, ConnectionTimeoutException) as e: | 69 except (NoConnection, ConnectionTimeoutException) as e: |
70 raise EnvironmentPending( | 70 raise EnvironmentPending( |
71 "Cannot connect to environment using %s " | 71 "Cannot connect to environment using %s " |
72 "(perhaps still initializing): %s" % ( | 72 "(perhaps still initializing): %s" % ( |
73 chosen.dns_name, str(e))) | 73 chosen.dns_name, str(e))) |
74 | 74 |
75 yield self.wait_for_initialization(client) | 75 yield self.wait_for_initialization(client) |
76 returnValue(client) | 76 returnValue(client) |
77 | 77 |
78 @inlineCallbacks | 78 @inlineCallbacks |
79 def wait_for_initialization(self, client): | 79 def wait_for_initialization(self, client): |
80 exists_d, watch_d = client.exists_and_watch("/initialized") | 80 exists_d, watch_d = client.exists_and_watch("/initialized") |
81 exists = yield exists_d | 81 exists = yield exists_d |
82 if not exists: | 82 if not exists: |
83 log.debug("Environment still initializing. Will wait.") | 83 log.debug("Environment still initializing. Will wait.") |
84 yield watch_d | 84 yield watch_d |
85 else: | 85 else: |
86 log.debug("Environment is initialized.") | 86 log.debug("Environment is initialized.") |
OLD | NEW |