Statistics
| Branch: | Tag: | Revision:

root / lib / cmdlib / common.py @ fb3891d0

History | View | Annotate | Download (1.8 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
from ganeti import locking
26

    
27

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

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

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

    
44

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

    
49

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

    
54

    
55
def _ShareAll():
56
  """Returns a dict declaring all lock levels shared.
57

58
  """
59
  return dict.fromkeys(locking.LEVELS, 1)