e312983fb06250d43ea231df37a4048aed4dcd4a
[ganeti-github.git] / src / Ganeti / Objects / Instance.hs
1 {-# LANGUAGE TemplateHaskell, FunctionalDependencies #-}
2 {-# OPTIONS_GHC -O0 #-}
3
4 {-| Implementation of the Ganeti Instance config object.
5
6 -}
7
8 {-
9
10 Copyright (C) 2014 Google Inc.
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are
15 met:
16
17 1. Redistributions of source code must retain the above copyright notice,
18 this list of conditions and the following disclaimer.
19
20 2. Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in the
22 documentation and/or other materials provided with the distribution.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
28 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36 -}
37
38 module Ganeti.Objects.Instance where
39
40 import qualified Data.ByteString.UTF8 as UTF8
41 import Data.Monoid
42
43 import Ganeti.JSON (emptyContainer)
44 import Ganeti.Objects.Nic
45 import Ganeti.THH
46 import Ganeti.THH.Field
47 import Ganeti.Types
48 import Ganeti.Utils (parseUnitAssumeBinary)
49
50 $(buildParam "Be" "bep"
51 [ specialNumericalField 'parseUnitAssumeBinary
52 $ simpleField "minmem" [t| Int |]
53 , specialNumericalField 'parseUnitAssumeBinary
54 $ simpleField "maxmem" [t| Int |]
55 , simpleField "vcpus" [t| Int |]
56 , simpleField "auto_balance" [t| Bool |]
57 , simpleField "always_failover" [t| Bool |]
58 , simpleField "spindle_use" [t| Int |]
59 ])
60
61 $(buildObjectWithForthcoming "Instance" "inst" $
62 [ simpleField "name" [t| String |]
63 , simpleField "primary_node" [t| String |]
64 , simpleField "os" [t| String |]
65 , simpleField "hypervisor" [t| Hypervisor |]
66 , defaultField [| emptyContainer |]
67 $ simpleField "hvparams" [t| HvParams |]
68 , defaultField [| mempty |]
69 $ simpleField "beparams" [t| PartialBeParams |]
70 , defaultField [| emptyContainer |]
71 $ simpleField "osparams" [t| OsParams |]
72 , defaultField [| emptyContainer |]
73 $ simpleField "osparams_private" [t| OsParamsPrivate |]
74 , simpleField "admin_state" [t| AdminState |]
75 , simpleField "admin_state_source" [t| AdminStateSource |]
76 , defaultField [| [] |]
77 $ simpleField "nics" [t| [PartialNic] |]
78 , defaultField [| [] |]
79 $ simpleField "disks" [t| [String] |]
80 , simpleField "disks_active" [t| Bool |]
81 , optionalField $ simpleField "network_port" [t| Int |]
82 ]
83 ++ timeStampFields
84 ++ uuidFields
85 ++ serialFields
86 ++ tagsFields)
87
88 instance TimeStampObject Instance where
89 cTimeOf = instCtime
90 mTimeOf = instMtime
91
92 instance UuidObject Instance where
93 uuidOf = UTF8.toString . instUuid
94
95 instance SerialNoObject Instance where
96 serialOf = instSerial
97
98 instance TagsObject Instance where
99 tagsOf = instTags
100
101 instance ForthcomingObject Instance where
102 isForthcoming = instForthcoming