Revision 908c2f67

b/Makefile.am
549 549
	src/Ganeti/HTools/Group.hs \
550 550
	src/Ganeti/HTools/Instance.hs \
551 551
	src/Ganeti/HTools/Loader.hs \
552
	src/Ganeti/HTools/Nic.hs \
552 553
	src/Ganeti/HTools/Node.hs \
553 554
	src/Ganeti/HTools/PeerMap.hs \
554 555
	src/Ganeti/HTools/Program/Hail.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
b/src/Ganeti/HTools/Backend/Luxi.hs
173 173
  xdt <- convert "disk_template" disk_template
174 174
  xsu <- convert "be/spindle_use" su
175 175
  let inst = Instance.create xname xmem xdisk [xdisk] xvcpus
176
             xrunning xtags xauto_balance xpnode snode xdt xsu
176
             xrunning xtags xauto_balance xpnode snode xdt xsu []
177 177
  return (xname, inst)
178 178

  
179 179
parseInstance _ v = fail ("Invalid instance query result: " ++ show v)
b/src/Ganeti/HTools/Backend/Rapi.hs
140 140
  dt <- extract "disk_template" a
141 141
  su <- extract "spindle_use" beparams
142 142
  let inst = Instance.create name mem disk disks vcpus running tags
143
             auto_balance pnode snode dt su
143
             auto_balance pnode snode dt su []
144 144
  return (name, inst)
145 145

  
146 146
-- | Construct a node from a JSON object.
......
231 231
  let (node_names, node_idx) = assignIndices node_data
232 232
  inst_data <- inst_body >>= getInstances node_names
233 233
  let (_, inst_idx) = assignIndices inst_data
234
  (tags, ipolicy, master) <- 
234
  (tags, ipolicy, master) <-
235 235
    info_body >>=
236 236
    (fromJResult "Parsing cluster info" . decodeStrict) >>=
237 237
    parseCluster
b/src/Ganeti/HTools/Backend/Text.hs
247 247
           " has same primary and secondary node - " ++ pnode
248 248
  let vtags = commaSplit tags
249 249
      newinst = Instance.create name vmem vdsk [vdsk] vvcpus vstatus vtags
250
                auto_balance pidx sidx disk_template spindle_use
250
                auto_balance pidx sidx disk_template spindle_use []
251 251
  return (name, newinst)
252 252

  
253 253
loadInst ktn [ name, mem, dsk, vcpus, status, auto_bal, pnode, snode
b/src/Ganeti/HTools/Instance.hs
60 60
import Ganeti.BasicTypes
61 61
import qualified Ganeti.HTools.Types as T
62 62
import qualified Ganeti.HTools.Container as Container
63
import Ganeti.HTools.Nic (Nic)
63 64

  
64 65
import Ganeti.Utils
65 66

  
......
85 86
  , allTags      :: [String]  -- ^ List of all instance tags
86 87
  , exclTags     :: [String]  -- ^ List of instance exclusion tags
87 88
  , arPolicy     :: T.AutoRepairPolicy -- ^ Instance's auto-repair policy
89
  , nics         :: [Nic]     -- ^ NICs of the instance
88 90
  } deriving (Show, Eq)
89 91

  
90 92
instance T.Element Instance where
......
165 167
-- later (via 'setIdx' for example).
166 168
create :: String -> Int -> Int -> [Int] -> Int -> T.InstanceStatus
167 169
       -> [String] -> Bool -> T.Ndx -> T.Ndx -> T.DiskTemplate -> Int
168
       -> Instance
170
       -> [Nic] -> Instance
169 171
create name_init mem_init dsk_init disks_init vcpus_init run_init tags_init
170
       auto_balance_init pn sn dt su =
172
       auto_balance_init pn sn dt su nics_init =
171 173
  Instance { name = name_init
172 174
           , alias = name_init
173 175
           , mem = mem_init
......
186 188
           , allTags = tags_init
187 189
           , exclTags = []
188 190
           , arPolicy = T.ArNotEnabled
191
           , nics = nics_init
189 192
           }
190 193

  
191 194
-- | Changes the index.
b/src/Ganeti/HTools/Nic.hs
1
{-| Module describing an NIC.
2

  
3
The NIC data type only holds data about a NIC, but does not provide any
4
logic.
5

  
6
-}
7

  
8
{-
9

  
10
Copyright (C) 2009, 2010, 2011, 2012, 2013 Google Inc.
11

  
12
This program is free software; you can redistribute it and/or modify
13
it under the terms of the GNU General Public License as published by
14
the Free Software Foundation; either version 2 of the License, or
15
(at your option) any later version.
16

  
17
This program is distributed in the hope that it will be useful, but
18
WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
General Public License for more details.
21

  
22
You should have received a copy of the GNU General Public License
23
along with this program; if not, write to the Free Software
24
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
02110-1301, USA.
26

  
27
-}
28

  
29
module Ganeti.HTools.Nic
30
  ( Nic(..)
31
  , Mode(..)
32
  , List
33
  , create
34
  ) where
