b1b170d97875e91e788d4a9ebd34ad85363d9484
[ganeti-github.git] / src / Ganeti / Objects / Lens.hs
1 {-# LANGUAGE TemplateHaskell #-}
2
3 {-| Lenses for Ganeti config objects
4
5 -}
6
7 {-
8
9 Copyright (C) 2014 Google Inc.
10 All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are
14 met:
15
16 1. Redistributions of source code must retain the above copyright notice,
17 this list of conditions and the following disclaimer.
18
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35 -}
36
37 module Ganeti.Objects.Lens where
38
39 import qualified Data.Set as Set
40 import System.Time (ClockTime(..))
41
42 import Ganeti.Lens (makeCustomLenses, Lens')
43 import Ganeti.Objects
44
45 -- | Class of objects that have timestamps.
46 class TimeStampObject a => TimeStampObjectL a where
47 mTimeL :: Lens' a ClockTime
48
49 -- | Class of objects that have an UUID.
50 class UuidObject a => UuidObjectL a where
51 uuidL :: Lens' a String
52
53 -- | Class of object that have a serial number.
54 class SerialNoObject a => SerialNoObjectL a where
55 serialL :: Lens' a Int
56
57 -- | Class of objects that have tags.
58 class TagsObject a => TagsObjectL a where
59 tagsL :: Lens' a (Set.Set String)
60
61 $(makeCustomLenses ''AddressPool)
62
63 $(makeCustomLenses ''Network)
64
65 instance SerialNoObjectL Network where
66 serialL = networkSerialL
67
68 instance TagsObjectL Network where
69 tagsL = networkTagsL
70
71 instance UuidObjectL Network where
72 uuidL = networkUuidL
73
74 instance TimeStampObjectL Network where
75 mTimeL = networkMtimeL
76
77 $(makeCustomLenses ''PartialNic)
78
79 $(makeCustomLenses ''Disk)
80
81 $(makeCustomLenses ''Instance)
82
83 instance TimeStampObjectL Instance where
84 mTimeL = instMtimeL
85
86 instance UuidObjectL Instance where
87 uuidL = instUuidL
88
89 instance SerialNoObjectL Instance where
90 serialL = instSerialL
91
92 instance TagsObjectL Instance where
93 tagsL = instTagsL
94
95 $(makeCustomLenses ''MinMaxISpecs)
96
97 $(makeCustomLenses ''PartialIPolicy)
98
99 $(makeCustomLenses ''FilledIPolicy)
100
101 $(makeCustomLenses ''Node)
102
103 instance TimeStampObjectL Node where
104 mTimeL = nodeMtimeL
105
106 instance UuidObjectL Node where
107 uuidL = nodeUuidL
108
109 instance SerialNoObjectL Node where
110 serialL = nodeSerialL
111
112 instance TagsObjectL Node where
113 tagsL = nodeTagsL
114
115 $(makeCustomLenses ''NodeGroup)
116
117 instance TimeStampObjectL NodeGroup where
118 mTimeL = groupMtimeL
119
120 instance UuidObjectL NodeGroup where
121 uuidL = groupUuidL
122
123 instance SerialNoObjectL NodeGroup where
124 serialL = groupSerialL
125
126 instance TagsObjectL NodeGroup where
127 tagsL = groupTagsL
128
129 $(makeCustomLenses ''Cluster)
130
131 instance TimeStampObjectL Cluster where
132 mTimeL = clusterMtimeL
133
134 instance UuidObjectL Cluster where
135 uuidL = clusterUuidL
136
137 instance SerialNoObjectL Cluster where
138 serialL = clusterSerialL
139
140 instance TagsObjectL Cluster where
141 tagsL = clusterTagsL
142
143 $(makeCustomLenses ''ConfigData)
144
145 instance SerialNoObjectL ConfigData where
146 serialL = configSerialL
147
148 instance TimeStampObjectL ConfigData where
149 mTimeL = configMtimeL