Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ 4a826364

History | View | Annotate | Download (12.4 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
     , pInstTags
298
     ])
299
  , ("OpInstanceMultiAlloc",
300
     [ pIallocator
301
     , pMultiAllocInstances
302
     ])
303
  , ("OpInstanceReinstall",
304
     [ pInstanceName
305
     , pForceVariant
306
     , pInstOs
307
     , pTempOsParams
308
     ])
309
  , ("OpInstanceRemove",
310
     [ pInstanceName
311
     , pShutdownTimeout
312
     , pIgnoreFailures
313
     ])
314
  , ("OpInstanceRename",
315
     [ pInstanceName
316
     , pNewName
317
     , pNameCheck
318
     , pIpCheck
319
     ])
320
  , ("OpInstanceStartup",
321
     [ pInstanceName
322
     , pForce
323
     , pIgnoreOfflineNodes
324
     , pTempHvParams
325
     , pTempBeParams
326
     , pNoRemember
327
     , pStartupPaused
328
     ])
329
  , ("OpInstanceShutdown",
330
     [ pInstanceName
331
     , pIgnoreOfflineNodes
332
     , pShutdownTimeout'
333
     , pNoRemember
334
     ])
335
  , ("OpInstanceReboot",
336
     [ pInstanceName
337
     , pShutdownTimeout
338
     , pIgnoreSecondaries
339
     , pRebootType
340
     ])
341
  , ("OpInstanceMove",
342
     [ pInstanceName
343
     , pShutdownTimeout
344
     , pIgnoreIpolicy
345
     , pMoveTargetNode
346
     , pIgnoreConsistency
347
     ])
348
  , ("OpInstanceConsole",
349
     [ pInstanceName ])
350
  , ("OpInstanceActivateDisks",
351
     [ pInstanceName
352
     , pIgnoreDiskSize
353
     , pWaitForSyncFalse
354
     ])
355
  , ("OpInstanceDeactivateDisks",
356
     [ pInstanceName
357
     , pForce
358
     ])
359
  , ("OpInstanceRecreateDisks",
360
     [ pInstanceName
361
     , pRecreateDisksInfo
362
     , pNodes
363
     , pIallocator
364
     ])
365
  , ("OpInstanceQuery", dOldQuery)
366
  , ("OpInstanceQueryData",
367
     [ pUseLocking
368
     , pInstances
369
     , pStatic
370
     ])
371
  , ("OpInstanceSetParams",
372
     [ pInstanceName
373
     , pForce
374
     , pForceVariant
375
     , pIgnoreIpolicy
376
     , pInstParamsNicChanges
377
     , pInstParamsDiskChanges
378
     , pInstBeParams
379
     , pRuntimeMem
380
     , pInstHvParams
381
     , pDiskTemplate
382
     , pRemoteNode
383
     , pOsNameChange
384
     , pInstOsParams
385
     , pWaitForSync
386
     , pOffline
387
     , pIpConflictsCheck
388
     ])
389
  , ("OpInstanceGrowDisk",
390
     [ pInstanceName
391
     , pWaitForSync
392
     , pDiskIndex
393
     , pDiskChgAmount
394
     , pDiskChgAbsolute
395
     ])
396
  , ("OpInstanceChangeGroup",
397
     [ pInstanceName
398
     , pEarlyRelease
399
     , pIallocator
400
     , pTargetGroups
401
     ])
402
  , ("OpGroupAdd",
403
     [ pGroupName
404
     , pNodeGroupAllocPolicy
405
     , pGroupNodeParams
406
     , pDiskParams
407
     , pHvState
408
     , pDiskState
409
     , pIpolicy
410
     ])
411
  , ("OpGroupAssignNodes",
412
     [ pGroupName
413
     , pForce
414
     , pRequiredNodes
415
     ])
416
  , ("OpGroupQuery", dOldQueryNoLocking)
417
  , ("OpGroupSetParams",
418
     [ pGroupName
419
     , pNodeGroupAllocPolicy
420
     , pGroupNodeParams
421
     , pDiskParams
422
     , pHvState
423
     , pDiskState
424
     , pIpolicy
425
     ])
