Revision b165e77e

b/lib/cmdlib.py
574 574
               (mc_now, mc_max))
575 575

  
576 576

  
577
def _CheckInstanceBridgesExist(lu, instance):
577
def _CheckNicsBridgesExist(lu, target_nics, target_node,
578
                               profile=constants.PP_DEFAULT):
579
  """Check that the brigdes needed by a list of nics exist.
580

  
581
  """
582
  c_nicparams = lu.cfg.GetClusterInfo().nicparams[profile]
583
  paramslist = [objects.FillDict(c_nicparams, nic.nicparams)
584
                for nic in target_nics]
585
  brlist = [params[constants.NIC_LINK] for params in paramslist
586
            if params[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED]
587
  if brlist:
588
    result = lu.rpc.call_bridges_exist(target_node, brlist)
589
    result.Raise()
590
    if not result.data:
591
      raise errors.OpPrereqError("One or more target bridges %s does not"
592
                                 " exist on destination node '%s'" %
593
                                 (brlist, target_node))
594

  
595

  
596
def _CheckInstanceBridgesExist(lu, instance, node=None):
578 597
  """Check that the brigdes needed by an instance exist.
579 598

  
580 599
  """
581
  # check bridges existance
582
  brlist = [nic.bridge for nic in instance.nics]
583
  result = lu.rpc.call_bridges_exist(instance.primary_node, brlist)
584
  result.Raise()
585
  if not result.data:
586
    raise errors.OpPrereqError("One or more target bridges %s does not"
587
                               " exist on destination node '%s'" %
588
                               (brlist, instance.primary_node))
600
  if node is None:
601
    node=instance.primary_node
602
  _CheckNicsBridgesExist(lu, instance.nics, node)
589 603

  
590 604

  
591 605
class LUDestroyCluster(NoHooksLU):
......
3600 3614
    _CheckNodeFreeMemory(self, target_node, "failing over instance %s" %
3601 3615
                         instance.name, bep[constants.BE_MEMORY],
3602 3616
                         instance.hypervisor)
3603

  
3604 3617
    # check bridge existance
3605
    brlist = [nic.bridge for nic in instance.nics]
3606
    result = self.rpc.call_bridges_exist(target_node, brlist)
3607
    result.Raise()
3608
    if not result.data:
3609
      raise errors.OpPrereqError("One or more target bridges %s does not"
3610
                                 " exist on destination node '%s'" %
3611
                                 (brlist, target_node))
3618
    _CheckInstanceBridgesExist(self, instance, node=target_node)
3612 3619

  
3613 3620
  def Exec(self, feedback_fn):
3614 3621
    """Failover an instance.
......
3740 3747
                         instance.hypervisor)
3741 3748

  
3742 3749
    # check bridge existance
3743
    brlist = [nic.bridge for nic in instance.nics]
3744
    result = self.rpc.call_bridges_exist(target_node, brlist)
3745
    if result.failed or not result.data:
3746
      raise errors.OpPrereqError("One or more target bridges %s does not"
3747
                                 " exist on destination node '%s'" %
3748
                                 (brlist, target_node))
3750
    _CheckInstanceBridgesExist(self, instance, node=target_node)
3749 3751

  
3750 3752
    if not self.op.cleanup:
3751 3753
      _CheckNodeNotDrained(self, target_node)
......
4795 4797
      raise errors.OpPrereqError("OS '%s' not in supported os list for"
4796 4798
                                 " primary node"  % self.op.os_type)
4797 4799

  
4798
    # bridge check on primary node
4799
    bridges = [n.bridge for n in self.nics]
4800
    result = self.rpc.call_bridges_exist(self.pnode.name, bridges)
4801
    result.Raise()
4802
    if not result.data:
4803
      raise errors.OpPrereqError("One of the target bridges '%s' does not"
4804
                                 " exist on destination node '%s'" %
4805
                                 (",".join(bridges), pnode.name))
4800
    _CheckNicsBridgesExist(self, self.nics, self.pnode.name)
4806 4801

  
4807 4802
    # memory check on primary node
4808 4803
    if self.op.start:

Also available in: Unified diff