Statistics
| Branch: | Tag: | Revision:

root / lib / cmdlib / common.py @ 1a732a74

History | View | Annotate | Download (1.6 kB)

1
#
2
#
3

    
4
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

    
21

    
22
"""Common functions used by multiple logical units."""
23

    
24
from ganeti import errors
25

    
26

    
27
def _ExpandItemName(fn, name, kind):
28
  """Expand an item name.
29

30
  @param fn: the function to use for expansion
31
  @param name: requested item name
32
  @param kind: text description ('Node' or 'Instance')
33
  @return: the resolved (full) name
34
  @raise errors.OpPrereqError: if the item is not found
35

36
  """
37
  full_name = fn(name)
38
  if full_name is None:
39
    raise errors.OpPrereqError("%s '%s' not known" % (kind, name),
40
                               errors.ECODE_NOENT)
41
  return full_name
42

    
43

    
44
def _ExpandInstanceName(cfg, name):
45
  """Wrapper over L{_ExpandItemName} for instance."""
46
  return _ExpandItemName(cfg.ExpandInstanceName, name, "Instance")
47

    
48

    
49
def _ExpandNodeName(cfg, name):
50
  """Wrapper over L{_ExpandItemName} for nodes."""
51
  return _ExpandItemName(cfg.ExpandNodeName, name, "Node")