Commit 98020c12 authored by Baptiste Jonglez's avatar Baptiste Jonglez
Browse files

[schema] Validate IPv4 and IPv6 addresses

parent c88adc1f
......@@ -26,22 +26,40 @@ class HashValidator::Validator::LinecardPortValidator < HashValidator::Validator
end
end
class HashValidator::Validator::IpAddressValidator < HashValidator::Validator::Base
class HashValidator::Validator::Ipv4AddressValidator < HashValidator::Validator::Base
def initialize
super('ip_address')
super('ipv4_address')
end
def validate(key, values, _validations, errors)
if values.is_a?(String)
unless (values =~ Resolv::IPv4::Regex || values =~ Resolv::IPv6::Regex)
errors[key] = "Invalid ip address format #{values}"
unless values =~ Resolv::IPv4::Regex
errors[key] = "Invalid IPv4 address format #{values}"
end
else
errors[key] = "Ip address should be a String"
errors[key] = "IPv4 address should be a String"
end
end
end
class HashValidator::Validator::Ipv6AddressValidator < HashValidator::Validator::Base
def initialize
super('ipv6_address')
end
def validate(key, values, _validations, errors)
if values.is_a?(String)
unless values =~ Resolv::IPv6::Regex
errors[key] = "Invalid IPv6 address format #{values}"
end
else
errors[key] = "IPv6 address should be a String"
end
end
end
HashValidator.append_validator(HashValidator::Validator::LinecardPortValidator.new)
HashValidator.append_validator(HashValidator::Validator::IpAddressValidator.new)
HashValidator.append_validator(HashValidator::Validator::Ipv4AddressValidator.new)
HashValidator.append_validator(HashValidator::Validator::Ipv6AddressValidator.new)
......@@ -11,8 +11,8 @@ alias: optional_array
backplane_bps: optional_integer
mtu: optional_integer
snmp_community: string
ip: optional_string
ip6: optional_string
ip: optional_ipv4_address
ip6: optional_ipv6_address
network_adapters: optional
pdu:
<optional_array>:
......
......@@ -26,11 +26,11 @@ gpu_devices: optional_hash
kavlan:
<optional_hash>:
<multi>:
<multi>: ip_address
<multi>: ipv4_address
kavlan6:
<optional_hash>:
<multi>:
<multi>: ip_address
<multi>: ipv6_address
main_memory:
ram_size: integer
pmem_size: optional_integer
......@@ -49,7 +49,7 @@ network_adapters:
vendor: optional # optional_string
model: optional_string
driver: optional_string
ip: optional_ip_address
ip: optional_ipv4_address
netmask: optional # Create optional_netmask format ?
mac: optional_string
ib_switch_card: optional_string
......@@ -57,7 +57,7 @@ network_adapters:
switch: optional_string
switch_port: optional_string
hwid: optional_string
ip6: optional_ip_address
ip6: optional_ipv6_address
guid: optional_string
line_card: optional_string
position: optional_integer
......
......@@ -14,7 +14,7 @@ servers:
expire: optional
network_adapters:
<multi>:
ip: ip_address
ip: ipv4_address
mounted: optional_boolean
mac: optional_string
pdu:
......@@ -48,17 +48,17 @@ laptops:
network_adapters:
<multi>:
mounted: optional_boolean
ip: ip_address
ip: ipv4_address
mac: optional_string
g5ksubnet:
network: string
gateway: string
gateway: ipv4_address
kavlans:
<multi>:
network: string
gateway: string
gateway: ipv4_address
network_ipv6: string
gateway_ipv6: optional_string
gateway_ipv6: optional_ipv6_address
kavlan_ip_range: string
kavlan_topo: optional_string
kavlan_nef: optional_integer
......@@ -68,14 +68,14 @@ pdus:
type: string
uid: string
ports: optional_hash
ip: ip_address
ip: ipv4_address
mac: optional_string
vendor: optional_string
model: optional_string
metrics: optional_array
kind: optional_string
renater_ip: ip_address
frontend_ip: ip_address
renater_ip: ipv4_address
frontend_ip: ipv4_address
ipv6:
prefix: string
site_global_kavlan: integer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment