From 277a2ec9a63d7dc5adab5c6639065a8bc184b253 Mon Sep 17 00:00:00 2001
From: Constantinos Venetsanopoulos <cven@grnet.gr>
Date: Fri, 7 Sep 2012 13:15:40 +0300
Subject: [PATCH] ExtStorage support in htools

This just adds new constructors for the disk template and related
types, enabling the Ext storage.

Signed-off-by: Constantinos Venetsanopoulos <cven@grnet.gr>
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 htools/Ganeti/HTools/Cluster.hs  |  6 ++++++
 htools/Ganeti/HTools/Instance.hs |  1 +
 htools/Ganeti/HTools/Types.hs    |  1 +
 htools/Ganeti/Objects.hs         | 11 +++++++++++
 htools/Ganeti/Types.hs           |  1 +
 5 files changed, 20 insertions(+)

diff --git a/htools/Ganeti/HTools/Cluster.hs b/htools/Ganeti/HTools/Cluster.hs
index 0cf8a920d..35a75bff0 100644
--- a/htools/Ganeti/HTools/Cluster.hs
+++ b/htools/Ganeti/HTools/Cluster.hs
@@ -939,6 +939,12 @@ nodeEvacInstance nl il mode inst@(Instance.Instance
                    failOnSecondaryChange mode dt >>
                    evacOneNodeOnly nl il inst gdx avail_nodes
 
+nodeEvacInstance nl il mode inst@(Instance.Instance
+                                  {Instance.diskTemplate = dt@DTExt})
+                 gdx avail_nodes =
+                   failOnSecondaryChange mode dt >>
+                   evacOneNodeOnly nl il inst gdx avail_nodes
+
 nodeEvacInstance nl il ChangePrimary
                  inst@(Instance.Instance {Instance.diskTemplate = DTDrbd8})
                  _ _ =
diff --git a/htools/Ganeti/HTools/Instance.hs b/htools/Ganeti/HTools/Instance.hs
index b941df677..d1c67ee45 100644
--- a/htools/Ganeti/HTools/Instance.hs
+++ b/htools/Ganeti/HTools/Instance.hs
@@ -146,6 +146,7 @@ movableDiskTemplates =
   , T.DTBlock
   , T.DTSharedFile
   , T.DTRbd
+  , T.DTExt
   ]
 
 -- | A simple name for the int, instance association list.
diff --git a/htools/Ganeti/HTools/Types.hs b/htools/Ganeti/HTools/Types.hs
index 771407e68..160473b13 100644
--- a/htools/Ganeti/HTools/Types.hs
+++ b/htools/Ganeti/HTools/Types.hs
@@ -121,6 +121,7 @@ templateMirrorType DTPlain      = MirrorNone
 templateMirrorType DTBlock      = MirrorExternal
 templateMirrorType DTDrbd8      = MirrorInternal
 templateMirrorType DTRbd        = MirrorExternal
+templateMirrorType DTExt        = MirrorExternal
 
 -- | The resource spec type.
 data RSpec = RSpec
diff --git a/htools/Ganeti/Objects.hs b/htools/Ganeti/Objects.hs
index d4da6e41d..22aac937c 100644
--- a/htools/Ganeti/Objects.hs
+++ b/htools/Ganeti/Objects.hs
@@ -229,6 +229,7 @@ $(declareSADT "DiskType"
   , ("LD_FILE",     'C.ldFile)
   , ("LD_BLOCKDEV", 'C.ldBlockdev)
   , ("LD_RADOS",    'C.ldRbd)
+  , ("LD_EXT",      'C.ldExt)
   ])
 $(makeJSONInstance ''DiskType)
 
@@ -253,6 +254,7 @@ data DiskLogicalId
   | LIDFile FileDriver String -- ^ Driver, path
   | LIDBlockDev BlockDriver String -- ^ Driver, path (must be under /dev)
   | LIDRados String String -- ^ Unused, path
+  | LIDExt String String -- ^ ExtProvider, unique name
     deriving (Show, Eq)
 
 -- | Mapping from a logical id to a disk type.
@@ -262,6 +264,7 @@ lidDiskType (LIDDrbd8 {}) = LD_DRBD8
 lidDiskType (LIDFile  {}) = LD_FILE
 lidDiskType (LIDBlockDev {}) = LD_BLOCKDEV
 lidDiskType (LIDRados {}) = LD_RADOS
+lidDiskType (LIDExt {}) = LD_EXT
 
 -- | Builds the extra disk_type field for a given logical id.
 lidEncodeType :: DiskLogicalId -> [(String, JSValue)]
@@ -276,6 +279,7 @@ encodeDLId (LIDDrbd8 nodeA nodeB port minorA minorB key) =
 encodeDLId (LIDRados pool name) = JSArray [showJSON pool, showJSON name]
 encodeDLId (LIDFile driver name) = JSArray [showJSON driver, showJSON name]
 encodeDLId (LIDBlockDev driver name) = JSArray [showJSON driver, showJSON name]
+encodeDLId (LIDExt extprovider name) = JSArray [showJSON extprovider, showJSON name]
 
 -- | Custom encoder for DiskLogicalId, composing both the logical id
 -- and the extra disk_type field.
@@ -327,6 +331,13 @@ decodeDLId obj lid = do
           path'   <- readJSON path
           return $ LIDRados driver' path'
         _ -> fail "Can't read logical_id for rdb type"
+    LD_EXT ->
+      case lid of
+        JSArray [extprovider, name] -> do
+          extprovider' <- readJSON extprovider
+          name'   <- readJSON name
+          return $ LIDExt extprovider' name'
+        _ -> fail "Can't read logical_id for extstorage type"
 
 -- | Disk data structure.
 --
diff --git a/htools/Ganeti/Types.hs b/htools/Ganeti/Types.hs
index 208ae9d7f..ae692f6b8 100644
--- a/htools/Ganeti/Types.hs
+++ b/htools/Ganeti/Types.hs
@@ -175,6 +175,7 @@ $(THH.declareSADT "DiskTemplate"
        , ("DTBlock",      'C.dtBlock)
        , ("DTDrbd8",      'C.dtDrbd8)
        , ("DTRbd",        'C.dtRbd)
+       , ("DTExt",        'C.dtExt)
        ])
 $(THH.makeJSONInstance ''DiskTemplate)
 
-- 
GitLab