incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Lalancette <clala...@redhat.com>
Subject [PATCH] Remove EC2 instance tagging and load balancer registering.
Date Fri, 10 Jun 2011 13:05:02 GMT
During an EC2 create_instance call, two optional things
might be done; tagging the instance with the name provided,
and registering the new instance with a loadbalancer.

Unfortunately, there is a big problem with this; the instance
ID does not always exist immediately after the ec2.launch_instances
call returns.  This seems to be a generic problem with EC2,
as I've run into it several times.

Because of this, we *cannot* tag the instance or register
the instance with the load balancer right within the create_instance
call, since we can't be sure the instance ID yet exists.
Luckily, the loss of either function shouldn't be that huge;
the name can never be retrieved (since there is no generic tag
support), and you can always register an instance with a load
balancer later.

Therefore, totally remove these operations from create.  Not
only does this make create_instance more reliable, it restores
the "one deltacloud API -> one cloud backend call" semantic
that we try to preserve.

v2: Remove more of the tagging code that is now unnecessary; also
remove the "load_balancer" feature from the ec2 driver

Signed-off-by: Chris Lalancette <clalance@redhat.com>
---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |   59 --------------------
 .../drivers/eucalyptus/eucalyptus_driver.rb        |    4 -
 2 files changed, 0 insertions(+), 63 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 4edd989..b1d3504 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -42,7 +42,6 @@ module Deltacloud
         feature :instances, :instance_count
         feature :images, :owner_id
         feature :buckets, :bucket_location
-        feature :instances, :register_to_load_balancer
         feature :instances, :attach_snapshot
 
         DEFAULT_REGION = 'us-east-1'
@@ -176,19 +175,6 @@ module Deltacloud
             inst_arr = ec2.describe_instances.collect do |instance|
               convert_instance(instance) if instance
             end.flatten
-            if tagging?
-              tags = ec2.describe_tags('Filter.1.Name' => 'resource-type',
-                                       'Filter.1.Value' => 'instance')
-              inst_arr.each do |inst|
-                name_tag = tags.select do |t|
-                  (t[:aws_resource_id] == inst.id) and t[:aws_key] == 'name'
-                end
-                unless name_tag.empty?
-                  inst.name = name_tag.first[:aws_value]
-                end
-              end
-              delete_unused_tags(credentials, inst_arr.collect {|inst| inst.id})
-            end
           end
           inst_arr = filter_on( inst_arr, :id, opts )
           filter_on( inst_arr, :state, opts )
@@ -214,16 +200,6 @@ module Deltacloud
           end
           safely do
             new_instance = convert_instance(ec2.launch_instances(image_id, instance_options).first)
-            # TODO: Rework this to use client_id for name instead of tag
-            #       Tags should be keept as an optional feature
-            tag_instance(credentials, new_instance, opts[:name])
-            # Register Instance to Load Balancer if load_balancer_id is set.
-            # This parameter is a feature parameter
-            if opts[:load_balancer_id] and opts[:load_balancer_id]!=""
-              lb = lb_register_instance(credentials,
-                                        {'id' => opts[:load_balancer_id],
-                                         'instance_id' => new_instance.id})
-            end
             new_instance
           end
         end
@@ -255,7 +231,6 @@ module Deltacloud
           ec2 = new_client(credentials)
           instance_id = instance_id
           if ec2.terminate_instances([instance_id])
-            untag_instance(credentials, instance_id)
             instance(credentials, instance_id)
           else
             raise Deltacloud::BackendError.new(500, "Instance", "Instance cannot be terminated",
"")
@@ -600,10 +575,6 @@ module Deltacloud
           "machine"
         end
 
-        def tagging?
-          true
-        end
-
         def endpoint_for_service(service)
           endpoint = (Thread.current[:provider] || ENV['API_PROVIDER'] || DEFAULT_REGION)
           # return the endpoint if it does not map to a default endpoint, allowing
@@ -611,36 +582,6 @@ module Deltacloud
           Deltacloud::Drivers::driver_config[:ec2][:entrypoints][service.to_s][endpoint]
|| endpoint
         end
 
-        def tag_instance(credentials, instance, name)
-          if name
-            ec2 = new_client(credentials)
-            safely do
-              ec2.create_tag(instance.id, 'name', name)
-            end
-          end
-        end
-
-        def untag_instance(credentials, instance_id)
-          ec2 = new_client(credentials)
-          safely do
-            ec2.delete_tag(instance_id, 'name')
-          end
-        end
-
-        def delete_unused_tags(credentials, inst_ids)
-          ec2 = new_client(credentials)
-          tags = []
-          safely do
-            tags = ec2.describe_tags('Filter.1.Name' => 'resource-type', 'Filter.1.Value'
=> 'instance')
-            tags.collect! { |t| t[:aws_resource_id] }
-            inst_ids.each do |inst_id|
-              unless tags.include?(inst_id)
-                ec2.delete_tag(inst_id, 'name')
-              end
-            end
-          end
-        end
-
         def convert_bucket(s3_bucket)
           #get blob list:
           blob_list = []
diff --git a/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb b/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb
index a78ee63..0270f4f 100644
--- a/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb
+++ b/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb
@@ -82,10 +82,6 @@ module Deltacloud
           nil
         end
 
-        def tagging?
-          false
-        end
-
         def tag_instance(credentials, instance, name)
           # dummy
         end
-- 
1.7.4.4


Mime
View raw message