OpCodes.hs 27.1 KB
Newer Older
Jose A. Lopes's avatar
Jose A. Lopes committed
1 2
{-# LANGUAGE ExistentialQuantification, TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
3

4 5 6 7 8 9
{-| Implementation of the opcodes.

-}

{-

10
Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Google Inc.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.

-}

module Ganeti.OpCodes
Jose A. Lopes's avatar
Jose A. Lopes committed
30 31
  ( pyClasses
  , OpCode(..)
32
  , ReplaceDisksMode(..)
33 34 35
  , DiskIndex
  , mkDiskIndex
  , unDiskIndex
36
  , opID
37
  , allOpIDs
38
  , allOpFields
Iustin Pop's avatar
Iustin Pop committed
39
  , opSummary
40 41 42
  , CommonOpParams(..)
  , defOpParams
  , MetaOpCode(..)
43
  , resolveDependencies
44 45
  , wrapOpCode
  , setOpComment
46
  , setOpPriority
47
  ) where
48

Jose A. Lopes's avatar
Jose A. Lopes committed
49
import Text.JSON (readJSON, JSObject, JSON, JSValue(..), makeObj, fromJSObject)
50
import qualified Text.JSON
51

52
import Ganeti.THH
53

Jose A. Lopes's avatar
Jose A. Lopes committed
54
import qualified Ganeti.Hs2Py.OpDoc as OpDoc
55
import Ganeti.OpParams
56
import Ganeti.PyValue ()
Jose A. Lopes's avatar
Jose A. Lopes committed
57
import Ganeti.Types
Iustin Pop's avatar
Iustin Pop committed
58
import Ganeti.Query.Language (queryTypeOpToRaw)
59

Jose A. Lopes's avatar
Jose A. Lopes committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
import Data.List (intercalate)
import Data.Map (Map)

import qualified Ganeti.Constants as C

instance PyValue DiskIndex where
  showValue = showValue . unDiskIndex

instance PyValue IDiskParams where
  showValue _ = error "OpCodes.showValue(IDiskParams): unhandled case"

instance PyValue RecreateDisksInfo where
  showValue RecreateDisksAll = "[]"
  showValue (RecreateDisksIndices is) = showValue is
  showValue (RecreateDisksParams is) = showValue is

instance PyValue a => PyValue (SetParamsMods a) where
  showValue SetParamsEmpty = "[]"
  showValue _ = error "OpCodes.showValue(SetParamsMods): unhandled case"

instance PyValue a => PyValue (NonNegative a) where
  showValue = showValue . fromNonNegative
Thomas Thrainer's avatar
Thomas Thrainer committed
82

Jose A. Lopes's avatar
Jose A. Lopes committed
83 84
instance PyValue a => PyValue (NonEmpty a) where
  showValue = showValue . fromNonEmpty
Thomas Thrainer's avatar
Thomas Thrainer committed
85

Jose A. Lopes's avatar
Jose A. Lopes committed
86 87 88 89 90
-- FIXME: should use the 'toRaw' function instead of being harcoded or
-- perhaps use something similar to the NonNegative type instead of
-- using the declareSADT
instance PyValue ExportMode where
  showValue ExportModeLocal = show C.exportModeLocal
91
  showValue ExportModeRemote = show C.exportModeLocal
Jose A. Lopes's avatar
Jose A. Lopes committed
92 93 94

instance PyValue CVErrorCode where
  showValue = cVErrorCodeToRaw
Jose A. Lopes's avatar
Jose A. Lopes committed
95

Jose A. Lopes's avatar
Jose A. Lopes committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
instance PyValue VerifyOptionalChecks where
  showValue = verifyOptionalChecksToRaw

instance PyValue INicParams where
  showValue = error "instance PyValue INicParams: not implemented"

instance PyValue a => PyValue (JSObject a) where
  showValue obj =
    "{" ++ intercalate ", " (map showPair (fromJSObject obj)) ++ "}"
    where showPair (k, v) = show k ++ ":" ++ showValue v

instance PyValue JSValue where
  showValue (JSObject obj) = showValue obj
  showValue x = show x

111
type JobIdListOnly = Map String [(Bool, Either String JobId)]
Jose A. Lopes's avatar
Jose A. Lopes committed
112 113 114 115 116 117 118 119 120 121 122 123

type InstanceMultiAllocResponse =
  ([(Bool, Either String JobId)], NonEmptyString)

type QueryFieldDef =
  (NonEmptyString, NonEmptyString, TagKind, NonEmptyString)

type QueryResponse =
  ([QueryFieldDef], [[(QueryResultCode, JSValue)]])

type QueryFieldsResponse = [QueryFieldDef]

124 125
-- | OpCode representation.
--
126 127
-- We only implement a subset of Ganeti opcodes: those which are actually used
-- in the htools codebase.
128
$(genOpCode "OpCode"
Jose A. Lopes's avatar
Jose A. Lopes committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
  [ ("OpClusterPostInit",
     [t| Bool |],
     OpDoc.opClusterPostInit,
     [],
     [])
  , ("OpClusterDestroy",
     [t| NonEmptyString |],
     OpDoc.opClusterDestroy,
     [],
     [])
  , ("OpClusterQuery",
     [t| JSObject JSValue |],
     OpDoc.opClusterQuery,
     [],
     [])
144
  , ("OpClusterVerify",
Jose A. Lopes's avatar
Jose A. Lopes committed
145 146
     [t| JobIdListOnly |],
     OpDoc.opClusterVerify,
147 148 149 150 151 152
     [ pDebugSimulateErrors
     , pErrorCodes
     , pSkipChecks
     , pIgnoreErrors
     , pVerbose
     , pOptGroupName
Jose A. Lopes's avatar
Jose A. Lopes committed
153 154
     ],
     [])
155
  , ("OpClusterVerifyConfig",
Jose A. Lopes's avatar
Jose A. Lopes committed
156 157
     [t| Bool |],
     OpDoc.opClusterVerifyConfig,
158 159 160 161
     [ pDebugSimulateErrors
     , pErrorCodes
     , pIgnoreErrors
     , pVerbose
Jose A. Lopes's avatar
Jose A. Lopes committed
162 163
     ],
     [])
164
  , ("OpClusterVerifyGroup",
Jose A. Lopes's avatar
Jose A. Lopes committed
165 166
     [t| Bool |],
     OpDoc.opClusterVerifyGroup,
167 168 169 170 171 172
     [ pGroupName
     , pDebugSimulateErrors
     , pErrorCodes
     , pSkipChecks
     , pIgnoreErrors
     , pVerbose
Jose A. Lopes's avatar
Jose A. Lopes committed
173 174 175 176 177 178 179
     ],
     "group_name")
  , ("OpClusterVerifyDisks",
     [t| JobIdListOnly |],
     OpDoc.opClusterVerifyDisks,
     [],
     [])
180
  , ("OpGroupVerifyDisks",
Jose A. Lopes's avatar
Jose A. Lopes committed
181 182
     [t| (Map String String, [String], Map String [[String]]) |],
     OpDoc.opGroupVerifyDisks,
183
     [ pGroupName
Jose A. Lopes's avatar
Jose A. Lopes committed
184 185
     ],
     "group_name")
186
  , ("OpClusterRepairDiskSizes",
Jose A. Lopes's avatar
Jose A. Lopes committed
187 188
     [t| [(NonEmptyString, NonNegative Int, NonEmptyString, NonNegative Int)]|],
     OpDoc.opClusterRepairDiskSizes,
189
     [ pInstances
Jose A. Lopes's avatar
Jose A. Lopes committed
190 191
     ],
     [])
192
  , ("OpClusterConfigQuery",
Jose A. Lopes's avatar
Jose A. Lopes committed
193 194
     [t| [JSValue] |],
     OpDoc.opClusterConfigQuery,
195
     [ pOutputFields
Jose A. Lopes's avatar
Jose A. Lopes committed
196 197
     ],
     [])
198
  , ("OpClusterRename",
Jose A. Lopes's avatar
Jose A. Lopes committed
199 200
      [t| NonEmptyString |],
      OpDoc.opClusterRename,
201
     [ pName
Jose A. Lopes's avatar
Jose A. Lopes committed
202 203
     ],
     "name")
204
  , ("OpClusterSetParams",
Jose A. Lopes's avatar
Jose A. Lopes committed
205 206
     [t| () |],
     OpDoc.opClusterSetParams,
207 208
     [ pForce
     , pHvState
209 210 211 212 213 214
     , pDiskState
     , pVgName
     , pEnabledHypervisors
     , pClusterHvParams
     , pClusterBeParams
     , pOsHvp
215
     , pClusterOsParams
216
     , pClusterOsParamsPrivate
217 218
     , pDiskParams
     , pCandidatePoolSize
219
     , pMaxRunningJobs
220 221 222 223 224 225
     , pUidPool
     , pAddUids
     , pRemoveUids
     , pMaintainNodeHealth
     , pPreallocWipeDisks
     , pNicParams
Jose A. Lopes's avatar
Jose A. Lopes committed
226 227
     , withDoc "Cluster-wide node parameter defaults" pNdParams
     , withDoc "Cluster-wide ipolicy specs" pIpolicy
228 229
     , pDrbdHelper
     , pDefaultIAllocator
230
     , pDefaultIAllocatorParams
231
     , pMasterNetdev
232
     , pMasterNetmask
233 234 235 236
     , pReservedLvs
     , pHiddenOs
     , pBlacklistedOs
     , pUseExternalMipScript
237
     , pEnabledDiskTemplates
238
     , pModifyEtcHosts
239 240
     , pClusterFileStorageDir
     , pClusterSharedFileStorageDir
241
     , pClusterGlusterStorageDir
242
     , pInstanceCommunicationNetwork
Jose A. Lopes's avatar
Jose A. Lopes committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
     ],
     [])
  , ("OpClusterRedistConf",
     [t| () |],
     OpDoc.opClusterRedistConf,
     [],
     [])
  , ("OpClusterActivateMasterIp",
     [t| () |],
     OpDoc.opClusterActivateMasterIp,
     [],
     [])
  , ("OpClusterDeactivateMasterIp",
     [t| () |],
     OpDoc.opClusterDeactivateMasterIp,
     [],
     [])
260 261 262 263 264
  , ("OpClusterRenewCrypto",
     [t| () |],
     OpDoc.opClusterRenewCrypto,
     [],
     [])
265
  , ("OpQuery",
Jose A. Lopes's avatar
Jose A. Lopes committed
266 267
     [t| QueryResponse |],
     OpDoc.opQuery,
268 269 270 271
     [ pQueryWhat
     , pUseLocking
     , pQueryFields
     , pQueryFilter
Jose A. Lopes's avatar
Jose A. Lopes committed
272 273
     ],
     "what")
274
  , ("OpQueryFields",
Jose A. Lopes's avatar
Jose A. Lopes committed
275 276
     [t| QueryFieldsResponse |],
     OpDoc.opQueryFields,
277
     [ pQueryWhat
Jose A. Lopes's avatar
Jose A. Lopes committed
278 279 280
     , pQueryFieldsFields
     ],
     "what")
281
  , ("OpOobCommand",
Jose A. Lopes's avatar
Jose A. Lopes committed
282 283
     [t| [[(QueryResultCode, JSValue)]] |],
     OpDoc.opOobCommand,
284
     [ pNodeNames
Jose A. Lopes's avatar
Jose A. Lopes committed
285
     , withDoc "List of node UUIDs to run the OOB command against" pNodeUuids
286 287 288 289
     , pOobCommand
     , pOobTimeout
     , pIgnoreStatus
     , pPowerDelay
Jose A. Lopes's avatar
Jose A. Lopes committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
     ],
     [])
  , ("OpRestrictedCommand",
     [t| [(Bool, String)] |],
     OpDoc.opRestrictedCommand,
     [ pUseLocking
     , withDoc
       "Nodes on which the command should be run (at least one)"
       pRequiredNodes
     , withDoc
       "Node UUIDs on which the command should be run (at least one)"
       pRequiredNodeUuids
     , pRestrictedCommand
     ],
     [])
Thomas Thrainer's avatar
Thomas Thrainer committed
305
  , ("OpNodeRemove",
Jose A. Lopes's avatar
Jose A. Lopes committed
306 307
     [t| () |],
      OpDoc.opNodeRemove,
Thomas Thrainer's avatar
Thomas Thrainer committed
308 309
     [ pNodeName
     , pNodeUuid
Jose A. Lopes's avatar
Jose A. Lopes committed
310 311
     ],
     "node_name")
312
  , ("OpNodeAdd",
Jose A. Lopes's avatar
Jose A. Lopes committed
313 314
     [t| () |],
      OpDoc.opNodeAdd,
315 316 317 318 319 320 321 322 323 324
     [ pNodeName
     , pHvState
     , pDiskState
     , pPrimaryIp
     , pSecondaryIp
     , pReadd
     , pNodeGroup
     , pMasterCapable
     , pVmCapable
     , pNdParams
Jose A. Lopes's avatar
Jose A. Lopes committed
325 326
     ],
     "node_name")
327
  , ("OpNodeQueryvols",
Jose A. Lopes's avatar
Jose A. Lopes committed
328 329
     [t| [JSValue] |],
     OpDoc.opNodeQueryvols,
330
     [ pOutputFields
Jose A. Lopes's avatar
Jose A. Lopes committed
331 332 333
     , withDoc "Empty list to query all nodes, node names otherwise" pNodes
     ],
     [])
334
  , ("OpNodeQueryStorage",
Jose A. Lopes's avatar
Jose A. Lopes committed
335 336
     [t| [[JSValue]] |],
     OpDoc.opNodeQueryStorage,
337
     [ pOutputFields
338
     , pStorageTypeOptional
Jose A. Lopes's avatar
Jose A. Lopes committed
339 340 341
     , withDoc
       "Empty list to query all, list of names to query otherwise"
       pNodes
342
     , pStorageName
Jose A. Lopes's avatar
Jose A. Lopes committed
343 344
     ],
     [])
345
  , ("OpNodeModifyStorage",
Jose A. Lopes's avatar
Jose A. Lopes committed
346 347
     [t| () |],
     OpDoc.opNodeModifyStorage,
348
     [ pNodeName
Thomas Thrainer's avatar
Thomas Thrainer committed
349
     , pNodeUuid
350 351 352
     , pStorageType
     , pStorageName
     , pStorageChanges
Jose A. Lopes's avatar
Jose A. Lopes committed
353 354
     ],
     "node_name")
355
  , ("OpRepairNodeStorage",
Jose A. Lopes's avatar
Jose A. Lopes committed
356 357
      [t| () |],
      OpDoc.opRepairNodeStorage,
358
     [ pNodeName
Thomas Thrainer's avatar
Thomas Thrainer committed
359
     , pNodeUuid
360 361 362
     , pStorageType
     , pStorageName
     , pIgnoreConsistency
Jose A. Lopes's avatar
Jose A. Lopes committed
363 364
     ],
     "node_name")
365
  , ("OpNodeSetParams",
Jose A. Lopes's avatar
Jose A. Lopes committed
366 367
     [t| [(NonEmptyString, JSValue)] |],
     OpDoc.opNodeSetParams,
368
     [ pNodeName
Thomas Thrainer's avatar
Thomas Thrainer committed
369
     , pNodeUuid
370 371 372 373
     , pForce
     , pHvState
     , pDiskState
     , pMasterCandidate
Jose A. Lopes's avatar
Jose A. Lopes committed
374
     , withDoc "Whether to mark the node offline" pOffline
375 376 377 378 379 380
     , pDrained
     , pAutoPromote
     , pMasterCapable
     , pVmCapable
     , pSecondaryIp
     , pNdParams
381
     , pPowered
Jose A. Lopes's avatar
Jose A. Lopes committed
382 383
     ],
     "node_name")
384
  , ("OpNodePowercycle",
Jose A. Lopes's avatar
Jose A. Lopes committed
385 386
     [t| Maybe NonEmptyString |],
     OpDoc.opNodePowercycle,
387
     [ pNodeName
Thomas Thrainer's avatar
Thomas Thrainer committed
388
     , pNodeUuid
389
     , pForce
Jose A. Lopes's avatar
Jose A. Lopes committed
390 391
     ],
     "node_name")
392
  , ("OpNodeMigrate",
Jose A. Lopes's avatar
Jose A. Lopes committed
393 394
     [t| JobIdListOnly |],
     OpDoc.opNodeMigrate,
395
     [ pNodeName
Thomas Thrainer's avatar
Thomas Thrainer committed
396
     , pNodeUuid
397 398 399
     , pMigrationMode
     , pMigrationLive
     , pMigrationTargetNode
Thomas Thrainer's avatar
Thomas Thrainer committed
400
     , pMigrationTargetNodeUuid
401 402 403
     , pAllowRuntimeChgs
     , pIgnoreIpolicy
     , pIallocator
Jose A. Lopes's avatar
Jose A. Lopes committed
404 405
     ],
     "node_name")
406
  , ("OpNodeEvacuate",
Jose A. Lopes's avatar
Jose A. Lopes committed
407 408
     [t| JobIdListOnly |],
     OpDoc.opNodeEvacuate,
409 410
     [ pEarlyRelease
     , pNodeName
Thomas Thrainer's avatar
Thomas Thrainer committed
411
     , pNodeUuid
412
     , pRemoteNode
Thomas Thrainer's avatar
Thomas Thrainer committed
413
     , pRemoteNodeUuid
414 415
     , pIallocator
     , pEvacMode
Jose A. Lopes's avatar
Jose A. Lopes committed
416 417
     ],
     "node_name")
418
  , ("OpInstanceCreate",
Jose A. Lopes's avatar
Jose A. Lopes committed
419 420
     [t| [NonEmptyString] |],
     OpDoc.opInstanceCreate,
421 422 423 424 425
     [ pInstanceName
     , pForceVariant
     , pWaitForSync
     , pNameCheck
     , pIgnoreIpolicy
Jose A. Lopes's avatar
Jose A. Lopes committed
426
     , pOpportunisticLocking
427 428
     , pInstBeParams
     , pInstDisks
429
     , pOptDiskTemplate
430 431 432 433 434 435 436 437 438 439 440 441
     , pFileDriver
     , pFileStorageDir
     , pInstHvParams
     , pHypervisor
     , pIallocator
     , pResetDefaults
     , pIpCheck
     , pIpConflictsCheck
     , pInstCreateMode
     , pInstNics
     , pNoInstall
     , pInstOsParams
442 443
     , pInstOsParamsPrivate
     , pInstOsParamsSecret
444 445
     , pInstOs
     , pPrimaryNode
Thomas Thrainer's avatar
Thomas Thrainer committed
446
     , pPrimaryNodeUuid
447
     , pSecondaryNode
Thomas Thrainer's avatar
Thomas Thrainer committed
448
     , pSecondaryNodeUuid
449 450 451 452 453
     , pSourceHandshake
     , pSourceInstance
     , pSourceShutdownTimeout
     , pSourceX509Ca
     , pSrcNode
Thomas Thrainer's avatar
Thomas Thrainer committed
454
     , pSrcNodeUuid
455
     , pSrcPath
456
     , pBackupCompress
457 458
     , pStartInstance
     , pInstTags
459
     , pInstanceCommunication
Jose A. Lopes's avatar
Jose A. Lopes committed
460 461
     ],
     "instance_name")
462
  , ("OpInstanceMultiAlloc",
Jose A. Lopes's avatar
Jose A. Lopes committed
463 464 465 466
     [t| InstanceMultiAllocResponse |],
     OpDoc.opInstanceMultiAlloc,
     [ pOpportunisticLocking
     , pIallocator
467
     , pMultiAllocInstances
Jose A. Lopes's avatar
Jose A. Lopes committed
468 469
     ],
     [])
470
  , ("OpInstanceReinstall",
Jose A. Lopes's avatar
Jose A. Lopes committed
471 472
     [t| () |],
     OpDoc.opInstanceReinstall,
473
     [ pInstanceName
474
     , pInstanceUuid
475 476 477
     , pForceVariant
     , pInstOs
     , pTempOsParams
478 479
     , pTempOsParamsPrivate
     , pTempOsParamsSecret
Jose A. Lopes's avatar
Jose A. Lopes committed
480 481
     ],
     "instance_name")
482
  , ("OpInstanceRemove",
Jose A. Lopes's avatar
Jose A. Lopes committed
483 484
     [t| () |],
     OpDoc.opInstanceRemove,
485
     [ pInstanceName
486
     , pInstanceUuid
487 488
     , pShutdownTimeout
     , pIgnoreFailures
Jose A. Lopes's avatar
Jose A. Lopes committed
489 490
     ],
     "instance_name")
491
  , ("OpInstanceRename",
Jose A. Lopes's avatar
Jose A. Lopes committed
492 493
     [t| NonEmptyString |],
     OpDoc.opInstanceRename,
494
     [ pInstanceName
495
     , pInstanceUuid
Jose A. Lopes's avatar
Jose A. Lopes committed
496
     , withDoc "New instance name" pNewName
497 498
     , pNameCheck
     , pIpCheck
Jose A. Lopes's avatar
Jose A. Lopes committed
499 500
     ],
     [])
501
  , ("OpInstanceStartup",
Jose A. Lopes's avatar
Jose A. Lopes committed
502 503
     [t| () |],
     OpDoc.opInstanceStartup,
504
     [ pInstanceName
505
     , pInstanceUuid
506 507 508 509 510 511
     , pForce
     , pIgnoreOfflineNodes
     , pTempHvParams
     , pTempBeParams
     , pNoRemember
     , pStartupPaused
Jose A. Lopes's avatar
Jose A. Lopes committed
512 513
     ],
     "instance_name")
514
  , ("OpInstanceShutdown",
Jose A. Lopes's avatar
Jose A. Lopes committed
515 516
     [t| () |],
     OpDoc.opInstanceShutdown,
517
     [ pInstanceName
518
     , pInstanceUuid
519
     , pForce
520
     , pIgnoreOfflineNodes
Jose A. Lopes's avatar
Jose A. Lopes committed
521
     , pShutdownTimeout'
522
     , pNoRemember
Jose A. Lopes's avatar
Jose A. Lopes committed
523 524
     ],
     "instance_name")
525
  , ("OpInstanceReboot",
Jose A. Lopes's avatar
Jose A. Lopes committed
526 527
     [t| () |],
     OpDoc.opInstanceReboot,
528
     [ pInstanceName
529
     , pInstanceUuid
530 531 532
     , pShutdownTimeout
     , pIgnoreSecondaries
     , pRebootType
Jose A. Lopes's avatar
Jose A. Lopes committed
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
     ],
     "instance_name")
  , ("OpInstanceReplaceDisks",
     [t| () |],
     OpDoc.opInstanceReplaceDisks,
     [ pInstanceName
     , pInstanceUuid
     , pEarlyRelease
     , pIgnoreIpolicy
     , pReplaceDisksMode
     , pReplaceDisksList
     , pRemoteNode
     , pRemoteNodeUuid
     , pIallocator
     ],
     "instance_name")
  , ("OpInstanceFailover",
     [t| () |],
     OpDoc.opInstanceFailover,
     [ pInstanceName
     , pInstanceUuid
     , pShutdownTimeout
     , pIgnoreConsistency
     , pMigrationTargetNode
     , pMigrationTargetNodeUuid
     , pIgnoreIpolicy
Thomas Thrainer's avatar
Thomas Thrainer committed
559
     , pMigrationCleanup
Jose A. Lopes's avatar
Jose A. Lopes committed
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
     , pIallocator
     ],
     "instance_name")
  , ("OpInstanceMigrate",
     [t| () |],
     OpDoc.opInstanceMigrate,
     [ pInstanceName
     , pInstanceUuid
     , pMigrationMode
     , pMigrationLive
     , pMigrationTargetNode
     , pMigrationTargetNodeUuid
     , pAllowRuntimeChgs
     , pIgnoreIpolicy
     , pMigrationCleanup
     , pIallocator
     , pAllowFailover
     ],
     "instance_name")
579
  , ("OpInstanceMove",
Jose A. Lopes's avatar
Jose A. Lopes committed
580 581
     [t| () |],
     OpDoc.opInstanceMove,
582
     [ pInstanceName
583
     , pInstanceUuid
584 585 586
     , pShutdownTimeout
     , pIgnoreIpolicy
     , pMoveTargetNode
Thomas Thrainer's avatar
Thomas Thrainer committed
587
     , pMoveTargetNodeUuid
588
     , pMoveCompress
589
     , pIgnoreConsistency
Jose A. Lopes's avatar
Jose A. Lopes committed
590 591
     ],
     "instance_name")
592
  , ("OpInstanceConsole",
Jose A. Lopes's avatar
Jose A. Lopes committed
593 594
     [t| JSObject JSValue |],
     OpDoc.opInstanceConsole,
595 596
     [ pInstanceName
     , pInstanceUuid
Jose A. Lopes's avatar
Jose A. Lopes committed
597 598
     ],
     "instance_name")
599
  , ("OpInstanceActivateDisks",
Jose A. Lopes's avatar
Jose A. Lopes committed
600 601
     [t| [(NonEmptyString, NonEmptyString, NonEmptyString)] |],
     OpDoc.opInstanceActivateDisks,
602
     [ pInstanceName
603
     , pInstanceUuid
604 605
     , pIgnoreDiskSize
     , pWaitForSyncFalse
Jose A. Lopes's avatar
Jose A. Lopes committed
606 607
     ],
     "instance_name")
608
  , ("OpInstanceDeactivateDisks",
Jose A. Lopes's avatar
Jose A. Lopes committed
609 610
     [t| () |],
     OpDoc.opInstanceDeactivateDisks,
611
     [ pInstanceName
612
     , pInstanceUuid
613
     , pForce
Jose A. Lopes's avatar
Jose A. Lopes committed
614 615
     ],
     "instance_name")
616
  , ("OpInstanceRecreateDisks",
Jose A. Lopes's avatar
Jose A. Lopes committed
617 618
     [t| () |],
     OpDoc.opInstanceRecreateDisks,
619
     [ pInstanceName
620
     , pInstanceUuid
621
     , pRecreateDisksInfo
Jose A. Lopes's avatar
Jose A. Lopes committed
622 623
     , withDoc "New instance nodes, if relocation is desired" pNodes
     , withDoc "New instance node UUIDs, if relocation is desired" pNodeUuids
624
     , pIallocator
Jose A. Lopes's avatar
Jose A. Lopes committed
625 626
     ],
     "instance_name")
627
  , ("OpInstanceQueryData",
Jose A. Lopes's avatar
Jose A. Lopes committed
628 629
     [t| JSObject (JSObject JSValue) |],
     OpDoc.opInstanceQueryData,
630 631 632
     [ pUseLocking
     , pInstances
     , pStatic
Jose A. Lopes's avatar
Jose A. Lopes committed
633 634
     ],
     [])
635
  , ("OpInstanceSetParams",
Jose A. Lopes's avatar
Jose A. Lopes committed
636 637
      [t| [(NonEmptyString, JSValue)] |],
      OpDoc.opInstanceSetParams,
638
     [ pInstanceName
639
     , pInstanceUuid
640 641 642 643 644 645 646 647
     , pForce
     , pForceVariant
     , pIgnoreIpolicy
     , pInstParamsNicChanges
     , pInstParamsDiskChanges
     , pInstBeParams
     , pRuntimeMem
     , pInstHvParams
648
     , pOptDiskTemplate
649
     , pPrimaryNode
Thomas Thrainer's avatar
Thomas Thrainer committed
650
     , pPrimaryNodeUuid
Jose A. Lopes's avatar
Jose A. Lopes committed
651 652 653 654
     , withDoc "Secondary node (used when changing disk template)" pRemoteNode
     , withDoc
       "Secondary node UUID (used when changing disk template)"
       pRemoteNodeUuid
655 656
     , pOsNameChange
     , pInstOsParams
657
     , pInstOsParamsPrivate
658
     , pWaitForSync
Jose A. Lopes's avatar
Jose A. Lopes committed
659
     , withDoc "Whether to mark the instance as offline" pOffline
660
     , pIpConflictsCheck
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
661
     , pHotplug
662
     , pHotplugIfPossible
Jose A. Lopes's avatar
Jose A. Lopes committed
663 664
     ],
     "instance_name")
665
  , ("OpInstanceGrowDisk",
Jose A. Lopes's avatar
Jose A. Lopes committed
666 667
     [t| () |],
     OpDoc.opInstanceGrowDisk,
668
     [ pInstanceName
669
     , pInstanceUuid
670 671 672 673
     , pWaitForSync
     , pDiskIndex
     , pDiskChgAmount
     , pDiskChgAbsolute
Jose A. Lopes's avatar
Jose A. Lopes committed
674 675
     ],
     "instance_name")
676
  , ("OpInstanceChangeGroup",
Jose A. Lopes's avatar
Jose A. Lopes committed
677 678
     [t| JobIdListOnly |],
     OpDoc.opInstanceChangeGroup,
679
     [ pInstanceName
680
     , pInstanceUuid
681 682 683
     , pEarlyRelease
     , pIallocator
     , pTargetGroups
Jose A. Lopes's avatar
Jose A. Lopes committed
684 685
     ],
     "instance_name")
Iustin Pop's avatar
Iustin Pop committed
686
  , ("OpGroupAdd",
Jose A. Lopes's avatar
Jose A. Lopes committed
687 688
     [t| () |],
     OpDoc.opGroupAdd,
Iustin Pop's avatar
Iustin Pop committed
689 690 691 692 693 694
     [ pGroupName
     , pNodeGroupAllocPolicy
     , pGroupNodeParams
     , pDiskParams
     , pHvState
     , pDiskState
Jose A. Lopes's avatar
Jose A. Lopes committed
695 696 697
     , withDoc "Group-wide ipolicy specs" pIpolicy
     ],
     "group_name")
Iustin Pop's avatar
Iustin Pop committed
698
  , ("OpGroupAssignNodes",
Jose A. Lopes's avatar
Jose A. Lopes committed
699 700
     [t| () |],
     OpDoc.opGroupAssignNodes,
Iustin Pop's avatar
Iustin Pop committed
701 702
     [ pGroupName
     , pForce
Jose A. Lopes's avatar
Jose A. Lopes committed
703 704 705 706
     , withDoc "List of nodes to assign" pRequiredNodes
     , withDoc "List of node UUIDs to assign" pRequiredNodeUuids
     ],
     "group_name")
Iustin Pop's avatar
Iustin Pop committed
707
  , ("OpGroupSetParams",
Jose A. Lopes's avatar
Jose A. Lopes committed
708 709
     [t| [(NonEmptyString, JSValue)] |],
     OpDoc.opGroupSetParams,
Iustin Pop's avatar
Iustin Pop committed
710 711 712 713 714 715
     [ pGroupName
     , pNodeGroupAllocPolicy
     , pGroupNodeParams
     , pDiskParams
     , pHvState
     , pDiskState
Jose A. Lopes's avatar
Jose A. Lopes committed
716 717 718
     , withDoc "Group-wide ipolicy specs" pIpolicy
     ],
     "group_name")
Iustin Pop's avatar
Iustin Pop committed
719
  , ("OpGroupRemove",
Jose A. Lopes's avatar
Jose A. Lopes committed
720 721 722 723 724
     [t| () |],
     OpDoc.opGroupRemove,
     [ pGroupName
     ],
     "group_name")
Iustin Pop's avatar
Iustin Pop committed
725
  , ("OpGroupRename",
Jose A. Lopes's avatar
Jose A. Lopes committed
726 727
     [t| NonEmptyString |],
     OpDoc.opGroupRename,
Iustin Pop's avatar
Iustin Pop committed
728
     [ pGroupName
Jose A. Lopes's avatar
Jose A. Lopes committed
729 730 731
     , withDoc "New group name" pNewName
     ],
     [])
Iustin Pop's avatar
Iustin Pop committed
732
  , ("OpGroupEvacuate",
Jose A. Lopes's avatar
Jose A. Lopes committed
733 734
     [t| JobIdListOnly |],
     OpDoc.opGroupEvacuate,
Iustin Pop's avatar
Iustin Pop committed
735 736 737 738
     [ pGroupName
     , pEarlyRelease
     , pIallocator
     , pTargetGroups
Jose A. Lopes's avatar
Jose A. Lopes committed
739 740
     ],
     "group_name")
Iustin Pop's avatar
Iustin Pop committed
741
  , ("OpOsDiagnose",
Jose A. Lopes's avatar
Jose A. Lopes committed
742 743
     [t| [[JSValue]] |],
     OpDoc.opOsDiagnose,
Iustin Pop's avatar
Iustin Pop committed
744
     [ pOutputFields
Jose A. Lopes's avatar
Jose A. Lopes committed
745 746 747
     , withDoc "Which operating systems to diagnose" pNames
     ],
     [])
748
  , ("OpExtStorageDiagnose",
Jose A. Lopes's avatar
Jose A. Lopes committed
749 750
     [t| [[JSValue]] |],
     OpDoc.opExtStorageDiagnose,
751
     [ pOutputFields
Jose A. Lopes's avatar
Jose A. Lopes committed
752 753 754
     , withDoc "Which ExtStorage Provider to diagnose" pNames
     ],
     [])
Iustin Pop's avatar
Iustin Pop committed
755
  , ("OpBackupPrepare",
Jose A. Lopes's avatar
Jose A. Lopes committed
756 757
     [t| Maybe (JSObject JSValue) |],
     OpDoc.opBackupPrepare,
Iustin Pop's avatar
Iustin Pop committed
758
     [ pInstanceName
759
     , pInstanceUuid
Iustin Pop's avatar
Iustin Pop committed
760
     , pExportMode
Jose A. Lopes's avatar
Jose A. Lopes committed
761 762
     ],
     "instance_name")
Iustin Pop's avatar
Iustin Pop committed
763
  , ("OpBackupExport",
Jose A. Lopes's avatar
Jose A. Lopes committed
764 765
     [t| (Bool, [Bool]) |],
     OpDoc.opBackupExport,
Iustin Pop's avatar
Iustin Pop committed
766
     [ pInstanceName
767
     , pInstanceUuid
768
     , pBackupCompress
Iustin Pop's avatar
Iustin Pop committed
769 770
     , pShutdownTimeout
     , pExportTargetNode
Thomas Thrainer's avatar
Thomas Thrainer committed
771
     , pExportTargetNodeUuid
772
     , pShutdownInstance
Iustin Pop's avatar
Iustin Pop committed
773 774
     , pRemoveInstance
     , pIgnoreRemoveFailures
Jose A. Lopes's avatar
Jose A. Lopes committed
775
     , defaultField [| ExportModeLocal |] pExportMode
Iustin Pop's avatar
Iustin Pop committed
776 777
     , pX509KeyName
     , pX509DestCA
Jose A. Lopes's avatar
Jose A. Lopes committed
778 779
     ],
     "instance_name")
Iustin Pop's avatar
Iustin Pop committed
780
  , ("OpBackupRemove",
Jose A. Lopes's avatar
Jose A. Lopes committed
781 782
     [t| () |],
     OpDoc.opBackupRemove,
783 784
     [ pInstanceName
     , pInstanceUuid
Jose A. Lopes's avatar
Jose A. Lopes committed
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
     ],
     "instance_name")
  , ("OpTagsGet",
     [t| [NonEmptyString] |],
     OpDoc.opTagsGet,
     [ pTagsObject
     , pUseLocking
     , withDoc "Name of object to retrieve tags from" pTagsName
     ],
     "name")
  , ("OpTagsSearch",
     [t| [(NonEmptyString, NonEmptyString)] |],
     OpDoc.opTagsSearch,
     [ pTagSearchPattern
     ],
     "pattern")
  , ("OpTagsSet",
     [t| () |],
     OpDoc.opTagsSet,
     [ pTagsObject
     , pTagsList
     , withDoc "Name of object where tag(s) should be added" pTagsName
     ],
     [])
  , ("OpTagsDel",
     [t| () |],
     OpDoc.opTagsDel,
     [ pTagsObject
     , pTagsList
     , withDoc "Name of object where tag(s) should be deleted" pTagsName
     ],
     [])
  , ("OpTestDelay",
     [t| () |],
     OpDoc.opTestDelay,
     [ pDelayDuration
     , pDelayOnMaster
     , pDelayOnNodes
     , pDelayOnNodeUuids
     , pDelayRepeat
     ],
     "duration")
Iustin Pop's avatar
Iustin Pop committed
827
  , ("OpTestAllocator",
Jose A. Lopes's avatar
Jose A. Lopes committed
828
     [t| String |],
Jose A. Lopes's avatar
Jose A. Lopes committed
829
     OpDoc.opTestAllocator,
Iustin Pop's avatar
Iustin Pop committed
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
     [ pIAllocatorDirection
     , pIAllocatorMode
     , pIAllocatorReqName
     , pIAllocatorNics
     , pIAllocatorDisks
     , pHypervisor
     , pIallocator
     , pInstTags
     , pIAllocatorMemory
     , pIAllocatorVCpus
     , pIAllocatorOs
     , pDiskTemplate
     , pIAllocatorInstances
     , pIAllocatorEvacMode
     , pTargetGroups
     , pIAllocatorSpindleUse
     , pIAllocatorCount
Jose A. Lopes's avatar
Jose A. Lopes committed
847 848
     ],
     "iallocator")
Iustin Pop's avatar
Iustin Pop committed
849
  , ("OpTestJqueue",
Jose A. Lopes's avatar
Jose A. Lopes committed
850
     [t| Bool |],
Jose A. Lopes's avatar
Jose A. Lopes committed
851
     OpDoc.opTestJqueue,
Iustin Pop's avatar
Iustin Pop committed
852 853 854 855
     [ pJQueueNotifyWaitLock
     , pJQueueNotifyExec
     , pJQueueLogMessages
     , pJQueueFail
Jose A. Lopes's avatar
Jose A. Lopes committed
856 857
     ],
     [])
Iustin Pop's avatar
Iustin Pop committed
858
  , ("OpTestDummy",
Jose A. Lopes's avatar
Jose A. Lopes committed
859 860
     [t| () |],
     OpDoc.opTestDummy,
Iustin Pop's avatar
Iustin Pop committed
861 862 863 864
     [ pTestDummyResult
     , pTestDummyMessages
     , pTestDummyFail
     , pTestDummySubmitJobs
Jose A. Lopes's avatar
Jose A. Lopes committed
865 866
     ],
     [])
867
  , ("OpNetworkAdd",
Jose A. Lopes's avatar
Jose A. Lopes committed
868 869
     [t| () |],
     OpDoc.opNetworkAdd,
870 871 872 873 874 875 876
     [ pNetworkName
     , pNetworkAddress4
     , pNetworkGateway4
     , pNetworkAddress6
     , pNetworkGateway6
     , pNetworkMacPrefix
     , pNetworkAddRsvdIps
Iustin Pop's avatar
Iustin Pop committed
877
     , pIpConflictsCheck
Jose A. Lopes's avatar
Jose A. Lopes committed
878 879 880
     , withDoc "Network tags" pInstTags
     ],
     "network_name")
881
  , ("OpNetworkRemove",
Jose A. Lopes's avatar
Jose A. Lopes committed
882 883
     [t| () |],
     OpDoc.opNetworkRemove,
884 885
     [ pNetworkName
     , pForce
Jose A. Lopes's avatar
Jose A. Lopes committed
886 887
     ],
     "network_name")
888
  , ("OpNetworkSetParams",
Jose A. Lopes's avatar
Jose A. Lopes committed
889 890
     [t| () |],
     OpDoc.opNetworkSetParams,
891 892 893 894 895
     [ pNetworkName
     , pNetworkGateway4
     , pNetworkAddress6
     , pNetworkGateway6
     , pNetworkMacPrefix
Jose A. Lopes's avatar
Jose A. Lopes committed
896
     , withDoc "Which external IP addresses to reserve" pNetworkAddRsvdIps
897
     , pNetworkRemoveRsvdIps
Jose A. Lopes's avatar
Jose A. Lopes committed
898 899
     ],
     "network_name")
900
  , ("OpNetworkConnect",
Jose A. Lopes's avatar
Jose A. Lopes committed
901 902
     [t| () |],
     OpDoc.opNetworkConnect,
903 904 905 906 907
     [ pGroupName
     , pNetworkName
     , pNetworkMode
     , pNetworkLink
     , pIpConflictsCheck
Jose A. Lopes's avatar
Jose A. Lopes committed
908 909
     ],
     "network_name")
910
  , ("OpNetworkDisconnect",
Jose A. Lopes's avatar
Jose A. Lopes committed
911 912
     [t| () |],
     OpDoc.opNetworkDisconnect,
913 914
     [ pGroupName
     , pNetworkName
Jose A. Lopes's avatar
Jose A. Lopes committed
915 916
     ],
     "network_name")
917
  ])
918

919
-- | Returns the OP_ID for a given opcode value.
920
$(genOpID ''OpCode "opID")
921

922 923 924
-- | A list of all defined/supported opcode IDs.
$(genAllOpIDs ''OpCode "allOpIDs")

925
instance JSON OpCode where
926