35

  
36
import qualified Ganeti.HTools.Container as Container
37

  
38
import qualified Ganeti.HTools.Types as T
39

  
40
-- * Type declarations
41

  
42
data Mode = Bridged | Routed | OpenVSwitch deriving (Show, Eq)
43

  
44
-- | The NIC type.
45
--
46
-- It holds the data for a NIC as it is provided via the IAllocator protocol
47
-- for an instance creation request. All data in those request is optional,
48
-- that's why all fields are Maybe's.
49
--
50
-- TODO: Another name might be more appropriate for this type, as for example
51
-- RequestedNic. But this type is used as a field in the Instance type, which
52
-- is not named RequestedInstance, so such a name would be weird. PartialNic
53
-- already exists in Objects, but doesn't fit the bill here, as it contains
54
-- a required field (mac). Objects and the types therein are subject to being
55
-- reworked, so until then this type is left as is.
56
data Nic = Nic
57
  { mac          :: Maybe String -- ^ MAC address of the NIC
58
  , ip           :: Maybe String -- ^ IP address of the NIC
59
  , mode         :: Maybe Mode   -- ^ the mode the NIC operates in
60
  , link         :: Maybe String -- ^ the link of the NIC
61
  , bridge       :: Maybe String -- ^ the bridge this NIC is connected to if
62
                                 --   the mode is Bridged
63
  , network      :: Maybe T.NetworkID -- ^ network UUID if this NIC is connected
64
                                 --   to a network
65
  } deriving (Show, Eq)
66

  
67
-- | A simple name for an instance map.
68
type List = Container.Container Nic
69

  
70
-- * Initialization
71

  
72
-- | Create a NIC.
73
--
74
create :: Maybe String
75
       -> Maybe String
76
       -> Maybe Mode
77
       -> Maybe String
78
       -> Maybe String
79
       -> Maybe T.NetworkID
80
       -> Nic
81
create mac_init ip_init mode_init link_init bridge_init network_init =
82
  Nic { mac = mac_init
83
      , ip = ip_init
84
      , mode = mode_init
85
      , link = link_init
86
      , bridge = bridge_init
87
      , network = network_init
88
      }
b/src/Ganeti/HTools/Program/Hspace.hs
394 394
-- of the disk space to individual disks), sensible defaults are guessed (e.g.,
395 395
-- having a single disk).
396 396
instFromSpec :: RSpec -> DiskTemplate -> Int -> Instance.Instance
397
instFromSpec spx =
397
instFromSpec spx dt su =
398 398
  Instance.create "new" (rspecMem spx) (rspecDsk spx) [rspecDsk spx]
399
    (rspecCpu spx) Running [] True (-1) (-1)
399
    (rspecCpu spx) Running [] True (-1) (-1) dt su []
400 400

  
401 401
combineTiered :: Maybe Int -> Cluster.AllocNodes -> Cluster.AllocResult ->
402 402
           Instance.Instance -> Result Cluster.AllocResult
b/test/data/htools/hail-alloc-invalid-twodisks.json
85 85
    "spindle_use": 2,
86 86
    "tags": [],
87 87
    "type": "allocate",
88
    "vcpus": 1
88
    "vcpus": 1,
89
    "nics": []
89 90
  },
90 91
  "version": 2
91 92
}
b/test/data/htools/hail-alloc-twodisks.json
85 85
    "spindle_use": 2,
86 86
    "tags": [],
87 87
    "type": "allocate",
88
    "vcpus": 1
88
    "vcpus": 1,
89
    "nics": []
89 90
  },
90 91
  "version": 2
91 92
}
b/test/hs/Test/Ganeti/HTools/Instance.hs
62 62
  sn <- arbitrary
63 63
  vcpus <- choose (0, lim_cpu)
64 64
  dt <- arbitrary
65
  return $ Instance.create name mem dsk [dsk] vcpus run_st [] True pn sn dt 1
65
  return $ Instance.create name mem dsk [dsk] vcpus run_st [] True pn sn dt 1 []
66 66

  
67 67
-- | Generates an instance smaller than a node.
68 68
genInstanceSmallerThanNode :: Node.Node -> Gen Instance.Instance
b/test/hs/Test/Ganeti/TestHTools.hs
100 100
createInstance :: Int -> Int -> Int -> Instance.Instance
101 101
createInstance mem dsk vcpus =
102 102
  Instance.create "inst-unnamed" mem dsk [dsk] vcpus Types.Running [] True (-1)
103
    (-1) Types.DTDrbd8 1
103
    (-1) Types.DTDrbd8 1 []
104 104

  
105 105
-- | Create a small cluster by repeating a node spec.
106 106
makeSmallCluster :: Node.Node -> Int -> Node.List

Also available in: Unified diff