Add mount Gluster operations in CreateDisks.

Signed-off-by: Weiwei Jia <[email protected]>
---
 lib/backend.py                 |   32 +++++++++++++++++++++++++++++++
 lib/cmdlib/instance_storage.py |   41 ++++++++++++++++++++++++++++++++++++++++
 lib/constants.py               |    3 +++
 lib/rpc_defs.py                |    3 +++
 lib/server/noded.py            |    8 ++++++++
 5 files changed, 87 insertions(+)

diff --git a/lib/backend.py b/lib/backend.py
index c37c102..35dd555 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1181,6 +1181,38 @@ def GetBlockDevSizes(devices):
   return blockdevs
 
 
+def GetGlusterMountLine(gluster_mount_point):
+  """Get Gluster Mount line.
+
+  @type gluster_mount_point: string
+  @param gluster_mount_point: the gluster mount point
+  @rtype: string
+  @return: None if the gluster mount point line can not be found,
+      otherwise, the list of Gluster mount information
+
+
+  """
+  result = utils.RunCmd(["mount"])
+  if result.failed:
+    _Fail("Failed to run mount command, mount output: %s", result.output)
+
+  for line in result.stdout.splitlines():
+    line = line.strip()
+    if gluster_mount_point in line:
+      mount_line = line.split(" ")
+      gluster_hostname = mount_line[0].split(":/")[0]
+      gluster_volname = mount_line[0].split(":/")[1]
+      gluster_dir = mount_line[2]
+      mount_type = mount_line[4]
+      return (gluster_hostname, gluster_volname,
+              gluster_dir, mount_type)
+
+  _Fail("Failed to get gluster mount line, glust mount point: %s",
+                                               gluster_mount_point)
+
+  return None
+
+
 def GetVolumeList(vg_names):
   """Compute list of logical volumes and their size.
 
diff --git a/lib/cmdlib/instance_storage.py b/lib/cmdlib/instance_storage.py
index 4c602ae..0f7cc18 100644
--- a/lib/cmdlib/instance_storage.py
+++ b/lib/cmdlib/instance_storage.py
@@ -248,6 +248,47 @@ def CreateDisks(lu, instance, to_skip=None, 
target_node_uuid=None, disks=None):
   CheckDiskTemplateEnabled(lu.cfg.GetClusterInfo(), instance.disk_template)
 
   if instance.disk_template in constants.DTS_FILEBASED:
+    if instance.disk_template == constants.DT_GLUSTER_FILE:
+      gluster_storage_dir = lu.cfg.GetClusterInfo().gluster_file_storage_dir
+      if not os.path.ismount(gluster_storage_dir):
+        diskparams = lu.cfg.GetClusterInfo().diskparams
+        glusterparams = diskparams[constants.DT_GLUSTER_FILE]
+        gluster_volname = glusterparams[constants.LDP_VOLNAME]
+        gluster_hostname = glusterparams[constants.LDP_HOSTNAME]
+        result = lu.rpc.call_mount_gluster_storage_dir(pnode_uuid,
+                                                   gluster_hostname,
+                                                   gluster_volname,
+                                                   gluster_storage_dir)
+
+        result.Raise("Failed to mount directory '%s' on"
+                     " node %s" % (gluster_storage_dir,
+                                  lu.cfg.GetNodeName(pnode_uuid)))
+      else:
+        result = lu.rpc.call_gluster_mount_line(pnode_uuid,
+                                                gluster_storage_dir)
+
+        result.Raise("Failed to get mount infos '%s' on"
+                     " node %s" % (gluster_storage_dir,
+                                  lu.cfg.GetNodeName(pnode_uuid)))
+
+        mount_line = result.payload
+        _gluster_hostname = mount_line[0]
+        _gluster_volname = mount_line[1]
+        _gluster_dir = mount_line[2]
+        _gluster_type = mount_line[3]
+
+        diskparams = lu.cfg.GetClusterInfo().diskparams
+        glusterparams = diskparams[constants.DT_GLUSTER_FILE]
+        gluster_volname = glusterparams[constants.LDP_VOLNAME]
+        gluster_hostname = glusterparams[constants.LDP_HOSTNAME]
+
+        if (_gluster_hostname != gluster_hostname or
+           _gluster_volname != gluster_volname or
+           _gluster_type != constants.GLUSTER_MOUNT_TYPE or
+           _gluster_dir != gluster_storage_dir):
+          raise errors.OpPrereqError("Invalid Gluster disk on node UUID %s" % 
+                                      pnode_uuid, errors.ECODE_ENVIRON)
+
     file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1])
     result = lu.rpc.call_file_storage_dir_create(pnode_uuid, file_storage_dir)
 
diff --git a/lib/constants.py b/lib/constants.py
index d6e4eb3..1b91760 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -2487,6 +2487,9 @@ IALLOC_HAIL = "hail"
 FAKE_OP_MASTER_TURNUP = "OP_CLUSTER_IP_TURNUP"
 FAKE_OP_MASTER_TURNDOWN = "OP_CLUSTER_IP_TURNDOWN"
 
+# mount type
+GLUSTER_MOUNT_TYPE = "fuse.glusterfs"
+
 # SSH key types
 SSHK_RSA = "rsa"
 SSHK_DSA = "dsa"
diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py
index 83416c9..918902d 100644
--- a/lib/rpc_defs.py
+++ b/lib/rpc_defs.py
@@ -190,6 +190,9 @@ _FILE_STORAGE_CALLS = [
   ("file_storage_dir_create", SINGLE, None, constants.RPC_TMO_FAST, [
     ("file_storage_dir", None, "File storage directory"),
     ], None, None, "Create the given file storage directory"),
+  ("gluster_mount_line", SINGLE, None, constants.RPC_TMO_FAST, [
+    ("gluster_mount_point", None, "gluster mount point"),
+    ], None, None, "Gets the gluster mount line by executing mount command"),
   ("mount_gluster_storage_dir", SINGLE, None, constants.RPC_TMO_FAST, [
     ("gluster_hostname", None, "gluster host name"),
     ("gluster_volname", None, "gluster volume name"),
diff --git a/lib/server/noded.py b/lib/server/noded.py
index 75229d7..d570896 100644
--- a/lib/server/noded.py
+++ b/lib/server/noded.py
@@ -994,6 +994,14 @@ class NodeRequestHandler(http.server.HttpServerHandler):
                                           gluster_storage_dir)
 
   @staticmethod
+  def perspective_gluster_mount_line(params):
+    """Get the gluster mount line.
+
+    """
+    gluster_mount_point = params[0]
+    return backend.GetGlusterMountLine(gluster_mount_point)
+
+  @staticmethod
   def perspective_file_storage_dir_remove(params):
     """Remove the file storage directory.
 
-- 
1.7.10.4

Reply via email to