d13d5530f76a905e173a34599c831fc7b72da72f
[mirror/dsa-puppet.git] / 3rdparty / modules / neutron / lib / puppet / parser / functions / validate_tunnel_id_ranges.rb
1 #
2 # Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
3 #
4 # Author: Emilien Macchi <emilien.macchi@enovance.com>
5 #         Martin Magr <mmagr@redhat.com>
6 #
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
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
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
17 # under the License.
18 #
19 # Advanced validation when using GRE
20 #
21
22 module Puppet::Parser::Functions
23   newfunction(:validate_tunnel_id_ranges) do |args|
24     value = args[0]
25     if not value.kind_of?(Array)
26       value = [value]
27     end
28
29     value.each do |range|
30       if m = /^(\d+):(\d+)$/.match(range)
31         first_id = Integer(m[1])
32         second_id = Integer(m[2])
33         if ((second_id - first_id) > 1000000)
34           raise Puppet::Error, "tunnel id ranges are to large."
35         end
36         if ((second_id - first_id) < 0 )
37           raise Puppet::Error, "tunnel id ranges are invalid."
38         end
39       elsif range
40         raise Puppet::Error, "tunnel id ranges are invalid."
41       end
42     end
43   end
44 end