Ejemplo n.º 1
0
Archivo: _nova.py Proyecto: 4383/tobiko
 def create_key_file(self):
     key_file = os.path.realpath(self.key_file)
     if not os.path.isfile(key_file):
         key_dir = os.path.dirname(key_file)
         tobiko.makedirs(key_dir)
         try:
             sh.local_execute(['ssh-keygen', '-f', key_file, '-P', ''])
         except sh.ShellCommandFailed:
             if not os.path.isfile(key_file):
                 raise
         else:
             assert os.path.isfile(key_file)
Ejemplo n.º 2
0
    def setup_key_file(self):
        key_filename = self.key_filename
        key_dirname = os.path.dirname(key_filename)
        tobiko.makedirs(key_dirname, mode=0o700)

        ssh_client = undercloud.undercloud_ssh_client()
        _get_undercloud_file(ssh_client=ssh_client,
                             source='~/.ssh/id_rsa',
                             destination=key_filename,
                             mode=0o600)
        _get_undercloud_file(ssh_client=ssh_client,
                             source='~/.ssh/id_rsa.pub',
                             destination=key_filename + '.pub',
                             mode=0o600)
Ejemplo n.º 3
0
    def _download_image_file(self, image_file, chunks, expected_size):
        image_dir = os.path.dirname(image_file)
        LOG.debug('Ensure image directory exists: %r', image_dir)
        tobiko.makedirs(image_dir)

        fd, temp_file = tempfile.mkstemp(dir=image_dir)
        with io.open(fd, 'wb', io.DEFAULT_BUFFER_SIZE) as image_data:
            for chunk in chunks:
                image_data.write(chunk)

        actual_size = os.path.getsize(temp_file)
        LOG.debug('Downloaded image %r from URL %r to file %r (%d bytes)',
                  self.image_name, self.image_url, image_file, actual_size)

        if expected_size and actual_size != expected_size:
            message = "Download file size mismatch: {!s} != {!r}".format(
                expected_size, actual_size)
            raise RuntimeError(message)
        os.rename(temp_file, image_file)
Ejemplo n.º 4
0
    def generate_config_file(self, config_filename):
        """Generates os-faults configuration file."""

        self.template_filename = template_filename = (
            self.get_template_filename())
        template_basename = os.path.basename(template_filename)
        if config_filename is None:
            config_dirname = os.path.realpath(
                os.path.expanduser(self.config.generate_config_dirname))
            config_basename, template_ext = os.path.splitext(template_basename)
            assert template_ext == '.j2'
            config_filename = os.path.join(config_dirname, config_basename)
        else:
            config_dirname = os.path.dirname(config_filename)

        LOG.info("Generating os-fault config file from template %r to %r.",
                 template_filename, config_filename)
        tobiko.makedirs(config_dirname)

        make_os_faults_config_file(config_filename=config_filename,
                                   template_filename=template_filename,
                                   topo=self.topo)
        return config_filename