Revision 57a2fb91 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
2541 | 2541 |
|
2542 | 2542 |
def ExpandNames(self): |
2543 | 2543 |
self.dynamic_fields = frozenset(["oper_state", "oper_ram", "status"]) |
2544 |
_CheckOutputFields(static=["name", "os", "pnode", "snodes", |
|
2545 |
"admin_state", "admin_ram", |
|
2546 |
"disk_template", "ip", "mac", "bridge", |
|
2547 |
"sda_size", "sdb_size", "vcpus", "tags", |
|
2548 |
"auto_balance", |
|
2549 |
"network_port", "kernel_path", "initrd_path", |
|
2550 |
"hvm_boot_order", "hvm_acpi", "hvm_pae", |
|
2551 |
"hvm_cdrom_image_path", "hvm_nic_type", |
|
2552 |
"hvm_disk_type", "vnc_bind_address"], |
|
2544 |
self.static_fields = frozenset([ |
|
2545 |
"name", "os", "pnode", "snodes", |
|
2546 |
"admin_state", "admin_ram", |
|
2547 |
"disk_template", "ip", "mac", "bridge", |
|
2548 |
"sda_size", "sdb_size", "vcpus", "tags", |
|
2549 |
"auto_balance", |
|
2550 |
"network_port", "kernel_path", "initrd_path", |
|
2551 |
"hvm_boot_order", "hvm_acpi", "hvm_pae", |
|
2552 |
"hvm_cdrom_image_path", "hvm_nic_type", |
|
2553 |
"hvm_disk_type", "vnc_bind_address", |
|
2554 |
]) |
|
2555 |
_CheckOutputFields(static=self.static_fields, |
|
2553 | 2556 |
dynamic=self.dynamic_fields, |
2554 | 2557 |
selected=self.op.output_fields) |
2555 | 2558 |
|
... | ... | |
2557 | 2560 |
self.share_locks[locking.LEVEL_INSTANCE] = 1 |
2558 | 2561 |
self.share_locks[locking.LEVEL_NODE] = 1 |
2559 | 2562 |
|
2560 |
# TODO: we could lock instances (and nodes) only if the user asked for |
|
2561 |
# dynamic fields. For that we need atomic ways to get info for a group of |
|
2562 |
# instances from the config, though. |
|
2563 |
if not self.op.names: |
|
2564 |
self.needed_locks[locking.LEVEL_INSTANCE] = locking.ALL_SET |
|
2563 |
if self.op.names: |
|
2564 |
self.wanted = _GetWantedInstances(self, self.op.names) |
|
2565 | 2565 |
else: |
2566 |
self.needed_locks[locking.LEVEL_INSTANCE] = \ |
|
2567 |
_GetWantedInstances(self, self.op.names) |
|
2566 |
self.wanted = locking.ALL_SET |
|
2568 | 2567 |
|
2569 |
self.needed_locks[locking.LEVEL_NODE] = [] |
|
2570 |
self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE |
|
2568 |
self.do_locking = not self.static_fields.issuperset(self.op.output_fields) |
|
2569 |
if self.do_locking: |
|
2570 |
self.needed_locks[locking.LEVEL_INSTANCE] = self.wanted |
|
2571 |
self.needed_locks[locking.LEVEL_NODE] = [] |
|
2572 |
self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE |
|
2571 | 2573 |
|
2572 | 2574 |
def DeclareLocks(self, level): |
2573 |
# TODO: locking of nodes could be avoided when not querying them |
|
2574 |
if level == locking.LEVEL_NODE: |
|
2575 |
if level == locking.LEVEL_NODE and self.do_locking: |
|
2575 | 2576 |
self._LockInstancesNodes() |
2576 | 2577 |
|
2577 | 2578 |
def CheckPrereq(self): |
2578 | 2579 |
"""Check prerequisites. |
2579 | 2580 |
|
2580 | 2581 |
""" |
2581 |
# This of course is valid only if we locked the instances |
|
2582 |
self.wanted = self.acquired_locks[locking.LEVEL_INSTANCE] |
|
2582 |
pass |
|
2583 | 2583 |
|
2584 | 2584 |
def Exec(self, feedback_fn): |
2585 | 2585 |
"""Computes the list of nodes and their attributes. |
2586 | 2586 |
|
2587 | 2587 |
""" |
2588 |
instance_names = self.wanted |
|
2589 |
instance_list = [self.cfg.GetInstanceInfo(iname) for iname |
|
2590 |
in instance_names] |
|
2588 |
all_info = self.cfg.GetAllInstancesInfo() |
|
2589 |
if self.do_locking: |
|
2590 |
instance_names = self.acquired_locks[locking.LEVEL_INSTANCE] |
|
2591 |
else: |
|
2592 |
instance_names = all_info.keys() |
|
2593 |
instance_list = [all_info[iname] for iname in instance_names] |
|
2591 | 2594 |
|
2592 | 2595 |
# begin data gathering |
2593 | 2596 |
|
Also available in: Unified diff