Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / HTools / Nic.hs @ 9d049fb4

History | View | Annotate | Download (2.8 kB)

1 908c2f67 Thomas Thrainer
{-| Module describing an NIC.
2 908c2f67 Thomas Thrainer
3 908c2f67 Thomas Thrainer
The NIC data type only holds data about a NIC, but does not provide any
4 908c2f67 Thomas Thrainer
logic.
5 908c2f67 Thomas Thrainer
6 908c2f67 Thomas Thrainer
-}
7 908c2f67 Thomas Thrainer
8 908c2f67 Thomas Thrainer
{-
9 908c2f67 Thomas Thrainer
10 908c2f67 Thomas Thrainer
Copyright (C) 2009, 2010, 2011, 2012, 2013 Google Inc.
11 908c2f67 Thomas Thrainer
12 908c2f67 Thomas Thrainer
This program is free software; you can redistribute it and/or modify
13 908c2f67 Thomas Thrainer
it under the terms of the GNU General Public License as published by
14 908c2f67 Thomas Thrainer
the Free Software Foundation; either version 2 of the License, or
15 908c2f67 Thomas Thrainer
(at your option) any later version.
16 908c2f67 Thomas Thrainer
17 908c2f67 Thomas Thrainer
This program is distributed in the hope that it will be useful, but
18 908c2f67 Thomas Thrainer
WITHOUT ANY WARRANTY; without even the implied warranty of
19 908c2f67 Thomas Thrainer
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 908c2f67 Thomas Thrainer
General Public License for more details.
21 908c2f67 Thomas Thrainer
22 908c2f67 Thomas Thrainer
You should have received a copy of the GNU General Public License
23 908c2f67 Thomas Thrainer
along with this program; if not, write to the Free Software
24 908c2f67 Thomas Thrainer
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 908c2f67 Thomas Thrainer
02110-1301, USA.
26 908c2f67 Thomas Thrainer
27 908c2f67 Thomas Thrainer
-}
28 908c2f67 Thomas Thrainer
29 908c2f67 Thomas Thrainer
module Ganeti.HTools.Nic
30 908c2f67 Thomas Thrainer
  ( Nic(..)
31 908c2f67 Thomas Thrainer
  , Mode(..)
32 908c2f67 Thomas Thrainer
  , List
33 908c2f67 Thomas Thrainer
  , create
34 908c2f67 Thomas Thrainer
  ) where
35 908c2f67 Thomas Thrainer
36 908c2f67 Thomas Thrainer
import qualified Ganeti.HTools.Container as Container
37 908c2f67 Thomas Thrainer
38 908c2f67 Thomas Thrainer
import qualified Ganeti.HTools.Types as T
39 908c2f67 Thomas Thrainer
40 908c2f67 Thomas Thrainer
-- * Type declarations
41 908c2f67 Thomas Thrainer
42 908c2f67 Thomas Thrainer
data Mode = Bridged | Routed | OpenVSwitch deriving (Show, Eq)
43 908c2f67 Thomas Thrainer
44 908c2f67 Thomas Thrainer
-- | The NIC type.
45 908c2f67 Thomas Thrainer
--
46 908c2f67 Thomas Thrainer
-- It holds the data for a NIC as it is provided via the IAllocator protocol
47 908c2f67 Thomas Thrainer
-- for an instance creation request. All data in those request is optional,
48 908c2f67 Thomas Thrainer
-- that's why all fields are Maybe's.
49 908c2f67 Thomas Thrainer
--
50 908c2f67 Thomas Thrainer
-- TODO: Another name might be more appropriate for this type, as for example
51 908c2f67 Thomas Thrainer
-- RequestedNic. But this type is used as a field in the Instance type, which
52 908c2f67 Thomas Thrainer
-- is not named RequestedInstance, so such a name would be weird. PartialNic
53 908c2f67 Thomas Thrainer
-- already exists in Objects, but doesn't fit the bill here, as it contains
54 908c2f67 Thomas Thrainer
-- a required field (mac). Objects and the types therein are subject to being
55 908c2f67 Thomas Thrainer
-- reworked, so until then this type is left as is.
56 908c2f67 Thomas Thrainer
data Nic = Nic
57 908c2f67 Thomas Thrainer
  { mac          :: Maybe String -- ^ MAC address of the NIC
58 908c2f67 Thomas Thrainer
  , ip           :: Maybe String -- ^ IP address of the NIC
59 908c2f67 Thomas Thrainer
  , mode         :: Maybe Mode   -- ^ the mode the NIC operates in
60 908c2f67 Thomas Thrainer
  , link         :: Maybe String -- ^ the link of the NIC
61 908c2f67 Thomas Thrainer
  , bridge       :: Maybe String -- ^ the bridge this NIC is connected to if
62 908c2f67 Thomas Thrainer
                                 --   the mode is Bridged
63 908c2f67 Thomas Thrainer
  , network      :: Maybe T.NetworkID -- ^ network UUID if this NIC is connected
64 908c2f67 Thomas Thrainer
                                 --   to a network
65 908c2f67 Thomas Thrainer
  } deriving (Show, Eq)
66 908c2f67 Thomas Thrainer
67 908c2f67 Thomas Thrainer
-- | A simple name for an instance map.
68 908c2f67 Thomas Thrainer
type List = Container.Container Nic
69 908c2f67 Thomas Thrainer
70 908c2f67 Thomas Thrainer
-- * Initialization
71 908c2f67 Thomas Thrainer
72 908c2f67 Thomas Thrainer
-- | Create a NIC.
73 908c2f67 Thomas Thrainer
--
74 908c2f67 Thomas Thrainer
create :: Maybe String
75 908c2f67 Thomas Thrainer
       -> Maybe String
76 908c2f67 Thomas Thrainer
       -> Maybe Mode
77 908c2f67 Thomas Thrainer
       -> Maybe String
78 908c2f67 Thomas Thrainer
       -> Maybe String
79 908c2f67 Thomas Thrainer
       -> Maybe T.NetworkID
80 908c2f67 Thomas Thrainer
       -> Nic
81 908c2f67 Thomas Thrainer
create mac_init ip_init mode_init link_init bridge_init network_init =
82 908c2f67 Thomas Thrainer
  Nic { mac = mac_init
83 908c2f67 Thomas Thrainer
      , ip = ip_init
84 908c2f67 Thomas Thrainer
      , mode = mode_init
85 908c2f67 Thomas Thrainer
      , link = link_init
86 908c2f67 Thomas Thrainer
      , bridge = bridge_init
87 908c2f67 Thomas Thrainer
      , network = network_init
88 908c2f67 Thomas Thrainer
      }