Module: Staypuft::Deployment::IpAddressValidator
- Included in:
- CinderService::Equallogic::SanIpValueValidator, NeutronService::Cisconexus::IpValueValidator, NeutronService::N1kvIpAddressValidator
- Defined in:
- app/models/staypuft/deployment/ip_address_validator.rb
Constant Summary collapse
- NOT_RANGE_MSG =
N_("Specify single IP address, not range")
- INVALID_IP_OR_FQDN_MSG =
N_("Invalid IP address or FQDN supplied")
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/staypuft/deployment/ip_address_validator.rb', line 6 def validate_each(record, attribute, value) return if value.empty? begin ip_addr = IPAddr.new(value) ip_range = ip_addr.to_range if ip_range.begin == ip_range.end true else record.errors.add attribute, NOT_RANGE_MSG false end rescue # not IP addr # validating as fqdn if /(?=^.{1,254}$)(^(((?!-)[a-zA-Z0-9-]{1,63}(?<!-))|((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63})$)/ =~ value true else record.errors.add attribute, INVALID_IP_OR_FQDN_MSG false end end end |