426
  , ("OpGroupRemove",
427
     [ pGroupName ])
428
  , ("OpGroupRename",
429
     [ pGroupName
430
     , pNewName
431
     ])
432
  , ("OpGroupEvacuate",
433
     [ pGroupName
434
     , pEarlyRelease
435
     , pIallocator
436
     , pTargetGroups
437
     ])
438
  , ("OpOsDiagnose",
439
     [ pOutputFields
440
     , pNames ])
441
  , ("OpBackupQuery",
442
     [ pUseLocking
443
     , pNodes
444
     ])
445
  , ("OpBackupPrepare",
446
     [ pInstanceName
447
     , pExportMode
448
     ])
449
  , ("OpBackupExport",
450
     [ pInstanceName
451
     , pShutdownTimeout
452
     , pExportTargetNode
453
     , pShutdownInstance
454
     , pRemoveInstance
455
     , pIgnoreRemoveFailures
456
     , pExportMode
457
     , pX509KeyName
458
     , pX509DestCA
459
     ])
460
  , ("OpBackupRemove",
461
     [ pInstanceName ])
462
  , ("OpTestAllocator",
463
     [ pIAllocatorDirection
464
     , pIAllocatorMode
465
     , pIAllocatorReqName
466
     , pIAllocatorNics
467
     , pIAllocatorDisks
468
     , pHypervisor
469
     , pIallocator
470
     , pInstTags
471
     , pIAllocatorMemory
472
     , pIAllocatorVCpus
473
     , pIAllocatorOs
474
     , pDiskTemplate
475
     , pIAllocatorInstances
476
     , pIAllocatorEvacMode
477
     , pTargetGroups
478
     , pIAllocatorSpindleUse
479
     , pIAllocatorCount
480
     ])
481
  , ("OpTestJqueue",
482
     [ pJQueueNotifyWaitLock
483
     , pJQueueNotifyExec
484
     , pJQueueLogMessages
485
     , pJQueueFail
486
     ])
487
  , ("OpTestDummy",
488
     [ pTestDummyResult
489
     , pTestDummyMessages
490
     , pTestDummyFail
491
     , pTestDummySubmitJobs
492
     ])
493
  , ("OpNetworkAdd",
494
     [ pNetworkName
495
     , pNetworkType
496
     , pNetworkAddress4
497
     , pNetworkGateway4
498
     , pNetworkAddress6
499
     , pNetworkGateway6
500
     , pNetworkMacPrefix
501
     , pNetworkAddRsvdIps
502
     , pIpConflictsCheck
503
     , pInstTags
504
     ])
505
  , ("OpNetworkRemove",
506
     [ pNetworkName
507
     , pForce
508
     ])
509
  , ("OpNetworkSetParams",
510
     [ pNetworkName
511
     , pNetworkType
512
     , pNetworkGateway4
513
     , pNetworkAddress6
514
     , pNetworkGateway6
515
     , pNetworkMacPrefix
516
     , pNetworkAddRsvdIps
517
     , pNetworkRemoveRsvdIps
518
     ])
519
  , ("OpNetworkConnect",
520
     [ pGroupName
521
     , pNetworkName
522
     , pNetworkMode
523
     , pNetworkLink
524
     , pIpConflictsCheck
525
     ])
526
  , ("OpNetworkDisconnect",
527
     [ pGroupName
528
     , pNetworkName
529
     , pIpConflictsCheck
530
     ])
531
  , ("OpNetworkQuery", dOldQueryNoLocking)
532
  , ("OpRestrictedCommand",
533
     [ pUseLocking
534
     , pRequiredNodes
535
     , pRestrictedCommand
536
     ])
537
  ])
538

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

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

    
545
instance JSON OpCode where
546
  readJSON = loadOpCode
547
  showJSON = saveOpCode
548

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

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

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

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

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

    
586
instance JSON MetaOpCode where
587
  showJSON = showMeta
588
  readJSON = readMeta
589

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

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