Introduce --hotplug-if-possible option
[ganeti-local] / src / Ganeti / OpParams.hs
index 7e91ae4..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
@@ -237,7 +244,7 @@ module Ganeti.OpParams
   , pDependencies
   , pComment
   , pReason
-  , pEnabledStorageTypes
+  , pEnabledDiskTemplates
   , dOldQuery
   , dOldQueryNoLocking
   ) where
@@ -403,6 +410,7 @@ $(buildObject "INicParams" "inic"
   , optionalField $ simpleField C.inicIp   [t| String         |]
   , optionalField $ simpleField C.inicMode [t| NonEmptyString |]
   , optionalField $ simpleField C.inicLink [t| NonEmptyString |]
+  , optionalField $ simpleField C.inicName [t| NonEmptyString |]
   ])
 
 -- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
@@ -412,8 +420,13 @@ $(buildObject "IDiskParams" "idisk"
   , optionalField $ simpleField C.idiskAdopt  [t| NonEmptyString |]
   , optionalField $ simpleField C.idiskVg     [t| NonEmptyString |]
   , optionalField $ simpleField C.idiskMetavg [t| NonEmptyString |]
+  , 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
@@ -482,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
@@ -699,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.
@@ -730,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 |]
@@ -759,11 +807,11 @@ pEnabledHypervisors =
   optionalField $
   simpleField "enabled_hypervisors" [t| NonEmpty Hypervisor |]
 
--- | List of enabled storage methods.
-pEnabledStorageTypes :: Field
-pEnabledStorageTypes =
+-- | List of enabled disk templates.
+pEnabledDiskTemplates :: Field
+pEnabledDiskTemplates =
   optionalField $
-  simpleField "enabled_storage_types" [t| NonEmpty StorageType |]
+  simpleField "enabled_disk_templates" [t| NonEmpty DiskTemplate |]
 
 -- | Selected hypervisor for an instance.
 pHypervisor :: Field
@@ -863,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"
@@ -1443,9 +1495,9 @@ pDependencies =
 pComment :: Field
 pComment = optionalNullSerField $ stringField "comment"
 
--- | The description of the state change reason.
+-- | Reason trail field.
 pReason :: Field
-pReason = simpleField "reason" [t| (InstReasonSrc, NonEmptyString) |]
+pReason = simpleField C.opcodeReason [t| ReasonTrail |]
 
 -- * Entire opcode parameter list