---
.../lib/deltacloud/drivers/gogrid/gogrid_driver.rb | 52 +++++++++++++++-----
server/server.rb | 5 ++-
server/views/instances/new.html.haml | 2 +-
server/views/instances/show.html.haml | 9 +++
server/views/instances/show.xml.haml | 5 ++
5 files changed, 59 insertions(+), 14 deletions(-)
diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index 875b876..2538da7 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -18,12 +18,19 @@
require 'deltacloud/base_driver'
require 'deltacloud/drivers/gogrid/gogrid_client'
+class Instance
+ attr_accessor :username
+ attr_accessor :password
+end
+
module Deltacloud
module Drivers
module Gogrid
class GogridDriver < Deltacloud::BaseDriver
+ feature :instances, :authentification_password
+
define_hardware_profile 'server' do
cpu 2
memory [512, 1024, 2048, 4096, 8192]
@@ -78,12 +85,20 @@ class GogridDriver < Deltacloud::BaseDriver
end
name = (opts[:name] && opts[:name]!='') ? opts[:name] :
get_random_instance_name
safely do
- convert_instance(new_client(credentials).request('grid/server/add', {
+ instance = new_client(credentials).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(instance[:id])
+ instance['username'] = login_data['username']
+ instance['password'] = login_data['password']
+ return convert_instance(instance, credentials.user)
+ else
+ return nil
+ end
end
end
@@ -91,7 +106,10 @@ 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
+ instance = new_client(credentials).request('grid/server/get', { 'name'
=> opts[:id]})['list'].first
+ login_data = get_login_data(credentials, instance['name'])
+ instance['username'] = login_data['username']
+ instance['password'] = login_data['password']
instances = [convert_instance(instance, credentials.user)]
end
else
@@ -107,22 +125,18 @@ class GogridDriver < Deltacloud::BaseDriver
def reboot_instance(credentials, id)
safely do
- new_client(credentials).request('grid/server/power', { 'id' => id,
'power' => 'reboot'})
- end
- end
-
- def stop_instance(credentials, id)
- safely do
- new_client(credentials).request('grid/server/power', { 'id' => id,
'power' => 'off'})
+ new_client(credentials).request('grid/server/power', { 'name' => id,
'power' => 'reboot'})
end
end
def destroy_instance(credentials, id)
safely do
- new_client(credentials).request('grid/server/delete', { 'id' => id})
+ new_client(credentials).request('grid/server/delete', { 'name' => id})
end
end
+ alias :stop_instance :destroy_instance
+
define_instance_states do
start.to( :pending ) .automatically
pending.to( :running ) .automatically
@@ -137,6 +151,18 @@ class GogridDriver < Deltacloud::BaseDriver
GoGridClient.new('https://api.gogrid.com/api', credentials.user,
credentials.password)
end
+ def get_login_data(credentials, instance_id)
+ login_data = {}
+ new_client(credentials).request('support/password/list')['list'].each do
|passwd|
+ next unless passwd['server']
+ if passwd['server']['name'] == instance_id
+ login_data['username'], login_data['password'] = passwd['username'],
passwd['password']
+ break
+ end
+ end
+ return login_data
+ end
+
def convert_image(gg_image, owner_id=nil)
Image.new( {
:id=>gg_image['id'],
@@ -200,7 +226,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/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..debcda8 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?(:authentification_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 fd9d01d..5b7ccb4 100644
--- a/server/views/instances/show.xml.haml
+++ b/server/views/instances/show.xml.haml
@@ -29,3 +29,8 @@
- if driver_has_feature?(:authentification_key)
%keyname<
[email protected]
+ - if driver_has_feature?(:authentification_password)
+ %username<
+ [email protected]
+ %password<
+ [email protected]
--
1.7.1
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel