If VLAN parameter is present, check its format: either .<id>[:id], :id[:id...], or just id.
Signed-off-by: Sebastian Gebhard <[email protected]> --- lib/cmdlib/instance.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/cmdlib/instance.py b/lib/cmdlib/instance.py index 56806bf..2d5ded4 100644 --- a/lib/cmdlib/instance.py +++ b/lib/cmdlib/instance.py @@ -173,6 +173,7 @@ def _ComputeNics(op, cluster, default_ip, cfg, ec_id): net = nic.get(constants.INIC_NETWORK, None) link = nic.get(constants.NIC_LINK, None) ip = nic.get(constants.INIC_IP, None) + vlan = nic.get(constants.INIC_VLAN, None) if net is None or net.lower() == constants.VALUE_NONE: net = None @@ -230,6 +231,8 @@ def _ComputeNics(op, cluster, default_ip, cfg, ec_id): nicparams[constants.NIC_MODE] = nic_mode if link: nicparams[constants.NIC_LINK] = link + if vlan: + nicparams[constants.NIC_VLAN] = vlan check_params = cluster.SimpleFillNIC(nicparams) objects.NIC.CheckParameterSyntax(check_params) @@ -383,6 +386,44 @@ class LUInstanceCreate(LogicalUnit): self.adopt_disks = has_adopt + def _CheckVLANArguments(self): + """ Check validity of VLANs if given + """ + for nic in self.op.nics: + if nic[constants.INIC_VLAN]: + #FIXME: This check should also include the check if the default mode + # is openvswitch + if (nic.has_key(constants.INIC_MODE) and nic[constants.INIC_MODE] == \ + constants.NIC_MODE_OVS): + vlan = nic[constants.INIC_VLAN] + if vlan[0] == ".": + # vlan starting with dot means single untagged vlan, + # might be followed by trunk (:) + if vlan[1:].isdigit() == False: + vlanlist = vlan[1:].split(':') + for vl in vlanlist: + if vl.isdigit() == False: + raise errors.OpPrereqError("Specified VLAN parameter is " + "invalid : %s" % vlan, + errors.ECODE_INVAL) + elif vlan[0] == ":": + # Trunk - tagged only + vlanlist = vlan[1:].split(':') + for vl in vlanlist: + if vl.isdigit() == False: + raise errors.OpPrereqError("Specified VLAN parameter is invalid" + " : %s" % vlan, errors.ECODE_INVAL) + elif vlan.isdigit(): + # This is the simplest case. No dots, only single digit + # -> Create untagged access port, dot needs to be added + nic[constants.INIC_VLAN] = "."+vlan + else: + raise errors.OpPrereqError("Specified VLAN parameter is invalid" + " : %s" % vlan, errors.ECODE_INVAL) + else: + raise errors.OpPrereqError("VLANs can only be used in mode " + "openvswitch", errors.ECODE_INVAL) + def CheckArguments(self): """Check arguments. @@ -407,6 +448,8 @@ class LUInstanceCreate(LogicalUnit): # check that NIC's parameters names are unique and valid utils.ValidateDeviceNames("NIC", self.op.nics) + self._CheckVLANArguments() + self._CheckDiskArguments() # instance name verification -- 1.8.1.2
