Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpCodes.hs @ a3f02317

History | View | Annotate | Download (10 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",
191
     [ pOutputFields
192
     , pUseLocking
193
     , pNames
194
     ])
195
  , ("OpNodeQueryvols",
196
     [ pOutputFields
197
     , pNodes
198
     ])
199
  , ("OpNodeQueryStorage",
200
     [ pOutputFields
201
     , pStorageType
202
     , pNodes
203
     , pStorageName
204
     ])
205
  , ("OpNodeModifyStorage",
206
     [ pNodeName
207
     , pStorageType
208
     , pStorageName
209
     , pStorageChanges
210
     ])
211
  , ("OpRepairNodeStorage",
212
     [ pNodeName
213
     , pStorageType
214
     , pStorageName
215
     , pIgnoreConsistency
216
     ])
217
  , ("OpNodeSetParams",
218
     [ pNodeName
219
     , pForce
220
     , pHvState
221
     , pDiskState
222
     , pMasterCandidate
223
     , pOffline
224
     , pDrained
225
     , pAutoPromote
226
     , pMasterCapable
227
     , pVmCapable
228
     , pSecondaryIp
229
     , pNdParams
230
     ])
231
  , ("OpNodePowercycle",
232
     [ pNodeName
233
     , pForce
234
     ])
235
  , ("OpNodeMigrate",
236
     [ pNodeName
237
     , pMigrationMode
238
     , pMigrationLive
239
     , pMigrationTargetNode
240
     , pAllowRuntimeChgs
241
     , pIgnoreIpolicy
242
     , pIallocator
243
     ])
244
  , ("OpNodeEvacuate",
245
     [ pEarlyRelease
246
     , pNodeName
247
     , pRemoteNode
248
     , pIallocator
249
     , pEvacMode
250
     ])
251
  , ("OpInstanceCreate",
252
     [ pInstanceName
253
     , pForceVariant
254
     , pWaitForSync
255
     , pNameCheck
256
     , pIgnoreIpolicy
257
     , pInstBeParams
258
     , pInstDisks
259
     , pDiskTemplate
260
     , pFileDriver
261
     , pFileStorageDir
262
     , pInstHvParams
263
     , pHypervisor
264
     , pIallocator
265
     , pResetDefaults
266
     , pIpCheck
267
     , pIpConflictsCheck
268
     , pInstCreateMode
269
     , pInstNics
270
     , pNoInstall
271
     , pInstOsParams
272
     , pInstOs
273
     , pPrimaryNode
274
     , pSecondaryNode
275
     , pSourceHandshake
276
     , pSourceInstance
277
     , pSourceShutdownTimeout
278
     , pSourceX509Ca
279
     , pSrcNode
280
     , pSrcPath
281
     , pStartInstance
282
     , pInstTags
283
     ])
284
  , ("OpInstanceMultiAlloc",
285
     [ pIallocator
286
     , pMultiAllocInstances
287
     ])
288
  , ("OpInstanceReinstall",
289
     [ pInstanceName
290
     , pForceVariant
291
     , pInstOs
292
     , pTempOsParams
293
     ])
294
  , ("OpInstanceRemove",
295
     [ pInstanceName
296
     , pShutdownTimeout
297
     , pIgnoreFailures
298
     ])
299
  , ("OpInstanceRename",
300
     [ pInstanceName
301
     , pNewName
302
     , pNameCheck
303
     , pIpCheck
304
     ])
305
  , ("OpInstanceStartup",
306
     [ pInstanceName
307
     , pForce
308
     , pIgnoreOfflineNodes
309
     , pTempHvParams
310
     , pTempBeParams
311
     , pNoRemember
312
     , pStartupPaused
313
     ])
314
  , ("OpInstanceShutdown",
315
     [ pInstanceName
316
     , pIgnoreOfflineNodes
317
     , pShutdownTimeout'
318
     , pNoRemember
319
     ])
320
  , ("OpInstanceReboot",
321
     [ pInstanceName
322
     , pShutdownTimeout
323
     , pIgnoreSecondaries
324
     , pRebootType
325
     ])
326
  , ("OpInstanceMove",
327
     [ pInstanceName
328
     , pShutdownTimeout
329
     , pIgnoreIpolicy
330
     , pMoveTargetNode
331
     , pIgnoreConsistency
332
     ])
333
  , ("OpInstanceConsole",
334
     [ pInstanceName ])
335
  , ("OpInstanceActivateDisks",
336
     [ pInstanceName
337
     , pIgnoreDiskSize
338
     , pWaitForSyncFalse
339
     ])
340
  , ("OpInstanceDeactivateDisks",
341
     [ pInstanceName
342
     , pForce
343
     ])
