incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1034315 - in /incubator/deltacloud/trunk/server: ./ lib/deltacloud/base_driver/ lib/deltacloud/helpers/ public/javascripts/ views/instances/ views/load_balancers/
Date Fri, 12 Nov 2010 09:52:53 GMT
Author: mfojtik
Date: Fri Nov 12 09:52:52 2010
New Revision: 1034315

URL: http://svn.apache.org/viewvc?rev=1034315&view=rev
Log:
Added support for load_balancer collection

Added:
    incubator/deltacloud/trunk/server/views/load_balancers/
    incubator/deltacloud/trunk/server/views/load_balancers/index.html.haml
    incubator/deltacloud/trunk/server/views/load_balancers/index.xml.haml
    incubator/deltacloud/trunk/server/views/load_balancers/new.html.haml
    incubator/deltacloud/trunk/server/views/load_balancers/show.html.haml
    incubator/deltacloud/trunk/server/views/load_balancers/show.xml.haml
Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
    incubator/deltacloud/trunk/server/public/javascripts/application.js
    incubator/deltacloud/trunk/server/server.rb
    incubator/deltacloud/trunk/server/views/instances/new.html.haml

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb?rev=1034315&r1=1034314&r2=1034315&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb Fri Nov 12 09:52:52
2010
@@ -169,5 +169,13 @@ module Deltacloud
         param :location, :string, :optional
       end
     end
+
+    declare_feature :instances, :register_to_load_balancer do
+      description "Register instance to load balancer"
+      operation :create do
+        param :load_balancer_id, :string, :optional
+      end
+    end
+
   end
 end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb?rev=1034315&r1=1034314&r2=1034315&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb Fri Nov
12 09:52:52 2010
@@ -41,8 +41,8 @@ module ApplicationHelper
     collections[:instances].operations[action.to_sym].method
   end
 
-  def driver_has_feature?(feature_name)
-    not driver.features(:instances).select{ |f| f.name.eql?(feature_name) }.empty?
+  def driver_has_feature?(feature_name, collection_name = :instances)
+    not driver.features(collection_name).select{ |f| f.name.eql?(feature_name) }.empty?
   end
 
   def driver_has_auth_features?

Modified: incubator/deltacloud/trunk/server/public/javascripts/application.js
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/public/javascripts/application.js?rev=1034315&r1=1034314&r2=1034315&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/public/javascripts/application.js (original)
+++ incubator/deltacloud/trunk/server/public/javascripts/application.js Fri Nov 12 09:52:52
2010
@@ -29,4 +29,16 @@ $(document).ready(function() {
     return false;
   })
 
+  if ($('select#list_instances').length) {
+    $('select#list_instances').html("<option>Loading instances...</option>");
+    $.getJSON("/api/instances?state=RUNNING&format=json",
+      function(data){
+        $('select#list_instances').empty();
+        $.each(data.instances, function(i,item){
+          $('select#list_instances').append('<option value="'+item.id+'">'+item.id+'</option>');
+        });
+      }
+    );
+  }
+
 })

Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=1034315&r1=1034314&r2=1034315&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Fri Nov 12 09:52:52 2010
@@ -175,11 +175,87 @@ get "/api/instances/new" do
   @image   = driver.image( credentials, :id => params[:image_id] )
   @hardware_profiles = driver.hardware_profiles(credentials, :architecture => @image.architecture
)
   @realms = driver.realms(credentials)
+  if driver_has_feature?(:register_to_load_balancer)
+    @load_balancers = driver.load_balancers(credentials)
+  end
   respond_to do |format|
     format.html { haml :"instances/new" }
   end
 end
 
