Revision ec3cc4a8
b/Makefile.am | ||
---|---|---|
317 | 317 |
lib/cmdlib/instance.py \ |
318 | 318 |
lib/cmdlib/instance_utils.py \ |
319 | 319 |
lib/cmdlib/backup.py \ |
320 |
lib/cmdlib/query.py \ |
|
320 | 321 |
lib/cmdlib/tags.py \ |
321 | 322 |
lib/cmdlib/network.py \ |
322 | 323 |
lib/cmdlib/test.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) |
b/lib/cmdlib/query.py | ||
---|---|---|
1 |
# |
|
2 |
# |
|
3 |
|
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc. |
|
5 |
# |
|
6 |
# This program is free software; you can redistribute it and/or modify |
|
7 |
# it under the terms of the GNU General Public License as published by |
|
8 |
# the Free Software Foundation; either version 2 of the License, or |
|
9 |
# (at your option) any later version. |
|
10 |
# |
|
11 |
# This program is distributed in the hope that it will be useful, but |
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
# General Public License for more details. |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License |
|
17 |
# along with this program; if not, write to the Free Software |
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
19 |
# 02110-1301, USA. |
|
20 |
|
|
21 |
|
|
22 |
"""Logical units for queries.""" |
|
23 |
|
|
24 |
from ganeti import constants |
|
25 |
from ganeti import errors |
|
26 |
from ganeti import query |
|
27 |
from ganeti.cmdlib import _ExtStorageQuery |
|
28 |
from ganeti.cmdlib import _OsQuery |
|
29 |
from ganeti.cmdlib.backup import _ExportQuery |
|
30 |
from ganeti.cmdlib.base import NoHooksLU |
|
31 |
from ganeti.cmdlib.cluster import _ClusterQuery |
|
32 |
from ganeti.cmdlib.group import _GroupQuery |
|
33 |
from ganeti.cmdlib.instance import _InstanceQuery |
|
34 |
from ganeti.cmdlib.network import _NetworkQuery |
|
35 |
from ganeti.cmdlib.node import _NodeQuery |
|
36 |
|
|
37 |
|
|
38 |
#: Query type implementations |
|
39 |
_QUERY_IMPL = { |
|
40 |
constants.QR_CLUSTER: _ClusterQuery, |
|
41 |
constants.QR_INSTANCE: _InstanceQuery, |
|
42 |
constants.QR_NODE: _NodeQuery, |
|
43 |
constants.QR_GROUP: _GroupQuery, |
|
44 |
constants.QR_NETWORK: _NetworkQuery, |
|
45 |
constants.QR_OS: _OsQuery, |
|
46 |
constants.QR_EXTSTORAGE: _ExtStorageQuery, |
|
47 |
constants.QR_EXPORT: _ExportQuery, |
|
48 |
} |
|
49 |
|
|
50 |
assert set(_QUERY_IMPL.keys()) == constants.QR_VIA_OP |
|
51 |
|
|
52 |
|
|
53 |
def _GetQueryImplementation(name): |
|
54 |
"""Returns the implemtnation for a query type. |
|
55 |
|
|
56 |
@param name: Query type, must be one of L{constants.QR_VIA_OP} |
|
57 |
|
|
58 |
""" |
|
59 |
try: |
|
60 |
return _QUERY_IMPL[name] |
|
61 |
except KeyError: |
|
62 |
raise errors.OpPrereqError("Unknown query resource '%s'" % name, |
|
63 |
errors.ECODE_INVAL) |
|
64 |
|
|
65 |
|
|
66 |
class LUQuery(NoHooksLU): |
|
67 |
"""Query for resources/items of a certain kind. |
|
68 |
|
|
69 |
""" |
|
70 |
# pylint: disable=W0142 |
|
71 |
REQ_BGL = False |
|
72 |
|
|
73 |
def CheckArguments(self): |
|
74 |
qcls = _GetQueryImplementation(self.op.what) |
|
75 |
|
|
76 |
self.impl = qcls(self.op.qfilter, self.op.fields, self.op.use_locking) |
|
77 |
|
|
78 |
def ExpandNames(self): |
|
79 |
self.impl.ExpandNames(self) |
|
80 |
|
|
81 |
def DeclareLocks(self, level): |
|
82 |
self.impl.DeclareLocks(self, level) |
|
83 |
|
|
84 |
def Exec(self, feedback_fn): |
|
85 |
return self.impl.NewStyleQuery(self) |
|
86 |
|
|
87 |
|
|
88 |
class LUQueryFields(NoHooksLU): |
|
89 |
"""Query for resources/items of a certain kind. |
|
90 |
|
|
91 |
""" |
|
92 |
# pylint: disable=W0142 |
|
93 |
REQ_BGL = False |
|
94 |
|
|
95 |
def CheckArguments(self): |
|
96 |
self.qcls = _GetQueryImplementation(self.op.what) |
|
97 |
|
|
98 |
def ExpandNames(self): |
|
99 |
self.needed_locks = {} |
|
100 |
|
|
101 |
def Exec(self, feedback_fn): |
|
102 |
return query.QueryFields(self.qcls.FIELDS, self.op.fields) |
b/test/py/ganeti.cmdlib_unittest.py | ||
---|---|---|
37 | 37 |
from ganeti.cmdlib import group |
38 | 38 |
from ganeti.cmdlib import instance |
39 | 39 |
from ganeti.cmdlib import common |
40 |
from ganeti.cmdlib import query |
|
40 | 41 |
from ganeti import opcodes |
41 | 42 |
from ganeti import errors |
42 | 43 |
from ganeti import utils |
... | ... | |
164 | 165 |
|
165 | 166 |
class TestLUQuery(unittest.TestCase): |
166 | 167 |
def test(self): |
167 |
self.assertEqual(sorted(cmdlib._QUERY_IMPL.keys()),
|
|
168 |
self.assertEqual(sorted(query._QUERY_IMPL.keys()),
|
|
168 | 169 |
sorted(constants.QR_VIA_OP)) |
169 | 170 |
|
170 | 171 |
assert constants.QR_NODE in constants.QR_VIA_OP |
171 | 172 |
assert constants.QR_INSTANCE in constants.QR_VIA_OP |
172 | 173 |
|
173 | 174 |
for i in constants.QR_VIA_OP: |
174 |
self.assert_(cmdlib._GetQueryImplementation(i))
|
|
175 |
self.assert_(query._GetQueryImplementation(i))
|
|
175 | 176 |
|
176 |
self.assertRaises(errors.OpPrereqError, cmdlib._GetQueryImplementation,
|
|
177 |
self.assertRaises(errors.OpPrereqError, query._GetQueryImplementation,
|
|
177 | 178 |
"") |
178 |
self.assertRaises(errors.OpPrereqError, cmdlib._GetQueryImplementation,
|
|
179 |
self.assertRaises(errors.OpPrereqError, query._GetQueryImplementation,
|
|
179 | 180 |
"xyz") |
180 | 181 |
|
181 | 182 |
|
Also available in: Unified diff