Setup constant generation infrastructure
[ganeti-local] / lib / backend.py
index a795f46..fc3315a 100644 (file)
 
 """
 
-# 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
@@ -622,12 +624,13 @@ def _GetLvmVgSpaceInfo(name, params):
   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))
@@ -651,7 +654,7 @@ def _GetLvmPvSpaceInfo(name, params):
   """
   excl_stor = _CheckLvmStorageParams(params)
   return _GetVgSpindlesInfo(name, excl_stor)
+
 
 def _GetVgSpindlesInfo(
     name, excl_stor, info_fn=bdev.LogicalVolume.GetVgSpindlesInfo):
@@ -1129,9 +1132,21 @@ def VerifyNode(what, cluster_name, all_hvparams):
                                     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
 
@@ -3194,11 +3209,7 @@ def _TransformFileStorageDir(fs_dir):
   @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)
 
@@ -4250,6 +4261,33 @@ def SetWatcherPause(until, _filename=pathutils.WATCHER_PAUSEFILE):
     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.