Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Objects / Lens.hs @ 227c0ef3

History | View | Annotate | Download (3.1 kB)

1
{-# LANGUAGE TemplateHaskell #-}
2

    
3
{-| Lenses for Ganeti config objects
4

    
5
-}
6

    
7
{-
8

    
9
Copyright (C) 2014 Google Inc.
10

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

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

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

    
26
-}
27

    
28
module Ganeti.Objects.Lens where
29

    
30
import qualified Data.Set as Set
31
import System.Time (ClockTime(..))
32

    
33
import Ganeti.Lens (makeCustomLenses, Lens')
34
import Ganeti.Objects
35

    
36
-- | Class of objects that have timestamps.
37
class TimeStampObject a => TimeStampObjectL a where
38
  mTimeL :: Lens' a ClockTime
39

    
40
-- | Class of objects that have an UUID.
41
class UuidObject a => UuidObjectL a where
42
  uuidL :: Lens' a String
43

    
44
-- | Class of object that have a serial number.
45
class SerialNoObject a => SerialNoObjectL a where
46
  serialL :: Lens' a Int
47

    
48
-- | Class of objects that have tags.
49
class TagsObject a => TagsObjectL a where
50
  tagsL :: Lens' a (Set.Set String)
51

    
52
$(makeCustomLenses ''Network)
53

    
54
instance SerialNoObjectL Network where
55
  serialL = networkSerialL
56

    
57
instance TagsObjectL Network where
58
  tagsL = networkTagsL
59

    
60
instance UuidObjectL Network where
61
  uuidL = networkUuidL
62

    
63
instance TimeStampObjectL Network where
64
  mTimeL = networkMtimeL
65

    
66
$(makeCustomLenses ''PartialNic)
67

    
68
$(makeCustomLenses ''Disk)
69

    
70
$(makeCustomLenses ''Instance)
71

    
72
instance TimeStampObjectL Instance where
73
  mTimeL = instMtimeL
74

    
75
instance UuidObjectL Instance where
76
  uuidL = instUuidL
77

    
78
instance SerialNoObjectL Instance where
79
  serialL = instSerialL
80

    
81
instance TagsObjectL Instance where
82
  tagsL = instTagsL
83

    
84
$(makeCustomLenses ''MinMaxISpecs)
85

    
86
$(makeCustomLenses ''PartialIPolicy)
87

    
88
$(makeCustomLenses ''FilledIPolicy)
89

    
90
$(makeCustomLenses ''Node)
91

    
92
instance TimeStampObjectL Node where
93
  mTimeL = nodeMtimeL
94

    
95
instance UuidObjectL Node where
96
  uuidL = nodeUuidL
97

    
98
instance SerialNoObjectL Node where
99
  serialL = nodeSerialL
100

    
101
instance TagsObjectL Node where
102
  tagsL = nodeTagsL
103

    
104
$(makeCustomLenses ''NodeGroup)
105

    
106
instance TimeStampObjectL NodeGroup where
107
  mTimeL = groupMtimeL
108

    
109
instance UuidObjectL NodeGroup where
110
  uuidL = groupUuidL
111

    
112
instance SerialNoObjectL NodeGroup where
113
  serialL = groupSerialL
114

    
115
instance TagsObjectL NodeGroup where
116
  tagsL = groupTagsL
117

    
118
$(makeCustomLenses ''Cluster)
119

    
120
instance TimeStampObjectL Cluster where
121
  mTimeL = clusterMtimeL
122

    
123
instance UuidObjectL Cluster where
124
  uuidL = clusterUuidL
125

    
126
instance SerialNoObjectL Cluster where
127
  serialL = clusterSerialL
128

    
129
instance TagsObjectL Cluster where
130
  tagsL = clusterTagsL
131

    
132
$(makeCustomLenses ''ConfigData)
133

    
134
instance SerialNoObjectL ConfigData where
135
  serialL = configSerialL
136

    
137
instance TimeStampObjectL ConfigData where
138
  mTimeL = configMtimeL