incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 3/4] Added support for Addresses collection to API
Date Wed, 08 Dec 2010 12:34:24 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 server/server.rb                       |   80 ++++++++++++++++++++++++++++++++
 server/views/addresses/index.html.haml |   26 ++++++++++
 server/views/addresses/index.xml.haml  |    4 ++
 server/views/addresses/show.html.haml  |   26 ++++++++++
 server/views/addresses/show.xml.haml   |   14 ++++++
 5 files changed, 150 insertions(+), 0 deletions(-)
 create mode 100644 server/views/addresses/index.html.haml
 create mode 100644 server/views/addresses/index.xml.haml
 create mode 100644 server/views/addresses/show.html.haml
 create mode 100644 server/views/addresses/show.xml.haml

diff --git a/server/server.rb b/server/server.rb
index 9585f9b..4a7f05f 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -486,6 +486,86 @@ collection :keys do
 
 end
 
+collection :addresses do
+  description "Manage IP addresses"
+
+  operation :index do
+    description "List all IP addresses provided by backend cloud"
+    with_capability :addresses
+    control do
+      filter_all :addresses
+    end
+  end
+
+  operation :show do
+    description "Show details about specific IP address"
+    with_capability :address
+    control do
+      show :address
+    end
+  end
+
+  operation :create do
+    description "Allocate a new IP address if provider support that"
+    with_capability :create_address
+    param :instance_id, :string, :optional, "Associate IP to instance after create"
+    control do
+      @address = driver.create_address(credentials, params)
+      respond_to do |format|
+        format.html { haml :"addresses/show" }
+        format.xml { haml :"addresses/show" }
+      end
+    end
+  end
+
+  operation :destroy do
+    description "Deallocate IP address if provider support that"
+    with_capability :destroy_address
+    control do
+      retval = driver.destroy_address(credentials, params)
+      respond_to do |format|
+        format.html do
+          if retval
+            redirect addresses_url
+          end
+        end
+        format.xml { status 410 }
+        format.json { status 410 }
+      end
+    end
+  end
+
+  operation :associate, :member => true, :method => :put do
+    description "Associate IP address to instance"
+    with_capability :associate_address
+    param :id, :string,  :required
+    param :instance_id, :string,  :required
+    control do
+      driver.associate_address(credentials, params)
+      respond_to do |format|
+        format.html { redirect address_url(params[:id]) }
+        format.xml { redirect address_url(params[:id]) }
+        format.json { redirect address_url(params[:id]) }
+      end
+    end
+  end
+
+  operation :release, :member => true, :method => :post do
+    description "Release instance from address"
+    with_capability :release_address
+    param :id,  :string,  :required
+    control do
+      driver.release_address(credentials, params)
+      respond_to do |format|
+        format.html { redirect address_url(params[:id]) }
+        format.xml { redirect address_url(params[:id]) }
+        format.json { redirect address_url(params[:id]) }
+      end
+    end
+  end
+
+end
+
 #get html form for creating a new blob
 get '/api/buckets/:bucket/new_blob' do
   @bucket_id = params[:bucket]
diff --git a/server/views/addresses/index.html.haml b/server/views/addresses/index.html.haml
new file mode 100644
index 0000000..9cc16ff
--- /dev/null
+++ b/server/views/addresses/index.html.haml
@@ -0,0 +1,26 @@
+%h1 Addresses
+
+%table.display
+  %thead
+    %tr
+      %th ID
+      %th Instance
+      %th Visibility
+      %th Actions
+  %tbody
+    - @elements.each do |address|
+      %tr
+        %td
+          = link_to address.id, address_url( address.id )
+        %td
+          = link_to(address.instance_id, instance_url(address.instance_id)) if address.instance_id
+        %td
+          = address.is_public? ? "PUBLIC" : "PRIVATE"
+        %td
+          - if driver.respond_to?(:destroy_address)
+            =link_to_action 'Destroy', destroy_address_url(address.id), :delete
+  %tfoot
+    - if driver.respond_to?(:create_address)
+      %tr
+        %td{:colspan => 4, :style => "text-align:right;"}
+          =link_to_action 'Create', addresses_url, :post
diff --git a/server/views/addresses/index.xml.haml b/server/views/addresses/index.xml.haml
new file mode 100644
index 0000000..abf83b7
--- /dev/null
+++ b/server/views/addresses/index.xml.haml
@@ -0,0 +1,4 @@
+!!!XML
+%addresses
+  - @elements.each do |c|
+    = haml :'addresses/show', :locals => { :@address => c, :partial => true }
diff --git a/server/views/addresses/show.html.haml b/server/views/addresses/show.html.haml
new file mode 100644
index 0000000..6cb28a1
--- /dev/null
+++ b/server/views/addresses/show.html.haml
@@ -0,0 +1,26 @@
+%h1
+  = @address.id
+
+%dl
+  %di
+    %dt Address visibility
+    %dd
+      = @address.is_public? ? "PUBLIC" : "PRIVATE"
+  %di
+    %dt Associated instance
+    %dd
+      = @address.instance_id ? @address.instance_id : "No instance"
+  - unless @address.instance_id
+    %di
+      %dt 
+        Associate Instance:
+      %dd
+        %form{ :action => associate_address_url(@address.id), :method => :post}
+          %input{ :type => :hidden, :name => '_method', :value => :put }
+          %input{ :type => :text, :name => 'instance_id', :value => ''}
+          %input{ :type => :submit, :value => "Associate" }
+  - else
+    %di
+      %dt
+        Release Instance:
+        = link_to_action "Release", release_address_url(@address.id), :post
diff --git a/server/views/addresses/show.xml.haml b/server/views/addresses/show.xml.haml
new file mode 100644
index 0000000..a33648b
--- /dev/null
+++ b/server/views/addresses/show.xml.haml
@@ -0,0 +1,14 @@
+- unless defined?(partial)
+  !!! XML
+%address{ :href => address_url(@address.id), :id => @address.id }
+  %actions
+    - if driver.respond_to?(:destroy_address)
+      %link{ :href => destroy_address_url(@address.id), :rel => "destroy", :method
=> :delete }
+    - if driver.respond_to?(:associate_address)
+      - if @address.instance_id
+        %link{ :href => release_address_url(@address.id), :rel => "release", :method
=> :post }
+  %visibility<
+    =@address.is_public? ? "PUBLIC" : "PRIVATE"
+  - if @address.instance_id
+    %instance{ :href => instance_url(@address.instance_id), :rel => "instance", :id
=> @address.instance_id}
+  
-- 
1.7.3.2


Mime
View raw message