Updated mcollective.init according to OSCI-658
[packages/precise/mcollective.git] / plugins / mcollective / validator / ipv4address_validator.rb
diff --git a/plugins/mcollective/validator/ipv4address_validator.rb b/plugins/mcollective/validator/ipv4address_validator.rb
new file mode 100644 (file)
index 0000000..b85a207
--- /dev/null
@@ -0,0 +1,16 @@
+module MCollective
+  module Validator
+    class Ipv4addressValidator
+      require 'ipaddr'
+
+      def self.validate(validator)
+        begin
+          ip = IPAddr.new(validator)
+          raise ValidatorError, "value should be an ipv4 adddress" unless ip.ipv4?
+        rescue
+          raise ValidatorError, "value should be an ipv4 address"
+        end
+      end
+    end
+  end
+end