Hi,
Second revision of authentification features includes new XML schema, suggested by lutter:
<authentication name="key|password"> </authentication>
And:
- Fixed authentification -> authentication - Added more error reporting: - GoGrid: report if no password / username - EC2: report if no key was assigned to instance
-- Michal
--- server/lib/deltacloud/base_driver/features.rb | 15 +++++++++++++++ server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 8 +++++++- server/views/instances/new.html.haml | 12 +++++++++--- server/views/instances/show.html.haml | 5 +++++ server/views/instances/show.xml.haml | 3 +++ 5 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb index 43ec9c3..f4f456e 100644 --- a/server/lib/deltacloud/base_driver/features.rb +++ b/server/lib/deltacloud/base_driver/features.rb @@ -136,6 +136,21 @@ module Deltacloud end end
+ declare_feature :instances, :authentification_key do + operation :create do + param :keyname, :string, :optional, nil + "EC2 key authentification method" + end + operation :show do + end + end + + declare_feature :instances, :authentification_password do + operation :create do + param :password, :string, :optional + end + end + declare_feature :instances, :hardware_profiles do description "Size instances according to changes to a hardware profile" # The parameters are filled in from the hardware profiles diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb index 69356e2..d2152db 100644 --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb @@ -19,12 +19,17 @@ require 'deltacloud/base_driver' require 'AWS'
+class Instance + attr_accessor :keyname +end + module Deltacloud module Drivers module EC2 class EC2Driver < Deltacloud::BaseDriver
feature :instances, :user_data + feature :instances, :authentification_key
define_hardware_profile('m1-small') do cpu 1 @@ -156,7 +161,7 @@ class EC2Driver < Deltacloud::BaseDriver ec2_instances = ec2.run_instances( :image_id => image.id, :user_data => opts[:user_data], - :key_name => opts[:key_name], + :key_name => opts[:keyname], :availability_zone => realm_id, :monitoring_enabled => true, :instance_type => hwp.name.tr('-', '.'), @@ -278,6 +283,7 @@ class EC2Driver < Deltacloud::BaseDriver :flavor_id=>ec2_instance['instanceType'].gsub( /./, '-'), :instance_profile =>InstanceProfile.new(hwp_name), :actions=>instance_actions_for( state ), + :keyname => ec2_instance['keyName'] } ) end
diff --git a/server/views/instances/new.html.haml b/server/views/instances/new.html.haml index c746475..25d8689 100644 --- a/server/views/instances/new.html.haml +++ b/server/views/instances/new.html.haml @@ -5,9 +5,15 @@
%form{ :action => instances_url, :method => :post } %input{ :name => :image_id, :type => :hidden, :value => @instance.image_id }/ - %label - Instance Name: - %input{ :name => 'name', :size => 30 }/ + %p + %label + Instance Name: + %input{ :name => 'name', :size => 30 }/ + -if driver_has_feature(:authentification_key) + %p + %label + Instance Keyname: + %input{:name => 'keyname', :size => 30 } - if !@hardware_profiles.empty? %h3 What size machine? - for hwp in @hardware_profiles diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml index dabcc61..ebbdd2a 100644 --- a/server/views/instances/show.html.haml +++ b/server/views/instances/show.html.haml @@ -36,6 +36,11 @@ %dt Private Addresses %dd = @instance.private_addresses.collect { |address| "<div>#{address}</div>" }.join + - if driver_has_feature?(:authentification_key) + %di + %dt Keyname + %dd + = @instance.keyname %di %dt %dd diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml index a4859b0..9dc513b 100644 --- a/server/views/instances/show.xml.haml +++ b/server/views/instances/show.xml.haml @@ -26,3 +26,6 @@ - @instance.private_addresses.each do |address| %address< =address + - if driver_has_feature?(:authentification_key) + %keyname< + =@instance.keyname
--- server/lib/deltacloud/base_driver/features.rb | 4 +- server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 12 +++- .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb | 75 ++++++++++++++++--- .../lib/deltacloud/helpers/application_helper.rb | 9 +++ server/server.rb | 5 +- server/views/instances/new.html.haml | 2 +- server/views/instances/show.html.haml | 9 +++ server/views/instances/show.xml.haml | 14 +++- 8 files changed, 109 insertions(+), 21 deletions(-)
diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb index f4f456e..8ad354a 100644 --- a/server/lib/deltacloud/base_driver/features.rb +++ b/server/lib/deltacloud/base_driver/features.rb @@ -136,7 +136,7 @@ module Deltacloud end end
- declare_feature :instances, :authentification_key do + declare_feature :instances, :authentication_key do operation :create do param :keyname, :string, :optional, nil "EC2 key authentification method" @@ -145,7 +145,7 @@ module Deltacloud end end
- declare_feature :instances, :authentification_password do + declare_feature :instances, :authentication_password do operation :create do param :password, :string, :optional end diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb index d2152db..a0dbbf7 100644 --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb @@ -21,6 +21,12 @@ require 'AWS'
class Instance attr_accessor :keyname + attr_accessor :auth_error + + def authentification_feature_failed? + return true unless auth_error.nil? + end + end
module Deltacloud @@ -29,7 +35,7 @@ module Deltacloud class EC2Driver < Deltacloud::BaseDriver
feature :instances, :user_data - feature :instances, :authentification_key + feature :instances, :authentication_key
define_hardware_profile('m1-small') do cpu 1 @@ -271,7 +277,7 @@ class EC2Driver < Deltacloud::BaseDriver realm_id = ec2_instance['placement']['availabilityZone'] (realm_id = nil ) if ( realm_id == '' ) hwp_name = ec2_instance['instanceType'].gsub( /./, '-') - Instance.new( { + instance = Instance.new( { :id=>ec2_instance['instanceId'], :name => ec2_instance['imageId'], :state=>state, @@ -285,6 +291,8 @@ class EC2Driver < Deltacloud::BaseDriver :actions=>instance_actions_for( state ), :keyname => ec2_instance['keyName'] } ) + instance.auth_error = "Key not set for instance" unless ec2_instance['keyName'] + return instance end
def convert_volume(ec2_volume) diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb index 875b876..8f4bf60 100644 --- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb @@ -18,12 +18,24 @@ require 'deltacloud/base_driver' require 'deltacloud/drivers/gogrid/gogrid_client'
+class Instance + attr_accessor :username + attr_accessor :password + attr_accessor :auth_error + + def authentification_feature_failed? + return true unless auth_error.nil? + end +end + module Deltacloud module Drivers module Gogrid
class GogridDriver < Deltacloud::BaseDriver
+ feature :instances, :authentication_password + define_hardware_profile 'server' do cpu 2 memory [512, 1024, 2048, 4096, 8192] @@ -76,14 +88,29 @@ class GogridDriver < Deltacloud::BaseDriver else server_ram = "512MB" end + client = new_client(credentials) name = (opts[:name] && opts[:name]!='') ? opts[:name] : get_random_instance_name safely do - convert_instance(new_client(credentials).request('grid/server/add', { + instance = client.request('grid/server/add', { 'name' => name, 'image' => image_id, 'server.ram' => server_ram, 'ip' => get_next_free_ip(credentials) - })['list'].first, credentials.user) + })['list'].first + if instance + login_data = get_login_data(client, instance[:id]) + if login_data['username'] and login_data['password'] + instance['username'] = login_data['username'] + instance['password'] = login_data['password'] + inst = convert_instance(instance, credentials.user) + else + inst = convert_instance(instance, credentials.user) + inst.auth_error = "Unable to fetch password" + end + return inst + else + return nil + end end end
@@ -91,8 +118,18 @@ class GogridDriver < Deltacloud::BaseDriver instances = [] if opts and opts[:id] safely do - instance = new_client(credentials).request('grid/server/get', { 'id' => opts[:id]})['list'].first - instances = [convert_instance(instance, credentials.user)] + client = new_client(credentials) + instance = client.request('grid/server/get', { 'id' => opts[:id] })['list'].first + login_data = get_login_data(client, instance['id']) + if login_data['username'] and login_data['password'] + instance['username'] = login_data['username'] + instance['password'] = login_data['password'] + inst = convert_instance(instance, credentials.user) + else + inst = convert_instance(instance, credentials.user) + inst.auth_error = "Unable to fetch password" + end + instances = [inst] end else safely do @@ -111,18 +148,14 @@ class GogridDriver < Deltacloud::BaseDriver end end
- def stop_instance(credentials, id) - safely do - new_client(credentials).request('grid/server/power', { 'id' => id, 'power' => 'off'}) - end - end - def destroy_instance(credentials, id) safely do new_client(credentials).request('grid/server/delete', { 'id' => id}) end end
+ alias :stop_instance :destroy_instance + define_instance_states do start.to( :pending ) .automatically pending.to( :running ) .automatically @@ -137,6 +170,22 @@ class GogridDriver < Deltacloud::BaseDriver GoGridClient.new('https://api.gogrid.com/api', credentials.user, credentials.password) end
+ def get_login_data(client, instance_id) + login_data = {} + begin + client.request('support/password/list')['list'].each do |passwd| + next unless passwd['server'] + if passwd['server']['id'] == instance_id + login_data['username'], login_data['password'] = passwd['username'], passwd['password'] + break + end + end + rescue Exception => e + login_data[:error] = e.message + end + return login_data + end + def convert_image(gg_image, owner_id=nil) Image.new( { :id=>gg_image['id'], @@ -190,7 +239,7 @@ class GogridDriver < Deltacloud::BaseDriver prof = InstanceProfile.new("server", opts)
Instance.new( - :id => instance['name'], + :id => instance['id'], :owner_id => owner_id, :image_id => instance['image']['id'], :flavor_id => instance['ram']['id'], @@ -200,7 +249,9 @@ class GogridDriver < Deltacloud::BaseDriver :state => convert_server_state(instance['state']['name'], instance['id']), :actions => instance_actions_for(convert_server_state(instance['state']['name'], instance['id'])), :public_addresses => [ instance['ip']['ip'] ], - :private_addresses => [] + :private_addresses => [], + :username => instance['username'], + :password => instance['password'] ) end
diff --git a/server/lib/deltacloud/helpers/application_helper.rb b/server/lib/deltacloud/helpers/application_helper.rb index 9cf00bb..850fab4 100644 --- a/server/lib/deltacloud/helpers/application_helper.rb +++ b/server/lib/deltacloud/helpers/application_helper.rb @@ -44,4 +44,13 @@ module ApplicationHelper not driver.features(:instances).select{ |f| f.name.eql?(feature_name) }.empty? end
+ def driver_has_auth_features? + driver_has_feature?(:authentication_password) || driver_has_feature?(:authentication_key) + end + + def driver_auth_feature_name + return 'key' if driver_has_feature?(:authentication_key) + return 'password' if driver_has_feature?(:authentication_password) + end + end diff --git a/server/server.rb b/server/server.rb index 9f91d86..c4a4125 100644 --- a/server/server.rb +++ b/server/server.rb @@ -242,7 +242,10 @@ collection :instances do @instance = instance haml :"instances/show" end - format.html { redirect instance_url(instance.id) } + format.html do + redirect instance_url(instance.id) if instance + redirect instances_url + end end end end diff --git a/server/views/instances/new.html.haml b/server/views/instances/new.html.haml index 25d8689..6d67c2d 100644 --- a/server/views/instances/new.html.haml +++ b/server/views/instances/new.html.haml @@ -9,7 +9,7 @@ %label Instance Name: %input{ :name => 'name', :size => 30 }/ - -if driver_has_feature(:authentification_key) + -if driver_has_feature?(:authentication_key) %p %label Instance Keyname: diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml index ebbdd2a..e000041 100644 --- a/server/views/instances/show.html.haml +++ b/server/views/instances/show.html.haml @@ -41,6 +41,15 @@ %dt Keyname %dd = @instance.keyname + - if driver_has_feature?(:authentification_password) + %di + %dt Username + %dd + = @instance.username + %di + %dt Password + %dd + = @instance.password %di %dt %dd diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml index 9dc513b..6b94446 100644 --- a/server/views/instances/show.xml.haml +++ b/server/views/instances/show.xml.haml @@ -26,6 +26,14 @@ - @instance.private_addresses.each do |address| %address< =address - - if driver_has_feature?(:authentification_key) - %keyname< - =@instance.keyname + - if driver_has_auth_features? + %authentication{ :type => driver_auth_feature_name } + - if @instance.authentification_feature_failed? + %error #{@instance.auth_error} + - else + - if driver_auth_feature_name == 'password' + %username #{@instance.username} + %password #{@instance.password} + - if driver_auth_feature_name == 'key' + %keyname #{@instance.keyname} +
Hi,
Sorry, sometime my fingers can type faster than my brain can think ;-)
- alias :stop_instance :destroy_instance
This will be removed in push.
format.html do
redirect instance_url(instance.id) if instance
redirect instances_url
end
This was needed, because GoGrid is not reporting ID for new instance, until this instance isn't fully created.
- if driver_has_feature?(:authentification_password)
- %di
%dt Username
%dd
= @instance.username
- %di
%dt Password
%dd
= @instance.password
So this will be removed as well ;)
-- Michal
deltacloud-devel@lists.fedorahosted.org