Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ 3131adc7

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
  ) where
41

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

    
44
import Ganeti.THH
45

    
46
import Ganeti.OpParams
47

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

    
518
-- | Returns the OP_ID for a given opcode value.
519
$(genOpID ''OpCode "opID")
520

    
521
-- | A list of all defined/supported opcode IDs.
522
$(genAllOpIDs ''OpCode "allOpIDs")
523

    
524
instance JSON OpCode where
525
  readJSON = loadOpCode
526
  showJSON = saveOpCode