[pkg-eucalyptus-commits] [SCM] managing cloud instances for Eucalyptus branch, experimental, updated. debian/2.1.1-1_experimental1-51-g95835b7

Andrew Hamilton ahamilton55 at gmail.com
Thu Jan 3 11:06:06 UTC 2013


The following commit has been merged in the experimental branch:
commit 60e3dffb3d7e5e124ec0c32d19dbc440df809fb1
Author: Andrew Hamilton <ahamilton55 at gmail.com>
Date:   Fri Jul 20 21:11:40 2012 -0700

     Add a way to save private keyfiles with euca-create-keypair
    
        - Added a -f <filename> flag to allow the user to enter a filename
          for the private key.
        - Private key is saved to the filename provided and is the file
          permissions are changed to 0600 so that the key is ready to use.

diff --git a/euca2ools/commands/euca/createkeypair.py b/euca2ools/commands/euca/createkeypair.py
index 4a72283..14c0f17 100644
--- a/euca2ools/commands/euca/createkeypair.py
+++ b/euca2ools/commands/euca/createkeypair.py
@@ -33,10 +33,18 @@
 
 import euca2ools.commands.eucacommand
 from boto.roboto.param import Param
+from os import chmod
+from stat import *
 
 class CreateKeyPair(euca2ools.commands.eucacommand.EucaCommand):
 
     Description = 'Creates a new key pair for use with instances'
+    Options = [Param(name='filename', short_name='f', 
+                  long_name='filename', ptype='string',
+                  doc='Filename to save the private key. Default ' +
+                  'action is to overwire the file.',
+                  optional=True)]
+
     Args = [Param(name='keypair_name', ptype='string',
                   doc='unique name for a keypair to be created',
                   cardinality=1, optional=False)]
@@ -45,6 +53,13 @@ class CreateKeyPair(euca2ools.commands.eucacommand.EucaCommand):
         print 'KEYPAIR\t%s\t%s' % (keypair.name, keypair.fingerprint)
         print keypair.material
 
+    def save_keypair_to_file(self, keypair):
+        keyfile = open(self.filename, 'w')
+        keyfile.write(keypair.material)
+        keyfile.close()
+
+        chmod(self.filename, S_IRUSR|S_IWUSR)
+
     def main(self):
         conn = self.make_connection_cli()
         return self.make_request_cli(conn, 'create_key_pair',
@@ -53,5 +68,6 @@ class CreateKeyPair(euca2ools.commands.eucacommand.EucaCommand):
     def main_cli(self):
         keypair = self.main()
         self.display_keypair(keypair)
-
+        if self.filename != None:
+            self.save_keypair_to_file(keypair)
 

-- 
managing cloud instances for Eucalyptus



More information about the pkg-eucalyptus-commits mailing list