Merge "Use json instead of regexp to parse subnet data"

This commit is contained in:
Jenkins 2015-10-19 16:36:28 +00:00 committed by Gerrit Code Review
commit df5bb97ba9

View File

@ -1,3 +1,4 @@
require 'json'
require File.join(File.dirname(__FILE__), '..','..','..',
'puppet/provider/neutron')
@ -57,9 +58,9 @@ Puppet::Type.type(:neutron_subnet).provide(
allocation_pools = []
return [] if values.empty?
for value in Array(values)
matchdata = /\{\s*"start"\s*:\s*"(.*)"\s*,\s*"end"\s*:\s*"(.*)"\s*\}/.match(value.gsub(/\\"/,'"'))
start_ip = matchdata[1]
end_ip = matchdata[2]
allocation_pool = JSON.parse(value.gsub(/\\"/,'"'))
start_ip = allocation_pool['start']
end_ip = allocation_pool['end']
allocation_pools << "start=#{start_ip},end=#{end_ip}"
end
return allocation_pools
@ -69,9 +70,9 @@ Puppet::Type.type(:neutron_subnet).provide(
host_routes = []
return [] if values.empty?
for value in Array(values)
matchdata = /\{\s*"nexthop"\s*:\s*"(.*)"\s*,\s*"destination"\s*:\s*"(.*)"\s*\}/.match(value.gsub(/\\"/,'"'))
nexthop = matchdata[1]
destination = matchdata[2]
host_route = JSON.parse(value.gsub(/\\"/,'"'))
nexthop = host_route['nexthop']
destination = host_route['destination']
host_routes << "nexthop=#{nexthop},destination=#{destination}"
end
return host_routes