+get '/api/load_balancers/new' do
+  @realms = driver.realms(credentials)
+  @instances = driver.instances(credentials) if driver_has_feature?(:register_instance, :load_balancers)
+  respond_to do |format|
+    format.html { haml :"load_balancers/new" }
+  end
+end
+
+
+collection :load_balancers do
+  description "Load balancers"
+
+  operation :index do
+    description "List of all active load balancers"
+    control do
+      filter_all :load_balancers
+    end
+  end
+
+  operation :show do
+    description "Show details about given load balancer"
+    param :id,  :string,  :required
+    control { show :load_balancer }
+  end
+
+  operation :create do
+    description "Create a new load balancer"
+    param :name,  :string,  :required
+    param :realm_id,  :string,  :required
+    param :listener_protocol,  :string,  :required, ['HTTP', 'TCP']
+    param :listener_lbr_port,  :string,  :required
+    param :listener_inst_port,  :string,  :required
+    control do
+      @load_balancer = driver.create_load_balancer(credentials, params)
+      respond_to do |format|
+        format.xml { haml :"load_balancers/show" }
+        format.html { haml :"load_balancers/show" }
+      end
+    end
+  end
+
+  operation :register, :method => :post, :member => true do
+    description "Add instance to loadbalancer"
+    param :id,  :string,  :required
+    param :instance_id, :string,  :required
+    control do
+      driver.lb_register_instance(credentials, params)
+      redirect(load_balancer_url(params[:id]))
+    end
+  end
+
+  operation :unregister, :method => :post, :member => true do
+    description "Remove instance from loadbalancer"
+    param :id,  :string,  :required
+    param :instance_id, :string,  :required
+    control do
+      driver.lb_unregister_instance(credentials, params)
+      redirect(load_balancer_url(params[:id]))
+    end
+  end
+
+  operation :destroy do
+    description "Destroy given load balancer"
+    param :id,  :string,  :required
+    control do
+      driver.destroy_load_balancer(credentials, params[:id])
+      redirect(load_balancers_url)
+    end
+  end
+
+end
+
+
 collection :instances do
   description <<END
   An instance is a concrete machine realized from an image.

Modified: incubator/deltacloud/trunk/server/views/instances/new.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/instances/new.html.haml?rev=1034315&r1=1034314&r2=1034315&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/views/instances/new.html.haml (original)
+++ incubator/deltacloud/trunk/server/views/instances/new.html.haml Fri Nov 12 09:52:52 2010
@@ -9,6 +9,14 @@
     %label
       Instance Name:
       %input{ :name => 'name', :size => 30 }/
+  -if driver_has_feature?(:register_to_load_balancer)
+    %p
+      %label
+        Assign to load balancer:
+        %select{:name => 'load_balancer_id'}
+          %option{:value => ""}
+          - @load_balancers.each do |load_balancer|
+            %option{:value => load_balancer.id} #{load_balancer.id}
   -if driver_has_feature?(:authentication_key)
     %p
       %label

Added: incubator/deltacloud/trunk/server/views/load_balancers/index.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/load_balancers/index.html.haml?rev=1034315&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/load_balancers/index.html.haml (added)
+++ incubator/deltacloud/trunk/server/views/load_balancers/index.html.haml Fri Nov 12 09:52:52
2010
@@ -0,0 +1,33 @@
+%h1 Load Balancers
+
+%table.display
+  %thead
+    %tr
+      %th ID
+      %th Hostname
+      %th Realm
+      %th Balancer port
+      %th Instances port
+      %th Actions
+  %tbody
+    - @elements.each do |balancer|
+      %tr
+        %td
+          = link_to balancer.id, load_balancer_url( balancer.id )
+        %td
+          = balancer.public_addresses.first
+        %td
+          = link_to balancer.realms.first.id, realm_url( balancer.realms.first.id )
+        %td
+          - balancer.listeners.each do |listener|
+            ="#{listener.protocol}[#{listener.load_balancer_port}]<br/>"
+        %td
+          - balancer.listeners.each do |listener|
+            ="#{listener.protocol}[#{listener.load_balancer_port}]<br/>"
+        %td
+          =link_to 'Destroy', destroy_load_balancer_url(balancer.id), :class => 'delete'
+  %tfoot
+    %tr
+      %td{:colspan => 6, :style => "text-align:right;"}
+        =link_to 'Create &raquo;', "#{url_for('/api/load_balancers/new')}", :class =>
'button'
+

Added: incubator/deltacloud/trunk/server/views/load_balancers/index.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/load_balancers/index.xml.haml?rev=1034315&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/load_balancers/index.xml.haml (added)
+++ incubator/deltacloud/trunk/server/views/load_balancers/index.xml.haml Fri Nov 12 09:52:52
2010
@@ -0,0 +1,5 @@
+
+!!!XML
+%load_balancers
+  - @elements.each do |c|
+    = haml :'load_balancers/show', :locals => { :@load_balancer => c, :partial =>
true }

