Package ganeti :: Module opcodes
[hide private]
[frames] | no frames]

Source Code for Module ganeti.opcodes

   1  # 
   2  # 
   3   
   4  # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc. 
   5  # 
   6  # This program is free software; you can redistribute it and/or modify 
   7  # it under the terms of the GNU General Public License as published by 
   8  # the Free Software Foundation; either version 2 of the License, or 
   9  # (at your option) any later version. 
  10  # 
  11  # This program is distributed in the hope that it will be useful, but 
  12  # WITHOUT ANY WARRANTY; without even the implied warranty of 
  13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
  14  # General Public License for more details. 
  15  # 
  16  # You should have received a copy of the GNU General Public License 
  17  # along with this program; if not, write to the Free Software 
  18  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
  19  # 02110-1301, USA. 
  20   
  21   
  22  """OpCodes module 
  23   
  24  This module implements the data structures which define the cluster 
  25  operations - the so-called opcodes. 
  26   
  27  Every operation which modifies the cluster state is expressed via 
  28  opcodes. 
  29   
  30  """ 
  31   
  32  # this are practically structures, so disable the message about too 
  33  # few public methods: 
  34  # pylint: disable=R0903 
  35   
  36  import logging 
  37  import re 
  38   
  39  from ganeti import compat 
  40  from ganeti import constants 
  41  from ganeti import errors 
  42  from ganeti import ht 
  43   
  44   
  45  # Common opcode attributes 
  46   
  47  #: output fields for a query operation 
  48  _POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), 
  49                    "Selected output fields") 
  50   
  51  #: the shutdown timeout 
  52  _PShutdownTimeout = \ 
  53    ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt, 
  54     "How long to wait for instance to shut down") 
  55   
  56  #: the force parameter 
  57  _PForce = ("force", False, ht.TBool, "Whether to force the operation") 
  58   
  59  #: a required instance name (for single-instance LUs) 
  60  _PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString, 
  61                    "Instance name") 
  62   
  63  #: Whether to ignore offline nodes 
  64  _PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool, 
  65                          "Whether to ignore offline nodes") 
  66   
  67  #: a required node name (for single-node LUs) 
  68  _PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString, "Node name") 
  69   
  70  #: a required node group name (for single-group LUs) 
  71  _PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString, "Group name") 
  72   
  73  #: Migration type (live/non-live) 
  74  _PMigrationMode = ("mode", None, 
  75                     ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)), 
  76                     "Migration mode") 
  77   
  78  #: Obsolete 'live' migration mode (boolean) 
  79  _PMigrationLive = ("live", None, ht.TMaybeBool, 
  80                     "Legacy setting for live migration, do not use") 
  81   
  82  #: Tag type 
  83  _PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES), None) 
  84   
  85  #: List of tag strings 
  86  _PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None) 
  87   
  88  _PForceVariant = ("force_variant", False, ht.TBool, 
  89                    "Whether to force an unknown OS variant") 
  90   
  91  _PWaitForSync = ("wait_for_sync", True, ht.TBool, 
  92                   "Whether to wait for the disk to synchronize") 
  93   
  94  _PIgnoreConsistency = ("ignore_consistency", False, ht.TBool, 
  95                         "Whether to ignore disk consistency") 
  96   
  97  _PStorageName = ("name", ht.NoDefault, ht.TMaybeString, "Storage name") 
  98   
  99  _PUseLocking = ("use_locking", False, ht.TBool, 
 100                  "Whether to use synchronization") 
 101   
 102  _PNameCheck = ("name_check", True, ht.TBool, "Whether to check name") 
 103   
 104  _PNodeGroupAllocPolicy = \ 
 105    ("alloc_policy", None, 
 106     ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES)), 
 107     "Instance allocation policy") 
 108   
 109  _PGroupNodeParams = ("ndparams", None, ht.TMaybeDict, 
 110                       "Default node parameters for group") 
 111   
 112  _PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP), 
 113                 "Resource(s) to query for") 
 114   
 115  _PEarlyRelease = ("early_release", False, ht.TBool, 
 116                    "Whether to release locks as soon as possible") 
 117   
 118  _PIpCheckDoc = "Whether to ensure instance's IP address is inactive" 
 119   
 120  #: Do not remember instance state changes 
 121  _PNoRemember = ("no_remember", False, ht.TBool, 
 122                  "Do not remember the state change") 
 123   
 124  #: Target node for instance migration/failover 
 125  _PMigrationTargetNode = ("target_node", None, ht.TMaybeString, 
 126                           "Target node for shared-storage instances") 
 127   
 128  _PStartupPaused = ("startup_paused", False, ht.TBool, 
 129                     "Pause instance at startup") 
 130   
 131  _PVerbose = ("verbose", False, ht.TBool, "Verbose mode") 
 132   
 133  # Parameters for cluster verification 
 134  _PDebugSimulateErrors = ("debug_simulate_errors", False, ht.TBool, 
 135                           "Whether to simulate errors (useful for debugging)") 
 136  _PErrorCodes = ("error_codes", False, ht.TBool, "Error codes") 
 137  _PSkipChecks = ("skip_checks", ht.EmptyList, 
 138                  ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)), 
 139                  "Which checks to skip") 
 140   
 141  #: OP_ID conversion regular expression 
 142  _OPID_RE = re.compile("([a-z])([A-Z])") 
 143   
 144  #: Utility function for L{OpClusterSetParams} 
 145  _TestClusterOsList = ht.TOr(ht.TNone, 
 146    ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2), 
 147      ht.TMap(ht.WithDesc("GetFirstItem")(compat.fst), 
 148              ht.TElemOf(constants.DDMS_VALUES))))) 
 149   
 150   
 151  # TODO: Generate check from constants.INIC_PARAMS_TYPES 
 152  #: Utility function for testing NIC definitions 
 153  _TestNicDef = ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS), 
 154                           ht.TOr(ht.TNone, ht.TNonEmptyString)) 
 155   
 156  _TSetParamsResultItemItems = [ 
 157    ht.Comment("name of changed parameter")(ht.TNonEmptyString), 
 158    ht.TAny, 
 159    ] 
 160   
 161  _TSetParamsResult = \ 
 162    ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)), 
 163                       ht.TItems(_TSetParamsResultItemItems))) 
 164   
 165  _SUMMARY_PREFIX = { 
 166    "CLUSTER_": "C_", 
 167    "GROUP_": "G_", 
 168    "NODE_": "N_", 
 169    "INSTANCE_": "I_", 
 170    } 
 171   
 172  #: Attribute name for dependencies 
 173  DEPEND_ATTR = "depends" 
 174   
 175  #: Attribute name for comment 
 176  COMMENT_ATTR = "comment" 
