root / src / Ganeti / HTools / Nic.hs @ 9d049fb4
History | View | Annotate | Download (2.8 kB)
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 |
} |