Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ 1dbceab9

History | View | Annotate | Download (10.8 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
  ) where
42

    
43
import Text.JSON (readJSON, showJSON, JSON())
44

    
45
import Ganeti.THH
46

    
47
import Ganeti.OpParams
48

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

    
532
-- | Returns the OP_ID for a given opcode value.
533
$(genOpID ''OpCode "opID")
534

    
535
-- | A list of all defined/supported opcode IDs.
536
$(genAllOpIDs ''OpCode "allOpIDs")
537

    
538
instance JSON OpCode where
539
  readJSON = loadOpCode
540
  showJSON = saveOpCode