177 178 179 -def _NameToId(name):
180 """Convert an opcode class name to an OP_ID. 181 182 @type name: string 183 @param name: the class name, as OpXxxYyy 184 @rtype: string 185 @return: the name in the OP_XXXX_YYYY format 186 187 """ 188 if not name.startswith("Op"): 189 return None 190 # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't 191 # consume any input, and hence we would just have all the elements 192 # in the list, one by one; but it seems that split doesn't work on 193 # non-consuming input, hence we have to process the input string a 194 # bit 195 name = _OPID_RE.sub(r"\1,\2", name) 196 elems = name.split(",") 197 return "_".join(n.upper() for n in elems)
198
199 200 -def RequireFileStorage():
201 """Checks that file storage is enabled. 202 203 While it doesn't really fit into this module, L{utils} was deemed too large 204 of a dependency to be imported for just one or two functions. 205 206 @raise errors.OpPrereqError: when file storage is disabled 207 208 """ 209 if not constants.ENABLE_FILE_STORAGE: 210 raise errors.OpPrereqError("File storage disabled at configure time", 211 errors.ECODE_INVAL)
212
213 214 -def RequireSharedFileStorage():
215 """Checks that shared file storage is enabled. 216 217 While it doesn't really fit into this module, L{utils} was deemed too large 218 of a dependency to be imported for just one or two functions. 219 220 @raise errors.OpPrereqError: when shared file storage is disabled 221 222 """ 223 if not constants.ENABLE_SHARED_FILE_STORAGE: 224 raise errors.OpPrereqError("Shared file storage disabled at" 225 " configure time", errors.ECODE_INVAL)
226
227 228 @ht.WithDesc("CheckFileStorage") 229 -def _CheckFileStorage(value):
230 """Ensures file storage is enabled if used. 231 232 """ 233 if value == constants.DT_FILE: 234 RequireFileStorage() 235 elif value == constants.DT_SHARED_FILE: 236 RequireSharedFileStorage() 237 return True
238 239 240 _CheckDiskTemplate = ht.TAnd(ht.TElemOf(constants.DISK_TEMPLATES), 241 _CheckFileStorage)
242 243 244 -def _CheckStorageType(storage_type):
245 """Ensure a given storage type is valid. 246 247 """ 248 if storage_type not in constants.VALID_STORAGE_TYPES: 249 raise errors.OpPrereqError("Unknown storage type: %s" % storage_type, 250 errors.ECODE_INVAL) 251 if storage_type == constants.ST_FILE: 252 RequireFileStorage() 253 return True
254 255 256 #: Storage type parameter 257 _PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType, 258 "Storage type")
259 260 261 -class _AutoOpParamSlots(type):
262 """Meta class for opcode definitions. 263 264 """
265 - def __new__(mcs, name, bases, attrs):
266 """Called when a class should be created. 267 268 @param mcs: The meta class 269 @param name: Name of created class 270 @param bases: Base classes 271 @type attrs: dict 272 @param attrs: Class attributes 273 274 """ 275 assert "__slots__" not in attrs, \ 276 "Class '%s' defines __slots__ when it should use OP_PARAMS" % name 277 assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name 278 279 attrs["OP_ID"] = _NameToId(name) 280 281 # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams 282 params = attrs.setdefault("OP_PARAMS", []) 283 284 # Use parameter names as slots 285 slots = [pname for (pname, _, _, _) in params] 286 287 assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \ 288 "Class '%s' uses unknown field in OP_DSC_FIELD" % name 289 290 attrs["__slots__"] = slots 291 292 return type.__new__(mcs, name, bases, attrs)
293
294 295 -class BaseOpCode(object):
296 """A simple serializable object. 297 298 This object serves as a parent class for OpCode without any custom 299 field handling. 300 301 """ 302 # pylint: disable=E1101 303 # as OP_ID is dynamically defined 304 __metaclass__ = _AutoOpParamSlots 305
306 - def __init__(self, **kwargs):
307 """Constructor for BaseOpCode. 308 309 The constructor takes only keyword arguments and will set 310 attributes on this object based on the passed arguments. As such, 311 it means that you should not pass arguments which are not in the 312 __slots__ attribute for this class. 313 314 """ 315 slots = self._all_slots() 316 for key in kwargs: 317 if key not in slots: 318 raise TypeError("Object %s doesn't support the parameter '%s'" % 319 (self.__class__.__name__, key)) 320 setattr(self, key, kwargs[key])
321
322 - def __getstate__(self):
323 """Generic serializer. 324 325 This method just returns the contents of the instance as a 326 dictionary. 327 328 @rtype: C{dict} 329 @return: the instance attributes and their values 330 331 """ 332 state = {} 333 for name in self._all_slots(): 334 if hasattr(self, name): 335 state[name] = getattr(self, name) 336 return state
337
338 - def __setstate__(self, state):
339 """Generic unserializer. 340 341 This method just restores from the serialized state the attributes 342 of the current instance. 343 344 @param state: the serialized opcode data 345 @type state: C{dict} 346 347 """ 348 if not isinstance(state, dict): 349 raise ValueError("Invalid data to __setstate__: expected dict, got %s" % 350 type(state)) 351 352 for name in self._all_slots(): 353 if name not in state and hasattr(self, name): 354 delattr(self, name) 355 356 for name in state: 357 setattr(self, name, state[name])
358 359 @classmethod
360 - def _all_slots(cls):
361 """Compute the list of all declared slots for a class. 362 363 """ 364 slots = [] 365 for parent in cls.__mro__: 366 slots.extend(getattr(parent, "__slots__", [])) 367 return slots
368 369 @classmethod
370 - def GetAllParams(cls):
371 """Compute list of all parameters for an opcode. 372 373 """ 374 slots = [] 375 for parent in cls.__mro__: 376 slots.extend(getattr(parent, "OP_PARAMS", [])) 377 return slots
378
379 - def Validate(self, set_defaults):
380 """Validate opcode parameters, optionally setting default values. 381 382 @type set_defaults: bool 383 @param set_defaults: Whether to set default values 384 @raise errors.OpPrereqError: When a parameter value doesn't match 385 requirements 386 387 """ 388 for (attr_name, default, test, _) in self.GetAllParams(): 389 assert test == ht.NoType or callable(test) 390 391 if not hasattr(self, attr_name): 392 if default == ht.NoDefault: 393 raise errors.OpPrereqError("Required parameter '%s.%s' missing" % 394 (self.OP_ID, attr_name), 395 errors.ECODE_INVAL) 396 elif set_defaults: 397 if callable(default): 398 dval = default() 399 else: 400 dval = default 401 setattr(self, attr_name, dval) 402 403 if test == ht.NoType: 404 # no tests here 405 continue 406 407 if set_defaults or hasattr(self, attr_name): 408 attr_val = getattr(self, attr_name) 409 if not test(attr_val): 410 logging.error("OpCode %s, parameter %s, has invalid type %s/value %s", 411 self.OP_ID, attr_name, type(attr_val), attr_val) 412 raise errors.OpPrereqError("Parameter '%s.%s' fails validation" % 413 (self.OP_ID, attr_name), 414 errors.ECODE_INVAL)
415
416 417 -def _BuildJobDepCheck(relative):
418 """Builds check for job dependencies (L{DEPEND_ATTR}). 419 420 @type relative: bool 421 @param relative: Whether to accept relative job IDs (negative) 422 @rtype: callable 423 424 """ 425 if relative: 426 job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId) 427 else: 428 job_id = ht.TJobId 429 430 job_dep = \ 431 ht.TAnd(ht.TIsLength(2), 432 ht.TItems([job_id, 433 ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))])) 434 435 return ht.TOr(ht.TNone, ht.TListOf(job_dep))
436 437 438 TNoRelativeJobDependencies = _BuildJobDepCheck(False) 439 440 #: List of submission status and job ID as returned by C{SubmitManyJobs} 441 _TJobIdListItem = \ 442 ht.TAnd(ht.TIsLength(2), 443 ht.TItems([ht.Comment("success")(ht.TBool), 444 ht.Comment("Job ID if successful, error message" 445 " otherwise")(ht.TOr(ht.TString, 446 ht.TJobId))])) 447 TJobIdList = ht.TListOf(_TJobIdListItem) 448 449 #: Result containing only list of submitted jobs 450 TJobIdListOnly = ht.TStrictDict(True, True, { 451 constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList), 452 })
453 454 455 -class OpCode(BaseOpCode):
456 """Abstract OpCode. 457 458 This is the root of the actual OpCode hierarchy. All clases derived 459 from this class should override OP_ID. 460 461 @cvar OP_ID: The ID of this opcode. This should be unique amongst all 462 children of this class. 463 @cvar OP_DSC_FIELD: The name of a field whose value will be included in the 464 string returned by Summary(); see the docstring of that 465 method for details). 466 @cvar OP_PARAMS: List of opcode attributes, the default values they should 467 get if not already defined, and types they must match. 468 @cvar OP_RESULT: Callable to verify opcode result 469 @cvar WITH_LU: Boolean that specifies whether this should be included in 470 mcpu's dispatch table 471 @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just 472 the check steps 473 @ivar priority: Opcode priority for queue 474 475 """ 476 # pylint: disable=E1101 477 # as OP_ID is dynamically defined 478 WITH_LU = True 479 OP_PARAMS = [ 480 ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"), 481 ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"), 482 ("priority", constants.OP_PRIO_DEFAULT, 483 ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"), 484 (DEPEND_ATTR, None, _BuildJobDepCheck(True), 485 "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)" 486 " job IDs can be used"), 487 (COMMENT_ATTR, None, ht.TMaybeString, 488 "Comment describing the purpose of the opcode"), 489 ] 490 OP_RESULT = None 491
492 - def __getstate__(self):
493 """Specialized getstate for opcodes. 494 495 This method adds to the state dictionary the OP_ID of the class, 496 so that on unload we can identify the correct class for 497 instantiating the opcode. 498 499 @rtype: C{dict} 500 @return: the state as a dictionary 501 502 """ 503 data = BaseOpCode.__getstate__(self) 504 data["OP_ID"] = self.OP_ID 505 return data
506 507 @classmethod
508 - def LoadOpCode(cls, data):
509 """Generic load opcode method. 510 511 The method identifies the correct opcode class from the dict-form 512 by looking for a OP_ID key, if this is not found, or its value is 513 not available in this module as a child of this class, we fail. 514 515 @type data: C{dict} 516 @param data: the serialized opcode 517 518 """ 519 if not isinstance(data, dict): 520 raise ValueError("Invalid data to LoadOpCode (%s)" % type(data)) 521 if "OP_ID" not in data: 522 raise ValueError("Invalid data to LoadOpcode, missing OP_ID") 523 op_id = data["OP_ID"] 524 op_class = None 525 if op_id in OP_MAPPING: 526 op_class = OP_MAPPING[op_id] 527 else: 528 raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" % 529 op_id) 530 op = op_class() 531 new_data = data.copy() 532 del new_data["OP_ID"] 533 op.__setstate__(new_data) 534 return op
535
536 - def Summary(self):
537 """Generates a summary description of this opcode. 538 539 The summary is the value of the OP_ID attribute (without the "OP_" 540 prefix), plus the value of the OP_DSC_FIELD attribute, if one was 541 defined; this field should allow to easily identify the operation 542 (for an instance creation job, e.g., it would be the instance 543 name). 544 545 """ 546 assert self.OP_ID is not None and len(self.OP_ID) > 3 547 # all OP_ID start with OP_, we remove that 548 txt = self.OP_ID[3:] 549 field_name = getattr(self, "OP_DSC_FIELD", None) 550 if field_name: 551 field_value = getattr(self, field_name, None) 552 if isinstance(field_value, (list, tuple)): 553 field_value = ",".join(str(i) for i in field_value) 554 txt = "%s(%s)" % (txt, field_value) 555 return txt
556
557 - def TinySummary(self):
558 """Generates a compact summary description of the opcode. 559 560 """ 561 assert self.OP_ID.startswith("OP_") 562 563 text = self.OP_ID[3:] 564 565 for (prefix, supplement) in _SUMMARY_PREFIX.items(): 566 if text.startswith(prefix): 567 return supplement + text[len(prefix):] 568 569 return text
570
571 572 # cluster opcodes 573 574 -class OpClusterPostInit(OpCode):
575 """Post cluster initialization. 576 577 This opcode does not touch the cluster at all. Its purpose is to run hooks 578 after the cluster has been initialized. 579 580 """
581
582 583 -class OpClusterDestroy(OpCode):
584 """Destroy the cluster. 585 586 This opcode has no other parameters. All the state is irreversibly 587 lost after the execution of this opcode. 588 589 """
590
591 592 -class OpClusterQuery(OpCode):
593 """Query cluster information."""
594
595 596 -class OpClusterVerify(OpCode):
597 """Submits all jobs necessary to verify the cluster. 598 599 """ 600 OP_PARAMS = [ 601 _PDebugSimulateErrors, 602 _PErrorCodes, 603 _PSkipChecks, 604 _PVerbose, 605 ("group_name", None, ht.TMaybeString, "Group to verify") 606 ] 607 OP_RESULT = TJobIdListOnly
608
609 610 -class OpClusterVerifyConfig(OpCode):
611 """Verify the cluster config. 612 613 """ 614 OP_PARAMS = [ 615 _PDebugSimulateErrors, 616 _PErrorCodes, 617 _PVerbose, 618 ] 619 OP_RESULT = ht.TBool
620
621 622 -class OpClusterVerifyGroup(OpCode):
623 """Run verify on a node group from the cluster. 624 625 @type skip_checks: C{list} 626 @ivar skip_checks: steps to be skipped from the verify process; this 627 needs to be a subset of 628 L{constants.VERIFY_OPTIONAL_CHECKS}; currently 629 only L{constants.VERIFY_NPLUSONE_MEM} can be passed 630 631 """ 632 OP_DSC_FIELD = "group_name" 633 OP_PARAMS = [ 634 _PGroupName, 635 _PDebugSimulateErrors, 636 _PErrorCodes, 637 _PSkipChecks, 638 _PVerbose, 639 ] 640 OP_RESULT = ht.TBool
641
642 643 -class OpClusterVerifyDisks(OpCode):
644 """Verify the cluster disks. 645 646 """ 647 OP_RESULT = TJobIdListOnly
648
649 650 -class OpGroupVerifyDisks(OpCode):
651 """Verifies the status of all disks in a node group. 652 653 Result: a tuple of three elements: 654 - dict of node names with issues (values: error msg) 655 - list of instances with degraded disks (that should be activated) 656 - dict of instances with missing logical volumes (values: (node, vol) 657 pairs with details about the missing volumes) 658 659 In normal operation, all lists should be empty. A non-empty instance 660 list (3rd element of the result) is still ok (errors were fixed) but 661 non-empty node list means some node is down, and probably there are 662 unfixable drbd errors. 663 664 Note that only instances that are drbd-based are taken into 665 consideration. This might need to be revisited in the future. 666 667 """ 668 OP_DSC_FIELD = "group_name" 669 OP_PARAMS = [ 670 _PGroupName, 671 ] 672 OP_RESULT = \ 673 ht.TAnd(ht.TIsLength(3), 674 ht.TItems([ht.TDictOf(ht.TString, ht.TString), 675 ht.TListOf(ht.TString), 676 ht.TDictOf(ht.TString, 677 ht.TListOf(ht.TListOf(ht.TString)))]))
678
679 680 -class OpClusterRepairDiskSizes(OpCode):
681 """Verify the disk sizes of the instances and fixes configuration 682 mimatches. 683 684 Parameters: optional instances list, in case we want to restrict the 685 checks to only a subset of the instances. 686 687 Result: a list of tuples, (instance, disk, new-size) for changed 688 configurations. 689 690 In normal operation, the list should be empty. 691 692 @type instances: list 693 @ivar instances: the list of instances to check, or empty for all instances 694 695 """ 696 OP_PARAMS = [ 697 ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None), 698 ]
699
700 701 -class OpClusterConfigQuery(OpCode):
702 """Query cluster configuration values.""" 703 OP_PARAMS = [ 704 _POutputFields 705 ]
706
707 708 -class OpClusterRename(OpCode):
709 """Rename the cluster. 710 711 @type name: C{str} 712 @ivar name: The new name of the cluster. The name and/or the master IP 713 address will be changed to match the new name and its IP 714 address. 715 716 """ 717 OP_DSC_FIELD = "name" 718 OP_PARAMS = [ 719 ("name", ht.NoDefault, ht.TNonEmptyString, None), 720 ]
721
722 723 -class OpClusterSetParams(OpCode):
724 """Change the parameters of the cluster. 725 726 @type vg_name: C{str} or C{None} 727 @ivar vg_name: The new volume group name or None to disable LVM usage. 728 729 """ 730 OP_PARAMS = [ 731 ("vg_name", None, ht.TMaybeString, "Volume group name"), 732 ("enabled_hypervisors", None, 733 ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue), 734 ht.TNone), 735 "List of enabled hypervisors"), 736 ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), 737 ht.TNone), 738 "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"), 739 ("beparams", None, ht.TOr(ht.TDict, ht.TNone), 740 "Cluster-wide backend parameter defaults"), 741 ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), 742 ht.TNone), 743 "Cluster-wide per-OS hypervisor parameter defaults"), 744 ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), 745 ht.TNone), 746 "Cluster-wide OS parameter defaults"), 747 ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone), 748 "Master candidate pool size"), 749 ("uid_pool", None, ht.NoType, 750 "Set UID pool, must be list of lists describing UID ranges (two items," 751 " start and end inclusive)"), 752 ("add_uids", None, ht.NoType, 753 "Extend UID pool, must be list of lists describing UID ranges (two" 754 " items, start and end inclusive) to be added"), 755 ("remove_uids", None, ht.NoType, 756 "Shrink UID pool, must be list of lists describing UID ranges (two" 757 " items, start and end inclusive) to be removed"), 758 ("maintain_node_health", None, ht.TMaybeBool, 759 "Whether to automatically maintain node health"), 760 ("prealloc_wipe_disks", None, ht.TMaybeBool, 761 "Whether to wipe disks before allocating them to instances"), 762 ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"), 763 ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"), 764 ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"), 765 ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone), 766 "Default iallocator for cluster"), 767 ("master_netdev", None, ht.TOr(ht.TString, ht.TNone), 768 "Master network device"), 769 ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone), 770 "List of reserved LVs"), 771 ("hidden_os", None, _TestClusterOsList, 772 "Modify list of hidden operating systems. Each modification must have" 773 " two items, the operation and the OS name. The operation can be" 774 " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)), 775 ("blacklisted_os", None, _TestClusterOsList, 776 "Modify list of blacklisted operating systems. Each modification must have" 777 " two items, the operation and the OS name. The operation can be" 778 " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)), 779 ]
780
781 782 -class OpClusterRedistConf(OpCode):
783 """Force a full push of the cluster configuration. 784 785 """
786
787 788 -class OpQuery(OpCode):
789 """Query for resources/items. 790 791 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP} 792 @ivar fields: List of fields to retrieve 793 @ivar filter: Query filter 794 795 """ 796 OP_DSC_FIELD = "what" 797 OP_PARAMS = [ 798 _PQueryWhat, 799 _PUseLocking, 800 ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), 801 "Requested fields"), 802 ("filter", None, ht.TOr(ht.TNone, ht.TList), 803 "Query filter"), 804 ]
805
806 807 -class OpQueryFields(OpCode):
808 """Query for available resource/item fields. 809 810 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP} 811 @ivar fields: List of fields to retrieve 812 813 """ 814 OP_DSC_FIELD = "what" 815 OP_PARAMS = [ 816 _PQueryWhat, 817 ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), 818 "Requested fields; if not given, all are returned"), 819 ]
820
821 822 -class OpOobCommand(OpCode):
823 """Interact with OOB.""" 824 OP_PARAMS = [ 825 ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), 826 "List of nodes to run the OOB command against"), 827 ("command", None, ht.TElemOf(constants.OOB_COMMANDS), 828 "OOB command to be run"), 829 ("timeout", constants.OOB_TIMEOUT, ht.TInt, 830 "Timeout before the OOB helper will be terminated"), 831 ("ignore_status", False, ht.TBool, 832 "Ignores the node offline status for power off"), 833 ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat, 834 "Time in seconds to wait between powering on nodes"), 835 ]
836
837 838 # node opcodes 839 840 -class OpNodeRemove(OpCode):
841 """Remove a node. 842 843 @type node_name: C{str} 844 @ivar node_name: The name of the node to remove. If the node still has 845 instances on it, the operation will fail. 846 847 """ 848 OP_DSC_FIELD = "node_name" 849 OP_PARAMS = [ 850 _PNodeName, 851 ]
852
853 854 -class OpNodeAdd(OpCode):
855 """Add a node to the cluster. 856 857 @type node_name: C{str} 858 @ivar node_name: The name of the node to add. This can be a short name, 859 but it will be expanded to the FQDN. 860 @type primary_ip: IP address 861 @ivar primary_ip: The primary IP of the node. This will be ignored when the 862 opcode is submitted, but will be filled during the node 863 add (so it will be visible in the job query). 864 @type secondary_ip: IP address 865 @ivar secondary_ip: The secondary IP of the node. This needs to be passed 866 if the cluster has been initialized in 'dual-network' 867 mode, otherwise it must not be given. 868 @type readd: C{bool} 869 @ivar readd: Whether to re-add an existing node to the cluster. If 870 this is not passed, then the operation will abort if the node 871 name is already in the cluster; use this parameter to 'repair' 872 a node that had its configuration broken, or was reinstalled 873 without removal from the cluster. 874 @type group: C{str} 875 @ivar group: The node group to which this node will belong. 876 @type vm_capable: C{bool} 877 @ivar vm_capable: The vm_capable node attribute 878 @type master_capable: C{bool} 879 @ivar master_capable: The master_capable node attribute 880 881 """ 882 OP_DSC_FIELD = "node_name" 883 OP_PARAMS = [ 884 _PNodeName, 885 ("primary_ip", None, ht.NoType, "Primary IP address"), 886 ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"), 887 ("readd", False, ht.TBool, "Whether node is re-added to cluster"), 888 ("group", None, ht.TMaybeString, "Initial node group"), 889 ("master_capable", None, ht.TMaybeBool, 890 "Whether node can become master or master candidate"), 891 ("vm_capable", None, ht.TMaybeBool, 892 "Whether node can host instances"), 893 ("ndparams", None, ht.TMaybeDict, "Node parameters"), 894 ]
895
896 897 -class OpNodeQuery(OpCode):
898 """Compute the list of nodes.""" 899 OP_PARAMS = [ 900 _POutputFields, 901 _PUseLocking, 902 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), 903 "Empty list to query all nodes, node names otherwise"), 904 ]
905
906 907 -class OpNodeQueryvols(OpCode):
908 """Get list of volumes on node.""" 909 OP_PARAMS = [ 910 _POutputFields, 911 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), 912 "Empty list to query all nodes, node names otherwise"), 913 ]
914
915 916 -class OpNodeQueryStorage(OpCode):
917 """Get information on storage for node(s).""" 918 OP_PARAMS = [ 919 _POutputFields, 920 _PStorageType, 921 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"), 922 ("name", None, ht.TMaybeString, "Storage name"), 923 ]
924
925 926 -class OpNodeModifyStorage(OpCode):
927 """Modifies the properies of a storage unit""" 928 OP_PARAMS = [ 929 _PNodeName, 930 _PStorageType, 931 _PStorageName, 932 ("changes", ht.NoDefault, ht.TDict, "Requested changes"), 933 ]
934
935 936 -class OpRepairNodeStorage(OpCode):
937 """Repairs the volume group on a node.""" 938 OP_DSC_FIELD = "node_name" 939 OP_PARAMS = [ 940 _PNodeName, 941 _PStorageType, 942 _PStorageName, 943 _PIgnoreConsistency, 944 ]
945
946 947 -class OpNodeSetParams(OpCode):
948 """Change the parameters of a node.""" 949 OP_DSC_FIELD = "node_name" 950 OP_PARAMS = [ 951 _PNodeName, 952 _PForce, 953 ("master_candidate", None, ht.TMaybeBool, 954 "Whether the node should become a master candidate"), 955 ("offline", None, ht.TMaybeBool, 956 "Whether the node should be marked as offline"), 957 ("drained", None, ht.TMaybeBool, 958 "Whether the node should be marked as drained"), 959 ("auto_promote", False, ht.TBool, 960 "Whether node(s) should be promoted to master candidate if necessary"), 961 ("master_capable", None, ht.TMaybeBool, 962 "Denote whether node can become master or master candidate"), 963 ("vm_capable", None, ht.TMaybeBool, 964 "Denote whether node can host instances"), 965 ("secondary_ip", None, ht.TMaybeString, 966 "Change node's secondary IP address"), 967 ("ndparams", None, ht.TMaybeDict, "Set node parameters"), 968 ("powered", None, ht.TMaybeBool, 969 "Whether the node should be marked as powered"), 970 ] 971 OP_RESULT = _TSetParamsResult
972
973 974 -class OpNodePowercycle(OpCode):
975 """Tries to powercycle a node.""" 976 OP_DSC_FIELD = "node_name" 977 OP_PARAMS = [ 978 _PNodeName, 979 _PForce, 980 ]
981
982 983 -class OpNodeMigrate(OpCode):
984 """Migrate all instances from a node.""" 985 OP_DSC_FIELD = "node_name" 986 OP_PARAMS = [ 987 _PNodeName, 988 _PMigrationMode, 989 _PMigrationLive, 990 _PMigrationTargetNode, 991 ("iallocator", None, ht.TMaybeString, 992 "Iallocator for deciding the target node for shared-storage instances"), 993 ] 994 OP_RESULT = TJobIdListOnly
995
996 997 -class OpNodeEvacuate(OpCode):
998 """Evacuate instances off a number of nodes.""" 999 OP_DSC_FIELD = "node_name" 1000 OP_PARAMS = [ 1001 _PEarlyRelease, 1002 _PNodeName, 1003 ("remote_node", None, ht.TMaybeString, "New secondary node"), 1004 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"), 1005 ("mode", ht.NoDefault, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES), 1006 "Node evacuation mode"), 1007 ] 1008 OP_RESULT = TJobIdListOnly
1009
1010 1011 # instance opcodes 1012 1013 -class OpInstanceCreate(OpCode):
1014 """Create an instance. 1015 1016 @ivar instance_name: Instance name 1017 @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES}) 1018 @ivar source_handshake: Signed handshake from source (remote import only) 1019 @ivar source_x509_ca: Source X509 CA in PEM format (remote import only) 1020 @ivar source_instance_name: Previous name of instance (remote import only) 1021 @ivar source_shutdown_timeout: Shutdown timeout used for source instance 1022 (remote import only) 1023 1024 """ 1025 OP_DSC_FIELD = "instance_name" 1026 OP_PARAMS = [ 1027 _PInstanceName, 1028 _PForceVariant, 1029 _PWaitForSync, 1030 _PNameCheck, 1031 ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"), 1032 ("disks", ht.NoDefault, 1033 # TODO: Generate check from constants.IDISK_PARAMS_TYPES 1034 ht.TListOf(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS), 1035 ht.TOr(ht.TNonEmptyString, ht.TInt))), 1036 "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;" 1037 " each disk definition must contain a ``%s`` value and" 1038 " can contain an optional ``%s`` value denoting the disk access mode" 1039 " (%s)" % 1040 (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE, 1041 constants.IDISK_MODE, 1042 " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))), 1043 ("disk_template", ht.NoDefault, _CheckDiskTemplate, "Disk template"), 1044 ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)), 1045 "Driver for file-backed disks"), 1046 ("file_storage_dir", None, ht.TMaybeString, 1047 "Directory for storing file-backed disks"), 1048 ("hvparams", ht.EmptyDict, ht.TDict, 1049 "Hypervisor parameters for instance, hypervisor-dependent"), 1050 ("hypervisor", None, ht.TMaybeString, "Hypervisor"), 1051 ("iallocator", None, ht.TMaybeString, 1052 "Iallocator for deciding which node(s) to use"), 1053 ("identify_defaults", False, ht.TBool, 1054 "Reset instance parameters to default if equal"), 1055 ("ip_check", True, ht.TBool, _PIpCheckDoc), 1056 ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES), 1057 "Instance creation mode"), 1058 ("nics", ht.NoDefault, ht.TListOf(_TestNicDef), 1059 "List of NIC (network interface) definitions, for example" 1060 " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can" 1061 " contain the optional values %s" % 1062 (constants.INIC_IP, 1063 ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))), 1064 ("no_install", None, ht.TMaybeBool, 1065 "Do not install the OS (will disable automatic start)"), 1066 ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"), 1067 ("os_type", None, ht.TMaybeString, "Operating system"), 1068 ("pnode", None, ht.TMaybeString, "Primary node"), 1069 ("snode", None, ht.TMaybeString, "Secondary node"), 1070 ("source_handshake", None, ht.TOr(ht.TList, ht.TNone), 1071 "Signed handshake from source (remote import only)"), 1072 ("source_instance_name", None, ht.TMaybeString, 1073 "Source instance name (remote import only)"), 1074 ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, 1075 ht.TPositiveInt, 1076 "How long source instance was given to shut down (remote import only)"), 1077 ("source_x509_ca", None, ht.TMaybeString, 1078 "Source X509 CA in PEM format (remote import only)"), 1079 ("src_node", None, ht.TMaybeString, "Source node for import"), 1080 ("src_path", None, ht.TMaybeString, "Source directory for import"), 1081 ("start", True, ht.TBool, "Whether to start instance after creation"), 1082 ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"), 1083 ] 1084 OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
1085
1086 1087 -class OpInstanceReinstall(OpCode):
1088 """Reinstall an instance's OS.""" 1089 OP_DSC_FIELD = "instance_name" 1090 OP_PARAMS = [ 1091 _PInstanceName, 1092 _PForceVariant, 1093 ("os_type", None, ht.TMaybeString, "Instance operating system"), 1094 ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"), 1095 ]
1096
1097 1098 -class OpInstanceRemove(OpCode):
1099 """Remove an instance.""" 1100 OP_DSC_FIELD = "instance_name" 1101 OP_PARAMS = [ 1102 _PInstanceName, 1103 _PShutdownTimeout, 1104 ("ignore_failures", False, ht.TBool, 1105 "Whether to ignore failures during removal"), 1106 ]
1107
1108 1109 -class OpInstanceRename(OpCode):
1110 """Rename an instance.""" 1111 OP_PARAMS = [ 1112 _PInstanceName, 1113 _PNameCheck, 1114 ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"), 1115 ("ip_check", False, ht.TBool, _PIpCheckDoc), 1116 ] 1117 OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
1118
1119 1120 -class OpInstanceStartup(OpCode):
1121 """Startup an instance.""" 1122 OP_DSC_FIELD = "instance_name" 1123 OP_PARAMS = [ 1124 _PInstanceName, 1125 _PForce, 1126 _PIgnoreOfflineNodes, 1127 ("hvparams", ht.EmptyDict, ht.TDict, 1128 "Temporary hypervisor parameters, hypervisor-dependent"), 1129 ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"), 1130 _PNoRemember, 1131 _PStartupPaused, 1132 ]
1133
1134 1135 -class OpInstanceShutdown(OpCode):
1136 """Shutdown an instance.""" 1137 OP_DSC_FIELD = "instance_name" 1138 OP_PARAMS = [ 1139 _PInstanceName, 1140 _PIgnoreOfflineNodes, 1141 ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt, 1142 "How long to wait for instance to shut down"), 1143 _PNoRemember, 1144 ]
1145
1146 1147 -class OpInstanceReboot(OpCode):
1148 """Reboot an instance.""" 1149 OP_DSC_FIELD = "instance_name" 1150 OP_PARAMS = [ 1151 _PInstanceName, 1152 _PShutdownTimeout, 1153 ("ignore_secondaries", False, ht.TBool, 1154 "Whether to start the instance even if secondary disks are failing"), 1155 ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES), 1156 "How to reboot instance"), 1157 ]
1158
1159 1160 -class OpInstanceReplaceDisks(OpCode):
1161 """Replace the disks of an instance.""" 1162 OP_DSC_FIELD = "instance_name" 1163 OP_PARAMS = [ 1164 _PInstanceName, 1165 _PEarlyRelease, 1166 ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES), 1167 "Replacement mode"), 1168 ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt), 1169 "Disk indexes"), 1170 ("remote_node", None, ht.TMaybeString, "New secondary node"), 1171 ("iallocator", None, ht.TMaybeString, 1172 "Iallocator for deciding new secondary node"), 1173 ]
1174
1175 1176 -class OpInstanceFailover(OpCode):
1177 """Failover an instance.""" 1178 OP_DSC_FIELD = "instance_name" 1179 OP_PARAMS = [ 1180 _PInstanceName, 1181 _PShutdownTimeout, 1182 _PIgnoreConsistency, 1183 _PMigrationTargetNode, 1184 ("iallocator", None, ht.TMaybeString, 1185 "Iallocator for deciding the target node for shared-storage instances"), 1186 ]
1187
1188 1189 -class OpInstanceMigrate(OpCode):
1190 """Migrate an instance. 1191 1192 This migrates (without shutting down an instance) to its secondary 1193 node. 1194 1195 @ivar instance_name: the name of the instance 1196 @ivar mode: the migration mode (live, non-live or None for auto) 1197 1198 """ 1199 OP_DSC_FIELD = "instance_name" 1200 OP_PARAMS = [ 1201 _PInstanceName, 1202 _PMigrationMode, 1203 _PMigrationLive, 1204 _PMigrationTargetNode, 1205 ("cleanup", False, ht.TBool, 1206 "Whether a previously failed migration should be cleaned up"), 1207 ("iallocator", None, ht.TMaybeString, 1208 "Iallocator for deciding the target node for shared-storage instances"), 1209 ("allow_failover", False, ht.TBool, 1210 "Whether we can fallback to failover if migration is not possible"), 1211 ]
1212
1213 1214 -class OpInstanceMove(OpCode):
1215 """Move an instance. 1216 1217 This move (with shutting down an instance and data copying) to an 1218 arbitrary node. 1219 1220 @ivar instance_name: the name of the instance 1221 @ivar target_node: the destination node 1222 1223 """ 1224 OP_DSC_FIELD = "instance_name" 1225 OP_PARAMS = [ 1226 _PInstanceName, 1227 _PShutdownTimeout, 1228 ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"), 1229 _PIgnoreConsistency, 1230 ]
1231
1232 1233 -class OpInstanceConsole(OpCode):
1234 """Connect to an instance's console.""" 1235 OP_DSC_FIELD = "instance_name" 1236 OP_PARAMS = [ 1237 _PInstanceName 1238 ]
1239
1240 1241 -class OpInstanceActivateDisks(OpCode):
1242 """Activate an instance's disks.""" 1243 OP_DSC_FIELD = "instance_name" 1244 OP_PARAMS = [ 1245 _PInstanceName, 1246 ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"), 1247 ]
1248
1249 1250 -class OpInstanceDeactivateDisks(OpCode):
1251 """Deactivate an instance's disks.""" 1252 OP_DSC_FIELD = "instance_name" 1253 OP_PARAMS = [ 1254 _PInstanceName, 1255 _PForce, 1256 ]
1257
1258 1259 -class OpInstanceRecreateDisks(OpCode):
1260 """Deactivate an instance's disks.""" 1261 OP_DSC_FIELD = "instance_name" 1262 OP_PARAMS = [ 1263 _PInstanceName, 1264 ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt), 1265 "List of disk indexes"), 1266 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), 1267 "New instance nodes, if relocation is desired"), 1268 ]
1269
1270 1271 -class OpInstanceQuery(OpCode):
1272 """Compute the list of instances.""" 1273 OP_PARAMS = [ 1274 _POutputFields, 1275 _PUseLocking, 1276 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), 1277 "Empty list to query all instances, instance names otherwise"), 1278 ]
1279
1280 1281 -class OpInstanceQueryData(OpCode):
1282 """Compute the run-time status of instances.""" 1283 OP_PARAMS = [ 1284 _PUseLocking, 1285 ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), 1286 "Instance names"), 1287 ("static", False, ht.TBool, 1288 "Whether to only return configuration data without querying" 1289 " nodes"), 1290 ]
1291
1292 1293 -class OpInstanceSetParams(OpCode):
1294 """Change the parameters of an instance.""" 1295 OP_DSC_FIELD = "instance_name" 1296 OP_PARAMS = [ 1297 _PInstanceName, 1298 _PForce, 1299 _PForceVariant, 1300 # TODO: Use _TestNicDef 1301 ("nics", ht.EmptyList, ht.TList, 1302 "List of NIC changes. Each item is of the form ``(op, settings)``." 1303 " ``op`` can be ``%s`` to add a new NIC with the specified settings," 1304 " ``%s`` to remove the last NIC or a number to modify the settings" 1305 " of the NIC with that index." % 1306 (constants.DDM_ADD, constants.DDM_REMOVE)), 1307 ("disks", ht.EmptyList, ht.TList, "List of disk changes. See ``nics``."), 1308 ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"), 1309 ("hvparams", ht.EmptyDict, ht.TDict, 1310 "Per-instance hypervisor parameters, hypervisor-dependent"), 1311 ("disk_template", None, ht.TOr(ht.TNone, _CheckDiskTemplate), 1312 "Disk template for instance"), 1313 ("remote_node", None, ht.TMaybeString, 1314 "Secondary node (used when changing disk template)"), 1315 ("os_name", None, ht.TMaybeString, 1316 "Change instance's OS name. Does not reinstall the instance."), 1317 ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"), 1318 ("wait_for_sync", True, ht.TBool, 1319 "Whether to wait for the disk to synchronize, when changing template"), 1320 ] 1321 OP_RESULT = _TSetParamsResult
1322
1323 1324 -class OpInstanceGrowDisk(OpCode):
1325 """Grow a disk of an instance.""" 1326 OP_DSC_FIELD = "instance_name" 1327 OP_PARAMS = [ 1328 _PInstanceName, 1329 _PWaitForSync, 1330 ("disk", ht.NoDefault, ht.TInt, "Disk index"), 1331 ("amount", ht.NoDefault, ht.TInt, 1332 "Amount of disk space to add (megabytes)"), 1333 ]
1334
1335 1336 -class OpInstanceChangeGroup(OpCode):
1337 """Moves an instance to another node group.""" 1338 OP_DSC_FIELD = "instance_name" 1339 OP_PARAMS = [ 1340 _PInstanceName, 1341 _PEarlyRelease, 1342 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"), 1343 ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), 1344 "Destination group names or UUIDs (defaults to \"all but current group\""), 1345 ] 1346 OP_RESULT = TJobIdListOnly
1347
1348 1349 # Node group opcodes 1350 1351 -class OpGroupAdd(OpCode):
1352 """Add a node group to the cluster.""" 1353 OP_DSC_FIELD = "group_name" 1354 OP_PARAMS = [ 1355 _PGroupName, 1356 _PNodeGroupAllocPolicy, 1357 _PGroupNodeParams, 1358 ]
1359
1360 1361 -class OpGroupAssignNodes(OpCode):
1362 """Assign nodes to a node group.""" 1363 OP_DSC_FIELD = "group_name" 1364 OP_PARAMS = [ 1365 _PGroupName, 1366 _PForce, 1367 ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), 1368 "List of nodes to assign"), 1369 ]
1370
1371 1372 -class OpGroupQuery(OpCode):
1373 """Compute the list of node groups.""" 1374 OP_PARAMS = [ 1375 _POutputFields, 1376 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), 1377 "Empty list to query all groups, group names otherwise"), 1378 ]
1379
1380 1381 -class OpGroupSetParams(OpCode):
1382 """Change the parameters of a node group.""" 1383 OP_DSC_FIELD = "group_name" 1384 OP_PARAMS = [ 1385 _PGroupName, 1386 _PNodeGroupAllocPolicy, 1387 _PGroupNodeParams, 1388 ] 1389 OP_RESULT = _TSetParamsResult
1390
1391 1392 -class OpGroupRemove(OpCode):
1393 """Remove a node group from the cluster.""" 1394 OP_DSC_FIELD = "group_name" 1395 OP_PARAMS = [ 1396 _PGroupName, 1397 ]
1398
1399 1400 -class OpGroupRename(OpCode):
1401 """Rename a node group in the cluster.""" 1402 OP_PARAMS = [ 1403 _PGroupName, 1404 ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"), 1405 ] 1406 OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
1407
1408 1409 -class OpGroupEvacuate(OpCode):
1410 """Evacuate a node group in the cluster.""" 1411 OP_DSC_FIELD = "group_name" 1412 OP_PARAMS = [ 1413 _PGroupName, 1414 _PEarlyRelease, 1415 ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"), 1416 ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), 1417 "Destination group names or UUIDs"), 1418 ] 1419 OP_RESULT = TJobIdListOnly
1420
1421 1422 # OS opcodes 1423 -class OpOsDiagnose(OpCode):
1424 """Compute the list of guest operating systems.""" 1425 OP_PARAMS = [ 1426 _POutputFields, 1427 ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), 1428 "Which operating systems to diagnose"), 1429 ]
1430
1431 1432 # Exports opcodes 1433 -class OpBackupQuery(OpCode):
1434 """Compute the list of exported images.""" 1435 OP_PARAMS = [ 1436 _PUseLocking, 1437 ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), 1438 "Empty list to query all nodes, node names otherwise"), 1439 ]
1440
1441 1442 -class OpBackupPrepare(OpCode):
1443 """Prepares an instance export. 1444 1445 @ivar instance_name: Instance name 1446 @ivar mode: Export mode (one of L{constants.EXPORT_MODES}) 1447 1448 """ 1449 OP_DSC_FIELD = "instance_name" 1450 OP_PARAMS = [ 1451 _PInstanceName, 1452 ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES), 1453 "Export mode"), 1454 ]
1455
1456 1457 -class OpBackupExport(OpCode):
1458 """Export an instance. 1459 1460 For local exports, the export destination is the node name. For remote 1461 exports, the export destination is a list of tuples, each consisting of 1462 hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using 1463 the cluster domain secret over the value "${index}:${hostname}:${port}". The 1464 destination X509 CA must be a signed certificate. 1465 1466 @ivar mode: Export mode (one of L{constants.EXPORT_MODES}) 1467 @ivar target_node: Export destination 1468 @ivar x509_key_name: X509 key to use (remote export only) 1469 @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export 1470 only) 1471 1472 """ 1473 OP_DSC_FIELD = "instance_name" 1474 OP_PARAMS = [ 1475 _PInstanceName, 1476 _PShutdownTimeout, 1477 # TODO: Rename target_node as it changes meaning for different export modes 1478 # (e.g. "destination") 1479 ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList), 1480 "Destination information, depends on export mode"), 1481 ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"), 1482 ("remove_instance", False, ht.TBool, 1483 "Whether to remove instance after export"), 1484 ("ignore_remove_failures", False, ht.TBool, 1485 "Whether to ignore failures while removing instances"), 1486 ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES), 1487 "Export mode"), 1488 ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone), 1489 "Name of X509 key (remote export only)"), 1490 ("destination_x509_ca", None, ht.TMaybeString, 1491 "Destination X509 CA (remote export only)"), 1492 ]
1493
1494 1495 -class OpBackupRemove(OpCode):
1496 """Remove an instance's export.""" 1497 OP_DSC_FIELD = "instance_name" 1498 OP_PARAMS = [ 1499 _PInstanceName, 1500 ]
1501
1502 1503 # Tags opcodes 1504 -class OpTagsGet(OpCode):
1505 """Returns the tags of the given object.""" 1506 OP_DSC_FIELD = "name" 1507 OP_PARAMS = [ 1508 _PTagKind, 1509 # Name is only meaningful for nodes and instances 1510 ("name", ht.NoDefault, ht.TMaybeString, None), 1511 ]
1512
1513 1514 -class OpTagsSearch(OpCode):
1515 """Searches the tags in the cluster for a given pattern.""" 1516 OP_DSC_FIELD = "pattern" 1517 OP_PARAMS = [ 1518 ("pattern", ht.NoDefault, ht.TNonEmptyString, None), 1519 ]
1520
1521 1522 -class OpTagsSet(OpCode):
1523 """Add a list of tags on a given object.""" 1524 OP_PARAMS = [ 1525 _PTagKind, 1526 _PTags, 1527 # Name is only meaningful for nodes and instances 1528 ("name", ht.NoDefault, ht.TMaybeString, None), 1529 ]
1530
1531 1532 -class OpTagsDel(OpCode):
1533 """Remove a list of tags from a given object.""" 1534 OP_PARAMS = [ 1535 _PTagKind, 1536 _PTags, 1537 # Name is only meaningful for nodes and instances 1538 ("name", ht.NoDefault, ht.TMaybeString, None), 1539 ]
1540
1541 1542 # Test opcodes 1543 -class OpTestDelay(OpCode):
1544 """Sleeps for a configured amount of time. 1545 1546 This is used just for debugging and testing. 1547 1548 Parameters: 1549 - duration: the time to sleep 1550 - on_master: if true, sleep on the master 1551 - on_nodes: list of nodes in which to sleep 1552 1553 If the on_master parameter is true, it will execute a sleep on the 1554 master (before any node sleep). 1555 1556 If the on_nodes list is not empty, it will sleep on those nodes 1557 (after the sleep on the master, if that is enabled). 1558 1559 As an additional feature, the case of duration < 0 will be reported 1560 as an execution error, so this opcode can be used as a failure 1561 generator. The case of duration == 0 will not be treated specially. 1562 1563 """ 1564 OP_DSC_FIELD = "duration" 1565 OP_PARAMS = [ 1566 ("duration", ht.NoDefault, ht.TNumber, None), 1567 ("on_master", True, ht.TBool, None), 1568 ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None), 1569 ("repeat", 0, ht.TPositiveInt, None), 1570 ]
1571
1572 1573 -class OpTestAllocator(OpCode):
1574 """Allocator framework testing. 1575 1576 This opcode has two modes: 1577 - gather and return allocator input for a given mode (allocate new 1578 or replace secondary) and a given instance definition (direction 1579 'in') 1580 - run a selected allocator for a given operation (as above) and 1581 return the allocator output (direction 'out') 1582 1583 """ 1584 OP_DSC_FIELD = "allocator" 1585 OP_PARAMS = [ 1586 ("direction", ht.NoDefault, 1587 ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None), 1588 ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None), 1589 ("name", ht.NoDefault, ht.TNonEmptyString, None), 1590 ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf( 1591 ht.TDictOf(ht.TElemOf([constants.INIC_MAC, constants.INIC_IP, "bridge"]), 1592 ht.TOr(ht.TNone, ht.TNonEmptyString)))), None), 1593 ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None), 1594 ("hypervisor", None, ht.TMaybeString, None), 1595 ("allocator", None, ht.TMaybeString, None), 1596 ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None), 1597 ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None), 1598 ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None), 1599 ("os", None, ht.TMaybeString, None), 1600 ("disk_template", None, ht.TMaybeString, None), 1601 ("instances", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), 1602 None), 1603 ("evac_mode", None, 1604 ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None), 1605 ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), 1606 None), 1607 ]
1608
1609 1610 -class OpTestJqueue(OpCode):
1611 """Utility opcode to test some aspects of the job queue. 1612 1613 """ 1614 OP_PARAMS = [ 1615 ("notify_waitlock", False, ht.TBool, None), 1616 ("notify_exec", False, ht.TBool, None), 1617 ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None), 1618 ("fail", False, ht.TBool, None), 1619 ]
1620
1621 1622 -class OpTestDummy(OpCode):
1623 """Utility opcode used by unittests. 1624 1625 """ 1626 OP_PARAMS = [ 1627 ("result", ht.NoDefault, ht.NoType, None), 1628 ("messages", ht.NoDefault, ht.NoType, None), 1629 ("fail", ht.NoDefault, ht.NoType, None), 1630 ("submit_jobs", None, ht.NoType, None), 1631 ] 1632 WITH_LU = False
1633
1634 1635 -def _GetOpList():
1636 """Returns list of all defined opcodes. 1637 1638 Does not eliminate duplicates by C{OP_ID}. 1639 1640 """ 1641 return [v for v in globals().values() 1642 if (isinstance(v, type) and issubclass(v, OpCode) and 1643 hasattr(v, "OP_ID") and v is not OpCode)]
1644 1645 1646 OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList()) 1647