Revision 13f6af81 lib/cmdlib/instance_utils.py

b/lib/cmdlib/instance_utils.py
513 513
    result = lu.rpc.call_bridges_exist(target_node, brlist)
514 514
    result.Raise("Error checking bridges on destination node '%s'" %
515 515
                 target_node, prereq=True, ecode=errors.ECODE_ENVIRON)
516

  
517

  
518
def _CheckNodeHasOS(lu, node, os_name, force_variant):
519
  """Ensure that a node supports a given OS.
520

  
521
  @param lu: the LU on behalf of which we make the check
522
  @param node: the node to check
523
  @param os_name: the OS to query about
524
  @param force_variant: whether to ignore variant errors
525
  @raise errors.OpPrereqError: if the node is not supporting the OS
526

  
527
  """
528
  result = lu.rpc.call_os_get(node, os_name)
529
  result.Raise("OS '%s' not in supported OS list for node %s" %
530
               (os_name, node),
531
               prereq=True, ecode=errors.ECODE_INVAL)
532
  if not force_variant:
533
    _CheckOSVariant(result.payload, os_name)
534

  
535

  
536
def _CheckOSVariant(os_obj, name):
537
  """Check whether an OS name conforms to the os variants specification.
538

  
539
  @type os_obj: L{objects.OS}
540
  @param os_obj: OS object to check
541
  @type name: string
542
  @param name: OS name passed by the user, to check for validity
543

  
544
  """
545
  variant = objects.OS.GetVariant(name)
546
  if not os_obj.supported_variants:
547
    if variant:
548
      raise errors.OpPrereqError("OS '%s' doesn't support variants ('%s'"
549
                                 " passed)" % (os_obj.name, variant),
550
                                 errors.ECODE_INVAL)
551
    return
552
  if not variant:
553
    raise errors.OpPrereqError("OS name must include a variant",
554
                               errors.ECODE_INVAL)
555

  
556
  if variant not in os_obj.supported_variants:
557
    raise errors.OpPrereqError("Unsupported OS variant", errors.ECODE_INVAL)

Also available in: Unified diff