"""
-# pylint: disable=E1103
+# pylint: disable=E1103,C0302
# E1103: %s %r has no %r member (but some types could not be
# inferred), because the _TryOSFromDisk returns either (True, os_obj)
# or (False, "string") which confuses pylint
+# C0302: This module has become too big and should be split up
+
import os
import os.path
return _GetVgInfo(name, excl_stor)
-def _GetVgInfo(name, excl_stor):
+def _GetVgInfo(
+ name, excl_stor, info_fn=bdev.LogicalVolume.GetVGInfo):
"""Retrieves information about a LVM volume group.
"""
# TODO: GetVGInfo supports returning information for multiple VGs at once
- vginfo = bdev.LogicalVolume.GetVGInfo([name], excl_stor)
+ vginfo = info_fn([name], excl_stor)
if vginfo:
vg_free = int(round(vginfo[0][0], 0))
vg_size = int(round(vginfo[0][1], 0))
def _GetLvmPvSpaceInfo(name, params):
"""Wrapper around C{_GetVgSpindlesInfo} with sanity checks.
- @see C{_GetLvmVgSpaceInfo}
+ @see: C{_GetLvmVgSpaceInfo}
"""
excl_stor = _CheckLvmStorageParams(params)
return _GetVgSpindlesInfo(name, excl_stor)
-
-def _GetVgSpindlesInfo(name, excl_stor):
+
+def _GetVgSpindlesInfo(
+ name, excl_stor, info_fn=bdev.LogicalVolume.GetVgSpindlesInfo):
"""Retrieves information about spindles in an LVM volume group.
@type name: string
"""
if excl_stor:
- (vg_free, vg_size) = bdev.LogicalVolume.GetVgSpindlesInfo(name)
+ (vg_free, vg_size) = info_fn(name)
else:
vg_free = 0
vg_size = 0
for bridge in what[constants.NV_BRIDGES]
if not utils.BridgeExists(bridge)]
- if what.get(constants.NV_FILE_STORAGE_PATHS) == my_name:
- result[constants.NV_FILE_STORAGE_PATHS] = \
- bdev.ComputeWrongFileStoragePaths()
+ if what.get(constants.NV_ACCEPTED_STORAGE_PATHS) == my_name:
+ result[constants.NV_ACCEPTED_STORAGE_PATHS] = \
+ filestorage.ComputeWrongFileStoragePaths()
+
+ if what.get(constants.NV_FILE_STORAGE_PATH):
+ pathresult = filestorage.CheckFileStoragePath(
+ what[constants.NV_FILE_STORAGE_PATH])
+ if pathresult:
+ result[constants.NV_FILE_STORAGE_PATH] = pathresult
+
+ if what.get(constants.NV_SHARED_FILE_STORAGE_PATH):
+ pathresult = filestorage.CheckFileStoragePath(
+ what[constants.NV_SHARED_FILE_STORAGE_PATH])
+ if pathresult:
+ result[constants.NV_SHARED_FILE_STORAGE_PATH] = pathresult
return result
@return: the normalized path if valid, None otherwise
"""
- if not (constants.ENABLE_FILE_STORAGE or
- constants.ENABLE_SHARED_FILE_STORAGE):
- _Fail("File storage disabled at configure time")
-
- bdev.CheckFileStoragePath(fs_dir)
+ filestorage.CheckFileStoragePath(fs_dir)
return os.path.normpath(fs_dir)
utils.WriteFile(_filename, data="%d\n" % (until, ), mode=0644)
+def ConfigureOVS(ovs_name, ovs_link):
+ """Creates a OpenvSwitch on the node.
+
+ This function sets up a OpenvSwitch on the node with given name nad
+ connects it via a given eth device.
+
+ @type ovs_name: string
+ @param ovs_name: Name of the OpenvSwitch to create.
+ @type ovs_link: None or string
+ @param ovs_link: Ethernet device for outside connection (can be missing)
+
+ """
+ # Initialize the OpenvSwitch
+ result = utils.RunCmd(["ovs-vsctl", "add-br", ovs_name])
+ if result.failed:
+ _Fail("Failed to create openvswitch %s. Script return value: %s, output:"
+ " '%s'" % result.exit_code, result.output, log=True)
+
+ # And connect it to a physical interface, if given
+ if ovs_link:
+ result = utils.RunCmd(["ovs-vsctl", "add-port", ovs_name, ovs_link])
+ if result.failed:
+ _Fail("Failed to connect openvswitch to interface %s. Script return"
+ " value: %s, output: '%s'" % ovs_link, result.exit_code,
+ result.output, log=True)
+
+
class HooksRunner(object):
"""Hook runner.