Commit 841b4c3e authored by MICHON Nicolas's avatar MICHON Nicolas
Browse files

[dev] Added network_equipments schema validation

parent 974a2e78
class HashValidator::Validator::LinecardPortValidator < HashValidator::Validator::Base
def initialize
super('linecard_port')
@port_properties = ["uid", "name", "port", "kind", "mtu", "rate", "site"]
end
def validate(key, values, validations, errors)
if values.is_a?(Hash)
values.each do |k, v|
if @port_properties.index(k) == nil
errors[key] = "unexpected key '#{k}'."
end
end
if values["uid"].nil? || values["uid"].empty?
errors[key] = "port 'uid' property should be defined."
end
elsif values.is_a?(String) || values == nil
#Allow any string and nil values
else
errors[key] = "port definition should be either empty, a String or a Hash (with required 'uid' and #{@port_properties} allowed properties)."
end
end
end
HashValidator.append_validator(HashValidator::Validator::LinecardPortValidator.new)
......@@ -11,6 +11,7 @@ dir = Pathname(__FILE__).parent
require 'json'
require 'hash_validator' # https://github.com/jamesbrooks/hash_validator
require "#{dir}/multihash_validator" # custom validator for <multi> array-like Hash support
require "#{dir}/custom_validators" # other custom validators
# Simple required_hash validator
HashValidator.append_validator(HashValidator::Validator::SimpleValidator.new('required_hash', lambda { |v| v.is_a?(Hash) }))
......
---
model: string
kind: string
site: string
backplane_bps: optional_integer
mtu: optional_integer
snmp_community: string
network_adapters: optional
weathermap:
<optional_hash>:
use_cacti: string
sensors:
<optional_hash>:
network:
<optional_hash>:
available: boolean
resolution: optional_integer
via: optional
power:
<optional_hash>:
available: boolean
resolution: optional_integer
via: optional
# pdu:
# uid: string
# port: integer
monitoring:
<optional_hash>:
wattmeter: optional
metric: optional_string
vlans:
<optional_hash>:
<multi>:
<optional_hash>:
administrative: optional_boolean
name: optional_string
addresses: optional_array
mtu: optional_integer
linecards:
<multi>:
snmp_pattern: string
kind: optional_string
rate: integer
model: optional_string
backplane_bps: optional_integer
port: optional_string
ports:
<multi>: linecard_port #custom linecard port validation (see lib/custom-validators.rb)
......@@ -30,6 +30,7 @@ def yaml_input_schema_validator(global_hash, sites = nil, clusters = nil)
schema_site = load_yaml_schema("#{dir}/schema-site.yaml")
schema_cluster = load_yaml_schema("#{dir}/schema-cluster.yaml")
schema_node = load_yaml_schema("#{dir}/schema-node.yaml")
schema_network_equipments = load_yaml_schema("#{dir}/schema-network_equipments.yaml")
r = true
......@@ -40,9 +41,13 @@ def yaml_input_schema_validator(global_hash, sites = nil, clusters = nil)
r &= run_validator(site_uid, site, schema_site) #
site["clusters"].each do |cluster_uid, cluster|
next if clusters and not clusters.include?(cluster_uid)
site['networks'].each do |network_equipment_uid, network_equipment|
r &= run_validator(site_uid, network_equipment, schema_network_equipments)
end
site["clusters"].each do |cluster_uid, cluster|
next if clusters and not clusters.include?(cluster_uid)
r &= run_validator(cluster_uid, cluster, schema_cluster) #
cluster["nodes"].each do |node_uid, node|
......
Supports Markdown
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