Statistics
| Branch: | Tag: | Revision:

root / lib / storage / filestorage.py @ 577edf04

History | View | Annotate | Download (1.5 kB)

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

24 820bade9 Helga Velroyen
"""
25 820bade9 Helga Velroyen
26 5d94c034 Helga Velroyen
import os
27 820bade9 Helga Velroyen
28 5d94c034 Helga Velroyen
from ganeti import errors
29 820bade9 Helga Velroyen
30 820bade9 Helga Velroyen
31 5d94c034 Helga Velroyen
def GetSpaceInfo(path):
32 820bade9 Helga Velroyen
  """Retrieves the free and total space of the device where the file is
33 820bade9 Helga Velroyen
     located.
34 820bade9 Helga Velroyen

35 820bade9 Helga Velroyen
     @type path: string
36 820bade9 Helga Velroyen
     @param path: Path of the file whose embracing device's capacity is
37 820bade9 Helga Velroyen
       reported.
38 5d94c034 Helga Velroyen
     @return: a dictionary containing 'vg_size' and 'vg_free' given in MebiBytes
39 5d94c034 Helga Velroyen

40 820bade9 Helga Velroyen
  """
41 5d94c034 Helga Velroyen
  try:
42 5d94c034 Helga Velroyen
    result = os.statvfs(path)
43 5d94c034 Helga Velroyen
    free = (result.f_frsize * result.f_bavail) / (1024 * 1024)
44 5d94c034 Helga Velroyen
    size = (result.f_frsize * result.f_blocks) / (1024 * 1024)
45 5d94c034 Helga Velroyen
    return {"vg_size": size, "vg_free": free}
46 5d94c034 Helga Velroyen
  except OSError, e:
47 5d94c034 Helga Velroyen
    raise errors.CommandError("Failed to retrieve file system information about"
48 5d94c034 Helga Velroyen
                              " path: %s - %s" % (path, e.strerror))