Revision 04610c2a lib/cmdlib/instance_operation.py
b/lib/cmdlib/instance_operation.py | ||
---|---|---|
500 | 500 |
logging.debug("Connecting to console of %s on %s", instance.name, node) |
501 | 501 |
|
502 | 502 |
return GetInstanceConsole(self.cfg.GetClusterInfo(), instance) |
503 |
|
|
504 |
|
|
505 |
class LUInstanceSnapshot(LogicalUnit): |
|
506 |
"""Take a snapshot of the instance. |
|
507 |
|
|
508 |
""" |
|
509 |
HPATH = "instance-snapshot" |
|
510 |
HTYPE = constants.HTYPE_INSTANCE |
|
511 |
REQ_BGL = False |
|
512 |
|
|
513 |
def ExpandNames(self): |
|
514 |
self._ExpandAndLockInstance() |
|
515 |
|
|
516 |
def BuildHooksEnv(self): |
|
517 |
"""Build hooks env. |
|
518 |
|
|
519 |
This runs on master, primary and secondary nodes of the instance. |
|
520 |
|
|
521 |
""" |
|
522 |
return BuildInstanceHookEnvByObject(self, self.instance) |
|
523 |
|
|
524 |
def BuildHooksNodes(self): |
|
525 |
"""Build hooks nodes. |
|
526 |
|
|
527 |
""" |
|
528 |
nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
|
529 |
return (nl, nl) |
|
530 |
|
|
531 |
def CheckPrereq(self): |
|
532 |
"""Check prerequisites. |
|
533 |
|
|
534 |
This checks that the instance is in the cluster and is not running. |
|
535 |
|
|
536 |
""" |
|
537 |
instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
|
538 |
assert instance is not None, \ |
|
539 |
"Cannot retrieve locked instance %s" % self.op.instance_name |
|
540 |
CheckNodeOnline(self, instance.primary_node, "Instance primary node" |
|
541 |
" offline, cannot snapshot") |
|
542 |
|
|
543 |
#if not instance.disk_template == constants.ST_EXT: |
|
544 |
# raise errors.OpPrereqError("Instance '%s' disk templates is not 'ext'" % |
|
545 |
# self.op.instance_name, |
|
546 |
# errors.ECODE_INVAL) |
|
547 |
#CheckInstanceState(self, instance, INSTANCE_DOWN, msg="cannot reinstall") |
|
548 |
|
|
549 |
self.instance = instance |
|
550 |
|
|
551 |
def Exec(self, feedback_fn): |
|
552 |
"""Take a snapshot of the instance the instance. |
|
553 |
|
|
554 |
""" |
|
555 |
inst = self.instance |
|
556 |
for (idx, disk) in enumerate(inst.disks): |
|
557 |
node_uuid = inst.primary_node |
|
558 |
self.cfg.SetDiskID(disk, node_uuid) |
|
559 |
feedback_fn("Taking a snapshot of instance...") |
|
560 |
info = "snapshot:%s" % self.op.snapshot_name |
|
561 |
result = self.rpc.call_blockdev_setinfo(node_uuid, disk, info) |
|
562 |
result.Raise("Could not take a snapshot for instance %s disk %s" |
|
563 |
" on node %s" % (inst, disk, inst.primary_node)) |
Also available in: Unified diff