Revision 874f6148 lib/hypervisor/hv_xen.py
b/lib/hypervisor/hv_xen.py | ||
---|---|---|
519 | 519 |
(instance.name, result.fail_reason, |
520 | 520 |
result.output, stashed_config)) |
521 | 521 |
|
522 |
def StopInstance(self, instance, force=False, retry=False, name=None): |
|
522 |
def StopInstance(self, instance, force=False, retry=False, name=None, |
|
523 |
timeout=None): |
|
523 | 524 |
"""Stop an instance. |
524 | 525 |
|
526 |
A soft shutdown can be interrupted. A hard shutdown tries forever. |
|
527 |
|
|
525 | 528 |
""" |
529 |
assert(timeout is None or force is not None) |
|
530 |
|
|
526 | 531 |
if name is None: |
527 | 532 |
name = instance.name |
528 | 533 |
|
529 |
return self._StopInstance(name, force) |
|
534 |
return self._StopInstance(name, force, timeout)
|
|
530 | 535 |
|
531 |
def _ShutdownInstance(self, name): |
|
536 |
def _ShutdownInstance(self, name, timeout):
|
|
532 | 537 |
"""Shutdown an instance if the instance is running. |
533 | 538 |
|
534 | 539 |
The '-w' flag waits for shutdown to complete which avoids the need |
... | ... | |
537 | 542 |
|
538 | 543 |
@type name: string |
539 | 544 |
@param name: name of the instance to stop |
545 |
@type timeout: int or None |
|
546 |
@param timeout: a timeout after which the shutdown command should be killed, |
|
547 |
or None for no timeout |
|
540 | 548 |
|
541 | 549 |
""" |
542 | 550 |
instance_info = self.GetInstanceInfo(name) |
... | ... | |
545 | 553 |
logging.info("Failed to shutdown instance %s, not running", name) |
546 | 554 |
return None |
547 | 555 |
|
548 |
return self._RunXen(["shutdown", "-w", name]) |
|
556 |
return self._RunXen(["shutdown", "-w", name], timeout)
|
|
549 | 557 |
|
550 | 558 |
def _DestroyInstance(self, name): |
551 | 559 |
"""Destroy an instance if the instance if the instance exists. |
... | ... | |
562 | 570 |
|
563 | 571 |
return self._RunXen(["destroy", name]) |
564 | 572 |
|
565 |
def _StopInstance(self, name, force): |
|
573 |
def _StopInstance(self, name, force, timeout):
|
|
566 | 574 |
"""Stop an instance. |
567 | 575 |
|
568 | 576 |
@type name: string |
... | ... | |
571 | 579 |
@type force: boolean |
572 | 580 |
@param force: whether to do a "hard" stop (destroy) |
573 | 581 |
|
582 |
@type timeout: int or None |
|
583 |
@param timeout: a timeout after which the shutdown command should be killed, |
|
584 |
or None for no timeout |
|
585 |
|
|
574 | 586 |
""" |
575 | 587 |
if force: |
576 | 588 |
result = self._DestroyInstance(name) |
577 | 589 |
else: |
578 |
self._ShutdownInstance(name) |
|
590 |
self._ShutdownInstance(name, timeout)
|
|
579 | 591 |
result = self._DestroyInstance(name) |
580 | 592 |
|
581 | 593 |
if result is not None and result.failed and \ |
Also available in: Unified diff