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