Remove unsafePerformIO usage
[ganeti-local] / htools / Ganeti / HTools / Program / Hspace.hs
index 2c20ab1..d1b62c3 100644 (file)
@@ -23,7 +23,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
 -}
 
-module Ganeti.HTools.Program.Hspace (main, options) where
+module Ganeti.HTools.Program.Hspace
+  (main
+  , options
+  , arguments
+  ) where
 
 import Control.Monad
 import Data.Char (toUpper, toLower)
@@ -40,36 +44,42 @@ import qualified Ganeti.HTools.Cluster as Cluster
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Instance as Instance
 
-import Ganeti.HTools.Utils
+import Ganeti.BasicTypes
+import Ganeti.Common
 import Ganeti.HTools.Types
 import Ganeti.HTools.CLI
 import Ganeti.HTools.ExtLoader
 import Ganeti.HTools.Loader
+import Ganeti.Utils
 
 -- | Options list and functions.
-options :: [OptType]
-options =
-  [ oPrintNodes
-  , oDataFile
-  , oDiskTemplate
-  , oSpindleUse
-  , oNodeSim
-  , oRapiMaster
-  , oLuxiSocket
-  , oIAllocSrc
-  , oVerbose
-  , oQuiet
-  , oOfflineNode
-  , oMachineReadable
-  , oMaxCpu
-  , oMaxSolLength
-  , oMinDisk
-  , oStdSpec
-  , oTieredSpec
-  , oSaveCluster
-  , oShowVer
-  , oShowHelp
-  ]
+options :: IO [OptType]
+options = do
+  luxi <- oLuxiSocket
+  return
+    [ oPrintNodes
+    , oDataFile
+    , oDiskTemplate
+    , oSpindleUse
+    , oNodeSim
+    , oRapiMaster
+    , luxi
+    , oIAllocSrc
+    , oVerbose
+    , oQuiet
+    , oOfflineNode
+    , oMachineReadable
+    , oMaxCpu
+    , oMaxSolLength
+    , oMinDisk
+    , oStdSpec
+    , oTieredSpec
+    , oSaveCluster
+    ]
+
+-- | The list of arguments supported by the program.
+arguments :: [ArgCompletion]
+arguments = []
 
 -- | The allocation phase we're in (initial, after tiered allocs, or
 -- after regular allocation).
@@ -114,7 +124,7 @@ cpuEff :: Cluster.CStats -> Double
 cpuEff = effFn Cluster.csIcpu (fromIntegral . Cluster.csVcpu)
 
 -- | Holds data for converting a 'Cluster.CStats' structure into
--- detailed statictics.
+-- detailed statistics.
 statsData :: [(String, Cluster.CStats -> String)]
 statsData = [ ("SCORE", printf "%.8f" . Cluster.csScore)
             , ("INST_CNT", printf "%d" . Cluster.csNinst)
@@ -372,14 +382,14 @@ runAllocation cdata stop_allocation actual_result spec dt mode opts = do
 
 -- | Create an instance from a given spec.
 instFromSpec :: RSpec -> DiskTemplate -> Int -> Instance.Instance
-instFromSpec spx disk_template su =
+instFromSpec spx =
   Instance.create "new" (rspecMem spx) (rspecDsk spx)
-    (rspecCpu spx) Running [] True (-1) (-1) disk_template su
+    (rspecCpu spx) Running [] True (-1) (-1)
 
 -- | Main function.
 main :: Options -> [String] -> IO ()
 main opts args = do
-  exitUnless (null args) "this program doesn't take any arguments"
+  exitUnless (null args) "This program doesn't take any arguments."
 
   let verbose = optVerbose opts
       machine_r = optMachineReadable opts