Revision cd098c41

b/lib/cmdlib.py
5898 5898
          if not utils.IsValidIP(nic_ip):
5899 5899
            raise errors.OpPrereqError("Invalid IP address '%s'" % nic_ip)
5900 5900

  
5901
      nic_bridge = nic_dict.get('bridge', None)
5902
      nic_link = nic_dict.get('link', None)
5903
      if nic_bridge and nic_link:
5904
        raise errors.OpPrereqError("Cannot pass 'bridge' and 'link' at the same time")
5905
      elif nic_bridge and nic_bridge.lower() == constants.VALUE_NONE:
5906
        nic_dict['bridge'] = None
5907
      elif nic_link and nic_link.lower() == constants.VALUE_NONE:
5908
        nic_dict['link'] = None
5909

  
5901 5910
      if nic_op == constants.DDM_ADD:
5902
        nic_bridge = nic_dict.get('bridge', None)
5903
        if nic_bridge is None:
5904
          nic_dict['bridge'] = self.cfg.GetDefBridge()
5905 5911
        nic_mac = nic_dict.get('mac', None)
5906 5912
        if nic_mac is None:
5907 5913
          nic_dict['mac'] = constants.VALUE_AUTO
......
6089 6095
                             " secondary node %s" % node)
6090 6096

  
6091 6097
    # NIC processing
6098
    self.nic_pnew = {}
6099
    self.nic_pinst = {}
6092 6100
    for nic_op, nic_dict in self.op.nics:
6093 6101
      if nic_op == constants.DDM_REMOVE:
6094 6102
        if not instance.nics:
......
6100 6108
          raise errors.OpPrereqError("Invalid NIC index %s, valid values"
6101 6109
                                     " are 0 to %d" %
6102 6110
                                     (nic_op, len(instance.nics)))
6111
        old_nic_params = instance.nics[nic_op].nicparams
6112
        old_nic_ip = instance.nics[nic_op].ip
6113
      else:
6114
        old_nic_params = {}
6115
        old_nic_ip = None
6116

  
6117
      update_params_dict = dict([(key, nic_dict[key])
6118
                                 for key in constants.NICS_PARAMETERS
6119
                                 if key in nic_dict])
6120

  
6103 6121
      if 'bridge' in nic_dict:
6104
        nic_bridge = nic_dict['bridge']
6105
        if nic_bridge is None:
6106
          raise errors.OpPrereqError('Cannot set the nic bridge to None')
6107
        if not self.rpc.call_bridges_exist(pnode, [nic_bridge]):
6122
        update_params_dict[constants.NIC_LINK] = nic_dict['bridge']
6123

  
6124
      new_nic_params, new_filled_nic_params = \
6125
          self._GetUpdatedParams(old_nic_params, update_params_dict,
6126
                                 cluster.nicparams[constants.PP_DEFAULT],
6127
                                 constants.NICS_PARAMETER_TYPES)
6128
      objects.NIC.CheckParameterSyntax(new_filled_nic_params)
6129
      self.nic_pinst[nic_op] = new_nic_params
6130
      self.nic_pnew[nic_op] = new_filled_nic_params
6131
      new_nic_mode = new_filled_nic_params[constants.NIC_MODE]
6132

  
6133
      if new_nic_mode == constants.NIC_MODE_BRIDGED:
6134
        nic_bridge = new_filled_nic_params[constants.NIC_LINK]
6135
        result = self.rpc.call_bridges_exist(pnode, [nic_bridge])
6136
        result.Raise()
6137
        if not result.data:
6108 6138
          msg = ("Bridge '%s' doesn't exist on one of"
6109 6139
                 " the instance nodes" % nic_bridge)
6110 6140
          if self.force:
6111 6141
            self.warn.append(msg)
6112 6142
          else:
6113 6143
            raise errors.OpPrereqError(msg)
6144
      if new_nic_mode == constants.NIC_MODE_ROUTED:
6145
        if 'ip' in nic_dict:
6146
          nic_ip = nic_dict['ip']
6147
        else:
6148
          nic_ip = old_nic_ip
6149
        if nic_ip is None:
6150
          raise errors.OpPrereqError('Cannot set the nic ip to None'
6151
                                     ' on a routed nic')
6114 6152
      if 'mac' in nic_dict:
6115 6153
        nic_mac = nic_dict['mac']
6116 6154
        if nic_mac is None:
......
6167 6205

  
6168 6206
    result = []
6169 6207
    instance = self.instance
6208
    cluster = self.cluster
6170 6209
    # disk changes
6171 6210
    for disk_op, disk_dict in self.op.disks:
6172 6211
      if disk_op == constants.DDM_REMOVE:
......
6227 6266
      elif nic_op == constants.DDM_ADD:
6228 6267
        # mac and bridge should be set, by now
6229 6268
        mac = nic_dict['mac']
6230
        bridge = nic_dict['bridge']
6231
        new_nic = objects.NIC(mac=mac, ip=nic_dict.get('ip', None),
6232
                              bridge=bridge)
6269
        ip = nic_dict.get('ip', None)
6270
        nicparams = self.nic_pinst[constants.DDM_ADD]
6271
        new_nic = objects.NIC(mac=mac, ip=ip, nicparams=nicparams)
6233 6272
        instance.nics.append(new_nic)
6234 6273
        result.append(("nic.%d" % (len(instance.nics) - 1),
6235
                       "add:mac=%s,ip=%s,bridge=%s" %
6236
                       (new_nic.mac, new_nic.ip, new_nic.bridge)))
6274
                       "add:mac=%s,ip=%s,mode=%s,link=%s" %
6275
                       (new_nic.mac, new_nic.ip,
6276
                        self.nic_pnew[constants.DDM_ADD][constants.NIC_MODE],
6277
                        self.nic_pnew[constants.DDM_ADD][constants.NIC_LINK]
6278
                       )))
6237 6279
      else:
6238
        # change a given nic
6239
        for key in 'mac', 'ip', 'bridge':
6280
        for key in 'mac', 'ip':
6240 6281
          if key in nic_dict:
6241 6282
            setattr(instance.nics[nic_op], key, nic_dict[key])
6242
            result.append(("nic.%s/%d" % (key, nic_op), nic_dict[key]))
6283
        if nic_op in self.nic_pnew:
6284
          instance.nics[nic_op].nicparams = self.nic_pnew[nic_op]
6285
        for key, val in nic_dict.iteritems():
6286
          result.append(("nic.%s/%d" % (key, nic_op), val))
6243 6287

  
6244 6288
    # hvparams changes
6245 6289
    if self.op.hvparams:

Also available in: Unified diff