Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ c298ed02

History | View | Annotate | Download (12.5 kB)

1
{-# LANGUAGE TemplateHaskell #-}
2

    
3
{-| Implementation of the opcodes.
4

    
5
-}
6

    
7
{-
8

    
9
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
10

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

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

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

    
26
-}
27

    
28
module Ganeti.OpCodes
29
  ( OpCode(..)
30
  , TagObject(..)
31
  , tagObjectFrom
32
  , encodeTagObject
33
  , decodeTagObject
34
  , ReplaceDisksMode(..)
35
  , DiskIndex
36
  , mkDiskIndex
37
  , unDiskIndex
38
  , opID
39
  , allOpIDs
40
  , allOpFields
41
  , CommonOpParams(..)
42
  , defOpParams
43
  , MetaOpCode(..)
44
  , wrapOpCode
45
  , setOpComment
46
  ) where
47

    
48
import Text.JSON (readJSON, showJSON, JSON, JSValue, makeObj)
49
import qualified Text.JSON
50

    
51
import Ganeti.THH
52

    
53
import Ganeti.OpParams
54
import Ganeti.Types (OpSubmitPriority(..))
55

    
56
-- | OpCode representation.
57
--
58
-- We only implement a subset of Ganeti opcodes: those which are actually used
59
-- in the htools codebase.
60
$(genOpCode "OpCode"
61
  [ ("OpTestDelay",
62
     [ pDelayDuration
63
     , pDelayOnMaster
64
     , pDelayOnNodes
65
     , pDelayRepeat
66
     ])
67
  , ("OpInstanceReplaceDisks",
68
     [ pInstanceName
69
     , pEarlyRelease
70
     , pIgnoreIpolicy
71
     , pReplaceDisksMode
72
     , pReplaceDisksList
73
     , pRemoteNode
74
     , pIallocator
75
     ])
76
  , ("OpInstanceFailover",
77
     [ pInstanceName
78
     , pShutdownTimeout
79
     , pIgnoreConsistency
80
     , pMigrationTargetNode
81
     , pIgnoreIpolicy
82
     , pIallocator
83
     ])
84
  , ("OpInstanceMigrate",
85
     [ pInstanceName
86
     , pMigrationMode
87
     , pMigrationLive
88
     , pMigrationTargetNode
89
     , pAllowRuntimeChgs
90
     , pIgnoreIpolicy
91
     , pMigrationCleanup
92
     , pIallocator
93
     , pAllowFailover
94
     ])
95
  , ("OpTagsGet",
96
     [ pTagsObject
97
     , pUseLocking
98
     ])
99
  , ("OpTagsSearch",
100
     [ pTagSearchPattern ])
101
  , ("OpTagsSet",
102
     [ pTagsObject
103
     , pTagsList
104
     ])
105
  , ("OpTagsDel",
106
     [ pTagsObject
107
     , pTagsList
108
     ])
109
  , ("OpClusterPostInit", [])
110
  , ("OpClusterDestroy", [])
111
  , ("OpClusterQuery", [])
112
  , ("OpClusterVerify",
113
     [ pDebugSimulateErrors
114
     , pErrorCodes
115
     , pSkipChecks
116
     , pIgnoreErrors
117
     , pVerbose
118
     , pOptGroupName
119
     ])
120
  , ("OpClusterVerifyConfig",
121
     [ pDebugSimulateErrors
122
     , pErrorCodes
123
     , pIgnoreErrors
124
     , pVerbose
125
     ])
126
  , ("OpClusterVerifyGroup",
127
     [ pGroupName
128
     , pDebugSimulateErrors
129
     , pErrorCodes
130
     , pSkipChecks
131
     , pIgnoreErrors
132
     , pVerbose
133
     ])
134
  , ("OpClusterVerifyDisks", [])
135
  , ("OpGroupVerifyDisks",
136
     [ pGroupName
137
     ])
138
  , ("OpClusterRepairDiskSizes",
139
     [ pInstances
140
     ])
141
  , ("OpClusterConfigQuery",
142
     [ pOutputFields
143
     ])
144
  , ("OpClusterRename",
145
     [ pName
146
     ])
147
  , ("OpClusterSetParams",
148
     [ pHvState
149
     , pDiskState
150
     , pVgName
151
     , pEnabledHypervisors
152
     , pClusterHvParams
153
     , pClusterBeParams
154
     , pOsHvp
155
     , pClusterOsParams
156
     , pDiskParams
157
     , pCandidatePoolSize
158
     , pUidPool
159
     , pAddUids
160
     , pRemoveUids
161
     , pMaintainNodeHealth
162
     , pPreallocWipeDisks
163
     , pNicParams
164
     , pNdParams
165
     , pIpolicy
166
     , pDrbdHelper
167
     , pDefaultIAllocator
168
     , pMasterNetdev
169
     , pMasterNetmask
170
     , pReservedLvs
171
     , pHiddenOs
172
     , pBlacklistedOs
173
     , pUseExternalMipScript
174
     ])
175
  , ("OpClusterRedistConf", [])
176
  , ("OpClusterActivateMasterIp", [])
177
  , ("OpClusterDeactivateMasterIp", [])
178
  , ("OpQuery",
179
     [ pQueryWhat
180
     , pUseLocking
181
     , pQueryFields
182
     , pQueryFilter
183
     ])
184
  , ("OpQueryFields",
185
     [ pQueryWhat
186
     , pQueryFields
187
     ])
188
  , ("OpOobCommand",
189
     [ pNodeNames
190
     , pOobCommand
191
     , pOobTimeout
192
     , pIgnoreStatus
193
     , pPowerDelay
194
     ])
195
  , ("OpNodeRemove", [ pNodeName ])
196
  , ("OpNodeAdd",
197
     [ pNodeName
198
     , pHvState
199
     , pDiskState
200
     , pPrimaryIp
201
     , pSecondaryIp
202
     , pReadd
203
     , pNodeGroup
204
     , pMasterCapable
205
     , pVmCapable
206
     , pNdParams
207
    ])
208
  , ("OpNodeQuery", dOldQuery)
209
  , ("OpNodeQueryvols",
210
     [ pOutputFields
211
     , pNodes
212
     ])
213
  , ("OpNodeQueryStorage",
214
     [ pOutputFields
215
     , pStorageType
216
     , pNodes
217
     , pStorageName
218
     ])
219
  , ("OpNodeModifyStorage",
220
     [ pNodeName
221
     , pStorageType
222
     , pStorageName
223
     , pStorageChanges
224
     ])
225
  , ("OpRepairNodeStorage",
226
     [ pNodeName
227
     , pStorageType
228
     , pStorageName
229
     , pIgnoreConsistency
230
     ])
231
  , ("OpNodeSetParams",
232
     [ pNodeName
233
     , pForce
234
     , pHvState
235
     , pDiskState
236
     , pMasterCandidate
237
     , pOffline
238
     , pDrained
239
     , pAutoPromote
240
     , pMasterCapable
241
     , pVmCapable
242
     , pSecondaryIp
243
     , pNdParams
244
     , pPowered
245
     ])
246
  , ("OpNodePowercycle",
247
     [ pNodeName
248
     , pForce
249
     ])
250
  , ("OpNodeMigrate",
251
     [ pNodeName
252
     , pMigrationMode
253
     , pMigrationLive
254
     , pMigrationTargetNode
255
     , pAllowRuntimeChgs
256
     , pIgnoreIpolicy
257
     , pIallocator
258
     ])
259
  , ("OpNodeEvacuate",
260
     [ pEarlyRelease
261
     , pNodeName
262
     , pRemoteNode
263
     , pIallocator
264
     , pEvacMode
265
     ])
266
  , ("OpInstanceCreate",
267
     [ pInstanceName
268
     , pForceVariant
269
     , pWaitForSync
270
     , pNameCheck
271
     , pIgnoreIpolicy
272
     , pInstBeParams
273
     , pInstDisks
274
     , pDiskTemplate
275
     , pFileDriver
276
     , pFileStorageDir
277
     , pInstHvParams
278
     , pHypervisor
279
     , pIallocator
280
     , pResetDefaults
281
     , pIpCheck
282
     , pIpConflictsCheck
283
     , pInstCreateMode
284
     , pInstNics
285
     , pNoInstall
286
     , pInstOsParams
287
     , pInstOs
288
     , pPrimaryNode
289
     , pSecondaryNode
290
     , pSourceHandshake
291
     , pSourceInstance
292
     , pSourceShutdownTimeout
293
     , pSourceX509Ca
294
     , pSrcNode
295
     , pSrcPath
296
     , pStartInstance
297
     , pOpportunisticLocking
298
     , pInstTags
299
     ])
300
  , ("OpInstanceMultiAlloc",
301
     [ pIallocator
302
     , pMultiAllocInstances
303
     , pOpportunisticLocking
304
     ])
305
  , ("OpInstanceReinstall",
306
     [ pInstanceName
307
     , pForceVariant
308
     , pInstOs
309
     , pTempOsParams
310
     ])
311
  , ("OpInstanceRemove",
312
     [ pInstanceName
313
     , pShutdownTimeout
314
     , pIgnoreFailures
315
     ])
316
  , ("OpInstanceRename",
317
     [ pInstanceName
318
     , pNewName
319
     , pNameCheck
320
     , pIpCheck
321
     ])
322
  , ("OpInstanceStartup",
323
     [ pInstanceName
324
     , pForce
325
     , pIgnoreOfflineNodes
326
     , pTempHvParams
327
     , pTempBeParams
328
     , pNoRemember
329
     , pStartupPaused
330
     ])
331
  , ("OpInstanceShutdown",
332
     [ pInstanceName
333
     , pIgnoreOfflineNodes
334
     , pShutdownTimeout'
335
     , pNoRemember
336
     ])
337
  , ("OpInstanceReboot",
338
     [ pInstanceName
339
     , pShutdownTimeout
340
     , pIgnoreSecondaries
341
     , pRebootType
342
     ])
343
  , ("OpInstanceMove",
344
     [ pInstanceName
345
     , pShutdownTimeout
346
     , pIgnoreIpolicy
347
     , pMoveTargetNode
348
     , pIgnoreConsistency
349
     ])
350
  , ("OpInstanceConsole",
351
     [ pInstanceName ])
352
  , ("OpInstanceActivateDisks",
353
     [ pInstanceName
354
     , pIgnoreDiskSize
355
     , pWaitForSyncFalse
356
     ])
357
  , ("OpInstanceDeactivateDisks",
358
     [ pInstanceName
359
     , pForce
360
     ])
361
  , ("OpInstanceRecreateDisks",
362
     [ pInstanceName
363
     , pRecreateDisksInfo
364
     , pNodes
365
     , pIallocator
366
     ])
367
  , ("OpInstanceQuery", dOldQuery)
368
  , ("OpInstanceQueryData",
369
     [ pUseLocking
370
     , pInstances
371
     , pStatic
372
     ])
373
  , ("OpInstanceSetParams",
374
     [ pInstanceName
375
     , pForce
376
     , pForceVariant
377
     , pIgnoreIpolicy
378
     , pInstParamsNicChanges
379
     , pInstParamsDiskChanges
380
     , pInstBeParams
381
     , pRuntimeMem
382
     , pInstHvParams
383
     , pDiskTemplate
384
     , pRemoteNode
385
     , pOsNameChange
386
     , pInstOsParams
387
     , pWaitForSync
388
     , pOffline
389
     , pIpConflictsCheck
390
     ])
391
  , ("OpInstanceGrowDisk",
392
     [ pInstanceName
393
     , pWaitForSync
394
     , pDiskIndex
395
     , pDiskChgAmount
396
     , pDiskChgAbsolute
397
     ])
398
  , ("OpInstanceChangeGroup",
399
     [ pInstanceName
400
     , pEarlyRelease
401
     , pIallocator
402
     , pTargetGroups
403
     ])
404
  , ("OpGroupAdd",
405
     [ pGroupName
406
     , pNodeGroupAllocPolicy
407
     , pGroupNodeParams
408
     , pDiskParams
409
     , pHvState
410
     , pDiskState
411
     , pIpolicy
412
     ])
413
  , ("OpGroupAssignNodes",
414
     [ pGroupName
415
     , pForce
416
     , pRequiredNodes
417
     ])
418
  , ("OpGroupQuery", dOldQueryNoLocking)
419
  , ("OpGroupSetParams",
420
     [ pGroupName
421
     , pNodeGroupAllocPolicy
422
     , pGroupNodeParams
423
     , pDiskParams
424
     , pHvState
425
     , pDiskState
426
     , pIpolicy
427
     ])
428
  , ("OpGroupRemove",
429
     [ pGroupName ])
430
  , ("OpGroupRename",
431
     [ pGroupName
432
     , pNewName
433
     ])
434
  , ("OpGroupEvacuate",
435
     [ pGroupName
436
     , pEarlyRelease
437
     , pIallocator
438
     , pTargetGroups
439
     ])
440
  , ("OpOsDiagnose",
441
     [ pOutputFields
442
     , pNames ])
443
  , ("OpBackupQuery",
444
     [ pUseLocking
445
     , pNodes
446
     ])
447
  , ("OpBackupPrepare",
448
     [ pInstanceName
449
     , pExportMode
450
     ])
451
  , ("OpBackupExport",
452
     [ pInstanceName
453
     , pShutdownTimeout
454
     , pExportTargetNode
455
     , pShutdownInstance
456
     , pRemoveInstance
457
     , pIgnoreRemoveFailures
458
     , pExportMode
459
     , pX509KeyName
460
     , pX509DestCA
461
     ])
462
  , ("OpBackupRemove",
463
     [ pInstanceName ])
464
  , ("OpTestAllocator",
465
     [ pIAllocatorDirection
466
     , pIAllocatorMode
467
     , pIAllocatorReqName
468
     , pIAllocatorNics
469
     , pIAllocatorDisks
470
     , pHypervisor
471
     , pIallocator
472
     , pInstTags
473
     , pIAllocatorMemory
474
     , pIAllocatorVCpus
475
     , pIAllocatorOs
476
     , pDiskTemplate
477
     , pIAllocatorInstances
478
     , pIAllocatorEvacMode
479
     , pTargetGroups
480
     , pIAllocatorSpindleUse
481
     , pIAllocatorCount
482
     ])
483
  , ("OpTestJqueue",
484
     [ pJQueueNotifyWaitLock
485
     , pJQueueNotifyExec
486
     , pJQueueLogMessages
487
     , pJQueueFail
488
     ])
489
  , ("OpTestDummy",
490
     [ pTestDummyResult
491
     , pTestDummyMessages
492
     , pTestDummyFail
493
     , pTestDummySubmitJobs
494
     ])
495
  , ("OpNetworkAdd",
496
     [ pNetworkName
497
     , pNetworkType
498
     , pNetworkAddress4
499
     , pNetworkGateway4
500
     , pNetworkAddress6
501
     , pNetworkGateway6
502
     , pNetworkMacPrefix
503
     , pNetworkAddRsvdIps
504
     , pIpConflictsCheck
505
     , pInstTags
506
     ])
507
  , ("OpNetworkRemove",
508
     [ pNetworkName
509
     , pForce
510
     ])
511
  , ("OpNetworkSetParams",
512
     [ pNetworkName
513
     , pNetworkType
514
     , pNetworkGateway4
515
     , pNetworkAddress6
516
     , pNetworkGateway6
517
     , pNetworkMacPrefix
518
     , pNetworkAddRsvdIps
519
     , pNetworkRemoveRsvdIps
520
     ])
521
  , ("OpNetworkConnect",
522
     [ pGroupName
523
     , pNetworkName
524
     , pNetworkMode
525
     , pNetworkLink
526
     , pIpConflictsCheck
527
     ])
528
  , ("OpNetworkDisconnect",
529
     [ pGroupName
530
     , pNetworkName
531
     , pIpConflictsCheck
532
     ])
533
  , ("OpNetworkQuery", dOldQueryNoLocking)
534
  , ("OpRestrictedCommand",
535
     [ pUseLocking
536
     , pRequiredNodes
537
     , pRestrictedCommand
538
     ])
539
  ])
540

    
541
-- | Returns the OP_ID for a given opcode value.
542
$(genOpID ''OpCode "opID")
543

    
544
-- | A list of all defined/supported opcode IDs.
545
$(genAllOpIDs ''OpCode "allOpIDs")
546

    
547
instance JSON OpCode where
548
  readJSON = loadOpCode
549
  showJSON = saveOpCode
550

    
551
-- | Generic\/common opcode parameters.
552
$(buildObject "CommonOpParams" "op"
553
  [ pDryRun
554
  , pDebugLevel
555
  , pOpPriority
556
  , pDependencies
557
  , pComment
558
  ])
559

    
560
-- | Default common parameter values.
561
defOpParams :: CommonOpParams
562
defOpParams =
563
  CommonOpParams { opDryRun     = Nothing
564
                 , opDebugLevel = Nothing
565
                 , opPriority   = OpPrioNormal
566
                 , opDepends    = Nothing
567
                 , opComment    = Nothing
568
                 }
569

    
570
-- | The top-level opcode type.
571
data MetaOpCode = MetaOpCode CommonOpParams OpCode
572
                  deriving (Show, Eq)
573

    
574
-- | JSON serialisation for 'MetaOpCode'.
575
showMeta :: MetaOpCode -> JSValue
576
showMeta (MetaOpCode params op) =
577
  let objparams = toDictCommonOpParams params
578
      objop = toDictOpCode op
579
  in makeObj (objparams ++ objop)
580

    
581
-- | JSON deserialisation for 'MetaOpCode'
582
readMeta :: JSValue -> Text.JSON.Result MetaOpCode
583
readMeta v = do
584
  meta <- readJSON v
585
  op <- readJSON v
586
  return $ MetaOpCode meta op
587

    
588
instance JSON MetaOpCode where
589
  showJSON = showMeta
590
  readJSON = readMeta
591

    
592
-- | Wraps an 'OpCode' with the default parameters to build a
593
-- 'MetaOpCode'.
594
wrapOpCode :: OpCode -> MetaOpCode
595
wrapOpCode = MetaOpCode defOpParams
596

    
597
-- | Sets the comment on a meta opcode.
598
setOpComment :: String -> MetaOpCode -> MetaOpCode
599
setOpComment comment (MetaOpCode common op) =
600
  MetaOpCode (common { opComment = Just comment}) op