parameters: (self, name, path,
          keytype=None, passphrase="", bits=None, comment="")
docstring: Generates a new private and public key pair--stored in the user's directory
      using the given *name* and other optional parameters (using OpenSSH).
  
      If *keytype* is given, it must be one of "ecdsa", "rsa" or "dsa" (case
      insensitive).  If *keytype* is "rsa" or "ecdsa", *bits* may be specified to
      specify the size of the key.
  
      .. note:: Defaults to generating a 521-byte ecdsa key if OpenSSH is version 5.7+. Otherwise a 2048-bit rsa key will be used.
docstring_summary: Generates a new private and public key pair--stored in the user's directory
      using the given *name* and other optional parameters (using OpenSSH).
docstring_tokens: Generates a new private and public key pair -- stored in the user s directory using the given * name * and other optional parameters ( using OpenSSH ) .
function: def openssh_generate_new_keypair(self, name, path,
          keytype=None, passphrase="", bits=None, comment=""):
      """
      Generates a new private and public key pair--stored in the user's directory
      using the given *name* and other optional parameters (using OpenSSH).
  
      If *keytype* is given, it must be one of "ecdsa", "rsa" or "dsa" (case
      insensitive).  If *keytype* is "rsa" or "ecdsa", *bits* may be specified to
      specify the size of the key.
  
      .. note:: Defaults to generating a 521-byte ecdsa key if OpenSSH is version 5.7+. Otherwise a 2048-bit rsa key will be used.
      """
      self.ssh_log.debug('openssh_generate_new_keypair()')
      openssh_version = shell_command('ssh -V')[1]
      ssh_major_version = int(
          openssh_version.split()[0].split('_')[1].split('.')[0])
      key_path = os.path.join(path, name)
      ssh_minor_version = int(
          openssh_version.split()[0].split('_')[1].split('.')[1][0])
      ssh_version = "%s.%s" % (ssh_major_version, ssh_minor_version)
      ssh_version = float(ssh_version)
      if not keytype:
          if ssh_version >= 5.7:
              keytype = "ecdsa"
          else:
              keytype = "rsa"
      else:
          keytype = keytype.lower()
      if not bits and keytype == "ecdsa":
          bits = 521 # Not a typo: five-hundred-twenty-one bits
      elif not bits and keytype == "rsa":
          bits = 2048
      if not passphrase: # This just makes sure False and None end up as ''
          passphrase = ''
      hostname = os.uname()[1]
      if not comment:
          now = datetime.now().isoformat()
          comment = "Generated by Gate One on %s %s" % (hostname, now)
      ssh_keygen_path = which('ssh-keygen')
      command = (
          "%s "       # Path to ssh-keygen
          "-b %s "    # bits
          "-t %s "    # keytype
          "-C '%s' "  # comment
          "-f '%s'"   # Key path
          % (ssh_keygen_path, bits, keytype, comment, key_path)
      )
      self.ssh_log.debug("Keygen command: %s" % command)
      m = self.new_multiplex(command, "gen_ssh_keypair")
      call_errorback = partial(errorback, self)
      m.expect('^Overwrite.*',
          overwrite, optional=True, preprocess=False, timeout=10)
      passphrase_handler = partial(enter_passphrase, passphrase)
      m.expect('^Enter passphrase',
          passphrase_handler,
          errorback=call_errorback,
          preprocess=False,
          timeout=10)
      m.expect('^Enter same passphrase again',
          passphrase_handler,
          errorback=call_errorback,
          preprocess=False,
          timeout=10)
      finalize = partial(finished, self)
      # The regex below captures the md5 fingerprint which tells us the
      # operation was successful.
      m.expect(
          '(([0-9a-f][0-9a-f]\:){15}[0-9a-f][0-9a-f])',
          finalize,
          errorback=call_errorback,
          preprocess=False,
          timeout=15 # Key generation can take a little while
      )
      m.spawn()
function_tokens: def openssh_generate_new_keypair ( self , name , path , keytype = None , passphrase = "" , bits = None , comment = "" ) : self . ssh_log . debug ( 'openssh_generate_new_keypair()' ) openssh_version = shell_command ( 'ssh -V' ) [ 1 ] ssh_major_version = int ( openssh_version . split ( ) [ 0 ] . split ( '_' ) [ 1 ] . split ( '.' ) [ 0 ] ) key_path = os . path . join ( path , name ) ssh_minor_version = int ( openssh_version . split ( ) [ 0 ] . split ( '_' ) [ 1 ] . split ( '.' ) [ 1 ] [ 0 ] ) ssh_version = "%s.%s" % ( ssh_major_version , ssh_minor_version ) ssh_version = float ( ssh_version ) if not keytype : if ssh_version >= 5.7 : keytype = "ecdsa" else : keytype = "rsa" else : keytype = keytype . lower ( ) if not bits and keytype == "ecdsa" : bits = 521 # Not a typo: five-hundred-twenty-one bits elif not bits and keytype == "rsa" : bits = 2048 if not passphrase : # This just makes sure False and None end up as '' passphrase = '' hostname = os . uname ( ) [ 1 ] if not comment : now = datetime . now ( ) . isoformat ( ) comment = "Generated by Gate One on %s %s" % ( hostname , now ) ssh_keygen_path = which ( 'ssh-keygen' ) command = ( "%s " # Path to ssh-keygen "-b %s " # bits "-t %s " # keytype "-C '%s' " # comment "-f '%s'" # Key path % ( ssh_keygen_path , bits , keytype , comment , key_path ) ) self . ssh_log . debug ( "Keygen command: %s" % command ) m = self . new_multiplex ( command , "gen_ssh_keypair" ) call_errorback = partial ( errorback , self ) m . expect ( '^Overwrite.*' , overwrite , optional = True , preprocess = False , timeout = 10 ) passphrase_handler = partial ( enter_passphrase , passphrase ) m . expect ( '^Enter passphrase' , passphrase_handler , errorback = call_errorback , preprocess = False , timeout = 10 ) m . expect ( '^Enter same passphrase again' , passphrase_handler , errorback = call_errorback , preprocess = False , timeout = 10 ) finalize = partial ( finished , self ) # The regex below captures the md5 fingerprint which tells us the # operation was successful. m . expect ( '(([0-9a-f][0-9a-f]\:){15}[0-9a-f][0-9a-f])' , finalize , errorback = call_errorback , preprocess = False , timeout = 15 # Key generation can take a little while ) m . spawn ( )