344
  , ("OpInstanceRecreateDisks",
345
     [ pInstanceName
346
     , pRecreateDisksInfo
347
     , pNodes
348
     , pIallocator
349
     ])
350
  , ("OpInstanceQueryData",
351
     [ pUseLocking
352
     , pInstances
353
     , pStatic
354
     ])
355
  , ("OpInstanceSetParams",
356
     [ pInstanceName
357
     , pForce
358
     , pForceVariant
359
     , pIgnoreIpolicy
360
     , pInstParamsNicChanges
361
     , pInstParamsDiskChanges
362
     , pInstBeParams
363
     , pRuntimeMem
364
     , pInstHvParams
365
     , pDiskTemplate
366
     , pRemoteNode
367
     , pOsNameChange
368
     , pInstOsParams
369
     , pWaitForSync
370
     , pOffline
371
     , pIpConflictsCheck
372
     ])
373
  , ("OpInstanceGrowDisk",
374
     [ pInstanceName
375
     , pWaitForSync
376
     , pDiskIndex
377
     , pDiskChgAmount
378
     , pDiskChgAbsolute
379
     ])
380
  , ("OpInstanceChangeGroup",
381
     [ pInstanceName
382
     , pEarlyRelease
383
     , pIallocator
384
     , pTargetGroups
385
     ])
386
  , ("OpGroupAdd",
387
     [ pGroupName
388
     , pNodeGroupAllocPolicy
389
     , pGroupNodeParams
390
     , pDiskParams
391
     , pHvState
392
     , pDiskState
393
     , pIpolicy
394
     ])
395
  , ("OpGroupAssignNodes",
396
     [ pGroupName
397
     , pForce
398
     , pRequiredNodes
399
     ])
400
  , ("OpGroupQuery",
401
     [ pOutputFields
402
     , pNames
403
     ])
404
  , ("OpGroupSetParams",
405
     [ pGroupName
406
     , pNodeGroupAllocPolicy
407
     , pGroupNodeParams
408
     , pDiskParams
409
     , pHvState
410
     , pDiskState
411
     , pIpolicy
412
     ])
413
  , ("OpGroupRemove",
414
     [ pGroupName ])
415
  , ("OpGroupRename",
416
     [ pGroupName
417
     , pNewName
418
     ])
419
  , ("OpGroupEvacuate",
420
     [ pGroupName
421
     , pEarlyRelease
422
     , pIallocator
423
     , pTargetGroups
424
     ])
425
  , ("OpOsDiagnose",
426
     [ pOutputFields
427
     , pNames ])
428
  , ("OpBackupQuery",
429
     [ pUseLocking
430
     , pNodes
431
     ])
432
  , ("OpBackupPrepare",
433
     [ pInstanceName
434
     , pExportMode
435
     ])
436
  , ("OpBackupExport",
437
     [ pInstanceName
438
     , pShutdownTimeout
439
     , pExportTargetNode
440
     , pRemoveInstance
441
     , pIgnoreRemoveFailures
442
     , pExportMode
443
     , pX509KeyName
444
     , pX509DestCA
445
     ])
446
  , ("OpBackupRemove",
447
     [ pInstanceName ])
448
  , ("OpTestAllocator",
449
     [ pIAllocatorDirection
450
     , pIAllocatorMode
451
     , pIAllocatorReqName
452
     , pIAllocatorNics
453
     , pIAllocatorDisks
454
     , pHypervisor
455
     , pIallocator
456
     , pInstTags
457
     , pIAllocatorMemory
458
     , pIAllocatorVCpus
459
     , pIAllocatorOs
460
     , pDiskTemplate
461
     , pIAllocatorInstances
462
     , pIAllocatorEvacMode
463
     , pTargetGroups
464
     , pIAllocatorSpindleUse
465
     , pIAllocatorCount
466
     ])
467
  , ("OpTestJqueue",
468
     [ pJQueueNotifyWaitLock
469
     , pJQueueNotifyExec
470
     , pJQueueLogMessages
471
     , pJQueueFail
472
     ])
473
  , ("OpTestDummy",
474
     [ pTestDummyResult
475
     , pTestDummyMessages
476
     , pTestDummyFail
477
     , pTestDummySubmitJobs
478
     ])
479
  ])
480

    
481
-- | Returns the OP_ID for a given opcode value.
482
$(genOpID ''OpCode "opID")
483

    
484
-- | A list of all defined/supported opcode IDs.
485
$(genAllOpIDs ''OpCode "allOpIDs")
486

    
487
instance JSON OpCode where
488
  readJSON = loadOpCode
489
  showJSON = saveOpCode