Revision 70d9e3d8 lib/cmdlib.py

b/lib/cmdlib.py
476 476
    node: the name of this host as a fqdn
477 477

  
478 478
  """
479
  if os.path.exists('/root/.ssh/id_dsa'):
480
    utils.CreateBackup('/root/.ssh/id_dsa')
481
  if os.path.exists('/root/.ssh/id_dsa.pub'):
482
    utils.CreateBackup('/root/.ssh/id_dsa.pub')
479
  priv_key, pub_key, auth_keys = ssh.GetUserFiles(constants.GANETI_RUNAS)
483 480

  
484
  utils.RemoveFile('/root/.ssh/id_dsa')
485
  utils.RemoveFile('/root/.ssh/id_dsa.pub')
481
  for name in priv_key, pub_key:
482
    if os.path.exists(name):
483
      utils.CreateBackup(name)
484
    utils.RemoveFile(name)
486 485

  
487 486
  result = utils.RunCmd(["ssh-keygen", "-t", "dsa",
488
                         "-f", "/root/.ssh/id_dsa",
487
                         "-f", priv_key,
489 488
                         "-q", "-N", ""])
490 489
  if result.failed:
491 490
    raise errors.OpExecError("Could not generate ssh keypair, error %s" %
492 491
                             result.output)
493 492

  
494
  f = open('/root/.ssh/id_dsa.pub', 'r')
493
  f = open(pub_key, 'r')
495 494
  try:
496
    utils.AddAuthorizedKey('/root/.ssh/authorized_keys', f.read(8192))
495
    utils.AddAuthorizedKey(auth_keys, f.read(8192))
497 496
  finally:
498 497
    f.close()
499 498

  
......
627 626
    rpc.call_node_start_master(hostname.name)
628 627

  
629 628
    # set up ssh config and /etc/hosts
630
    f = open('/etc/ssh/ssh_host_rsa_key.pub', 'r')
629
    f = open(constants.SSH_HOST_RSA_PUB, 'r')
631 630
    try:
632 631
      sshline = f.read()
633 632
    finally:
......
676 675
    """Destroys the cluster.
677 676

  
678 677
    """
679
    utils.CreateBackup('/root/.ssh/id_dsa')
680
    utils.CreateBackup('/root/.ssh/id_dsa.pub')
678
    priv_key, pub_key, _ = ssh.GetUserFiles(constants.GANETI_RUNAS)
679
    utils.CreateBackup(priv_key)
680
    utils.CreateBackup(pub_key)
681 681
    rpc.call_node_leave_cluster(self.sstore.GetMasterNode())
682 682

  
683 683

  
......
1508 1508

  
1509 1509
    # setup ssh on node
1510 1510
    logger.Info("copy ssh key to node %s" % node)
1511
    priv_key, pub_key, _ = ssh.GetUserFiles(constants.GANETI_RUNAS)
1511 1512
    keyarray = []
1512
    keyfiles = ["/etc/ssh/ssh_host_dsa_key", "/etc/ssh/ssh_host_dsa_key.pub",
1513
                "/etc/ssh/ssh_host_rsa_key", "/etc/ssh/ssh_host_rsa_key.pub",
1514
                "/root/.ssh/id_dsa", "/root/.ssh/id_dsa.pub"]
1513
    keyfiles = [constants.SSH_HOST_DSA_PRIV, constants.SSH_HOST_DSA_PUB,
1514
                constants.SSH_HOST_RSA_PRIV, constants.SSH_HOST_RSA_PUB,
1515
                priv_key, pub_key]
1515 1516

  
1516 1517
    for i in keyfiles:
1517 1518
      f = open(i, 'r')

Also available in: Unified diff