root / lib / cmdlib / common.py @ 1a732a74
History | View | Annotate | Download (1.6 kB)
1 | 1a732a74 | Thomas Thrainer | #
|
---|---|---|---|
2 | 1a732a74 | Thomas Thrainer | #
|
3 | 1a732a74 | Thomas Thrainer | |
4 | 1a732a74 | Thomas Thrainer | # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
|
5 | 1a732a74 | Thomas Thrainer | #
|
6 | 1a732a74 | Thomas Thrainer | # This program is free software; you can redistribute it and/or modify
|
7 | 1a732a74 | Thomas Thrainer | # it under the terms of the GNU General Public License as published by
|
8 | 1a732a74 | Thomas Thrainer | # the Free Software Foundation; either version 2 of the License, or
|
9 | 1a732a74 | Thomas Thrainer | # (at your option) any later version.
|
10 | 1a732a74 | Thomas Thrainer | #
|
11 | 1a732a74 | Thomas Thrainer | # This program is distributed in the hope that it will be useful, but
|
12 | 1a732a74 | Thomas Thrainer | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 1a732a74 | Thomas Thrainer | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 1a732a74 | Thomas Thrainer | # General Public License for more details.
|
15 | 1a732a74 | Thomas Thrainer | #
|
16 | 1a732a74 | Thomas Thrainer | # You should have received a copy of the GNU General Public License
|
17 | 1a732a74 | Thomas Thrainer | # along with this program; if not, write to the Free Software
|
18 | 1a732a74 | Thomas Thrainer | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 1a732a74 | Thomas Thrainer | # 02110-1301, USA.
|
20 | 1a732a74 | Thomas Thrainer | |
21 | 1a732a74 | Thomas Thrainer | |
22 | 1a732a74 | Thomas Thrainer | """Common functions used by multiple logical units."""
|
23 | 1a732a74 | Thomas Thrainer | |
24 | 1a732a74 | Thomas Thrainer | from ganeti import errors |
25 | 1a732a74 | Thomas Thrainer | |
26 | 1a732a74 | Thomas Thrainer | |
27 | 1a732a74 | Thomas Thrainer | def _ExpandItemName(fn, name, kind): |
28 | 1a732a74 | Thomas Thrainer | """Expand an item name.
|
29 | 1a732a74 | Thomas Thrainer |
|
30 | 1a732a74 | Thomas Thrainer | @param fn: the function to use for expansion
|
31 | 1a732a74 | Thomas Thrainer | @param name: requested item name
|
32 | 1a732a74 | Thomas Thrainer | @param kind: text description ('Node' or 'Instance')
|
33 | 1a732a74 | Thomas Thrainer | @return: the resolved (full) name
|
34 | 1a732a74 | Thomas Thrainer | @raise errors.OpPrereqError: if the item is not found
|
35 | 1a732a74 | Thomas Thrainer |
|
36 | 1a732a74 | Thomas Thrainer | """
|
37 | 1a732a74 | Thomas Thrainer | full_name = fn(name) |
38 | 1a732a74 | Thomas Thrainer | if full_name is None: |
39 | 1a732a74 | Thomas Thrainer | raise errors.OpPrereqError("%s '%s' not known" % (kind, name), |
40 | 1a732a74 | Thomas Thrainer | errors.ECODE_NOENT) |
41 | 1a732a74 | Thomas Thrainer | return full_name
|
42 | 1a732a74 | Thomas Thrainer | |
43 | 1a732a74 | Thomas Thrainer | |
44 | 1a732a74 | Thomas Thrainer | def _ExpandInstanceName(cfg, name): |
45 | 1a732a74 | Thomas Thrainer | """Wrapper over L{_ExpandItemName} for instance."""
|
46 | 1a732a74 | Thomas Thrainer | return _ExpandItemName(cfg.ExpandInstanceName, name, "Instance") |
47 | 1a732a74 | Thomas Thrainer | |
48 | 1a732a74 | Thomas Thrainer | |
49 | 1a732a74 | Thomas Thrainer | def _ExpandNodeName(cfg, name): |
50 | 1a732a74 | Thomas Thrainer | """Wrapper over L{_ExpandItemName} for nodes."""
|
51 | 1a732a74 | Thomas Thrainer | return _ExpandItemName(cfg.ExpandNodeName, name, "Node") |