Revision 9f7d5fe4 lib/cmdlib/instance.py

b/lib/cmdlib/instance.py
174 174
    net = nic.get(constants.INIC_NETWORK, None)
175 175
    link = nic.get(constants.NIC_LINK, None)
176 176
    ip = nic.get(constants.INIC_IP, None)
177
    vlan = nic.get(constants.INIC_VLAN, None)
177 178

  
178 179
    if net is None or net.lower() == constants.VALUE_NONE:
179 180
      net = None
......
183 184
                                   " is allowed to be passed",
184 185
                                   errors.ECODE_INVAL)
185 186

  
187
    if vlan is not None and nic_mode != constants.NIC_MODE_OVS:
188
      raise errors.OpPrereqError("VLAN is given, but network mode is not"
189
                                 " openvswitch", errors.ECODE_INVAL)
190

  
186 191
    # ip validity checks
187 192
    if ip is None or ip.lower() == constants.VALUE_NONE:
188 193
      nic_ip = None
......
231 236
      nicparams[constants.NIC_MODE] = nic_mode
232 237
    if link:
233 238
      nicparams[constants.NIC_LINK] = link
239
    if vlan:
240
      nicparams[constants.NIC_VLAN] = vlan
234 241

  
235 242
    check_params = cluster.SimpleFillNIC(nicparams)
236 243
    objects.NIC.CheckParameterSyntax(check_params)
......
379 386

  
380 387
    self.adopt_disks = has_adopt
381 388

  
389
  def _CheckVLANArguments(self):
390
    """ Check validity of VLANs if given
391

  
392
    """
393
    for nic in self.op.nics:
394
      if nic[constants.INIC_VLAN]:
395
        vlan = nic[constants.INIC_VLAN]
396
        if vlan[0] == ".":
397
          # vlan starting with dot means single untagged vlan,
398
          # might be followed by trunk (:)
399
          if not vlan[1:].isdigit():
400
            vlanlist = vlan[1:].split(':')
401
            for vl in vlanlist:
402
              if not vl.isdigit():
403
                raise errors.OpPrereqError("Specified VLAN parameter is "
404
                                           "invalid : %s" % vlan,
405
                                             errors.ECODE_INVAL)
406
        elif vlan[0] == ":":
407
          # Trunk - tagged only
408
          vlanlist = vlan[1:].split(':')
409
          for vl in vlanlist:
410
            if not vl.isdigit():
411
              raise errors.OpPrereqError("Specified VLAN parameter is invalid"
412
                                           " : %s" % vlan, errors.ECODE_INVAL)
413
        elif vlan.isdigit():
414
          # This is the simplest case. No dots, only single digit
415
          # -> Create untagged access port, dot needs to be added
416
          nic[constants.INIC_VLAN] = "." + vlan
417
        else:
418
          raise errors.OpPrereqError("Specified VLAN parameter is invalid"
419
                                       " : %s" % vlan, errors.ECODE_INVAL)
420

  
382 421
  def CheckArguments(self):
383 422
    """Check arguments.
384 423

  
......
403 442
    # check that NIC's parameters names are unique and valid
404 443
    utils.ValidateDeviceNames("NIC", self.op.nics)
405 444

  
445
    self._CheckVLANArguments()
446

  
406 447
    self._CheckDiskArguments()
407 448

  
408 449
    # instance name verification

Also available in: Unified diff