#NEWLINE# @ classmethod #NEWLINE# def add_keypair( cls , options ) : #NEWLINE# #INDENT# 'Sets up passwordless SSH login to the machines used in a virtualized\n    cluster deployment.\n\n    Args:\n      options: A Namespace that has fields for each parameter that can be\n        passed in via the command-line interface.\n    Raises:\n      AppScaleException: If any of the machines named in the ips_layout are\n        not running, or do not have the SSH daemon running.\n    ' #NEWLINE# LocalState . require_ssh_commands ( options . auto , options . verbose ) #NEWLINE# LocalState . make_appscale_directory ( ) #NEWLINE# path = ( LocalState . LOCAL_APPSCALE_PATH + options . keyname ) #NEWLINE# if options . add_to_existing : #NEWLINE# #INDENT# public_key = ( path + '.pub' ) #NEWLINE# private_key = path #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( public_key , private_key ) = LocalState . generate_rsa_key ( options . keyname , options . verbose ) #NEWLINE# #UNINDENT# if options . auto : #NEWLINE# #INDENT# if ( 'root_password' in options ) : #NEWLINE# #INDENT# AppScaleLogger . log ( ( 'Using the provided root password to log into ' + 'your VMs.' ) ) #NEWLINE# password = options . root_password #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# AppScaleLogger . log ( ( 'Please enter the password for the root user on' + ' your VMs:' ) ) #NEWLINE# password = getpass . getpass ( ) #NEWLINE# #UNINDENT# #UNINDENT# node_layout = NodeLayout ( options ) #NEWLINE# if ( not node_layout . is_valid ( ) ) : #NEWLINE# #INDENT# raise BadConfigurationException ( ( ( 'There were problems with your ' + 'placement strategy: ' ) + str ( node_layout . errors ( ) ) ) ) #NEWLINE# #UNINDENT# all_ips = [ node . public_ip for node in node_layout . nodes ] #NEWLINE# for ip in all_ips : #NEWLINE# #INDENT# if ( not RemoteHelper . is_port_open ( ip , RemoteHelper . SSH_PORT , options . verbose ) ) : #NEWLINE# #INDENT# raise AppScaleException ( 'SSH does not appear to be running at {0}. Is the machine at {0} up and running? Make sure your IPs are correct!' . format ( ip ) ) #NEWLINE# #UNINDENT# AppScaleLogger . log ( 'Executing ssh-copy-id for host: {0}' . format ( ip ) ) #NEWLINE# if options . auto : #NEWLINE# #INDENT# LocalState . shell ( '{0} root@{1} {2} {3}' . format ( cls . EXPECT_SCRIPT , node_layout , private_key , password ) , options . verbose ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# LocalState . shell ( 'ssh-copy-id -i {0} root@{1}' . format ( private_key , ip ) , options . verbose ) #NEWLINE# #UNINDENT# #UNINDENT# AppScaleLogger . success ( ( 'Generated a new SSH key for this deployment ' + 'at {0}' . format ( private_key ) ) )