A few places in the code open a file "manually" rather than using our
wrapper function, because they need an array with the lines. Combining
the result of utils.ReadFile with splitlines() we get rid of the
exceptions.
Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
" a regular file" % os_dir)
try:
- f = open(api_file)
- try:
- api_versions = f.readlines()
- finally:
- f.close()
+ api_versions = utils.ReadFile(api_file).splitlines()
except EnvironmentError, err:
return False, ("Error while reading the API version file at %s: %s" %
(api_file, _ErrnoOrStr(err)))
"""
try:
- fh = file("/proc/meminfo")
- try:
- data = fh.readlines()
- finally:
- fh.close()
+ data = utils.ReadFile("/proc/meminfo").splitlines()
except EnvironmentError, err:
raise errors.HypervisorError("Failed to list node info: %s" % (err,))
import optparse
import time
-from ganeti.utils import RunCmd
+from ganeti.utils import RunCmd, ReadFile
from ganeti import constants
USAGE = ("\tlvmstrap diskinfo\n"
a mountpoint: device number dictionary
"""
- f = open("/proc/mounts", "r")
- mountlines = f.readlines()
- f.close()
+ mountlines = ReadFile("/proc/mounts").splitlines()
mounts = {}
for line in mountlines:
device, mountpoint, fstype, rest = line.split(None, 3)