root / lib / cmdlib / query.py @ a63985f3
History | View | Annotate | Download (2.8 kB)
1 | ec3cc4a8 | Thomas Thrainer | #
|
---|---|---|---|
2 | ec3cc4a8 | Thomas Thrainer | #
|
3 | ec3cc4a8 | Thomas Thrainer | |
4 | ec3cc4a8 | Thomas Thrainer | # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
|
5 | ec3cc4a8 | Thomas Thrainer | #
|
6 | ec3cc4a8 | Thomas Thrainer | # This program is free software; you can redistribute it and/or modify
|
7 | ec3cc4a8 | Thomas Thrainer | # it under the terms of the GNU General Public License as published by
|
8 | ec3cc4a8 | Thomas Thrainer | # the Free Software Foundation; either version 2 of the License, or
|
9 | ec3cc4a8 | Thomas Thrainer | # (at your option) any later version.
|
10 | ec3cc4a8 | Thomas Thrainer | #
|
11 | ec3cc4a8 | Thomas Thrainer | # This program is distributed in the hope that it will be useful, but
|
12 | ec3cc4a8 | Thomas Thrainer | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | ec3cc4a8 | Thomas Thrainer | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | ec3cc4a8 | Thomas Thrainer | # General Public License for more details.
|
15 | ec3cc4a8 | Thomas Thrainer | #
|
16 | ec3cc4a8 | Thomas Thrainer | # You should have received a copy of the GNU General Public License
|
17 | ec3cc4a8 | Thomas Thrainer | # along with this program; if not, write to the Free Software
|
18 | ec3cc4a8 | Thomas Thrainer | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | ec3cc4a8 | Thomas Thrainer | # 02110-1301, USA.
|
20 | ec3cc4a8 | Thomas Thrainer | |
21 | ec3cc4a8 | Thomas Thrainer | |
22 | ec3cc4a8 | Thomas Thrainer | """Logical units for queries."""
|
23 | ec3cc4a8 | Thomas Thrainer | |
24 | ec3cc4a8 | Thomas Thrainer | from ganeti import constants |
25 | ec3cc4a8 | Thomas Thrainer | from ganeti import errors |
26 | ec3cc4a8 | Thomas Thrainer | from ganeti import query |
27 | 5eacbcae | Thomas Thrainer | from ganeti.cmdlib.backup import ExportQuery |
28 | ec3cc4a8 | Thomas Thrainer | from ganeti.cmdlib.base import NoHooksLU |
29 | 5eacbcae | Thomas Thrainer | from ganeti.cmdlib.cluster import ClusterQuery |
30 | 5eacbcae | Thomas Thrainer | from ganeti.cmdlib.group import GroupQuery |
31 | 5eacbcae | Thomas Thrainer | from ganeti.cmdlib.instance_query import InstanceQuery |
32 | 5eacbcae | Thomas Thrainer | from ganeti.cmdlib.misc import ExtStorageQuery |
33 | 5eacbcae | Thomas Thrainer | from ganeti.cmdlib.network import NetworkQuery |
34 | 5eacbcae | Thomas Thrainer | from ganeti.cmdlib.node import NodeQuery |
35 | 5eacbcae | Thomas Thrainer | from ganeti.cmdlib.operating_system import OsQuery |
36 | ec3cc4a8 | Thomas Thrainer | |
37 | ec3cc4a8 | Thomas Thrainer | |
38 | ec3cc4a8 | Thomas Thrainer | #: Query type implementations
|
39 | ec3cc4a8 | Thomas Thrainer | _QUERY_IMPL = { |
40 | 5eacbcae | Thomas Thrainer | constants.QR_CLUSTER: ClusterQuery, |
41 | 5eacbcae | Thomas Thrainer | constants.QR_INSTANCE: InstanceQuery, |
42 | 5eacbcae | Thomas Thrainer | constants.QR_NODE: NodeQuery, |
43 | 5eacbcae | Thomas Thrainer | constants.QR_GROUP: GroupQuery, |
44 | 5eacbcae | Thomas Thrainer | constants.QR_NETWORK: NetworkQuery, |
45 | 5eacbcae | Thomas Thrainer | constants.QR_OS: OsQuery, |
46 | 5eacbcae | Thomas Thrainer | constants.QR_EXTSTORAGE: ExtStorageQuery, |
47 | 5eacbcae | Thomas Thrainer | constants.QR_EXPORT: ExportQuery, |
48 | ec3cc4a8 | Thomas Thrainer | } |
49 | ec3cc4a8 | Thomas Thrainer | |
50 | ec3cc4a8 | Thomas Thrainer | assert set(_QUERY_IMPL.keys()) == constants.QR_VIA_OP |
51 | ec3cc4a8 | Thomas Thrainer | |
52 | ec3cc4a8 | Thomas Thrainer | |
53 | ec3cc4a8 | Thomas Thrainer | def _GetQueryImplementation(name): |
54 | ec3cc4a8 | Thomas Thrainer | """Returns the implemtnation for a query type.
|
55 | ec3cc4a8 | Thomas Thrainer |
|
56 | ec3cc4a8 | Thomas Thrainer | @param name: Query type, must be one of L{constants.QR_VIA_OP}
|
57 | ec3cc4a8 | Thomas Thrainer |
|
58 | ec3cc4a8 | Thomas Thrainer | """
|
59 | ec3cc4a8 | Thomas Thrainer | try:
|
60 | ec3cc4a8 | Thomas Thrainer | return _QUERY_IMPL[name]
|
61 | ec3cc4a8 | Thomas Thrainer | except KeyError: |
62 | ec3cc4a8 | Thomas Thrainer | raise errors.OpPrereqError("Unknown query resource '%s'" % name, |
63 | ec3cc4a8 | Thomas Thrainer | errors.ECODE_INVAL) |
64 | ec3cc4a8 | Thomas Thrainer | |
65 | ec3cc4a8 | Thomas Thrainer | |
66 | ec3cc4a8 | Thomas Thrainer | class LUQuery(NoHooksLU): |
67 | ec3cc4a8 | Thomas Thrainer | """Query for resources/items of a certain kind.
|
68 | ec3cc4a8 | Thomas Thrainer |
|
69 | ec3cc4a8 | Thomas Thrainer | """
|
70 | ec3cc4a8 | Thomas Thrainer | # pylint: disable=W0142
|
71 | ec3cc4a8 | Thomas Thrainer | REQ_BGL = False
|
72 | ec3cc4a8 | Thomas Thrainer | |
73 | ec3cc4a8 | Thomas Thrainer | def CheckArguments(self): |
74 | ec3cc4a8 | Thomas Thrainer | qcls = _GetQueryImplementation(self.op.what)
|
75 | ec3cc4a8 | Thomas Thrainer | |
76 | ec3cc4a8 | Thomas Thrainer | self.impl = qcls(self.op.qfilter, self.op.fields, self.op.use_locking) |
77 | ec3cc4a8 | Thomas Thrainer | |
78 | ec3cc4a8 | Thomas Thrainer | def ExpandNames(self): |
79 | ec3cc4a8 | Thomas Thrainer | self.impl.ExpandNames(self) |
80 | ec3cc4a8 | Thomas Thrainer | |
81 | ec3cc4a8 | Thomas Thrainer | def DeclareLocks(self, level): |
82 | ec3cc4a8 | Thomas Thrainer | self.impl.DeclareLocks(self, level) |
83 | ec3cc4a8 | Thomas Thrainer | |
84 | ec3cc4a8 | Thomas Thrainer | def Exec(self, feedback_fn): |
85 | ec3cc4a8 | Thomas Thrainer | return self.impl.NewStyleQuery(self) |
86 | ec3cc4a8 | Thomas Thrainer | |
87 | ec3cc4a8 | Thomas Thrainer | |
88 | ec3cc4a8 | Thomas Thrainer | class LUQueryFields(NoHooksLU): |
89 | ec3cc4a8 | Thomas Thrainer | """Query for resources/items of a certain kind.
|
90 | ec3cc4a8 | Thomas Thrainer |
|
91 | ec3cc4a8 | Thomas Thrainer | """
|
92 | ec3cc4a8 | Thomas Thrainer | # pylint: disable=W0142
|
93 | ec3cc4a8 | Thomas Thrainer | REQ_BGL = False
|
94 | ec3cc4a8 | Thomas Thrainer | |
95 | ec3cc4a8 | Thomas Thrainer | def CheckArguments(self): |
96 | ec3cc4a8 | Thomas Thrainer | self.qcls = _GetQueryImplementation(self.op.what) |
97 | ec3cc4a8 | Thomas Thrainer | |
98 | ec3cc4a8 | Thomas Thrainer | def ExpandNames(self): |
99 | ec3cc4a8 | Thomas Thrainer | self.needed_locks = {}
|
100 | ec3cc4a8 | Thomas Thrainer | |
101 | ec3cc4a8 | Thomas Thrainer | def Exec(self, feedback_fn): |
102 | ec3cc4a8 | Thomas Thrainer | return query.QueryFields(self.qcls.FIELDS, self.op.fields) |