incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH] Allow setting the provider on the server side, and implement region overriding in the ec2 driver based off of the provider.
Date Fri, 10 Dec 2010 12:07:22 GMT
Hi Toby

On 10/12/10 14:02, Toby Crawley wrote:
> On 12/10/2010 02:14 AM, marios@redhat.com wrote:
>> ack, Toby should I push this? What are we doing about getting you
>> commit rights?
>>
>
> I don't yet have commit rights, so if you could push this, that would be
> great. Let me send a new patch that includes Michal's suggestions. What

Ok will wait for the new patch

> do I need to do to obtain commit rights? Is there a formal process, or
> do I just need to ask at this point?

I'm not entirely sure - I cc David here as I think he'll be the one to 
ask. I mentioned this to Michal on irc earlier and he said you  already 
signed a ASL contributor license (that is definitely a pre-requisite so 
if you haven't done that yet you should).

marios


>
>> I am assuming that 'API_PROVIDER' is what AWS call the 'Service
>> Endpoint' right? As in
>> http://docs.amazonwebservices.com/AWSEC2/2010-08-31/DeveloperGuide/index.html?Using_Endpoints.html#
>> - so we should document that valid
>> values are 'us-east-1' , 'us-west-1' , 'eu-west-1' , 'ap-southeast-1'.
>>
>
> 'provider' is the generic term for AWS 'regions' which we use to
> calculate the endpoint url. The meaning of provider would be driver
> specific - in the ec2 case, it maps to a region, but may map to some
> other concept for other drivers.
>
>> I was slightly confused at first as there is are slight differences
>> with the S3 endpoints as in
>> http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RequestEndpoints.html
>> .
>
> I was using the endpoint list here:
> http://aws.amazon.com/articles/3912?_encoding=UTF8&jiveRedirect=1
> which, oddly, has slightly different information (at least with regards
> to s3) - it reports that EU has no region specific s3 endpoint. I
> suspect that your link above to the s3 documentation above is more up to
> date.
>>
>> I want to add the s3_client construction into the current 'new_client'
>> method (i.e. in same way that you have both ec2 and elb there) and
>> then change the endpoint_for_service accordingly (e.g. s3 is
>> 's3-endpoint' whereas ec2 is 'ec2.endpoint'). However I think I'll
>> wait until
>> we start using the new aws gem for this (Is there any news regarding
>> that?)
>>
>
> We're still waiting for two patches to be merged, and a new gem to be
> released. Please upvote and comment on the issues to see if we can speed
> things up there:
> https://github.com/appoxy/aws/issues#issue/42
> https://github.com/appoxy/aws/issues#issue/43
>
>> marios
>>
>> On 09/12/10 22:57, tcrawley@redhat.com wrote:
>>> From: Tobias Crawley<tcrawley@redhat.com>
>>>
>>> The provider can now be set on the commandline to deltacloudd via
>>> -P/--provider
>>> (putting it in ENV['API_PROVIDER']), and also from the client via a
>>> header
>>> (putting it in Thread.current[:provider]).
>>>
>>> The ec2 driver is currently the only driver that understands
>>> providers, and
>>> looks in Thread.current[:provider], then ENV['API_PROVIDER'], then
>>> falls back
>>> to a default (currently 'us-east-1', the AWS default).
>>> ---
>>> server/bin/deltacloudd | 8 +++++++-
>>> server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 19 +++++++++++++++++--
>>> server/lib/sinatra/rack_driver_select.rb | 20 ++++++++++++++------
>>> 3 files changed, 38 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd
>>> index ed7883b..70be6ca 100755
>>> --- a/server/bin/deltacloudd
>>> +++ b/server/bin/deltacloudd
>>> @@ -36,6 +36,9 @@ BANNER
>>> opts.on( '-p', '--port PORT', 'Use PORT (default: 3001)') do |port|
>>> ENV["API_PORT"] = port
>>> end
>>> + opts.on( '-P', '--provider PROVIDER', 'Use PROVIDER (default is set
>>> in the driver)') do |provider|
>>> + ENV['API_PROVIDER'] = provider
>>> + end
>>> opts.on( '-e', '--env ENV', 'Environment (default: "development")') {
>>> |env| options[:env] = env }
>>> opts.on( '-h', '--help', '') { options[:help] = true }
>>> end
>>> @@ -55,7 +58,10 @@ end
>>> ENV["API_HOST"] = "localhost" unless ENV["API_HOST"]
>>> ENV["API_PORT"] = "3001" unless ENV["API_PORT"]
>>>
>>> -puts "Starting Deltacloud API :: #{ENV["API_DRIVER"]} ::
>>> http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
>>> +msg = "Starting Deltacloud API :: #{ENV["API_DRIVER"]} "
>>> +msg<< ":: #{ENV['API_PROVIDER']} " if ENV['API_PROVIDER']
>>> +msg<< ":: http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
>>> +puts msg
>>> puts
>>>
>>> dirname="#{File.dirname(__FILE__)}/.."
>>> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>>> b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>>> index efbfcc8..1bd4fc4 100644
>>> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>>> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>>> @@ -106,6 +106,8 @@ class EC2Driver< Deltacloud::BaseDriver
>>> stopped.to( :finish ) .automatically
>>> end
>>>
>>> + DEFAULT_REGION = 'us-east-1'
>>> +
>>> #
>>> # Images
>>> #
>>> @@ -504,9 +506,9 @@ class EC2Driver< Deltacloud::BaseDriver
>>> def new_client(credentials, provider_type = :ec2)
>>> opts = {
>>> :access_key_id => credentials.user,
>>> - :secret_access_key => credentials.password
>>> + :secret_access_key => credentials.password,
>>> + :server => endpoint_for_service(provider_type)
>>> }
>>> - opts[:server] = ENV['DCLOUD_EC2_URL'] if ENV['DCLOUD_EC2_URL']
>>> safely do
>>> case provider_type
>>> when :ec2
>>> @@ -517,6 +519,19 @@ class EC2Driver< Deltacloud::BaseDriver
>>> end
>>> end
>>>
>>> + def endpoint_for_service(service)
>>> + url = ""
>>> + case service
>>> + when :ec2
>>> + url<< 'ec2.'
>>> + when :elb
>>> + url<< 'elasticloadbalancing.'
>>> + end
>>> + url<< (Thread.current[:provider] || ENV['API_PROVIDER'] ||
>>> DEFAULT_REGION)
>>> + url<< '.amazonaws.com'
>>> + url
>>> + end
>>> +
>>> def convert_load_balancer(credentials, loadbalancer)
>>> balancer_realms = loadbalancer.AvailabilityZones.member.collect do |m|
>>> realm(credentials, m)
>>> diff --git a/server/lib/sinatra/rack_driver_select.rb
>>> b/server/lib/sinatra/rack_driver_select.rb
>>> index f00a2c8..3e7d038 100644
>>> --- a/server/lib/sinatra/rack_driver_select.rb
>>> +++ b/server/lib/sinatra/rack_driver_select.rb
>>> @@ -5,17 +5,25 @@ class RackDriverSelect
>>> @opts = opts
>>> end
>>>
>>> + HEADER_TO_ENV_MAP = {
>>> + 'HTTP_X_DELTACLOUD_DRIVER' => :driver,
>>> + 'HTTP_X_DELTACLOUD_PROVIDER' => :provider
>>> + }
>>> +
>>> def call(env)
>>> - original_driver = Thread.current[:driver]
>>> - new_driver = extract_driver(env)
>>> - Thread.current[:driver] = new_driver if new_driver
>>> + original_settings = { }
>>> + HEADER_TO_ENV_MAP.each do |header, name|
>>> + original_settings[name] = Thread.current[name]
>>> + new_setting = extract_header(env, header)
>>> + Thread.current[name] = new_setting if new_setting
>>> + end
>>> @app.call(env)
>>> ensure
>>> - Thread.current[:driver] = original_driver
>>> + original_settings.each { |name, value| Thread.current[name] = value }
>>> end
>>>
>>> - def extract_driver(env)
>>> - driver_name = env['HTTP_X_DELTACLOUD_DRIVER'].downcase if
>>> env['HTTP_X_DELTACLOUD_DRIVER']
>>> + def extract_header(env, header)
>>> + env[header].downcase if env[header]
>>> end
>>>
>>> end
>>
>


Mime
View raw message