Added: incubator/deltacloud/trunk/server/views/load_balancers/new.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/load_balancers/new.html.haml?rev=1034315&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/load_balancers/new.html.haml (added)
+++ incubator/deltacloud/trunk/server/views/load_balancers/new.html.haml Fri Nov 12 09:52:52
2010
@@ -0,0 +1,38 @@
+%h1 New Load Balancer
+
+%form{ :action => '/api/load_balancers', :method => :post }
+  %p
+    %label
+      Name:
+    %input{ :name => 'name', :size => 30 }/
+  -if @instances
+    %p
+      %label
+        Running instance:
+      %select{ :name => 'instance_id'}
+        - @instances.select{|i| i.state=="RUNNING"}.each do |instance|
+          %option{ :value => instance.id } #{instance.id}
+  %p
+    %label
+      Realm:
+    %select{ :name => 'realm_id'}
+      - @realms.each do |realm|
+        %option{ :value => realm.id } #{realm.id} - #{realm.name}
+  %hr
+  %p
+    %label
+      Protocol:
+    %select{ :name => 'listener_protocol'}
+      %option{ :value => 'HTTP'}  HTTP
+      %option{ :value => 'TCP'} TCP
+  %p
+    %label
+      Load balancer port:
+    %input{ :name => "listener_lbr_port", :size => 30}
+  %p
+    %label
+      Instances port:
+    %input{ :name => "listener_inst_port", :size => 30}
+  %p
+    %input{ :type => :submit, :name => "commit", :value => "create" }/
+

Added: incubator/deltacloud/trunk/server/views/load_balancers/show.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/load_balancers/show.html.haml?rev=1034315&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/load_balancers/show.html.haml (added)
+++ incubator/deltacloud/trunk/server/views/load_balancers/show.html.haml Fri Nov 12 09:52:52
2010
@@ -0,0 +1,37 @@
+%h1
+  = @load_balancer.id
+
+%dl
+  %di
+    %dt Public addresses
+    %dd
+      = @load_balancer.public_addresses.join(',')
+    - if @load_balancer.created_at
+      %dt Created at
+      %dd
+        = @load_balancer.created_at
+    %dt Realms
+    %dd
+      = @load_balancer.realms.collect { |r| "#{r.id} - #{r.name}" }.join(',')
+    %dt Listeners
+    %dd
+      - @load_balancer.listeners.each do |listener|
+        ="Load balancer port: #{listener.load_balancer_port}"
+        %br
+        ="Instance port: #{listener.instance_port}"
+        %br
+    - if @load_balancer.instances.class.eql?(Array)
+      %dt Instances
+      - @load_balancer.instances.each do |inst|
+        %dd
+          =inst.id
+          %a{:class => :post, :href => unregister_load_balancer_url(@load_balancer.id,
:instance_id => inst.id)} Delete
+
+%form{:action => url_for("/api/load_balancers/#{@load_balancer.id}/register"), :method
=> :post}
+  %p
+    %strong Add instances to load balancer
+  %p
+    %label Instance
+    %select{:name => :instance_id, :id => "list_instances"}
+    %input{:type => :submit, :value => "Assign"}
+

Added: incubator/deltacloud/trunk/server/views/load_balancers/show.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/load_balancers/show.xml.haml?rev=1034315&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/load_balancers/show.xml.haml (added)
+++ incubator/deltacloud/trunk/server/views/load_balancers/show.xml.haml Fri Nov 12 09:52:52
2010
@@ -0,0 +1,21 @@
+- unless defined?(partial)
+  !!! XML
+%load_balancer{ :href => key_url(@load_balancer.id), :id => @load_balancer.id}
+  %actions
+    %link{ :rel => "destroy", :method => "delete", :href => destroy_load_balancer_url(@load_balancer.id)}
+  %public_addresses
+    - @load_balancer.public_addresses.each do |address|
+      %address #{address}
+  %created_at<
+    = @load_balancer.created_at
+  %realm{ :href => realm_url(@load_balancer.realms.first.id), :id => @load_balancer.realms.first.id}
+  %listeners
+    - @load_balancer.listeners.each do |listener|
+      %listener{ :protocol => listener.protocol}
+        %load_balancer_port #{listener.load_balancer_port}
+        %instance_port #{listener.instance_port}
+  %instances
+    - @load_balancer.instances.each do |instance|
+      %instance{:href => instance_url(instance.id), :id => instance.id}
+        %link{:rel => "unregister", :href => unregister_load_balancer_url(@load_balancer.id,
{ :instance_id => instance.id})}
+



Mime
View raw message