Revision 908c2f67 src/Ganeti/HTools/Backend/IAlloc.hs

b/src/Ganeti/HTools/Backend/IAlloc.hs
44 44
import qualified Ganeti.HTools.Group as Group
45 45
import qualified Ganeti.HTools.Node as Node
46 46
import qualified Ganeti.HTools.Instance as Instance
47
import qualified Ganeti.HTools.Nic as Nic
47 48
import qualified Ganeti.Constants as C
48 49
import Ganeti.HTools.CLI
49 50
import Ganeti.HTools.Loader
......
56 57
-- | Type alias for the result of an IAllocator call.
57 58
type IAllocResult = (String, JSValue, Node.List, Instance.List)
58 59

  
60
-- | Parse a NIC within an instance (in a creation request)
61
parseNic :: String -> JSRecord -> Result Nic.Nic
62
parseNic n a = do
63
  mac     <- maybeFromObj a "mac"
64
  ip      <- maybeFromObj a "ip"
65
  mode    <- maybeFromObj a "mode" >>= \m -> case m of
66
               Just "bridged" -> Ok $ Just Nic.Bridged
67
               Just "routed" -> Ok $ Just Nic.Routed
68
               Just "openvswitch" -> Ok $ Just Nic.OpenVSwitch
69
               Nothing -> Ok Nothing
70
               _ -> Bad $ "invalid NIC mode in instance " ++ n
71
  link    <- maybeFromObj a "link"
72
  bridge  <- maybeFromObj a "bridge"
73
  network <- maybeFromObj a "network"
74
  return (Nic.create mac ip mode link bridge network)
75

  
59 76
-- | Parse the basic specifications of an instance.
60 77
--
61 78
-- Instances in the cluster instance list and the instance in an
......
75 92
  tags  <- extract "tags"
76 93
  dt    <- extract "disk_template"
77 94
  su    <- extract "spindle_use"
78
  return (n, Instance.create n mem disk disks vcpus Running tags True 0 0 dt su)
95
  nics  <- extract "nics" >>= toArray >>= asObjectList >>=
96
           mapM (parseNic n . fromJSObject)
97
  return
98
    (n,
99
     Instance.create n mem disk disks vcpus Running tags True 0 0 dt su nics)
79 100

  
80 101
-- | Parses an instance as found in the cluster instance list.
81 102
parseInstance :: NameAssoc -- ^ The node name-to-index association list

Also available in: Unified diff