Example #1
0
 def wait_for_ssh_host_key(self, max_retry=1800, sleep_time=1):
     """
     Wait for cloud-init to generate ssh host key
     """
     keypair_type = conf.get_ssh_host_keypair_type()
     path = conf.get_ssh_key_public_path()
     for retry in range(0, max_retry):
         if os.path.isfile(path):
             logger.info("ssh host key found at: {0}".format(path))
             try:
                 thumbprint = self.get_ssh_host_key_thumbprint(chk_err=False)
                 logger.info("Thumbprint obtained from : {0}".format(path))
                 return thumbprint
             except ProvisionError:
                 logger.warn("Could not get thumbprint from {0}".format(path))
         if retry < max_retry - 1:
             logger.info("Waiting for ssh host key be generated at {0} "
                         "[{1} attempts remaining, "
                         "sleeping {2}s]".format(path,
                                                 max_retry - retry,
                                                 sleep_time))
             if not self.validate_cloud_init():
                 logger.warn("cloud-init does not appear to be running")
             time.sleep(sleep_time)
     raise ProvisionError("Giving up, ssh host key was not found at {0} "
                          "after {1}s".format(path,
                                              max_retry * sleep_time))
Example #2
0
 def get_ssh_host_key_thumbprint(self, chk_err=True):
     cmd = "ssh-keygen -lf {0}".format(conf.get_ssh_key_public_path())
     ret = shellutil.run_get_output(cmd, chk_err=chk_err)
     if ret[0] == 0:
         return ret[1].rstrip().split()[1].replace(':', '')
     else:
         raise ProvisionError(("Failed to generate ssh host key: "
                               "ret={0}, out= {1}").format(ret[0], ret[1]))
Example #3
0
 def get_ssh_host_key_thumbprint(self, chk_err=True):
     cmd = "ssh-keygen -lf {0}".format(conf.get_ssh_key_public_path())
     ret = shellutil.run_get_output(cmd, chk_err=chk_err)
     if ret[0] == 0:
         return ret[1].rstrip().split()[1].replace(':', '')
     else:
         raise ProvisionError(("Failed to generate ssh host key: "
                               "ret={0}, out= {1}").format(ret[0], ret[1]))
Example #4
0
 def test_get_ssh_key_public_path(self):
     self.assertTrue(
         conf.get_ssh_key_public_path(
             self.conf).startswith("/notareal/path"))