Revision e0036155 lib/rpc.py
b/lib/rpc.py | ||
---|---|---|
188 | 188 |
http.HttpSslParams(ssl_key_path=constants.NODED_CERT_FILE, |
189 | 189 |
ssl_cert_path=constants.NODED_CERT_FILE) |
190 | 190 |
|
191 |
def ConnectList(self, node_list, address_list=None): |
|
191 |
def ConnectList(self, node_list, address_list=None, read_timeout=None):
|
|
192 | 192 |
"""Add a list of nodes to the target nodes. |
193 | 193 |
|
194 | 194 |
@type node_list: list |
... | ... | |
196 | 196 |
@type address_list: list or None |
197 | 197 |
@keyword address_list: either None or a list with node addresses, |
198 | 198 |
which must have the same length as the node list |
199 |
@type read_timeout: int |
|
200 |
@param read_timeout: overwrites the default read timeout for the |
|
201 |
given operation |
|
199 | 202 |
|
200 | 203 |
""" |
201 | 204 |
if address_list is None: |
... | ... | |
204 | 207 |
assert len(node_list) == len(address_list), \ |
205 | 208 |
"Name and address lists should have the same length" |
206 | 209 |
for node, address in zip(node_list, address_list): |
207 |
self.ConnectNode(node, address) |
|
210 |
self.ConnectNode(node, address, read_timeout=read_timeout)
|
|
208 | 211 |
|
209 |
def ConnectNode(self, name, address=None): |
|
212 |
def ConnectNode(self, name, address=None, read_timeout=None):
|
|
210 | 213 |
"""Add a node to the target list. |
211 | 214 |
|
212 | 215 |
@type name: str |
... | ... | |
223 | 226 |
"/%s" % self.procedure, |
224 | 227 |
post_data=self.body, |
225 | 228 |
ssl_params=self._ssl_params, |
226 |
ssl_verify_peer=True) |
|
229 |
ssl_verify_peer=True, |
|
230 |
read_timeout=read_timeout) |
|
227 | 231 |
|
228 | 232 |
def GetResults(self): |
229 | 233 |
"""Call nodes and return results. |
... | ... | |
318 | 322 |
nic['nicparams']) |
319 | 323 |
return idict |
320 | 324 |
|
321 |
def _ConnectList(self, client, node_list, call): |
|
325 |
def _ConnectList(self, client, node_list, call, read_timeout=None):
|
|
322 | 326 |
"""Helper for computing node addresses. |
323 | 327 |
|
324 | 328 |
@type client: L{ganeti.rpc.Client} |
... | ... | |
328 | 332 |
@type call: string |
329 | 333 |
@param call: the name of the remote procedure call, for filling in |
330 | 334 |
correctly any eventual offline nodes' results |
335 |
@type read_timeout: int |
|
336 |
@param read_timeout: overwrites the default read timeout for the |
|
337 |
given operation |
|
331 | 338 |
|
332 | 339 |
""" |
333 | 340 |
all_nodes = self._cfg.GetAllNodesInfo() |
... | ... | |
345 | 352 |
addr_list.append(val) |
346 | 353 |
name_list.append(node) |
347 | 354 |
if name_list: |
348 |
client.ConnectList(name_list, address_list=addr_list) |
|
355 |
client.ConnectList(name_list, address_list=addr_list, |
|
356 |
read_timeout=read_timeout) |
|
349 | 357 |
return skip_dict |
350 | 358 |
|
351 |
def _ConnectNode(self, client, node, call): |
|
359 |
def _ConnectNode(self, client, node, call, read_timeout=None):
|
|
352 | 360 |
"""Helper for computing one node's address. |
353 | 361 |
|
354 | 362 |
@type client: L{ganeti.rpc.Client} |
... | ... | |
358 | 366 |
@type call: string |
359 | 367 |
@param call: the name of the remote procedure call, for filling in |
360 | 368 |
correctly any eventual offline nodes' results |
369 |
@type read_timeout: int |
|
370 |
@param read_timeout: overwrites the default read timeout for the |
|
371 |
given operation |
|
361 | 372 |
|
362 | 373 |
""" |
363 | 374 |
node_info = self._cfg.GetNodeInfo(node) |
... | ... | |
367 | 378 |
addr = node_info.primary_ip |
368 | 379 |
else: |
369 | 380 |
addr = None |
370 |
client.ConnectNode(node, address=addr) |
|
381 |
client.ConnectNode(node, address=addr, read_timeout=read_timeout)
|
|
371 | 382 |
|
372 |
def _MultiNodeCall(self, node_list, procedure, args): |
|
383 |
def _MultiNodeCall(self, node_list, procedure, args, read_timeout=None):
|
|
373 | 384 |
"""Helper for making a multi-node call |
374 | 385 |
|
375 | 386 |
""" |
376 | 387 |
body = serializer.DumpJson(args, indent=False) |
377 | 388 |
c = Client(procedure, body, self.port) |
378 |
skip_dict = self._ConnectList(c, node_list, procedure) |
|
389 |
skip_dict = self._ConnectList(c, node_list, procedure, |
|
390 |
read_timeout=read_timeout) |
|
379 | 391 |
skip_dict.update(c.GetResults()) |
380 | 392 |
return skip_dict |
381 | 393 |
|
382 | 394 |
@classmethod |
383 | 395 |
def _StaticMultiNodeCall(cls, node_list, procedure, args, |
384 |
address_list=None): |
|
396 |
address_list=None, read_timeout=None):
|
|
385 | 397 |
"""Helper for making a multi-node static call |
386 | 398 |
|
387 | 399 |
""" |
388 | 400 |
body = serializer.DumpJson(args, indent=False) |
389 | 401 |
c = Client(procedure, body, utils.GetDaemonPort(constants.NODED)) |
390 |
c.ConnectList(node_list, address_list=address_list) |
|
402 |
c.ConnectList(node_list, address_list=address_list, |
|
403 |
read_timeout=read_timeout) |
|
391 | 404 |
return c.GetResults() |
392 | 405 |
|
393 |
def _SingleNodeCall(self, node, procedure, args): |
|
406 |
def _SingleNodeCall(self, node, procedure, args, read_timeout=None):
|
|
394 | 407 |
"""Helper for making a single-node call |
395 | 408 |
|
396 | 409 |
""" |
397 | 410 |
body = serializer.DumpJson(args, indent=False) |
398 | 411 |
c = Client(procedure, body, self.port) |
399 |
result = self._ConnectNode(c, node, procedure) |
|
412 |
result = self._ConnectNode(c, node, procedure, read_timeout=read_timeout)
|
|
400 | 413 |
if result is None: |
401 | 414 |
# we did connect, node is not offline |
402 | 415 |
result = c.GetResults()[node] |
403 | 416 |
return result |
404 | 417 |
|
405 | 418 |
@classmethod |
406 |
def _StaticSingleNodeCall(cls, node, procedure, args): |
|
419 |
def _StaticSingleNodeCall(cls, node, procedure, args, read_timeout=None):
|
|
407 | 420 |
"""Helper for making a single-node static call |
408 | 421 |
|
409 | 422 |
""" |
410 | 423 |
body = serializer.DumpJson(args, indent=False) |
411 | 424 |
c = Client(procedure, body, utils.GetDaemonPort(constants.NODED)) |
412 |
c.ConnectNode(node) |
|
425 |
c.ConnectNode(node, read_timeout=read_timeout)
|
|
413 | 426 |
return c.GetResults()[node] |
414 | 427 |
|
415 | 428 |
@staticmethod |
Also available in: Unified diff