Ack. Was able to verify with mock and ec2. Tested incorrect account
name, image, build, and target image ids during push.
On 11/10/2011 09:40 AM, mtaylor(a)redhat.com wrote:
From: Martyn Taylor<mtaylor(a)redhat.com>
---
lib/aeolus_cli/command/base_command.rb | 40 +++++++++------
lib/aeolus_cli/command/build_command.rb | 26 ++++++----
lib/aeolus_cli/command/delete_command.rb | 82 ++++++++++++++++++------------
lib/aeolus_cli/command/import_command.rb | 36 +++++++------
4 files changed, 110 insertions(+), 74 deletions(-)
diff --git a/lib/aeolus_cli/command/base_command.rb
b/lib/aeolus_cli/command/base_command.rb
index de86f03..fc25046 100644
--- a/lib/aeolus_cli/command/base_command.rb
+++ b/lib/aeolus_cli/command/base_command.rb
@@ -86,22 +86,32 @@ module Aeolus
private
def handle_exception(e)
- message = "Unable to perform task: \n"
- case e.class
- when ActiveResource::BadRequest : message += "- Bad Request Sent to
Server"
- when ActiveResource::UnauthorizedAccess : message += "- You are
unauthorized to view/edit this resource/collection"
- when ActiveResource::ForbiddenAccess : message += "- Access is forbidden
to this resource/collection"
- when ActiveResource::ResourceNotFound : message += "- Unable to find
resource"
- when ActiveResource::MethodNotAllowed : message += "- Method not
allowed"
- when ActiveResource::ResourceConflict : message += "- This resource
conflicts with another on the server"
- when ActiveResource::ResourceGone : message += "- This resource no londer
exists"
- when ActiveResource::ResourceInvalid : message += "- This resource is
invalid"
- when ActiveResource::ClientError : message += "- An error was thrown by
the client"
- when ActiveResource::ServerError : message += "- An unexplained error was
returned by the server"
- when ActiveResource::ConnectionError : message += "- Unable to connect to
the server"
- else message += "- Internal Error: " + e.message
+ doc = Nokogiri::XML e.response.body
+ code = doc.xpath("/error/code").text
+ message = doc.xpath("/error/message").text
+
+ if message.to_s.empty?
+ case code
+ when "BuildDeleteFailure" : message = "An error occured when
deleting the Build from the Image Warehouse"
+ when "BuildNotFound" : message = "Could not find the
specified Build"
+ when "ImageDeleteFailure" : message = "An error occured when
deleting the Image from the Image Warehouse"
+ when "ImageNotFound" : message = "Could not find the
specified Image"
+ when "InsufficientParametersSupplied" : message = "There were
insufficient parameters provided in the request"
+ when "ParameterDataIncorrect" : message = "The given
parameters are incorrect"
+ when "PushError" : message = "An error occured the Image
Factory when trying to push"
+ when "ProviderAccountNotFound" : message = "Could not find
the specified account"
+ when "ProviderImageDeleteFailure" : message = "An error
occurd when deleting the Provider Image from Image Warehouse"
+ when "ProviderImageNotFound" : message = "Could not find the
specified Provider Image"
+ when "ProviderImageStatusNotFound" : message = "There was no
status supplied in the Provider Image"
+ when "TargetImageDeleteFailure" : message = "An error occured
when deleting the Target Image from the Image Warehouse"
+ when "TargetImageNotFound" : message = "Could not locate the
specified Target Image"
+ when "TargetImageStatusNotFound" : message = "There was no
status supplied in the Target Image"
+ when "TargetNotFound" : message = "Could not locate the
specified Target"
+ else message = "Unknown Error"
+ end
end
- puts message
+ puts ""
+ puts "ERROR: " + code + " => " + message
quit(1)
end
diff --git a/lib/aeolus_cli/command/build_command.rb
b/lib/aeolus_cli/command/build_command.rb
index 6847542..90ea302 100644
--- a/lib/aeolus_cli/command/build_command.rb
+++ b/lib/aeolus_cli/command/build_command.rb
@@ -30,17 +30,21 @@ module Aeolus
def run
if combo_implemented?
- template = read_template
- validate_xml_schema(template)
+ begin
+ template = read_template
+ validate_xml_schema(template)
- image = Aeolus::CLI::Image.new({:targets => @options[:target] *
",", :tdl => template})
- image.save!
- puts "Image: " + image.id
- puts "Build: " + image.build.id
- Array(image.build.target_images.target_image).each do |target_image|
- puts "Target Image: " + target_image.id.to_s + "\t :Status
" + target_image.status
+ image = Aeolus::CLI::Image.new({:targets => @options[:target] *
",", :tdl => template})
+ image.save!
+ puts "Image: " + image.id
+ puts "Build: " + image.build.id
+ Array(image.build.target_images.target_image).each do |target_image|
+ puts "Target Image: " + target_image.id.to_s + "\t :Status
" + target_image.status
+ end
+ quit(0)
+ rescue => e
+ handle_exception(e)
end
- quit(0)
end
end
@@ -58,7 +62,7 @@ module Aeolus
def read_template
template = read_file(@options[:template])
if template.nil?
- puts "Cannot find specified file"
+ puts "Error: Cannot find specified file"
quit(1)
end
template
@@ -66,7 +70,7 @@ module Aeolus
def combo_implemented?
if @options[:template].empty? || @options[:target].empty?
- puts "This combination of parameters is not currently supported"
+ puts "Error: This combination of parameters is not currently
supported"
quit(1)
end
true
diff --git a/lib/aeolus_cli/command/delete_command.rb
b/lib/aeolus_cli/command/delete_command.rb
index 71dc2e3..e703918 100644
--- a/lib/aeolus_cli/command/delete_command.rb
+++ b/lib/aeolus_cli/command/delete_command.rb
@@ -20,55 +20,73 @@ module Aeolus
end
def provider_image
- if pi = ProviderImage.find(@options[:providerimage])
- if pi.destroy
- puts "Provider Image: " + @options[:providerimage] + "
Deleted Successfully"
- exit(0)
+ begin
+ if pi = ProviderImage.find(@options[:providerimage])
+ if pi.destroy
+ puts "Provider Image: " + @options[:providerimage] + "
Deleted Successfully"
+ exit(0)
+ end
+ puts "ERROR: Unable to Delete Provider Image: " +
@options[:providerimage]
+ exit(1)
+ else
+ puts "ERROR: Provider Image: " + @options[:providerimage] + "
does not exist"
+ exit(1)
end
- puts "ERROR: Unable to Delete Provider Image: " +
@options[:providerimage]
- else
- puts "Provider Image: " + @options[:providerimage] + " does not
exist"
+ rescue => e
+ handle_exception(e)
end
- exit(1)
end
def target_image
- if ti = TargetImage.find(@options[:targetimage])
- if ti.destroy
- puts "Target Image: " + @options[:targetimage] + " Deleted
Successfully"
- exit(0)
+ begin
+ if ti = TargetImage.find(@options[:targetimage])
+ if ti.destroy
+ puts "Target Image: " + @options[:targetimage] + " Deleted
Successfully"
+ exit(0)
+ end
+ puts "ERROR: Unable to Delete Target Image: " +
@options[:targetimage]
+ exit(1)
+ else
+ puts "ERROR: Target Image: " + @options[:targetimage] + "
does not exist"
+ exit(1)
end
- puts "ERROR: Unable to Delete Target Image: " +
@options[:targetimage]
- else
- puts "Target Image: " + @options[:targetimage] + " does not
exist"
+ rescue => e
+ handle_exception(e)
end
- exit(1)
end
def build
- if b = Build.find(@options[:build])
- if b.destroy
- puts "Build: " + @options[:build] + " Deleted
Successfully"
- exit(0)
+ begin
+ if b = Build.find(@options[:build])
+ if b.destroy
+ puts "Build: " + @options[:build] + " Deleted
Successfully"
+ exit(0)
+ end
+ puts "ERROR: Unable to Delete Build: " + @options[:build]
+ exit(1)
+ else
+ puts "ERROR: Build: " + @options[:build] + " does not
exist"
+ exit(1)
end
- puts "ERROR: Unable to Delete Build: " + @options[:build]
- else
- puts "Build: " + @options[:build] + " does not exist"
+ rescue => e
+ handle_exception(e)
end
- exit(1)
end
def image
- if i = Image.find(@options[:image])
- if i.destroy
- puts "Image: " + @options[:image] + " Deleted
Successfully"
- exit(0)
+ begin
+ if i = Image.find(@options[:image])
+ if i.destroy
+ puts "Image: " + @options[:image] + " Deleted
Successfully"
+ exit(0)
+ end
+ puts "ERROR: Unable to Delete Image: " + @options[:image]
+ else
+ puts "ERROR: Image: " + @options[:image] + " does not
exist"
end
- puts "ERROR: Unable to Delete Image: " + @options[:image]
- else
- puts "Image: " + @options[:image] + " does not exist"
+ rescue => e
+ exit(1)
end
- exit(1)
end
end
end
diff --git a/lib/aeolus_cli/command/import_command.rb
b/lib/aeolus_cli/command/import_command.rb
index 09d12b5..a91c405 100644
--- a/lib/aeolus_cli/command/import_command.rb
+++ b/lib/aeolus_cli/command/import_command.rb
@@ -29,23 +29,27 @@ module Aeolus
end
def import_image
- description = read_file(@options[:description])
- if !description.nil?
- @options[:description] = description
+ begin
+ description = read_file(@options[:description])
+ if !description.nil?
+ @options[:description] = description
+ end
+ # TODO: Validate Description XML
+ image = Aeolus::CLI::Image.new({:target_identifier => @options[:id],
+ :target_name => @options[:target].first,
+ :image_descriptor =>
@options[:description],
+ :provider_name =>
@options[:provider].first})
+ image.save!
+ puts ""
+ puts "Image: " + image.id
+ puts "Build: " + image.build.id
+ puts "Target Image: " + image.build.target_images.target_image.id
+ puts "Provider Image: " +
image.build.target_images.target_image.provider_images.provider_image.id
+ puts "Status: " +
image.build.target_images.target_image.provider_images.provider_image.status
+ quit(0)
+ rescue => e
+ handle_exception(e)
end
- # TODO: Validate Description XML
- image = Aeolus::CLI::Image.new({:target_identifier => @options[:id],
- :target_name => @options[:target].first,
- :image_descriptor =>
@options[:description],
- :provider_name =>
@options[:provider].first})
- image.save!
- puts ""
- puts "Image: " + image.id
- puts "Build: " + image.build.id
- puts "Target Image: " + image.build.target_images.target_image.id
- puts "Provider Image: " +
image.build.target_images.target_image.provider_images.provider_image.id
- puts "Status: " +
image.build.target_images.target_image.provider_images.provider_image.status
- quit(0)
end
end
end