Revision 06c2fb4a lib/cmdlib/instance_operation.py
b/lib/cmdlib/instance_operation.py | ||
---|---|---|
42 | 42 |
ShutdownInstanceDisks |
43 | 43 |
from ganeti.cmdlib.instance_utils import BuildInstanceHookEnvByObject, \ |
44 | 44 |
CheckInstanceBridgesExist, CheckNodeFreeMemory, CheckNodeHasOS |
45 |
from ganeti.cmdlib.instance import GetItemFromContainer |
|
45 | 46 |
|
46 | 47 |
|
47 | 48 |
class LUInstanceStartup(LogicalUnit): |
... | ... | |
500 | 501 |
logging.debug("Connecting to console of %s on %s", instance.name, node) |
501 | 502 |
|
502 | 503 |
return GetInstanceConsole(self.cfg.GetClusterInfo(), instance) |
504 |
|
|
505 |
|
|
506 |
class LUInstanceSnapshot(LogicalUnit): |
|
507 |
"""Take a snapshot of the instance. |
|
508 |
|
|
509 |
""" |
|
510 |
HPATH = "instance-snapshot" |
|
511 |
HTYPE = constants.HTYPE_INSTANCE |
|
512 |
REQ_BGL = False |
|
513 |
|
|
514 |
def ExpandNames(self): |
|
515 |
self._ExpandAndLockInstance() |
|
516 |
|
|
517 |
def BuildHooksEnv(self): |
|
518 |
"""Build hooks env. |
|
519 |
|
|
520 |
This runs on master, primary and secondary nodes of the instance. |
|
521 |
|
|
522 |
""" |
|
523 |
return BuildInstanceHookEnvByObject(self, self.instance) |
|
524 |
|
|
525 |
def BuildHooksNodes(self): |
|
526 |
"""Build hooks nodes. |
|
527 |
|
|
528 |
""" |
|
529 |
nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
|
530 |
return (nl, nl) |
|
531 |
|
|
532 |
def CheckPrereq(self): |
|
533 |
"""Check prerequisites. |
|
534 |
|
|
535 |
This checks that the instance is in the cluster and is not running. |
|
536 |
|
|
537 |
""" |
|
538 |
instance = self.cfg.GetInstanceInfo(self.op.instance_name) |
|
539 |
assert instance is not None, \ |
|
540 |
"Cannot retrieve locked instance %s" % self.op.instance_name |
|
541 |
CheckNodeOnline(self, instance.primary_node, "Instance primary node" |
|
542 |
" offline, cannot snapshot") |
|
543 |
|
|
544 |
self.snapshots = [] |
|
545 |
for ident, params in self.op.disks: |
|
546 |
idx, disk = GetItemFromContainer(ident, 'disk', instance.disks) |
|
547 |
snapshot_name = params.get("snapshot_name", None) |
|
548 |
if not snapshot_name: |
|
549 |
raise errors.OpPrereqError("No snapshot_name passed for disk %s", ident) |
|
550 |
self.snapshots.append((idx, disk, snapshot_name)) |
|
551 |
|
|
552 |
self.instance = instance |
|
553 |
|
|
554 |
def Exec(self, feedback_fn): |
|
555 |
"""Take a snapshot of the instance the instance. |
|
556 |
|
|
557 |
""" |
|
558 |
inst = self.instance |
|
559 |
node_uuid = inst.primary_node |
|
560 |
for idx, disk, snapshot_name in self.snapshots: |
|
561 |
self.cfg.SetDiskID(disk, node_uuid) |
|
562 |
feedback_fn("Taking a snapshot of instance...") |
|
563 |
result = self.rpc.call_blockdev_snapshot(node_uuid, |
|
564 |
(disk, inst), |
|
565 |
snapshot_name) |
|
566 |
result.Raise("Could not take a snapshot for instance %s disk/%d %s" |
|
567 |
" on node %s" % (inst, idx, disk.uuid, inst.primary_node)) |
Also available in: Unified diff