+ 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.
diff --git a/server/views/instances/new.html.haml
b/server/views/instances/new.html.haml
index 6d67c2d..558582d 100644
--- a/server/views/instances/new.html.haml
+++ b/server/views/instances/new.html.haml
@@ -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
diff --git a/server/views/load_balancers/index.html.haml
b/server/views/load_balancers/index.html.haml
new file mode 100644
index 0000000..65b109c
--- /dev/null
+++ b/server/views/load_balancers/index.html.haml
@@ -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»', "#{url_for('/api/load_balancers/new')}", :class
=> 'button'
+
diff --git a/server/views/load_balancers/index.xml.haml
b/server/views/load_balancers/index.xml.haml
new file mode 100644
index 0000000..22c6911
--- /dev/null
+++ b/server/views/load_balancers/index.xml.haml
@@ -0,0 +1,5 @@
+
+!!!XML
+%load_balancers
+ - @elements.each do |c|
+ = haml :'load_balancers/show', :locals => { :@load_balancer => c, :partial
=> true }
diff --git a/server/views/load_balancers/new.html.haml
b/server/views/load_balancers/new.html.haml
new file mode 100644
index 0000000..561caa4
--- /dev/null
+++ b/server/views/load_balancers/new.html.haml
@@ -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" }/
+
diff --git a/server/views/load_balancers/show.html.haml
b/server/views/load_balancers/show.html.haml
new file mode 100644
index 0000000..7b6f40b
--- /dev/null
+++ b/server/views/load_balancers/show.html.haml
@@ -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"}
+
diff --git a/server/views/load_balancers/show.xml.haml
b/server/views/load_balancers/show.xml.haml
new file mode 100644
index 0000000..e36f79f
--- /dev/null
+++ b/server/views/load_balancers/show.xml.haml
@@ -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})}
+