From 8bcdde0c0edc1083bb773d994731bb7ec515dcd2 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 29 Apr 2010 15:30:47 +0200
Subject: [PATCH] Add a new node/instance field

This new field ('alias') will hold the shortened/beautified display
name. When resetting the name, the alias is reset too, and there's a new
function to update only the alias.
---
 Ganeti/HTools/Instance.hs | 13 ++++++++++++-
 Ganeti/HTools/Node.hs     | 13 +++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/Ganeti/HTools/Instance.hs b/Ganeti/HTools/Instance.hs
index 45f634d6b..f6ec30867 100644
--- a/Ganeti/HTools/Instance.hs
+++ b/Ganeti/HTools/Instance.hs
@@ -33,6 +33,7 @@ module Ganeti.HTools.Instance
     , create
     , setIdx
     , setName
+    , setAlias
     , setPri
     , setSec
     , setBoth
@@ -49,6 +50,7 @@ import qualified Ganeti.HTools.Container as Container
 
 -- | The instance type
 data Instance = Instance { name :: String    -- ^ The instance name
+                         , alias :: String   -- ^ The shortened name
                          , mem :: Int        -- ^ Memory of the instance
                          , dsk :: Int        -- ^ Disk size of instance
                          , vcpus :: Int      -- ^ Number of VCPUs
@@ -88,6 +90,7 @@ create :: String -> Int -> Int -> Int -> String
        -> [String] -> T.Ndx -> T.Ndx -> Instance
 create name_init mem_init dsk_init vcpus_init run_init tags_init pn sn =
     Instance { name = name_init
+             , alias = name_init
              , mem = mem_init
              , dsk = dsk_init
              , vcpus = vcpus_init
@@ -115,7 +118,15 @@ setIdx t i = t { idx = i }
 setName :: Instance -- ^ The original instance
         -> String   -- ^ New name
         -> Instance -- ^ The modified instance
-setName t s = t { name = s }
+setName t s = t { name = s, alias = s }
+
+-- | Changes the alias.
+--
+-- This is used only during the building of the data structures.
+setAlias :: Instance -- ^ The original instance
+         -> String   -- ^ New alias
+         -> Instance -- ^ The modified instance
+setAlias t s = t { alias = s }
 
 -- * Update functions
 
diff --git a/Ganeti/HTools/Node.hs b/Ganeti/HTools/Node.hs
index bc99df58a..1848557f0 100644
--- a/Ganeti/HTools/Node.hs
+++ b/Ganeti/HTools/Node.hs
@@ -34,6 +34,7 @@ module Ganeti.HTools.Node
     , buildPeers
     , setIdx
     , setName
+    , setAlias
     , setOffline
     , setXmem
     , setFmem
@@ -85,6 +86,7 @@ type TagMap = Map.Map String Int
 -- | The node type.
 data Node = Node
     { name     :: String    -- ^ The node name
+    , alias    :: String    -- ^ The shortened name (for display purposes)
     , tMem     :: Double    -- ^ Total memory (MiB)
     , nMem     :: Int       -- ^ Node memory (MiB)
     , fMem     :: Int       -- ^ Free memory (MiB)
@@ -181,7 +183,8 @@ create :: String -> Double -> Int -> Int -> Double
        -> Int -> Double -> Bool -> Node
 create name_init mem_t_init mem_n_init mem_f_init
        dsk_t_init dsk_f_init cpu_t_init offline_init =
-    Node { name  = name_init
+    Node { name = name_init
+         , alias = name_init
          , tMem = mem_t_init
          , nMem = mem_n_init
          , fMem = mem_f_init
@@ -228,7 +231,13 @@ setIdx t i = t {idx = i}
 --
 -- This is used only during the building of the data structures.
 setName :: Node -> String -> Node
-setName t s = t {name = s}
+setName t s = t { name = s, alias = s }
+
+-- | Changes the alias.
+--
+-- This is used only during the building of the data structures.
+setAlias :: Node -> String -> Node
+setAlias t s = t { alias = s }
 
 -- | Sets the offline attribute.
 setOffline :: Node -> Bool -> Node
-- 
GitLab