Return-Path: Delivered-To: apmail-incubator-deltacloud-dev-archive@minotaur.apache.org Received: (qmail 20961 invoked from network); 8 Dec 2010 12:35:02 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Dec 2010 12:35:02 -0000 Received: (qmail 11124 invoked by uid 500); 8 Dec 2010 12:35:02 -0000 Delivered-To: apmail-incubator-deltacloud-dev-archive@incubator.apache.org Received: (qmail 11006 invoked by uid 500); 8 Dec 2010 12:35:02 -0000 Mailing-List: contact deltacloud-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: deltacloud-dev@incubator.apache.org Delivered-To: mailing list deltacloud-dev@incubator.apache.org Received: (qmail 10858 invoked by uid 99); 8 Dec 2010 12:34:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Dec 2010 12:34:58 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=10.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mfojtik@redhat.com designates 209.132.183.28 as permitted sender) Received: from [209.132.183.28] (HELO mx1.redhat.com) (209.132.183.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Dec 2010 12:34:52 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oB8CYVwM016710 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 8 Dec 2010 07:34:32 -0500 Received: from patashnik.brq.redhat.com (dhcp-2-138.brq.redhat.com [10.34.2.138]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oB8CYRMr010545 for ; Wed, 8 Dec 2010 07:34:31 -0500 From: mfojtik@redhat.com To: deltacloud-dev@incubator.apache.org Subject: [PATCH core 3/4] Added support for Addresses collection to API Date: Wed, 8 Dec 2010 13:34:24 +0100 Message-Id: <1291811665-26254-4-git-send-email-mfojtik@redhat.com> In-Reply-To: <1291811665-26254-1-git-send-email-mfojtik@redhat.com> References: <1291811665-26254-1-git-send-email-mfojtik@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 From: Michal Fojtik --- 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