41 |
41 |
, DiskIndex
|
42 |
42 |
, mkDiskIndex
|
43 |
43 |
, unDiskIndex
|
|
44 |
, DiskAccess(..)
|
44 |
45 |
, INicParams(..)
|
45 |
46 |
, IDiskParams(..)
|
46 |
47 |
, pInstanceName
|
... | ... | |
68 |
69 |
, pGroupNodeParams
|
69 |
70 |
, pQueryWhat
|
70 |
71 |
, pEarlyRelease
|
|
72 |
, pIpCheck
|
|
73 |
, pIpConflictsCheck
|
71 |
74 |
, pNoRemember
|
72 |
75 |
, pMigrationTargetNode
|
73 |
76 |
, pStartupPaused
|
... | ... | |
82 |
85 |
, pDiskState
|
83 |
86 |
, pIgnoreIpolicy
|
84 |
87 |
, pAllowRuntimeChgs
|
|
88 |
, pInstDisks
|
|
89 |
, pDiskTemplate
|
|
90 |
, pFileDriver
|
|
91 |
, pFileStorageDir
|
85 |
92 |
, pVgName
|
86 |
93 |
, pEnabledHypervisors
|
|
94 |
, pHypervisor
|
87 |
95 |
, pClusterHvParams
|
|
96 |
, pInstHvParams
|
88 |
97 |
, pClusterBeParams
|
|
98 |
, pInstBeParams
|
|
99 |
, pResetDefaults
|
89 |
100 |
, pOsHvp
|
90 |
|
, pOsParams
|
|
101 |
, pClusterOsParams
|
|
102 |
, pInstOsParams
|
91 |
103 |
, pCandidatePoolSize
|
92 |
104 |
, pUidPool
|
93 |
105 |
, pAddUids
|
... | ... | |
95 |
107 |
, pMaintainNodeHealth
|
96 |
108 |
, pPreallocWipeDisks
|
97 |
109 |
, pNicParams
|
|
110 |
, pInstNics
|
98 |
111 |
, pNdParams
|
99 |
112 |
, pIpolicy
|
100 |
113 |
, pDrbdHelper
|
... | ... | |
129 |
142 |
, pIallocator
|
130 |
143 |
, pRemoteNode
|
131 |
144 |
, pEvacMode
|
|
145 |
, pInstCreateMode
|
|
146 |
, pNoInstall
|
|
147 |
, pInstOs
|
|
148 |
, pPrimaryNode
|
|
149 |
, pSecondaryNode
|
|
150 |
, pSourceHandshake
|
|
151 |
, pSourceInstance
|
|
152 |
, pSourceShutdownTimeout
|
|
153 |
, pSourceX509Ca
|
|
154 |
, pSrcNode
|
|
155 |
, pSrcPath
|
|
156 |
, pStartInstance
|
|
157 |
, pInstTags
|
132 |
158 |
) where
|
133 |
159 |
|
134 |
160 |
import qualified Data.Set as Set
|
135 |
161 |
import Text.JSON (readJSON, showJSON, JSON, JSValue(..), fromJSString,
|
136 |
|
JSObject)
|
|
162 |
JSObject, toJSObject)
|
137 |
163 |
import Text.JSON.Pretty (pp_value)
|
138 |
164 |
|
|
165 |
import Ganeti.BasicTypes
|
139 |
166 |
import qualified Ganeti.Constants as C
|
140 |
167 |
import Ganeti.THH
|
141 |
168 |
import Ganeti.JSON
|
... | ... | |
176 |
203 |
-- | Unchecked dict, should be replaced by a better definition.
|
177 |
204 |
type UncheckedDict = JSObject JSValue
|
178 |
205 |
|
|
206 |
-- | Unchecked list, shoild be replaced by a better definition.
|
|
207 |
type UncheckedList = [JSValue]
|
|
208 |
|
|
209 |
-- | Function to force a non-negative value, without returning via a
|
|
210 |
-- monad. This is needed for, and should be used /only/ in the case of
|
|
211 |
-- forcing constants. In case the constant is wrong (< 0), this will
|
|
212 |
-- become a runtime error.
|
|
213 |
forceNonNeg :: (Num a, Ord a, Show a) => a -> NonNegative a
|
|
214 |
forceNonNeg i = case mkNonNegative i of
|
|
215 |
Ok n -> n
|
|
216 |
Bad msg -> error msg
|
|
217 |
|
179 |
218 |
-- ** Tags
|
180 |
219 |
|
181 |
220 |
-- | Data type representing what items do the tag operations apply to.
|
... | ... | |
279 |
318 |
, optionalField $ simpleField C.inicLink [t| NonEmptyString |]
|
280 |
319 |
])
|
281 |
320 |
|
282 |
|
-- | Disk modification definition.
|
|
321 |
-- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
|
283 |
322 |
$(buildObject "IDiskParams" "idisk"
|
284 |
|
[ simpleField C.idiskSize [t| Int |] -- FIXME: VTYPE_UNIT
|
285 |
|
, simpleField C.idiskMode [t| DiskAccess |]
|
286 |
|
, simpleField C.idiskAdopt [t| NonEmptyString |]
|
287 |
|
, simpleField C.idiskVg [t| NonEmptyString |]
|
288 |
|
, simpleField C.idiskMetavg [t| NonEmptyString |]
|
|
323 |
[ optionalField $ simpleField C.idiskSize [t| Int |]
|
|
324 |
, optionalField $ simpleField C.idiskMode [t| DiskAccess |]
|
|
325 |
, optionalField $ simpleField C.idiskAdopt [t| NonEmptyString |]
|
|
326 |
, optionalField $ simpleField C.idiskVg [t| NonEmptyString |]
|
|
327 |
, optionalField $ simpleField C.idiskMetavg [t| NonEmptyString |]
|
289 |
328 |
])
|
290 |
329 |
|
291 |
330 |
-- * Parameters
|
... | ... | |
400 |
439 |
pEarlyRelease :: Field
|
401 |
440 |
pEarlyRelease = defaultFalse "early_release"
|
402 |
441 |
|
403 |
|
-- _PIpCheckDoc = "Whether to ensure instance's IP address is inactive"
|
|
442 |
-- | Whether to ensure instance's IP address is inactive.
|
|
443 |
pIpCheck :: Field
|
|
444 |
pIpCheck = defaultTrue "ip_check"
|
|
445 |
|
|
446 |
-- | Check for conflicting IPs.
|
|
447 |
pIpConflictsCheck :: Field
|
|
448 |
pIpConflictsCheck = defaultTrue "conflicts_check"
|
404 |
449 |
|
405 |
450 |
-- | Do not remember instance state changes.
|
406 |
451 |
pNoRemember :: Field
|
... | ... | |
475 |
520 |
|
476 |
521 |
-- Utility type for NIC definitions.
|
477 |
522 |
--type TestNicDef = INicParams
|
478 |
|
--type TDiskParams = IDiskParams
|
|
523 |
|
|
524 |
-- | List of instance disks.
|
|
525 |
pInstDisks :: Field
|
|
526 |
pInstDisks = renameField "instDisks" $ simpleField "disks" [t| [IDiskParams] |]
|
|
527 |
|
|
528 |
-- | Instance disk template.
|
|
529 |
pDiskTemplate :: Field
|
|
530 |
pDiskTemplate = simpleField "disk_template" [t| DiskTemplate |]
|
|
531 |
|
|
532 |
-- | File driver.
|
|
533 |
pFileDriver :: Field
|
|
534 |
pFileDriver = optionalField $ simpleField "file_driver" [t| FileDriver |]
|
|
535 |
|
|
536 |
-- | Directory for storing file-backed disks.
|
|
537 |
pFileStorageDir :: Field
|
|
538 |
pFileStorageDir = optionalNEStringField "file_storage_dir"
|
479 |
539 |
|
480 |
540 |
-- | Volume group name.
|
481 |
541 |
pVgName :: Field
|
... | ... | |
487 |
547 |
optionalField $
|
488 |
548 |
simpleField "enabled_hypervisors" [t| NonEmpty Hypervisor |]
|
489 |
549 |
|
|
550 |
-- | Selected hypervisor for an instance.
|
|
551 |
pHypervisor :: Field
|
|
552 |
pHypervisor =
|
|
553 |
optionalField $
|
|
554 |
simpleField "hypervisor" [t| Hypervisor |]
|
|
555 |
|
490 |
556 |
-- | Cluster-wide hypervisor parameters, hypervisor-dependent.
|
491 |
557 |
pClusterHvParams :: Field
|
492 |
558 |
pClusterHvParams =
|
|
559 |
renameField "ClusterHvParams" .
|
493 |
560 |
optionalField $
|
494 |
561 |
simpleField "hvparams" [t| Container UncheckedDict |]
|
495 |
562 |
|
|
563 |
-- | Instance hypervisor parameters.
|
|
564 |
pInstHvParams :: Field
|
|
565 |
pInstHvParams =
|
|
566 |
renameField "InstHvParams" .
|
|
567 |
defaultField [| toJSObject [] |] $
|
|
568 |
simpleField "hvparams" [t| UncheckedDict |]
|
|
569 |
|
496 |
570 |
-- | Cluster-wide beparams.
|
497 |
571 |
pClusterBeParams :: Field
|
498 |
|
pClusterBeParams = optionalField $ simpleField "beparams" [t| UncheckedDict |]
|
|
572 |
pClusterBeParams =
|
|
573 |
renameField "ClusterBeParams" .
|
|
574 |
optionalField $ simpleField "beparams" [t| UncheckedDict |]
|
|
575 |
|
|
576 |
-- | Instance beparams.
|
|
577 |
pInstBeParams :: Field
|
|
578 |
pInstBeParams =
|
|
579 |
renameField "InstBeParams" .
|
|
580 |
defaultField [| toJSObject [] |] $
|
|
581 |
simpleField "beparams" [t| UncheckedDict |]
|
|
582 |
|
|
583 |
-- | Reset instance parameters to default if equal.
|
|
584 |
pResetDefaults :: Field
|
|
585 |
pResetDefaults = defaultFalse "identify_defaults"
|
499 |
586 |
|
500 |
587 |
-- | Cluster-wide per-OS hypervisor parameter defaults.
|
501 |
588 |
pOsHvp :: Field
|
502 |
589 |
pOsHvp = optionalField $ simpleField "os_hvp" [t| Container UncheckedDict |]
|
503 |
590 |
|
504 |
591 |
-- | Cluster-wide OS parameter defaults.
|
505 |
|
pOsParams :: Field
|
506 |
|
pOsParams =
|
|
592 |
pClusterOsParams :: Field
|
|
593 |
pClusterOsParams =
|
|
594 |
renameField "clusterOsParams" .
|
507 |
595 |
optionalField $ simpleField "osparams" [t| Container UncheckedDict |]
|
508 |
596 |
|
|
597 |
-- | Instance OS parameters.
|
|
598 |
pInstOsParams :: Field
|
|
599 |
pInstOsParams =
|
|
600 |
renameField "instOsParams" . defaultField [| toJSObject [] |] $
|
|
601 |
simpleField "osparams" [t| UncheckedDict |]
|
|
602 |
|
509 |
603 |
-- | Candidate pool size.
|
510 |
604 |
pCandidatePoolSize :: Field
|
511 |
605 |
pCandidatePoolSize =
|
... | ... | |
538 |
632 |
pNicParams :: Field
|
539 |
633 |
pNicParams = optionalField $ simpleField "nicparams" [t| INicParams |]
|
540 |
634 |
|
|
635 |
-- | Instance NIC definitions.
|
|
636 |
pInstNics :: Field
|
|
637 |
pInstNics = simpleField "nics" [t| [INicParams] |]
|
|
638 |
|
541 |
639 |
-- | Cluster-wide node parameter defaults.
|
542 |
640 |
pNdParams :: Field
|
543 |
641 |
pNdParams = optionalField $ simpleField "ndparams" [t| UncheckedDict |]
|
... | ... | |
685 |
783 |
-- | Node evacuation mode.
|
686 |
784 |
pEvacMode :: Field
|
687 |
785 |
pEvacMode = renameField "EvacMode" $ simpleField "mode" [t| NodeEvacMode |]
|
|
786 |
|
|
787 |
-- | Instance creation mode.
|
|
788 |
pInstCreateMode :: Field
|
|
789 |
pInstCreateMode =
|
|
790 |
renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]
|
|
791 |
|
|
792 |
-- | Do not install the OS (will disable automatic start).
|
|
793 |
pNoInstall :: Field
|
|
794 |
pNoInstall = optionalField $ booleanField "no_install"
|
|
795 |
|
|
796 |
-- | OS type for instance installation.
|
|
797 |
pInstOs :: Field
|
|
798 |
pInstOs = optionalNEStringField "os_type"
|
|
799 |
|
|
800 |
-- | Primary node for an instance.
|
|
801 |
pPrimaryNode :: Field
|
|
802 |
pPrimaryNode = optionalNEStringField "pnode"
|
|
803 |
|
|
804 |
-- | Secondary node for an instance.
|
|
805 |
pSecondaryNode :: Field
|
|
806 |
pSecondaryNode = optionalNEStringField "snode"
|
|
807 |
|
|
808 |
-- | Signed handshake from source (remote import only).
|
|
809 |
pSourceHandshake :: Field
|
|
810 |
pSourceHandshake =
|
|
811 |
optionalField $ simpleField "source_handshake" [t| UncheckedList |]
|
|
812 |
|
|
813 |
-- | Source instance name (remote import only).
|
|
814 |
pSourceInstance :: Field
|
|
815 |
pSourceInstance = optionalNEStringField "source_instance_name"
|
|
816 |
|
|
817 |
-- | How long source instance was given to shut down (remote import only).
|
|
818 |
-- FIXME: non-negative int, whereas the constant is a plain int.
|
|
819 |
pSourceShutdownTimeout :: Field
|
|
820 |
pSourceShutdownTimeout =
|
|
821 |
defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
|
|
822 |
simpleField "source_shutdown_timeout" [t| NonNegative Int |]
|
|
823 |
|
|
824 |
-- | Source X509 CA in PEM format (remote import only).
|
|
825 |
pSourceX509Ca :: Field
|
|
826 |
pSourceX509Ca = optionalNEStringField "source_x509_ca"
|
|
827 |
|
|
828 |
-- | Source node for import.
|
|
829 |
pSrcNode :: Field
|
|
830 |
pSrcNode = optionalNEStringField "src_node"
|
|
831 |
|
|
832 |
-- | Source directory for import.
|
|
833 |
pSrcPath :: Field
|
|
834 |
pSrcPath = optionalNEStringField "src_path"
|
|
835 |
|
|
836 |
-- | Whether to start instance after creation.
|
|
837 |
pStartInstance :: Field
|
|
838 |
pStartInstance = defaultTrue "start"
|
|
839 |
|
|
840 |
-- | Instance tags. FIXME: unify/simplify with pTags, once that
|
|
841 |
-- migrates to NonEmpty String.
|
|
842 |
pInstTags :: Field
|
|
843 |
pInstTags =
|
|
844 |
renameField "InstTags" .
|
|
845 |
defaultField [| [] |] $
|
|
846 |
simpleField "tags" [t| [NonEmptyString] |]
|