fd8c3d944876d45009b49268ea7c07ae934c0036
[ganeti-github.git] / src / Ganeti / Objects / Instance.hs
1 {-# LANGUAGE TemplateHaskell, FunctionalDependencies #-}
2
3 {-| Implementation of the Ganeti Instance config object.
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.Instance where
38
39 import qualified Data.ByteString.UTF8 as UTF8
40 import Data.Monoid
41
42 import Ganeti.JSON (emptyContainer)
43 import Ganeti.Objects.Nic
44 import Ganeti.THH
45 import Ganeti.THH.Field
46 import Ganeti.Types
47 import Ganeti.Utils (parseUnitAssumeBinary)
48
49 $(buildParam "Be" "bep"
50 [ specialNumericalField 'parseUnitAssumeBinary
51 $ simpleField "minmem" [t| Int |]
52 , specialNumericalField 'parseUnitAssumeBinary
53 $ simpleField "maxmem" [t| Int |]
54 , simpleField "vcpus" [t| Int |]
55 , simpleField "auto_balance" [t| Bool |]
56 , simpleField "always_failover" [t| Bool |]
57 , simpleField "spindle_use" [t| Int |]
58 ])
59
60 $(buildObjectWithForthcoming "Instance" "inst" $
61 [ simpleField "name" [t| String |]
62 , simpleField "primary_node" [t| String |]
63 , simpleField "os" [t| String |]
64 , simpleField "hypervisor" [t| Hypervisor |]
65 , defaultField [| emptyContainer |]
66 $ simpleField "hvparams" [t| HvParams |]
67 , defaultField [| mempty |]
68 $ simpleField "beparams" [t| PartialBeParams |]
69 , defaultField [| emptyContainer |]
70 $ simpleField "osparams" [t| OsParams |]
71 , defaultField [| emptyContainer |]
72 $ simpleField "osparams_private" [t| OsParamsPrivate |]
73 , simpleField "admin_state" [t| AdminState |]
74 , simpleField "admin_state_source" [t| AdminStateSource |]
75 , defaultField [| [] |]
76 $ simpleField "nics" [t| [PartialNic] |]
77 , defaultField [| [] |]
78 $ simpleField "disks" [t| [String] |]
79 , simpleField "disks_active" [t| Bool |]
80 , optionalField $ simpleField "network_port" [t| Int |]
81 ]
82 ++ timeStampFields
83 ++ uuidFields
84 ++ serialFields
85 ++ tagsFields)
86
87 instance TimeStampObject Instance where
88 cTimeOf = instCtime
89 mTimeOf = instMtime
90
91 instance UuidObject Instance where
92 uuidOf = UTF8.toString . instUuid
93
94 instance SerialNoObject Instance where
95 serialOf = instSerial
96
97 instance TagsObject Instance where
98 tagsOf = instTags
99
100 instance ForthcomingObject Instance where
101 isForthcoming = instForthcoming