incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] Client: Fixed destroy operation on firewall resource
Date Mon, 08 Aug 2011 11:42:54 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 client/lib/base_object.rb             |    8 ++++----
 client/lib/deltacloud.rb              |    2 +-
 server/views/firewalls/index.xml.haml |    7 ++++++-
 server/views/firewalls/show.xml.haml  |    5 +++++
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/client/lib/base_object.rb b/client/lib/base_object.rb
index f6ef149..5be7ca4 100644
--- a/client/lib/base_object.rb
+++ b/client/lib/base_object.rb
@@ -149,7 +149,7 @@ module DeltaCloud
         @actions = []
       end
 
-      # This trigger is called right after action. 
+      # This trigger is called right after action.
       # This method does nothing inside ActionObject
       # but it can be redifined and used in meta-programming
       def action_trigger(action)
@@ -314,14 +314,14 @@ module DeltaCloud
         DeltaCloud::API.class_eval("class #{class_name} < DeltaCloud::#{parent_class};
end")
         @defined_classes << class_name
       end
-      
+
       DeltaCloud::API.const_get(parent.classify).const_get(name.classify)
     end
 
     def self.guess_model_type(response)
       response = Nokogiri::XML(response.to_s)
-      return :action if ((response/'//actions').length == 1) and ((response/'//state').length
== 0)
-      return :stateful if ((response/'//actions').length == 1) and ((response/'//state').length
== 1)
+      return :action if ((response/'//actions').length >= 1) and ((response/'//state').length
== 0)
+      return :stateful if ((response/'//actions').length >= 1) and ((response/'//state').length
>= 1)
       return :base
     end
 
diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index e2db0ba..650e400 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -213,7 +213,7 @@ module DeltaCloud
         # If there are actions, add they to ActionObject/StateFullObject
         if attribute.name == 'actions'
           (attribute/'link').each do |link|
-            (obj.add_run_action!(item['id'], link) && next) if link[:rel] == 'run'

+            (obj.add_run_action!(item['id'], link) && next) if link[:rel] == 'run'
             obj.add_action_link!(item['id'], link)
           end && next
         end
diff --git a/server/views/firewalls/index.xml.haml b/server/views/firewalls/index.xml.haml
index f027785..0de740e 100644
--- a/server/views/firewalls/index.xml.haml
+++ b/server/views/firewalls/index.xml.haml
@@ -2,6 +2,9 @@
 %firewalls
   - @firewalls.each do |firewall|
     %firewall{:href => firewall_url(firewall.id), :id => firewall.id}
+      %actions
+        %link{ :rel => :destroy, :href => destroy_firewall_url(firewall.id), :method
=> :delete, :id => firewall.id}
+        %link{ :rel => :add_rule, :href => "#{firewall_url(firewall.name)}/rules",
:method => :post, :id => firewall.id}
       - firewall.attributes.select{ |attr| attr != :id && attr!= :rules}.each do
|attribute|
         - haml_tag("#{attribute}".tr('-', '_'), :<) do
           - if [:name, :description].include?(attribute)
@@ -12,6 +15,8 @@
       %rules
         - firewall.rules.each do |rule|
           %rule{:id => rule.id}
+          %actions
+            %link{ :rel => :rule, :href => "#{firewall_url(firewall.name)}/#{rule.id}",
:method => :delete, :id =>rule.id, :rel => :destroy }
             - rule.attributes.select{|attr| attr != :sources && attr != :id}.each
do |rule_attrib|
               - haml_tag("#{rule_attrib}".tr('-', '_'), :<) do
                 - haml_concat rule.send(rule_attrib)
@@ -20,4 +25,4 @@
                 - if source[:type] == "group"
                   %source{:name => source[:name], :type=> source[:type], :owner=>
source[:owner]}
                 - else
-                  %source{:prefix => source[:prefix], :address=> source[:address],
:family=>source[:family], :type => source[:type]}
\ No newline at end of file
+                  %source{:prefix => source[:prefix], :address=> source[:address],
:family=>source[:family], :type => source[:type]}
diff --git a/server/views/firewalls/show.xml.haml b/server/views/firewalls/show.xml.haml
index c2ea458..39ed9d2 100644
--- a/server/views/firewalls/show.xml.haml
+++ b/server/views/firewalls/show.xml.haml
@@ -1,5 +1,8 @@
 !!! XML
 %firewall{:href => firewall_url(@firewall.id), :id => @firewall.id}
+  %actions
+    %link{ :rel => :destroy, :href => destroy_firewall_url(@firewall.id), :method =>
:delete}
+    %link{ :rel => :update, :href => "#{firewall_url(@firewall_name)}/rules", :method
=> :post}
   - @firewall.attributes.select{ |attr| attr != :id && attr!= :rules}.each do |attribute|
     - haml_tag("#{attribute}".tr('-', '_'), :<) do
       - if [:name, :description].include?(attribute)
@@ -10,6 +13,8 @@
   %rules
     - @firewall.rules.each do |rule|
       %rule{:href => firewall_url(@firewall.id) + '/' + rule.id, :id => rule.id}
+        %actions
+          %link{ :rel => :destroy, :href => "#{firewall_url(@firewall.name)}/#{rule.id}",
:method => :delete}
         - rule.attributes.select{|attr| attr != :sources && attr != :id}.each do
|rule_attrib|
           - haml_tag("#{rule_attrib}".tr('-', '_'), :<) do
             - haml_concat rule.send(rule_attrib)
-- 
1.7.4.1


Mime
View raw message