Introduce --hotplug-if-possible option
[ganeti-local] / src / Ganeti / OpParams.hs
index e445aa9..80b7746 100644 (file)
@@ -45,9 +45,11 @@ module Ganeti.OpParams
   , DiskAccess(..)
   , INicParams(..)
   , IDiskParams(..)
+  , ISnapParams(..)
   , RecreateDisksInfo(..)
   , DdmOldChanges(..)
   , SetParamsMods(..)
+  , SetSnapParams(..)
   , ExportTarget(..)
   , pInstanceName
   , pInstances
@@ -94,8 +96,12 @@ module Ganeti.OpParams
   , pHvState
   , pDiskState
   , pIgnoreIpolicy
+  , pHotplug
+  , pHotplugIfPossible
+  , pKeepDisks
   , pAllowRuntimeChgs
   , pInstDisks
+  , pInstSnaps
   , pDiskTemplate
   , pOptDiskTemplate
   , pFileDriver
@@ -116,6 +122,7 @@ module Ganeti.OpParams
   , pAddUids
   , pRemoveUids
   , pMaintainNodeHealth
+  , pModifyEtcHosts
   , pPreallocWipeDisks
   , pNicParams
   , pInstNics
@@ -416,6 +423,10 @@ $(buildObject "IDiskParams" "idisk"
   , optionalField $ simpleField C.idiskName   [t| NonEmptyString |]
   ])
 
+-- | Disk snapshot definition.
+$(buildObject "ISnapParams" "idisk"
+  [ simpleField C.idiskSnapshotName [t| NonEmptyString |]])
+
 -- | Disk changes type for OpInstanceRecreateDisks. This is a bit
 -- strange, because the type in Python is something like Either
 -- [DiskIndex] [DiskChanges], but we can't represent the type of an
@@ -484,6 +495,24 @@ instance (JSON a) => JSON (SetParamsMods a) where
   showJSON (SetParamsNew v) = showJSON v
   readJSON = readSetParams
 
+-- | Instance snapshot params
+data SetSnapParams a
+  = SetSnapParamsEmpty
+  | SetSnapParamsValid (NonEmpty (Int, a))
+    deriving (Eq, Show)
+
+readSetSnapParams :: (JSON a) => JSValue -> Text.JSON.Result (SetSnapParams a)
+readSetSnapParams (JSArray []) = return SetSnapParamsEmpty
+readSetSnapParams v =
+  case readJSON v::Text.JSON.Result [(Int, JSValue)] of
+    Text.JSON.Ok _ -> liftM SetSnapParamsValid $ readJSON v
+    _ -> fail "Cannot parse snapshot params."
+
+instance (JSON a) => JSON (SetSnapParams a) where
+  showJSON SetSnapParamsEmpty = showJSON ()
+  showJSON (SetSnapParamsValid v) = showJSON v
+  readJSON = readSetSnapParams
+
 -- | Custom type for target_node parameter of OpBackupExport, which
 -- varies depending on mode. FIXME: this uses an UncheckedList since
 -- we don't care about individual rows (just like the Python code
@@ -701,6 +730,17 @@ pDiskParams = optionalField $
               simpleField "diskparams" [t| GenericContainer DiskTemplate
                                            UncheckedDict |]
 
+-- | Whether to hotplug device.
+pHotplug :: Field
+pHotplug = defaultFalse "hotplug"
+
+pHotplugIfPossible :: Field
+pHotplugIfPossible = defaultFalse "hotplug_if_possible"
+
+-- | Whether to remove disks.
+pKeepDisks :: Field
+pKeepDisks = defaultFalse "keep_disks"
+
 -- * Parameters for node resource model
 
 -- | Set hypervisor states.
@@ -732,6 +772,12 @@ type TestClusterOsList = [TestClusterOsListItem]
 pInstDisks :: Field
 pInstDisks = renameField "instDisks" $ simpleField "disks" [t| [IDiskParams] |]
 
+-- | List of instance snaps.
+pInstSnaps :: Field
+pInstSnaps =
+  renameField "instSnaps" $
+  simpleField "disks" [t| SetSnapParams ISnapParams |]
+
 -- | Instance disk template.
 pDiskTemplate :: Field
 pDiskTemplate = simpleField "disk_template" [t| DiskTemplate |]
@@ -865,6 +911,10 @@ pRemoveUids = optionalField $ simpleField "remove_uids" [t| [[(Int, Int)]] |]
 pMaintainNodeHealth :: Field
 pMaintainNodeHealth = optionalField $ booleanField "maintain_node_health"
 
+-- | Whether to modify and keep in sync the @/etc/hosts@ files of nodes.
+pModifyEtcHosts :: Field
+pModifyEtcHosts = optionalField $ booleanField "modify_etc_hosts"
+
 -- | Whether to wipe disks before allocating them to instances.
 pPreallocWipeDisks :: Field
 pPreallocWipeDisks = optionalField $ booleanField "prealloc_wipe_disks"