2 # Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
4 # Author: Emilien Macchi <emilien.macchi@enovance.com>
5 # Martin Magr <mmagr@redhat.com>
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
19 # Advanced validation for VLAN configuration
22 module Puppet::Parser::Functions
23 newfunction(:validate_network_vlan_ranges) do |args|
25 if not value.kind_of?(Array)
30 if m = /^(.+:)?(\d+):(\d+)$/.match(range)
31 first_id = Integer(m[-2])
32 second_id = Integer(m[-1])
33 if (first_id > 4094) || (second_id > 4094)
34 raise Puppet::Error, "vlan id are invalid."
36 if ((second_id - first_id) < 0 )
37 raise Puppet::Error, "network vlan ranges are invalid."
39 elsif m = /^([^:]+)?(:\d+)?$/.match(range)
40 # Either only name of physical network or single vlan id has
41 # been passed. This is also correct.
43 raise Puppet::Error, "network vlan ranges are invalid."