---
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<
- [email protected]
+ - if driver_has_auth_features?
+ %authentication{ :type => driver_auth_feature_name }
+ - if @instance.authentification_feature_failed?
+ %error #[email protected]_error}
+ - else
+ - if driver_auth_feature_name == 'password'
+ %username #[email protected]}
+ %password #[email protected]}
+ - if driver_auth_feature_name == 'key'
+ %keyname #[email protected]}
+
--
1.7.1
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel