Revision e89a9021 lib/opcodes.py

b/lib/opcodes.py
163 163
    """
164 164
    assert "__slots__" not in attrs, \
165 165
      "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
166
    assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
166 167

  
167
    op_id = _NameToId(name)
168
    if "OP_ID" in attrs:
169
      assert attrs["OP_ID"] == op_id, ("Class '%s' defining wrong OP_ID"
170
                                       " attribute %s, should be %s" %
171
                                       (name, attrs["OP_ID"], op_id))
172

  
173
    attrs["OP_ID"] = op_id
168
    attrs["OP_ID"] = _NameToId(name)
174 169

  
175 170
    # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
176 171
    params = attrs.setdefault("OP_PARAMS", [])
......
193 188
  field handling.
194 189

  
195 190
  """
191
  # pylint: disable-msg=E1101
192
  # as OP_ID is dynamically defined
196 193
  __metaclass__ = _AutoOpParamSlots
197 194

  
198
  OP_ID = None
199

  
200 195
  def __init__(self, **kwargs):
201 196
    """Constructor for BaseOpCode.
202 197

  
......
328 323
  @ivar priority: Opcode priority for queue
329 324

  
330 325
  """
331
  OP_ID = "OP_CODE"
326
  # pylint: disable-msg=E1101
327
  # as OP_ID is dynamically defined
332 328
  WITH_LU = True
333 329
  OP_PARAMS = [
334 330
    ("dry_run", None, ht.TMaybeBool),
......
412 408
  after the cluster has been initialized.
413 409

  
414 410
  """
415
  OP_ID = "OP_CLUSTER_POST_INIT"
416 411

  
417 412

  
418 413
class OpClusterDestroy(OpCode):
......
422 417
  lost after the execution of this opcode.
423 418

  
424 419
  """
425
  OP_ID = "OP_CLUSTER_DESTROY"
426 420

  
427 421

  
428 422
class OpClusterQuery(OpCode):
429 423
  """Query cluster information."""
430
  OP_ID = "OP_CLUSTER_QUERY"
431 424

  
432 425

  
433 426
class OpClusterVerify(OpCode):
......
440 433
                     only L{constants.VERIFY_NPLUSONE_MEM} can be passed
441 434

  
442 435
  """
443
  OP_ID = "OP_CLUSTER_VERIFY"
444 436
  OP_PARAMS = [
445 437
    ("skip_checks", ht.EmptyList,
446 438
     ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS))),
......
471 463
  consideration. This might need to be revisited in the future.
472 464

  
473 465
  """
474
  OP_ID = "OP_CLUSTER_VERIFY_DISKS"
475 466

  
476 467

  
477 468
class OpClusterRepairDiskSizes(OpCode):
......
490 481
  @ivar instances: the list of instances to check, or empty for all instances
491 482

  
492 483
  """
493
  OP_ID = "OP_CLUSTER_REPAIR_DISK_SIZES"
494 484
  OP_PARAMS = [
495 485
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
496 486
    ]
......
498 488

  
499 489
class OpClusterConfigQuery(OpCode):
500 490
  """Query cluster configuration values."""
501
  OP_ID = "OP_CLUSTER_CONFIG_QUERY"
502 491
  OP_PARAMS = [
503 492
    _POutputFields
504 493
    ]
......
513 502
              address.
514 503

  
515 504
  """
516
  OP_ID = "OP_CLUSTER_RENAME"
517 505
  OP_DSC_FIELD = "name"
518 506
  OP_PARAMS = [
519 507
    ("name", ht.NoDefault, ht.TNonEmptyString),
......
527 515
  @ivar vg_name: The new volume group name or None to disable LVM usage.
528 516

  
529 517
  """
530
  OP_ID = "OP_CLUSTER_SET_PARAMS"
531 518
  OP_PARAMS = [
532 519
    ("vg_name", None, ht.TMaybeString),
533 520
    ("enabled_hypervisors", None,
......
569 556
  """Force a full push of the cluster configuration.
570 557

  
571 558
  """
572
  OP_ID = "OP_CLUSTER_REDIST_CONF"
573 559

  
574 560

  
575 561
class OpQuery(OpCode):
......
580 566
  @ivar filter: Query filter
581 567

  
582 568
  """
583
  OP_ID = "OP_QUERY"
584 569
  OP_PARAMS = [
585 570
    ("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)),
586 571
    ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
......
596 581
  @ivar fields: List of fields to retrieve
597 582

  
598 583
  """
599
  OP_ID = "OP_QUERY_FIELDS"
600 584
  OP_PARAMS = [
601 585
    ("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)),
602 586
    ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString))),
......
605 589

  
606 590
class OpOobCommand(OpCode):
607 591
  """Interact with OOB."""
608
  OP_ID = "OP_OOB_COMMAND"
609 592
  OP_PARAMS = [
610 593
    _PNodeName,
611 594
    ("command", None, ht.TElemOf(constants.OOB_COMMANDS)),
......
623 606
                   instances on it, the operation will fail.
624 607

  
625 608
  """
626
  OP_ID = "OP_NODE_REMOVE"
627 609
  OP_DSC_FIELD = "node_name"
628 610
  OP_PARAMS = [
629 611
    _PNodeName,
......
658 640
  @ivar master_capable: The master_capable node attribute
659 641

  
660 642
  """
661
  OP_ID = "OP_NODE_ADD"
662 643
  OP_DSC_FIELD = "node_name"
663 644
  OP_PARAMS = [
664 645
    _PNodeName,
......
674 655

  
675 656
class OpNodeQuery(OpCode):
676 657
  """Compute the list of nodes."""
677
  OP_ID = "OP_NODE_QUERY"
678 658
  OP_PARAMS = [
679 659
    _POutputFields,
680 660
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
......
684 664

  
685 665
class OpNodeQueryvols(OpCode):
686 666
  """Get list of volumes on node."""
687
  OP_ID = "OP_NODE_QUERYVOLS"
688 667
  OP_PARAMS = [
689 668
    _POutputFields,
690 669
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
......
693 672

  
694 673
class OpNodeQueryStorage(OpCode):
695 674
  """Get information on storage for node(s)."""
696
  OP_ID = "OP_NODE_QUERY_STORAGE"
697 675
  OP_PARAMS = [
698 676
    _POutputFields,
699 677
    _PStorageType,
......
704 682

  
705 683
class OpNodeModifyStorage(OpCode):
706 684
  """Modifies the properies of a storage unit"""
707
  OP_ID = "OP_NODE_MODIFY_STORAGE"
708 685
  OP_PARAMS = [
709 686
    _PNodeName,
710 687
    _PStorageType,
......
715 692

  
716 693
class OpRepairNodeStorage(OpCode):
717 694
  """Repairs the volume group on a node."""
718
  OP_ID = "OP_REPAIR_NODE_STORAGE"
719 695
  OP_DSC_FIELD = "node_name"
720 696
  OP_PARAMS = [
721 697
    _PNodeName,
......
727 703

  
728 704
class OpNodeSetParams(OpCode):
729 705
  """Change the parameters of a node."""
730
  OP_ID = "OP_NODE_SET_PARAMS"
731 706
  OP_DSC_FIELD = "node_name"
732 707
  OP_PARAMS = [
733 708
    _PNodeName,
......
746 721

  
747 722
class OpNodePowercycle(OpCode):
748 723
  """Tries to powercycle a node."""
749
  OP_ID = "OP_NODE_POWERCYCLE"
750 724
  OP_DSC_FIELD = "node_name"
751 725
  OP_PARAMS = [
752 726
    _PNodeName,
......
756 730

  
757 731
class OpNodeMigrate(OpCode):
758 732
  """Migrate all instances from a node."""
759
  OP_ID = "OP_NODE_MIGRATE"
760 733
  OP_DSC_FIELD = "node_name"
761 734
  OP_PARAMS = [
762 735
    _PNodeName,
......
767 740

  
768 741
class OpNodeEvacStrategy(OpCode):
769 742
  """Compute the evacuation strategy for a list of nodes."""
770
  OP_ID = "OP_NODE_EVAC_STRATEGY"
771 743
  OP_DSC_FIELD = "nodes"
772 744
  OP_PARAMS = [
773 745
    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
......
790 762
    (remote import only)
791 763

  
792 764
  """
793
  OP_ID = "OP_INSTANCE_CREATE"
794 765
  OP_DSC_FIELD = "instance_name"
795 766
  OP_PARAMS = [
796 767
    _PInstanceName,
......
827 798

  
828 799
class OpInstanceReinstall(OpCode):
829 800
  """Reinstall an instance's OS."""
830
  OP_ID = "OP_INSTANCE_REINSTALL"
831 801
  OP_DSC_FIELD = "instance_name"
832 802
  OP_PARAMS = [
833 803
    _PInstanceName,
......
839 809

  
840 810
class OpInstanceRemove(OpCode):
841 811
  """Remove an instance."""
842
  OP_ID = "OP_INSTANCE_REMOVE"
843 812
  OP_DSC_FIELD = "instance_name"
844 813
  OP_PARAMS = [
845 814
    _PInstanceName,
......
850 819

  
851 820
class OpInstanceRename(OpCode):
852 821
  """Rename an instance."""
853
  OP_ID = "OP_INSTANCE_RENAME"
854 822
  OP_PARAMS = [
855 823
    _PInstanceName,
856 824
    ("new_name", ht.NoDefault, ht.TNonEmptyString),
......
861 829

  
862 830
class OpInstanceStartup(OpCode):
863 831
  """Startup an instance."""
864
  OP_ID = "OP_INSTANCE_STARTUP"
865 832
  OP_DSC_FIELD = "instance_name"
866 833
  OP_PARAMS = [
867 834
    _PInstanceName,
......
874 841

  
875 842
class OpInstanceShutdown(OpCode):
876 843
  """Shutdown an instance."""
877
  OP_ID = "OP_INSTANCE_SHUTDOWN"
878 844
  OP_DSC_FIELD = "instance_name"
879 845
  OP_PARAMS = [
880 846
    _PInstanceName,
......
885 851

  
886 852
class OpInstanceReboot(OpCode):
887 853
  """Reboot an instance."""
888
  OP_ID = "OP_INSTANCE_REBOOT"
889 854
  OP_DSC_FIELD = "instance_name"
890 855
  OP_PARAMS = [
891 856
    _PInstanceName,
......
897 862

  
898 863
class OpInstanceReplaceDisks(OpCode):
899 864
  """Replace the disks of an instance."""
900
  OP_ID = "OP_INSTANCE_REPLACE_DISKS"
901 865
  OP_DSC_FIELD = "instance_name"
902 866
  OP_PARAMS = [
903 867
    _PInstanceName,
......
911 875

  
912 876
class OpInstanceFailover(OpCode):
913 877
  """Failover an instance."""
914
  OP_ID = "OP_INSTANCE_FAILOVER"
915 878
  OP_DSC_FIELD = "instance_name"
916 879
  OP_PARAMS = [
917 880
    _PInstanceName,
......
930 893
  @ivar mode: the migration mode (live, non-live or None for auto)
931 894

  
932 895
  """
933
  OP_ID = "OP_INSTANCE_MIGRATE"
934 896
  OP_DSC_FIELD = "instance_name"
935 897
  OP_PARAMS = [
936 898
    _PInstanceName,
......
950 912
  @ivar target_node: the destination node
951 913

  
952 914
  """
953
  OP_ID = "OP_INSTANCE_MOVE"
954 915
  OP_DSC_FIELD = "instance_name"
955 916
  OP_PARAMS = [
956 917
    _PInstanceName,
......
961 922

  
962 923
class OpInstanceConsole(OpCode):
963 924
  """Connect to an instance's console."""
964
  OP_ID = "OP_INSTANCE_CONSOLE"
965 925
  OP_DSC_FIELD = "instance_name"
966 926
  OP_PARAMS = [
967 927
    _PInstanceName
......
970 930

  
971 931
class OpInstanceActivateDisks(OpCode):
972 932
  """Activate an instance's disks."""
973
  OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
974 933
  OP_DSC_FIELD = "instance_name"
975 934
  OP_PARAMS = [
976 935
    _PInstanceName,
......
980 939

  
981 940
class OpInstanceDeactivateDisks(OpCode):
982 941
  """Deactivate an instance's disks."""
983
  OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
984 942
  OP_DSC_FIELD = "instance_name"
985 943
  OP_PARAMS = [
986 944
    _PInstanceName
......
989 947

  
990 948
class OpInstanceRecreateDisks(OpCode):
991 949
  """Deactivate an instance's disks."""
992
  OP_ID = "OP_INSTANCE_RECREATE_DISKS"
993 950
  OP_DSC_FIELD = "instance_name"
994 951
  OP_PARAMS = [
995 952
    _PInstanceName,
......
999 956

  
1000 957
class OpInstanceQuery(OpCode):
1001 958
  """Compute the list of instances."""
1002
  OP_ID = "OP_INSTANCE_QUERY"
1003 959
  OP_PARAMS = [
1004 960
    _POutputFields,
1005 961
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
......
1009 965

  
1010 966
class OpInstanceQueryData(OpCode):
1011 967
  """Compute the run-time status of instances."""
1012
  OP_ID = "OP_INSTANCE_QUERY_DATA"
1013 968
  OP_PARAMS = [
1014 969
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
1015 970
    ("static", False, ht.TBool),
......
1018 973

  
1019 974
class OpInstanceSetParams(OpCode):
1020 975
  """Change the parameters of an instance."""
1021
  OP_ID = "OP_INSTANCE_SET_PARAMS"
1022 976
  OP_DSC_FIELD = "instance_name"
1023 977
  OP_PARAMS = [
1024 978
    _PInstanceName,
......
1037 991

  
1038 992
class OpInstanceGrowDisk(OpCode):
1039 993
  """Grow a disk of an instance."""
1040
  OP_ID = "OP_INSTANCE_GROW_DISK"
1041 994
  OP_DSC_FIELD = "instance_name"
1042 995
  OP_PARAMS = [
1043 996
    _PInstanceName,
......
1051 1004

  
1052 1005
class OpGroupAdd(OpCode):
1053 1006
  """Add a node group to the cluster."""
1054
  OP_ID = "OP_GROUP_ADD"
1055 1007
  OP_DSC_FIELD = "group_name"
1056 1008
  OP_PARAMS = [
1057 1009
    _PGroupName,
......
1063 1015

  
1064 1016
class OpGroupAssignNodes(OpCode):
1065 1017
  """Assign nodes to a node group."""
1066
  OP_ID = "OP_GROUP_ASSIGN_NODES"
1067 1018
  OP_DSC_FIELD = "group_name"
1068 1019
  OP_PARAMS = [
1069 1020
    _PGroupName,
......
1074 1025

  
1075 1026
class OpGroupQuery(OpCode):
1076 1027
  """Compute the list of node groups."""
1077
  OP_ID = "OP_GROUP_QUERY"
1078 1028
  OP_PARAMS = [
1079 1029
    _POutputFields,
1080 1030
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
......
1083 1033

  
1084 1034
class OpGroupSetParams(OpCode):
1085 1035
  """Change the parameters of a node group."""
1086
  OP_ID = "OP_GROUP_SET_PARAMS"
1087 1036
  OP_DSC_FIELD = "group_name"
1088 1037
  OP_PARAMS = [
1089 1038
    _PGroupName,
......
1095 1044

  
1096 1045
class OpGroupRemove(OpCode):
1097 1046
  """Remove a node group from the cluster."""
1098
  OP_ID = "OP_GROUP_REMOVE"
1099 1047
  OP_DSC_FIELD = "group_name"
1100 1048
  OP_PARAMS = [
1101 1049
    _PGroupName,
......
1104 1052

  
1105 1053
class OpGroupRename(OpCode):
1106 1054
  """Rename a node group in the cluster."""
1107
  OP_ID = "OP_GROUP_RENAME"
1108 1055
  OP_DSC_FIELD = "old_name"
1109 1056
  OP_PARAMS = [
1110 1057
    ("old_name", ht.NoDefault, ht.TNonEmptyString),
......
1115 1062
# OS opcodes
1116 1063
class OpOsDiagnose(OpCode):
1117 1064
  """Compute the list of guest operating systems."""
1118
  OP_ID = "OP_OS_DIAGNOSE"
1119 1065
  OP_PARAMS = [
1120 1066
    _POutputFields,
1121 1067
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
......
1125 1071
# Exports opcodes
1126 1072
class OpBackupQuery(OpCode):
1127 1073
  """Compute the list of exported images."""
1128
  OP_ID = "OP_BACKUP_QUERY"
1129 1074
  OP_PARAMS = [
1130 1075
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
1131 1076
    ("use_locking", False, ht.TBool),
......
1139 1084
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1140 1085

  
1141 1086
  """
1142
  OP_ID = "OP_BACKUP_PREPARE"
1143 1087
  OP_DSC_FIELD = "instance_name"
1144 1088
  OP_PARAMS = [
1145 1089
    _PInstanceName,
......
1163 1107
                             only)
1164 1108

  
1165 1109
  """
1166
  OP_ID = "OP_BACKUP_EXPORT"
1167 1110
  OP_DSC_FIELD = "instance_name"
1168 1111
  OP_PARAMS = [
1169 1112
    _PInstanceName,
......
1182 1125

  
1183 1126
class OpBackupRemove(OpCode):
1184 1127
  """Remove an instance's export."""
1185
  OP_ID = "OP_BACKUP_REMOVE"
1186 1128
  OP_DSC_FIELD = "instance_name"
1187 1129
  OP_PARAMS = [
1188 1130
    _PInstanceName,
......
1192 1134
# Tags opcodes
1193 1135
class OpTagsGet(OpCode):
1194 1136
  """Returns the tags of the given object."""
1195
  OP_ID = "OP_TAGS_GET"
1196 1137
  OP_DSC_FIELD = "name"
1197 1138
  OP_PARAMS = [
1198 1139
    _PTagKind,
......
1203 1144

  
1204 1145
class OpTagsSearch(OpCode):
1205 1146
  """Searches the tags in the cluster for a given pattern."""
1206
  OP_ID = "OP_TAGS_SEARCH"
1207 1147
  OP_DSC_FIELD = "pattern"
1208 1148
  OP_PARAMS = [
1209 1149
    ("pattern", ht.NoDefault, ht.TNonEmptyString),
......
1212 1152

  
1213 1153
class OpTagsSet(OpCode):
1214 1154
  """Add a list of tags on a given object."""
1215
  OP_ID = "OP_TAGS_SET"
1216 1155
  OP_PARAMS = [
1217 1156
    _PTagKind,
1218 1157
    _PTags,
......
1223 1162

  
1224 1163
class OpTagsDel(OpCode):
1225 1164
  """Remove a list of tags from a given object."""
1226
  OP_ID = "OP_TAGS_DEL"
1227 1165
  OP_PARAMS = [
1228 1166
    _PTagKind,
1229 1167
    _PTags,
......
1253 1191
  generator. The case of duration == 0 will not be treated specially.
1254 1192

  
1255 1193
  """
1256
  OP_ID = "OP_TEST_DELAY"
1257 1194
  OP_DSC_FIELD = "duration"
1258 1195
  OP_PARAMS = [
1259 1196
    ("duration", ht.NoDefault, ht.TFloat),
......
1274 1211
      return the allocator output (direction 'out')
1275 1212

  
1276 1213
  """
1277
  OP_ID = "OP_TEST_ALLOCATOR"
1278 1214
  OP_DSC_FIELD = "allocator"
1279 1215
  OP_PARAMS = [
1280 1216
    ("direction", ht.NoDefault,
......
1300 1236
  """Utility opcode to test some aspects of the job queue.
1301 1237

  
1302 1238
  """
1303
  OP_ID = "OP_TEST_JQUEUE"
1304 1239
  OP_PARAMS = [
1305 1240
    ("notify_waitlock", False, ht.TBool),
1306 1241
    ("notify_exec", False, ht.TBool),
......
1313 1248
  """Utility opcode used by unittests.
1314 1249

  
1315 1250
  """
1316
  OP_ID = "OP_TEST_DUMMY"
1317 1251
  OP_PARAMS = [
1318 1252
    ("result", ht.NoDefault, ht.NoType),
1319 1253
    ("messages", ht.NoDefault, ht.NoType),

Also available in: Unified diff