Return-Path: Delivered-To: apmail-incubator-deltacloud-dev-archive@minotaur.apache.org Received: (qmail 12135 invoked from network); 10 Mar 2011 23:26:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Mar 2011 23:26:07 -0000 Received: (qmail 1264 invoked by uid 500); 10 Mar 2011 23:26:07 -0000 Delivered-To: apmail-incubator-deltacloud-dev-archive@incubator.apache.org Received: (qmail 1245 invoked by uid 500); 10 Mar 2011 23:26:07 -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 1237 invoked by uid 99); 10 Mar 2011 23:26:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Mar 2011 23:26:07 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sang-min.park@eucalyptus.com designates 74.125.149.207 as permitted sender) Received: from [74.125.149.207] (HELO na3sys009aog112.obsmtp.com) (74.125.149.207) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 10 Mar 2011 23:26:02 +0000 Received: from source ([209.85.218.43]) (using TLSv1) by na3sys009aob112.postini.com ([74.125.148.12]) with SMTP ID DSNKTXld8gmh/0Nbc9e9GGhSU/Bmvs4tbtej@postini.com; Thu, 10 Mar 2011 15:25:41 PST Received: by mail-yi0-f43.google.com with SMTP id 13so957493yia.30 for ; Thu, 10 Mar 2011 15:25:38 -0800 (PST) Received: by 10.236.77.138 with SMTP id d10mr1949906yhe.110.1299799538246; Thu, 10 Mar 2011 15:25:38 -0800 (PST) Received: from localhost.localdomain (wsip-174-76-140-2.sb.sd.cox.net [174.76.140.2]) by mx.google.com with ESMTPS id z5sm2456375yhc.35.2011.03.10.15.25.35 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 10 Mar 2011 15:25:37 -0800 (PST) From: sang-min.park@eucalyptus.com To: deltacloud-dev@incubator.apache.org Cc: sang-min.park@eucalyptus.com, Sang-Min Park Subject: [PATCH] patch in preparating for Eucalyptus driver support Date: Thu, 10 Mar 2011 15:25:23 -0800 Message-Id: <1299799523-11126-2-git-send-email-sang-min.park@eucalyptus.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1299799523-11126-1-git-send-email-sang-min.park@eucalyptus.com> References: <1299799523-11126-1-git-send-email-sang-min.park@eucalyptus.com> From: Sang-Min Park --- server/lib/deltacloud/base_driver/base_driver.rb | 25 +++++++--- server/lib/deltacloud/base_driver/features.rb | 9 +++ server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 59 +++++++++++++-------- server/lib/deltacloud/validation.rb | 5 ++ 4 files changed, 68 insertions(+), 30 deletions(-) diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb index 2442385..2a7a758 100644 --- a/server/lib/deltacloud/base_driver/base_driver.rb +++ b/server/lib/deltacloud/base_driver/base_driver.rb @@ -44,11 +44,10 @@ module Deltacloud class BaseDriver def self.define_hardware_profile(name,&block) - @hardware_profiles ||= [] - hw_profile = @hardware_profiles.find{|e| e.name == name} + hw_profile = hardware_profiles.find{|e| e.name == name} return if hw_profile hw_profile = ::Deltacloud::HardwareProfile.new( name, &block ) - @hardware_profiles << hw_profile + hardware_profiles << hw_profile hw_params = hw_profile.params unless hw_params.empty? feature :instances, :hardware_profiles do @@ -56,10 +55,22 @@ module Deltacloud end end end + + def self.clear_hardware_profile + hardware_profiles.each do |e| + hw_params = e.params + unless hw_params.empty? + feature :instance, :hardware_profiles do + decl.operation(:create) { delete_params(hw_params) } + end + end + end + hardware_profiles.clear + end def self.hardware_profiles - @hardware_profiles ||= [] - @hardware_profiles + @@hardware_profiles ||= [] + @@hardware_profiles end def hardware_profiles(credentials, opts = nil) @@ -103,11 +114,11 @@ module Deltacloud def self.define_instance_states(&block) machine = ::Deltacloud::StateMachine.new(&block) - @instance_state_machine = machine + @@instance_state_machine = machine end def self.instance_state_machine - @instance_state_machine + @@instance_state_machine end def instance_state_machine diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb index 1f07843..86f44cd 100644 --- a/server/lib/deltacloud/base_driver/features.rb +++ b/server/lib/deltacloud/base_driver/features.rb @@ -136,6 +136,15 @@ module Deltacloud end features[collection] << Feature.new(decl, &block) end + + # A driver, inherited from another driver, may need to delete feature declaration from the base driver + # The example is Eucalyptus driver inherited from EC2 + def self.remove_feature(collection, name) + features[collection] ||= [] + if f = features[collection].find { |f| f.name == name } + features[collection].delete(f) + end + end def features(collection) self.class.features[collection] || [] diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb index 9a2abb6..70259f0 100644 --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb @@ -135,9 +135,9 @@ module Deltacloud end return img_arr end - owner_id = opts[:owner_id] || "amazon" + owner_id = opts[:owner_id] || default_image_owner safely do - img_arr = ec2.describe_images_by_owner(owner_id, "machine").collect do |image| + img_arr = ec2.describe_images_by_owner(owner_id, default_image_type).collect do |image| convert_image(image) end end @@ -171,16 +171,18 @@ module Deltacloud inst_arr = ec2.describe_instances.collect do |instance| convert_instance(instance) if instance end.flatten - tags = ec2.describe_tags( - 'Filter.1.Name' => 'resource-type', 'Filter.1.Value' => 'instance' - ) - inst_arr.each do |inst| - name_tag = tags.select { |t| (t[:aws_resource_id] == inst.id) and t[:aws_key] == 'name' } - unless name_tag.empty? - inst.name = name_tag.first[:aws_value] + if tagging? + tags = ec2.describe_tags( + 'Filter.1.Name' => 'resource-type', 'Filter.1.Value' => 'instance' + ) + inst_arr.each do |inst| + name_tag = tags.select { |t| (t[:aws_resource_id] == inst.id) and t[:aws_key] == 'name' } + unless name_tag.empty? + inst.name = name_tag.first[:aws_value] + end end - end - delete_unused_tags(credentials, inst_arr.collect {|inst| inst.id}) + 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 ) @@ -192,7 +194,7 @@ module Deltacloud instance_options.merge!(:user_data => opts[:user_data]) if opts[:user_data] instance_options.merge!(:key_name => opts[:keyname]) if opts[:keyname] instance_options.merge!(:availability_zone => opts[:realm_id]) if opts[:realm_id] - instance_options.merge!(:instance_type => opts[:hwp_id]) if opts[:hwp_id] + instance_options.merge!(:instance_type => opts[:hwp_id]) if opts[:hwp_id] && opts[:hwp_id].length > 0 instance_options.merge!(:group_ids => opts[:security_group]) if opts[:security_group] instance_options.merge!( :min_count => opts[:instance_count], @@ -202,15 +204,12 @@ module Deltacloud 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 - if opts[:name] - tag_instance(credentials, new_instance, opts[:name]) - end + 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].length>0 - elb = new_client(credentials, :elb) - elb.register_instances_with_load_balancer(opts[:load_balancer_id], [new_instance.id]) - end + if opts[:load_balancer_id] + lb = lb_register_instance(credentials, {'id' => opts[:load_balancer_id], 'instance_id' => new_instance.id}) + end new_instance end end @@ -523,6 +522,18 @@ module Deltacloud end klass.new(credentials.user, credentials.password, {:server => endpoint_for_service(type), :connection_mode => :per_thread}) end + + def default_image_owner + "amazon" + end + + def default_image_type + "machine" + end + + def tagging? + true + end def endpoint_for_service(service) endpoint = (Thread.current[:provider] || ENV['API_PROVIDER'] || DEFAULT_REGION) @@ -532,11 +543,13 @@ module Deltacloud end def tag_instance(credentials, instance, name) - ec2 = new_client(credentials) - safely do - ec2.create_tag(instance.id, 'name', name) + if name + ec2 = new_client(credentials) + safely do + ec2.create_tag(instance.id, 'name', name) + end end - end + end def untag_instance(credentials, instance_id) ec2 = new_client(credentials) diff --git a/server/lib/deltacloud/validation.rb b/server/lib/deltacloud/validation.rb index cfac4ce..efc9c84 100644 --- a/server/lib/deltacloud/validation.rb +++ b/server/lib/deltacloud/validation.rb @@ -73,6 +73,11 @@ module Deltacloud::Validation # to add_params should be cumulative new.each { |p| @params[p.name] = p } end + + # Delete the parameters from the hash if found + def delete_params(old) + old.each { |p| @params.delete(p) } + end def each_param(&block) params.each_value { |p| yield p } -- 1.7.1