incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Crawley <tcraw...@redhat.com>
Subject [PATCH 1/3] Add support files for capability checking.
Date Thu, 04 Nov 2010 13:51:19 GMT
---
 server/lib/deltacloud/backend_capability.rb        |   21 ++++++++++++++++++++
 .../errors/backend_capability_failure.html.haml    |   11 ++++++++++
 .../errors/backend_capability_failure.xml.haml     |    4 +++
 3 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 server/lib/deltacloud/backend_capability.rb
 create mode 100644 server/views/errors/backend_capability_failure.html.haml
 create mode 100644 server/views/errors/backend_capability_failure.xml.haml

diff --git a/server/lib/deltacloud/backend_capability.rb b/server/lib/deltacloud/backend_capability.rb
new file mode 100644
index 0000000..bec8714
--- /dev/null
+++ b/server/lib/deltacloud/backend_capability.rb
@@ -0,0 +1,21 @@
+module Deltacloud::BackendCapability
+
+  class Failure < StandardError
+    attr_reader :capability
+    def initialize(capability, msg='')
+      super(msg)
+      @capability = capability
+    end
+  end
+
+  attr_reader :capability
+  def with_capability(capability)
+    @capability = capability
+  end
+
+  def check_capability(backend)
+    if capability and !backend.respond_to?(capability)
+      raise Failure.new(capability, "#{capability} capability not supported by backend #{backend.class.name}")
+    end
+  end
+end
diff --git a/server/views/errors/backend_capability_failure.html.haml b/server/views/errors/backend_capability_failure.html.haml
new file mode 100644
index 0000000..dc830d8
--- /dev/null
+++ b/server/views/errors/backend_capability_failure.html.haml
@@ -0,0 +1,11 @@
+%h1 Backend Capability Failure
+
+%p= @error.message
+
+%dl
+  %di
+    %dt Request URL
+    %dd= request.env['REQUEST_URI']
+  %di
+    %dt Capability
+    %dd= @error.capability
diff --git a/server/views/errors/backend_capability_failure.xml.haml b/server/views/errors/backend_capability_failure.xml.haml
new file mode 100644
index 0000000..83892fb
--- /dev/null
+++ b/server/views/errors/backend_capability_failure.xml.haml
@@ -0,0 +1,4 @@
+%error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
+  %capability #{@error.capability}
+  %message #{@error.message}
+
-- 
1.7.2.3


Mime
View raw message