On Thu, Dec 22, 2011 at 06:42:53PM +0100, mzatko(a)redhat.com wrote:
From: Maros Zatko <mzatko(a)redhat.com>
---
lib/aeolus_cli/command/import_command.rb | 50 +++++++++++++++++++++++++++---
1 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/lib/aeolus_cli/command/import_command.rb
b/lib/aeolus_cli/command/import_command.rb
index 591a999..91a5d54 100644
--- a/lib/aeolus_cli/command/import_command.rb
+++ b/lib/aeolus_cli/command/import_command.rb
@@ -18,11 +18,7 @@ module Aeolus
def initialize(opts={}, logger=nil)
super(opts, logger)
default = {
- :image => '',
- :build => '', # TODO - Is this used anywhere?
- :id => '',
:description => '<image><name>' + @options[:id] +
'</name></image>',
- :provider_account => ''
}
@options = default.merge(@options)
end
@@ -33,7 +29,9 @@ module Aeolus
if !description.nil?
@options[:description] = description
end
- # TODO: Validate Description XML
+
+ import_params_valid!(@options)
+
image = Aeolus::CLI::Image.new({:target_identifier => @options[:id],
:image_descriptor =>
@options[:description],
:provider_account_name =>
@options[:provider_account].first})
@@ -49,6 +47,48 @@ module Aeolus
handle_exception(e)
end
end
+
+ private
+
+ def import_params_valid!(params)
+ if not params.is_a? Hash
+ raise TypeError, "params should be Hash instead of #{params.class}"
+ end
+
+ if not params.values.all?
+ raise ArgumentError, "params should not contain nil"
+ end
+
+ required_keys = [:id, :target, :description, :provider]
+
+ isect = params.keys & required_keys
+ diff = params.keys - required_keys
+
+ missing = required_keys - isect
+
+ if not missing == []
+ raise ArgumentError, "missing #{missing*', '}"
+ end
+
+ if not diff == []
+ raise ArgumentError, "unexpected #{diff*', '}"
+ end
+
+ validate_description_xml!(params[:description])
+ end
+
+ def validate_description_xml!(xml)
+ errors = validate_xml_document(File.dirname(__FILE__) +
"/../../../examples/image_desc.rng", xml)
+ if errors.length > 0
+ puts "ERROR: The given image descrition does not conform to the xml
schema, see below for specific details:"
ITYM "description" ^^^^^^^^^^
+ errors.each do |error|
+ puts "- " + error.message
+ end
+ raise ArgumentError, "Invalid description"
+ end
+ true
+ end
+
end
end
end
--
1.7.7.4
(Just happened to see that...)
--H
--
== Hugh Brock, hbrock(a)redhat.com ==
== Engineering Manager, Cloud BU ==
== Aeolus Project: Manage virtual infrastructure across clouds. ==
==
http://aeolusproject.org ==
"I know that you believe you understand what you think I said, but I’m
not sure you realize that what you heard is not what I meant."
--Robert McCloskey