root / lib / cmdlib / query.py @ 44ffd981
History | View | Annotate | Download (2.7 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.operating_system import OsQuery |
34 | ec3cc4a8 | Thomas Thrainer | |
35 | ec3cc4a8 | Thomas Thrainer | |
36 | ec3cc4a8 | Thomas Thrainer | #: Query type implementations
|
37 | ec3cc4a8 | Thomas Thrainer | _QUERY_IMPL = { |
38 | 5eacbcae | Thomas Thrainer | constants.QR_CLUSTER: ClusterQuery, |
39 | 5eacbcae | Thomas Thrainer | constants.QR_INSTANCE: InstanceQuery, |
40 | 5eacbcae | Thomas Thrainer | constants.QR_GROUP: GroupQuery, |
41 | 5eacbcae | Thomas Thrainer | constants.QR_OS: OsQuery, |
42 | 5eacbcae | Thomas Thrainer | constants.QR_EXTSTORAGE: ExtStorageQuery, |
43 | 5eacbcae | Thomas Thrainer | constants.QR_EXPORT: ExportQuery, |
44 | ec3cc4a8 | Thomas Thrainer | } |
45 | ec3cc4a8 | Thomas Thrainer | |
46 | ec3cc4a8 | Thomas Thrainer | assert set(_QUERY_IMPL.keys()) == constants.QR_VIA_OP |
47 | ec3cc4a8 | Thomas Thrainer | |
48 | ec3cc4a8 | Thomas Thrainer | |
49 | ec3cc4a8 | Thomas Thrainer | def _GetQueryImplementation(name): |
50 | 270df828 | Jose A. Lopes | """Returns the implementation for a query type.
|
51 | ec3cc4a8 | Thomas Thrainer |
|
52 | ec3cc4a8 | Thomas Thrainer | @param name: Query type, must be one of L{constants.QR_VIA_OP}
|
53 | ec3cc4a8 | Thomas Thrainer |
|
54 | ec3cc4a8 | Thomas Thrainer | """
|
55 | ec3cc4a8 | Thomas Thrainer | try:
|
56 | ec3cc4a8 | Thomas Thrainer | return _QUERY_IMPL[name]
|
57 | ec3cc4a8 | Thomas Thrainer | except KeyError: |
58 | ec3cc4a8 | Thomas Thrainer | raise errors.OpPrereqError("Unknown query resource '%s'" % name, |
59 | ec3cc4a8 | Thomas Thrainer | errors.ECODE_INVAL) |
60 | ec3cc4a8 | Thomas Thrainer | |
61 | ec3cc4a8 | Thomas Thrainer | |
62 | ec3cc4a8 | Thomas Thrainer | class LUQuery(NoHooksLU): |
63 | ec3cc4a8 | Thomas Thrainer | """Query for resources/items of a certain kind.
|
64 | ec3cc4a8 | Thomas Thrainer |
|
65 | ec3cc4a8 | Thomas Thrainer | """
|
66 | ec3cc4a8 | Thomas Thrainer | # pylint: disable=W0142
|
67 | ec3cc4a8 | Thomas Thrainer | REQ_BGL = False
|
68 | ec3cc4a8 | Thomas Thrainer | |
69 | ec3cc4a8 | Thomas Thrainer | def CheckArguments(self): |
70 | ec3cc4a8 | Thomas Thrainer | qcls = _GetQueryImplementation(self.op.what)
|
71 | ec3cc4a8 | Thomas Thrainer | |
72 | ec3cc4a8 | Thomas Thrainer | self.impl = qcls(self.op.qfilter, self.op.fields, self.op.use_locking) |
73 | ec3cc4a8 | Thomas Thrainer | |
74 | ec3cc4a8 | Thomas Thrainer | def ExpandNames(self): |
75 | ec3cc4a8 | Thomas Thrainer | self.impl.ExpandNames(self) |
76 | ec3cc4a8 | Thomas Thrainer | |
77 | ec3cc4a8 | Thomas Thrainer | def DeclareLocks(self, level): |
78 | ec3cc4a8 | Thomas Thrainer | self.impl.DeclareLocks(self, level) |
79 | ec3cc4a8 | Thomas Thrainer | |
80 | ec3cc4a8 | Thomas Thrainer | def Exec(self, feedback_fn): |
81 | ec3cc4a8 | Thomas Thrainer | return self.impl.NewStyleQuery(self) |
82 | ec3cc4a8 | Thomas Thrainer | |
83 | ec3cc4a8 | Thomas Thrainer | |
84 | ec3cc4a8 | Thomas Thrainer | class LUQueryFields(NoHooksLU): |
85 | ec3cc4a8 | Thomas Thrainer | """Query for resources/items of a certain kind.
|
86 | ec3cc4a8 | Thomas Thrainer |
|
87 | ec3cc4a8 | Thomas Thrainer | """
|
88 | ec3cc4a8 | Thomas Thrainer | # pylint: disable=W0142
|
89 | ec3cc4a8 | Thomas Thrainer | REQ_BGL = False
|
90 | ec3cc4a8 | Thomas Thrainer | |
91 | ec3cc4a8 | Thomas Thrainer | def CheckArguments(self): |
92 | ec3cc4a8 | Thomas Thrainer | self.qcls = _GetQueryImplementation(self.op.what) |
93 | ec3cc4a8 | Thomas Thrainer | |
94 | ec3cc4a8 | Thomas Thrainer | def ExpandNames(self): |
95 | ec3cc4a8 | Thomas Thrainer | self.needed_locks = {}
|
96 | ec3cc4a8 | Thomas Thrainer | |
97 | ec3cc4a8 | Thomas Thrainer | def Exec(self, feedback_fn): |
98 | ec3cc4a8 | Thomas Thrainer | return query.QueryFields(self.qcls.FIELDS, self.op.fields) |