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 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 43 44
  , CommonOpParams(..)
  , defOpParams
  , MetaOpCode(..)
  , wrapOpCode
  , setOpComment
45
  , setOpPriority
46
  ) where
47

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

51
import Ganeti.THH
52

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

Jose A. Lopes's avatar
Jose A. Lopes committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
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
81

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

Jose A. Lopes's avatar
Jose A. Lopes committed
85 86 87 88 89
-- 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
90
  showValue ExportModeRemote = show C.exportModeLocal
Jose A. Lopes's avatar
Jose A. Lopes committed
91 92 93

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

Jose A. Lopes's avatar
Jose A. Lopes committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
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

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

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

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

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

type QueryFieldsResponse = [QueryFieldDef]

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

941
-- | Returns the OP_ID for a given opcode value.
942
$(genOpID ''OpCode "opID")
943

944 945 946
-- | A list of all defined/supported opcode IDs.
$(genAllOpIDs ''OpCode "allOpIDs")

947
instance JSON OpCode where
948 949
  readJSON = loadOpCode
  showJSON = saveOpCode
950

Iustin Pop's avatar
Iustin Pop committed
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977