Revision 364c350f
b/lib/hypervisor/hv_xen.py | ||
---|---|---|
165 | 165 |
return _ParseXmList(lines, include_node) |
166 | 166 |
|
167 | 167 |
|
168 |
def _IsInstanceRunning(instance_info): |
|
169 |
return instance_info == "r-----" \ |
|
170 |
or instance_info == "-b----" |
|
171 |
|
|
172 |
|
|
173 |
def _IsInstanceShutdown(instance_info): |
|
174 |
return instance_info == "---s--" |
|
175 |
|
|
176 |
|
|
168 | 177 |
def _ParseNodeInfo(info): |
169 | 178 |
"""Return information about the node. |
170 | 179 |
|
... | ... | |
510 | 519 |
|
511 | 520 |
return self._StopInstance(name, force) |
512 | 521 |
|
522 |
def _ShutdownInstance(self, name): |
|
523 |
"""Shutdown an instance if the instance is running. |
|
524 |
|
|
525 |
@type name: string |
|
526 |
@param name: name of the instance to stop |
|
527 |
|
|
528 |
The '-w' flag waits for shutdown to complete which avoids the need |
|
529 |
to poll in the case where we want to destroy the domain |
|
530 |
immediately after shutdown. |
|
531 |
|
|
532 |
""" |
|
533 |
instance_info = self.GetInstanceInfo(name) |
|
534 |
|
|
535 |
if instance_info is None or _IsInstanceShutdown(instance_info[4]): |
|
536 |
logging.info("Failed to shutdown instance %s, not running", name) |
|
537 |
return None |
|
538 |
|
|
539 |
return self._RunXen(["shutdown", "-w", name]) |
|
540 |
|
|
541 |
def _DestroyInstance(self, name): |
|
542 |
"""Destroy an instance if the instance if the instance exists. |
|
543 |
|
|
544 |
@type name: string |
|
545 |
@param name: name of the instance to destroy |
|
546 |
|
|
547 |
""" |
|
548 |
instance_info = self.GetInstanceInfo(name) |
|
549 |
|
|
550 |
if instance_info is None: |
|
551 |
logging.info("Failed to destroy instance %s, does not exist", name) |
|
552 |
return None |
|
553 |
|
|
554 |
return self._RunXen(["destroy", name]) |
|
555 |
|
|
513 | 556 |
def _StopInstance(self, name, force): |
514 | 557 |
"""Stop an instance. |
515 | 558 |
|
559 |
@type name: string |
|
560 |
@param name: name of the instance to destroy |
|
561 |
|
|
562 |
@type force: boolean |
|
563 |
@param force: whether to do a "hard" stop (destroy) |
|
564 |
|
|
516 | 565 |
""" |
517 | 566 |
if force: |
518 |
action = "destroy"
|
|
567 |
result = self._DestroyInstance(name)
|
|
519 | 568 |
else: |
520 |
action = "shutdown" |
|
569 |
self._ShutdownInstance(name) |
|
570 |
result = self._DestroyInstance(name) |
|
521 | 571 |
|
522 |
result = self._RunXen([action, name])
|
|
523 |
if result.failed:
|
|
572 |
if result is not None and result.failed and \
|
|
573 |
self.GetInstanceInfo(name) is not None:
|
|
524 | 574 |
raise errors.HypervisorError("Failed to stop instance %s: %s, %s" % |
525 | 575 |
(name, result.fail_reason, result.output)) |
526 | 576 |
|
Also available in: Unified diff