You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/08/04 16:10:43 UTC

[PATCH core] EC2: Retrieve Windows administrator password and advertise it through instance show

From: Michal Fojtik <mf...@redhat.com>

---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   17 +++++++++++++++++
 server/views/instances/show.xml.haml            |    6 +++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 4c47db4..990cbdb 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -178,6 +178,23 @@ module Deltacloud
           end
         end
 
+        def instance(credentials, opts={})
+          ec2 = new_client(credentials)
+          inst_arr = []
+          safely do
+            instance = ec2.describe_instances([opts[:id]]).first
+            instance = convert_instance(instance)
+            return nil unless instance
+            console_output = ec2.get_console_output(instance.id)
+            windows_password = console_output[:aws_output][%r{<Password>(.+)</Password>}m] && $1
+            if windows_password
+              instance.username = 'Administrator'
+              instance.password = windows_password
+            end
+            instance
+          end
+        end
+
         def instances(credentials, opts={})
           ec2 = new_client(credentials)
           inst_arr = []
diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml
index 27f04a6..ab60fb7 100644
--- a/server/views/instances/show.xml.haml
+++ b/server/views/instances/show.xml.haml
@@ -49,11 +49,11 @@
       - if @instance.authn_feature_failed?
         %error  #{@instance.authn_error}
       - else
-        - if driver_auth_feature_name == 'password'
+        - if @instance.password
           %login
             %username #{@instance.username}
-            %password #{@instance.password}
-        - if driver_auth_feature_name == 'key'
+            %password=cdata(@instance.password)
+        - if @instance.keyname
           %login
             %keyname #{@instance.keyname}
 
-- 
1.7.6


Re: [PATCH core] EC2: Retrieve Windows administrator password and advertise it through instance show

Posted by Michal Fojtik <mf...@redhat.com>.
On Aug 5, 2011, at 11:28 PM, David Lutterkort wrote:

> On Thu, 2011-08-04 at 16:10 +0200, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@redhat.com>
>> 
>> ---
>> server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   17 +++++++++++++++++
>> server/views/instances/show.xml.haml            |    6 +++---
>> 2 files changed, 20 insertions(+), 3 deletions(-)
> 
> ACK.
> 
> I am a little uneasy that we now have to make two requests to the AWS
> API for each instance; is there any way to use the 'platform' attribute
> that DescribeInstances sends back to avoid the second call ? Supposedly
> it gets set to 'windows' for Windows instances, and not at all for
> others.

Yes, you're right. I'll look on the was gem if there is a way how to fetch
this platform string out there. Then I'll rework this patch.

  -- Michal

> 
> David
> 
> 

------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org


Re: [PATCH core] EC2: Retrieve Windows administrator password and advertise it through instance show

Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2011-08-04 at 16:10 +0200, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> ---
>  server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   17 +++++++++++++++++
>  server/views/instances/show.xml.haml            |    6 +++---
>  2 files changed, 20 insertions(+), 3 deletions(-)

ACK.

I am a little uneasy that we now have to make two requests to the AWS
API for each instance; is there any way to use the 'platform' attribute
that DescribeInstances sends back to avoid the second call ? Supposedly
it gets set to 'windows' for Windows instances, and not at all for
others.

David