You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/10/10 17:48:36 UTC

git commit: fgcp: add realm filter to instances and use it to select instances to register with lb

Updated Branches:
  refs/heads/master 6a7c6735b -> bbfb5ff8f


fgcp: add realm filter to instances and use it to select instances to register with lb


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/bbfb5ff8
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/bbfb5ff8
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/bbfb5ff8

Branch: refs/heads/master
Commit: bbfb5ff8fb97dd8347908cd34575d6b469ed2c37
Parents: 6a7c673
Author: Dies Koper <di...@fast.au.fujitsu.com>
Authored: Mon Oct 8 22:30:56 2012 +1100
Committer: Michal fojtik <mf...@redhat.com>
Committed: Wed Oct 10 17:49:02 2012 +0200

----------------------------------------------------------------------
 .../lib/deltacloud/collections/load_balancers.rb   |   10 ++++-
 server/lib/deltacloud/drivers/features.rb          |    6 +-
 server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb  |   33 +++++++--------
 server/views/load_balancers/show.html.haml         |    2 +-
 4 files changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bbfb5ff8/server/lib/deltacloud/collections/load_balancers.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/load_balancers.rb b/server/lib/deltacloud/collections/load_balancers.rb
index b2c7023..e13ccec 100644
--- a/server/lib/deltacloud/collections/load_balancers.rb
+++ b/server/lib/deltacloud/collections/load_balancers.rb
@@ -23,7 +23,7 @@ module Deltacloud::Collections
     end
 
     collection :load_balancers do
-      description "Load balancers are used distribute workload across multiple instances"
+      description "Load balancers are used to distribute workload across multiple instances"
 
       standard_index_operation
 
@@ -32,7 +32,13 @@ module Deltacloud::Collections
         control do
           @load_balancer = driver.load_balancer(credentials, params)
           @registered_instances = @load_balancer.instances.collect{|i| {:id => i.id, :name=> i.name}}
-          @unregistered_instances = driver.instances(credentials).collect{|i| {:id => i.id, :name => i.name}} - @registered_instances
+          # if provider supports realm_filter and load balancer has only one realm (which is mostly the case), use optimization:
+          if @load_balancer.realms.size == 1 and driver.class.has_feature?(:instances, :realm_filter)
+            all_instances = driver.instances(credentials, :realm_id => @load_balancer.realms.first.id).collect{|i| {:id => i.id, :name => i.name}}
+          elsif
+            all_instances = driver.instances(credentials).collect{|i| {:id => i.id, :name => i.name} }
+          end
+          @unregistered_instances = all_instances - @registered_instances
           respond_to do |format|
             format.xml { haml :'load_balancers/show' }
             format.json { xml_to_json('load_balancers/show') }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bbfb5ff8/server/lib/deltacloud/drivers/features.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/features.rb b/server/lib/deltacloud/drivers/features.rb
index 5fc8cfd..3e1b704 100644
--- a/server/lib/deltacloud/drivers/features.rb
+++ b/server/lib/deltacloud/drivers/features.rb
@@ -135,14 +135,14 @@ module Deltacloud
       end
 
       feature :instance_count, :for => :instances do
-        description "Number of instances to be launch with at once"
+        description "Number of instances to launch at once"
         operation :create do
           param :instance_count,  :string,  :optional
         end
       end
 
       feature :attach_snapshot, :for => :instances do
-        description "Attach an snapshot to instance on create"
+        description "Attach a snapshot to instance on create"
         operation :create do
           param :snapshot_id,  :string,  :optional
           param :device_name,  :string,  :optional
@@ -150,7 +150,7 @@ module Deltacloud
       end
 
       feature :sandboxing, :for => :instances do
-        description "Allow lanuching sandbox images"
+        description "Allow launching sandbox images"
         operation :create do
           param :sandbox, :string,  :optional
         end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bbfb5ff8/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb b/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
index b92c251..ea91762 100644
--- a/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
+++ b/server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
@@ -29,6 +29,7 @@ class FgcpDriver < Deltacloud::BaseDriver
 
   feature :instances, :user_name
   feature :instances, :metrics
+  feature :instances, :realm_filter
   feature :images, :user_name
   feature :images, :user_description
 
@@ -168,19 +169,18 @@ class FgcpDriver < Deltacloud::BaseDriver
     realms = []
     safely do
       client = new_client(credentials)
-  # opts may include scope: system, network
-  # first retrieve list of VSYS ids (and add if scope is not only filtering for network)
+
       if opts and opts[:id]
 
-        # determine id belongs to vsys or network
+        # determine id belongs to system or network
         vsys_id = client.extract_vsys_id(opts[:id])
         vsys = client.get_vsys_attributes(vsys_id)['vsys'][0]
         realm_name = vsys['vsysName'][0]
