Ejemplo n.º 1
0
    def _copy_image_file_from_host(self, remote_source_path,
                                   local_dest_dir, compress=False):
        """
        Copy a file from IVM to the nova-compute host,
        and return the location of the copy

        :param remote_source_path remote source file path
        :param local_dest_dir local destination directory
        :param compress: if True, compress the file before transfer;
                         if False (default), copy the file as is
        """

        temp_str = common.aix_path_join(local_dest_dir,
                                        os.path.basename(remote_source_path))
        local_file_path = temp_str + '.gz'

        if compress:
            copy_from_path = remote_source_path + '.gz'
        else:
            copy_from_path = remote_source_path

        if compress:
            # Gzip the file
            cmd = "/usr/bin/gzip %s" % remote_source_path
            self.run_vios_command_as_root(cmd)

            # Cleanup uncompressed remote file
            cmd = "/usr/bin/rm -f %s" % remote_source_path
            self.run_vios_command_as_root(cmd)

        # Get file checksum
        output = self._md5sum_remote_file(copy_from_path)
        if not output:
            LOG.error(_("Unable to get checksum"))
            msg_args = {'file_path': copy_from_path}
            raise exception.IBMPowerVMFileTransferFailed(**msg_args)
        else:
            source_chksum = output.split(' ')[0]

        # Copy file to host
#         common.scp_command(self.connection_data,
#                            local_file_path,
#                            copy_from_path,
#                            'get')
        cp_cmd = 'cp' + ' -f ' + copy_from_path + ' ' + local_file_path
        self.run_vios_command(cp_cmd)
        # Calculate copied image checksum
        dest_chksum = self._checksum_local_file(local_file_path)

        # do comparison
        if source_chksum and dest_chksum != source_chksum:
            LOG.error(_("Image checksums do not match"))
            raise exception.IBMPowerVMFileTransferFailed(
                file_path=local_file_path)

        # Cleanup transferred remote file
        cmd = "/usr/bin/rm -f %s" % copy_from_path
        output = self.run_vios_command_as_root(cmd)

        return local_file_path
Ejemplo n.º 2
0
    def _copy_compressed_image_file_from_host(self, device_name,
                                              remote_source_path,
                                              local_dest_dir, compress=False):
        """
        Copy a file from IVM to the nova-compute host,
        and return the location of the copy

        :param device_name device name to copy from
        :param remote_source_path remote source file path
        :param local_dest_dir local destination directory
        :param compress: if True, compress the file before transfer;
                         if False (default), copy the file as is
        """

        temp_str = common.aix_path_join(local_dest_dir,
                                        os.path.basename(remote_source_path))
        local_file_path = temp_str + '.gz'

        if compress:
            copy_from_path = remote_source_path + '.gz'
        else:
            copy_from_path = remote_source_path

        try:

            try:
                cmd = 'dd if=/dev/%s bs=1024k | /usr/bin/gzip -c > %s ' % (
                    device_name, copy_from_path)
                # self.run_vios_command_as_root(cmd)
                self.pvm_operator.run_vios_command_as_root_with_shell(cmd)
            except Exception as e:
                # dd command failed, raise an exception.
                free_staging_mb = self.pvm_operator.\
                    get_staging_free_space()
                raise exception.IBMPowerVMInsufficientStagingMemory(
                    operation='command - dd', free=free_staging_mb)

            # Get file checksum
            output = self._md5sum_remote_file(copy_from_path)
            if not output:
                LOG.error(_("Unable to get checksum"))
                msg_args = {'file_path': copy_from_path}
                raise exception.IBMPowerVMFileTransferFailed(**msg_args)
            else:
                source_chksum = output.split(' ')[0]
            # calculate file capture_file_size of copy_from_path.
            # Calculate file capture_file_size in multiples of 512 bytes |awk '{print $4}'
            output = self.run_vios_command("ls -o %s" % copy_from_path, check_exit_code=False)
            if output:
                out = output[0].split()
                capture_file_size = int(out[3])
            else:
                LOG.error(_("Copy compressed file failed, since"
                            " file %s not found") % copy_from_path)
                raise exception.IBMPowerVMFileTransferFailed(
                    filepath=copy_from_path)
            if (capture_file_size % 512 != 0):
                capture_file_size = (int(capture_file_size / 512) + 1) * 512
            # check if required space is available on Management Server.
            # raise an exception if capture_file_size is a constraint.
            self._check_space(local_dest_dir, capture_file_size * 2)

            # Copy file to host
            # common.scp_command(self.connection_data,
            #                   local_file_path,
            #                   copy_from_path,
            #                   'get')
            cp_cmd = 'cp' + ' -f ' + copy_from_path + ' ' + local_file_path
            self.run_vios_command(cp_cmd)
            # Calculate copied image checksum
            dest_chksum = self._checksum_local_file(local_file_path)

            # do comparison
            if source_chksum and dest_chksum != source_chksum:
                LOG.error(_("Image checksums do not match"))
                raise exception.IBMPowerVMFileTransferFailed(
                    file_path=local_file_path)
        finally:
            # Cleanup transferred remote file
            cmd = "/usr/bin/rm -f %s" % copy_from_path
            output = self.run_vios_command_as_root(cmd)
        # return capture_file_size to calling function
        return local_file_path, capture_file_size