Revision ec3cc4a8 lib/cmdlib/__init__.py
b/lib/cmdlib/__init__.py | ||
---|---|---|
62 | 62 |
|
63 | 63 |
from ganeti.cmdlib.cluster import LUClusterActivateMasterIp, \ |
64 | 64 |
LUClusterDeactivateMasterIp, LUClusterConfigQuery, LUClusterDestroy, \ |
65 |
LUClusterPostInit, _ClusterQuery, LUClusterQuery, LUClusterRedistConf, \ |
|
66 |
LUClusterRename, LUClusterRepairDiskSizes, LUClusterSetParams, \ |
|
67 |
LUClusterVerify, LUClusterVerifyConfig, LUClusterVerifyGroup, \ |
|
68 |
LUClusterVerifyDisks |
|
65 |
LUClusterPostInit, LUClusterQuery, LUClusterRedistConf, LUClusterRename, \ |
|
66 |
LUClusterRepairDiskSizes, LUClusterSetParams, LUClusterVerify, \ |
|
67 |
LUClusterVerifyConfig, LUClusterVerifyGroup, LUClusterVerifyDisks |
|
69 | 68 |
from ganeti.cmdlib.group import LUGroupAdd, LUGroupAssignNodes, \ |
70 |
_GroupQuery, LUGroupQuery, LUGroupSetParams, LUGroupRemove, \
|
|
71 |
LUGroupRename, LUGroupEvacuate, LUGroupVerifyDisks
|
|
69 |
LUGroupQuery, LUGroupSetParams, LUGroupRemove, LUGroupRename, \
|
|
70 |
LUGroupEvacuate, LUGroupVerifyDisks |
|
72 | 71 |
from ganeti.cmdlib.node import LUNodeAdd, LUNodeSetParams, \ |
73 | 72 |
LUNodePowercycle, LUNodeEvacuate, LUNodeMigrate, LUNodeModifyStorage, \ |
74 |
_NodeQuery, LUNodeQuery, LUNodeQueryvols, LUNodeQueryStorage, \
|
|
75 |
LUNodeRemove, LURepairNodeStorage
|
|
73 |
LUNodeQuery, LUNodeQueryvols, LUNodeQueryStorage, LUNodeRemove, \
|
|
74 |
LURepairNodeStorage |
|
76 | 75 |
from ganeti.cmdlib.instance import LUInstanceCreate, LUInstanceRename, \ |
77 |
LUInstanceRemove, LUInstanceMove, _InstanceQuery, LUInstanceQuery, \
|
|
78 |
LUInstanceQueryData, LUInstanceRecreateDisks, LUInstanceGrowDisk, \
|
|
79 |
LUInstanceReplaceDisks, LUInstanceActivateDisks, \
|
|
80 |
LUInstanceDeactivateDisks, LUInstanceStartup, LUInstanceShutdown, \
|
|
81 |
LUInstanceReinstall, LUInstanceReboot, LUInstanceConsole, \
|
|
82 |
LUInstanceFailover, LUInstanceMigrate, LUInstanceMultiAlloc, \
|
|
83 |
LUInstanceSetParams, LUInstanceChangeGroup
|
|
84 |
from ganeti.cmdlib.backup import _ExportQuery, LUBackupQuery, \
|
|
85 |
LUBackupPrepare, LUBackupExport, LUBackupRemove
|
|
76 |
LUInstanceRemove, LUInstanceMove, LUInstanceQuery, LUInstanceQueryData, \
|
|
77 |
LUInstanceRecreateDisks, LUInstanceGrowDisk, LUInstanceReplaceDisks, \
|
|
78 |
LUInstanceActivateDisks, LUInstanceDeactivateDisks, LUInstanceStartup, \
|
|
79 |
LUInstanceShutdown, LUInstanceReinstall, LUInstanceReboot, \
|
|
80 |
LUInstanceConsole, LUInstanceFailover, LUInstanceMigrate, \
|
|
81 |
LUInstanceMultiAlloc, LUInstanceSetParams, LUInstanceChangeGroup
|
|
82 |
from ganeti.cmdlib.backup import LUBackupQuery, LUBackupPrepare, \
|
|
83 |
LUBackupExport, LUBackupRemove
|
|
84 |
from ganeti.cmdlib.query import LUQuery, LUQueryFields
|
|
86 | 85 |
from ganeti.cmdlib.tags import LUTagsGet, LUTagsSearch, LUTagsSet, LUTagsDel |
87 | 86 |
from ganeti.cmdlib.network import LUNetworkAdd, LUNetworkRemove, \ |
88 |
LUNetworkSetParams, _NetworkQuery, LUNetworkQuery, LUNetworkConnect, \ |
|
89 |
LUNetworkDisconnect |
|
87 |
LUNetworkSetParams, LUNetworkQuery, LUNetworkConnect, LUNetworkDisconnect |
|
90 | 88 |
from ganeti.cmdlib.test import LUTestDelay, LUTestJqueue, LUTestAllocator |
91 | 89 |
|
92 | 90 |
|
... | ... | |
590 | 588 |
return self.eq.OldStyleQuery(self) |
591 | 589 |
|
592 | 590 |
|
593 |
class LUQuery(NoHooksLU): |
|
594 |
"""Query for resources/items of a certain kind. |
|
595 |
|
|
596 |
""" |
|
597 |
# pylint: disable=W0142 |
|
598 |
REQ_BGL = False |
|
599 |
|
|
600 |
def CheckArguments(self): |
|
601 |
qcls = _GetQueryImplementation(self.op.what) |
|
602 |
|
|
603 |
self.impl = qcls(self.op.qfilter, self.op.fields, self.op.use_locking) |
|
604 |
|
|
605 |
def ExpandNames(self): |
|
606 |
self.impl.ExpandNames(self) |
|
607 |
|
|
608 |
def DeclareLocks(self, level): |
|
609 |
self.impl.DeclareLocks(self, level) |
|
610 |
|
|
611 |
def Exec(self, feedback_fn): |
|
612 |
return self.impl.NewStyleQuery(self) |
|
613 |
|
|
614 |
|
|
615 |
class LUQueryFields(NoHooksLU): |
|
616 |
"""Query for resources/items of a certain kind. |
|
617 |
|
|
618 |
""" |
|
619 |
# pylint: disable=W0142 |
|
620 |
REQ_BGL = False |
|
621 |
|
|
622 |
def CheckArguments(self): |
|
623 |
self.qcls = _GetQueryImplementation(self.op.what) |
|
624 |
|
|
625 |
def ExpandNames(self): |
|
626 |
self.needed_locks = {} |
|
627 |
|
|
628 |
def Exec(self, feedback_fn): |
|
629 |
return query.QueryFields(self.qcls.FIELDS, self.op.fields) |
|
630 |
|
|
631 |
|
|
632 | 591 |
class LURestrictedCommand(NoHooksLU): |
633 | 592 |
"""Logical unit for executing restricted commands. |
634 | 593 |
|
... | ... | |
674 | 633 |
result.append((True, nres.payload)) |
675 | 634 |
|
676 | 635 |
return result |
677 |
|
|
678 |
|
|
679 |
#: Query type implementations |
|
680 |
_QUERY_IMPL = { |
|
681 |
constants.QR_CLUSTER: _ClusterQuery, |
|
682 |
constants.QR_INSTANCE: _InstanceQuery, |
|
683 |
constants.QR_NODE: _NodeQuery, |
|
684 |
constants.QR_GROUP: _GroupQuery, |
|
685 |
constants.QR_NETWORK: _NetworkQuery, |
|
686 |
constants.QR_OS: _OsQuery, |
|
687 |
constants.QR_EXTSTORAGE: _ExtStorageQuery, |
|
688 |
constants.QR_EXPORT: _ExportQuery, |
|
689 |
} |
|
690 |
|
|
691 |
assert set(_QUERY_IMPL.keys()) == constants.QR_VIA_OP |
|
692 |
|
|
693 |
|
|
694 |
def _GetQueryImplementation(name): |
|
695 |
"""Returns the implemtnation for a query type. |
|
696 |
|
|
697 |
@param name: Query type, must be one of L{constants.QR_VIA_OP} |
|
698 |
|
|
699 |
""" |
|
700 |
try: |
|
701 |
return _QUERY_IMPL[name] |
|
702 |
except KeyError: |
|
703 |
raise errors.OpPrereqError("Unknown query resource '%s'" % name, |
|
704 |
errors.ECODE_INVAL) |
Also available in: Unified diff