incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH] Restores delete firewall rule semantics:
Date Mon, 11 Jul 2011 13:39:46 GMT
From: marios <marios@redhat.com>

DELETE /api/firewalls/:firewall/:rule_id

Also, exposes URI for each firewall rule in
returned XML.

Signed-off-by: marios <marios@redhat.com>
---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |    2 +-
 server/server.rb                                |   31 ++++++++++------------
 server/views/firewalls/show.html.haml           |    3 +-
 server/views/firewalls/show.xml.haml            |    4 +-
 4 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 53f95b6..4e182a3 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -640,7 +640,7 @@ module Deltacloud
 #--
         def delete_firewall_rule(credentials, opts={})
           ec2 = new_client(credentials)
-          firewall = opts[:id]
+          firewall = opts[:firewall]
           protocol, from_port, to_port, addresses, groups = firewall_rule_params(opts[:rule_id])
           safely do
             ec2.manage_security_group_ingress(firewall, from_port, to_port, protocol, "revoke",
addresses, groups)
diff --git a/server/server.rb b/server/server.rb
index 21e04ad..c28ad03 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -994,6 +994,19 @@ get "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/firewalls/:firewall/new_rule"
   end
 end
 
+#delete a firewall rule
+delete '/api/firewalls/:firewall/:rule' do
+  opts = {}
+  opts[:firewall] = params[:firewall]
+  opts[:rule_id] = params[:rule]
+  driver.delete_firewall_rule(credentials, opts)
+  respond_to do |format|
+    format.html {redirect firewall_url(params[:firewall])}
+    format.xml {204}
+    format.json {204}
+  end
+end
+
 #FIREWALLS
 collection :firewalls do
   description "Allow user to define firewall rules for an instance (ec2 security groups)
eg expose ssh access [port 22, tcp]."
@@ -1073,20 +1086,4 @@ collection :firewalls do
     end
   end
 
-#delete a firewall rule DELETE /api/firewalls/:firewall/rule - with param rule_id
-  operation :rule, :method => :delete, :member => true do
-    description 'Delete the specified firewall rule from the given firewall'
-    param :firewall, :required, :string
-    param :rule_id,  :required, :string
-    with_capability :delete_firewall_rule
-    control do
-      driver.delete_firewall_rule(credentials, params)
-      respond_to do |format|
-        format.html {redirect firewall_url(params[:id])}
-        format.xml {204}
-        format.json {204}
-      end
-    end
-  end
-
-end #firewalls
+end
diff --git a/server/views/firewalls/show.html.haml b/server/views/firewalls/show.html.haml
index b77aaa4..53edf53 100644
--- a/server/views/firewalls/show.html.haml
+++ b/server/views/firewalls/show.html.haml
@@ -36,9 +36,8 @@
             type: #{source[:type]}, family: #{source[:family]}, address: #{source[:address]},
prefix: #{source[:prefix]}
             %br
       %dd
-        %form{ :action => "#{firewall_url(@firewall.name)}/rule", :method => :post}
+        %form{ :action => "#{firewall_url(@firewall.name)}/#{rule.id}", :method =>
:post}
           %input{:type => "hidden", :name => "_method", :value => "delete"}
-          %input{:type => "hidden", :name => "rule_id", :value => rule.id}
           %input{:type => :submit, :value => "Delete Rule"}
   %dd
     = link_to_action 'Delete Firewall', destroy_firewall_url(@firewall.name), :delete
diff --git a/server/views/firewalls/show.xml.haml b/server/views/firewalls/show.xml.haml
index 9d1fc48..c2ea458 100644
--- a/server/views/firewalls/show.xml.haml
+++ b/server/views/firewalls/show.xml.haml
@@ -9,7 +9,7 @@
         - haml_concat @firewall.send(attribute)
   %rules
     - @firewall.rules.each do |rule|
-      %rule{:id => rule.id}
+      %rule{:href => firewall_url(@firewall.id) + '/' + rule.id, :id => rule.id}
         - rule.attributes.select{|attr| attr != :sources && attr != :id}.each do
|rule_attrib|
           - haml_tag("#{rule_attrib}".tr('-', '_'), :<) do
             - haml_concat rule.send(rule_attrib)
@@ -18,4 +18,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]}
-- 
1.7.3.4


Mime
View raw message