-        limit = '[VSYS]'
+        limit = '[System]'
         if opts[:id] != vsys_id # network id specified
           opts[:id] =~ /^.*\b(\w+)$/
-          realm_name += ' [' + $1 + ']' # vsys name or vsys name + network [DMZ/SECURE1/SECURE2]
-          limit = '[Network segment]'
+          realm_name += ' [' + $1 + ']' # system name or system name + network [DMZ/SECURE1/SECURE2]
+          limit = '[Network]'
         end
         realms << Realm::new(
                     :id => opts[:id],
@@ -188,7 +188,6 @@ class FgcpDriver < Deltacloud::BaseDriver
                     #:limit => :unlimited,
                     :limit => limit,
                     :state => 'AVAILABLE' # map to state of FW/VSYS (reconfiguring = unavailable)?
-                   # :scope => 'system'
                   )
       elsif xml = client.list_vsys['vsyss']
 
@@ -197,11 +196,10 @@ class FgcpDriver < Deltacloud::BaseDriver
 
           realms << Realm::new(
                       :id => vsys['vsysId'][0], # vsysId or networkId
-                      :name => vsys['vsysName'][0], # vsys name or vsys name + network (DMZ/SECURE1/SECURE2)
+                      :name => vsys['vsysName'][0], # system name or system name + network (DMZ/SECURE1/SECURE2)
                       #:limit => :unlimited,
-                      :limit => '[VSYS]',
+                      :limit => '[System]',
                       :state => 'AVAILABLE' # map to state of FW/VSYS (reconfiguring = unavailable)?
-                     # :scope => 'system'
                     )
           # then retrieve and add list of network segments
           client.get_vsys_configuration(vsys['vsysId'][0])['vsys'][0]['vnets'][0]['vnet'].each do |vnet|
@@ -212,9 +210,8 @@ class FgcpDriver < Deltacloud::BaseDriver
                         :id => vnet['networkId'][0], # vsysId or networkId
                         :name => realm_name,
                         #:limit => :unlimited,
-                        :limit => '[Network segment]',
+                        :limit => '[Network]',
                         :state => 'AVAILABLE' # map to state of FW/VSYS (reconfiguring = unavailable)?
-                      #  :scope => 'network'
                       )
           end
         end
@@ -232,11 +229,13 @@ class FgcpDriver < Deltacloud::BaseDriver
     safely do
       client = new_client(credentials)
 
-      if opts and opts[:id]
-        vsys_id = client.extract_vsys_id(opts[:id])
+      if opts and opts[:id] or opts[:realm_id]
+        vsys_id = client.extract_vsys_id(opts[:id] || opts[:realm_id])
         vsys_config = client.get_vsys_configuration(vsys_id)
         vsys_config['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
-          if vserver['vserverId'][0] == opts[:id]
+          network_id = vserver['vnics'][0]['vnic'][0]['networkId'][0]
+          # :realm_id can point to system or network
+          if vsys_id == opts[:realm_id] or vserver['vserverId'][0] == opts[:id] or network_id == opts[:realm_id]
 
             # check state first as it may be filtered on
             state_data = instance_state_data(vserver, client)
@@ -1066,7 +1065,7 @@ eofwopxml
             realm = Realm::new(
               :id => vserver['vnics'][0]['vnic'][0]['networkId'][0],
               :name => realm_name,
-              :limit => '[Network segment]',
+              :limit => '[Network]',
               :state => 'AVAILABLE' # map to state of FW/VSYS (reconfiguring = unavailable)?
             )
             balancer = LoadBalancer.new({
@@ -1101,7 +1100,7 @@ eofwopxml
           realm = Realm::new(
             :id => vserver['vnics'][0]['vnic'][0]['networkId'][0],
             :name => realm_name,
-            :limit => '[Network segment]',
+            :limit => '[Network]',
             :state => 'AVAILABLE' # map to state of FW/VSYS (reconfiguring = unavailable)?
           )
           balancer = LoadBalancer.new({

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bbfb5ff8/server/views/load_balancers/show.html.haml
----------------------------------------------------------------------
diff --git a/server/views/load_balancers/show.html.haml b/server/views/load_balancers/show.html.haml
index a1c754d..3725f81 100644
--- a/server/views/load_balancers/show.html.haml
+++ b/server/views/load_balancers/show.html.haml
@@ -21,7 +21,7 @@
         %a{ :href => instance_url(instance[:id]), :'data-ajax' => 'false'}
           %h3=instance[:name]
           =link_to_action "UnRegister", url_for("load_balancers/#{@load_balancer.id}/unregister?instance_id=#{instance[:id]}"), :post
-    %li{ :'data-role' => 'list-divider'} UnRegistered Instances
+    %li{ :'data-role' => 'list-divider'} Unregistered Instances
     - @unregistered_instances.each do |instance|
       %li
         %a{:href => instance_url(instance[:id]), :'data-ajax' => 'false'}