1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.backup import ExportQuery
28 from ganeti.cmdlib.base import NoHooksLU
29 from ganeti.cmdlib.cluster import ClusterQuery
30 from ganeti.cmdlib.group import GroupQuery
31 from ganeti.cmdlib.instance_query import InstanceQuery
32 from ganeti.cmdlib.misc import ExtStorageQuery
33 from ganeti.cmdlib.network import NetworkQuery
34 from ganeti.cmdlib.node import NodeQuery
35 from ganeti.cmdlib.operating_system import OsQuery
36
37
38
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
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
67 """Query for resources/items of a certain kind.
68
69 """
70
71 REQ_BGL = False
72
74 qcls = _GetQueryImplementation(self.op.what)
75
76 self.impl = qcls(self.op.qfilter, self.op.fields, self.op.use_locking)
77
80
83
84 - def Exec(self, feedback_fn):
86
87
89 """Query for resources/items of a certain kind.
90
91 """
92
93 REQ_BGL = False
94
97
99 self.needed_locks = {}
100
101 - def Exec(self, feedback_fn):
103