Ejemplo n.º 1
0
    def download_file(self, key, stored_etag=None):
        """
        Download an OCP usage file.

        Args:
            key (str): The OCP file name.

        Returns:
            (String): The path and file name of the saved file

        """
        local_filename = utils.get_local_file_name(key)
        manifest_filename = 'manifest.json'
        source_manifest_path = f'{os.path.dirname(key)}/{manifest_filename}'

        directory_path = f'{DATA_DIR}/{self.customer_name}/ocp/{self.cluster_id}'
        full_file_path = f'{directory_path}/{local_filename}'
        full_manfiest_path = f'{directory_path}/{manifest_filename}'

        # Make sure the data directory exists
        os.makedirs(directory_path, exist_ok=True)
        etag_hasher = hashlib.new('ripemd160')
        etag_hasher.update(bytes(local_filename, 'utf-8'))
        ocp_etag = etag_hasher.hexdigest()

        if ocp_etag != stored_etag or not os.path.isfile(full_file_path):
            LOG.info('Downloading %s to %s', key, full_file_path)
            shutil.move(key, full_file_path)
            shutil.copy2(source_manifest_path, full_manfiest_path)
        return full_file_path, ocp_etag
Ejemplo n.º 2
0
    def download_file(self, key, stored_etag=None):
        """
        Download an OCP usage file.

        Args:
            key (str): The OCP file name.

        Returns:
            (String): The path and file name of the saved file

        """
        local_filename = utils.get_local_file_name(key)

        directory_path = f"{DATA_DIR}/{self.customer_name}/ocp/{self.cluster_id}"
        full_file_path = f"{directory_path}/{local_filename}"

        # Make sure the data directory exists
        os.makedirs(directory_path, exist_ok=True)
        etag_hasher = hashlib.new("ripemd160")
        etag_hasher.update(bytes(local_filename, "utf-8"))
        ocp_etag = etag_hasher.hexdigest()

        if ocp_etag != stored_etag or not os.path.isfile(full_file_path):
            LOG.info("Downloading %s to %s", key, full_file_path)
            shutil.move(key, full_file_path)
        return full_file_path, ocp_etag
Ejemplo n.º 3
0
    def download_file(self,
                      key,
                      stored_etag=None,
                      manifest_id=None,
                      start_date=None):
        """
        Download an OCP usage file.

        Args:
            key (str): The OCP file name.

        Returns:
            (String): The path and file name of the saved file

        """
        if not self.manifest:
            self.manifest = ReportManifestDBAccessor().get_manifest_by_id(
                manifest_id)
        self.context["version"] = self.manifest.operator_version
        local_filename = utils.get_local_file_name(key)

        directory_path = f"{DATA_DIR}/{self.customer_name}/ocp/{self.cluster_id}"
        full_file_path = f"{directory_path}/{local_filename}"

        # Make sure the data directory exists
        os.makedirs(directory_path, exist_ok=True)
        etag_hasher = hashlib.new("ripemd160")
        etag_hasher.update(bytes(local_filename, "utf-8"))
        ocp_etag = etag_hasher.hexdigest()

        file_creation_date = None
        if ocp_etag != stored_etag or not os.path.isfile(full_file_path):
            msg = f"Downloading {key} to {full_file_path}"
            LOG.info(log_json(self.request_id, msg, self.context))
            shutil.move(key, full_file_path)
            file_creation_date = datetime.datetime.fromtimestamp(
                os.path.getmtime(full_file_path))

        file_names = create_daily_archives(
            self.request_id,
            self.account,
            self._provider_uuid,
            local_filename,
            full_file_path,
            manifest_id,
            start_date,
            self.context,
        )

        return full_file_path, ocp_etag, file_creation_date, file_names
Ejemplo n.º 4
0
 def get_local_file_for_report(self, report):
     """Get full path for local report file."""
     return utils.get_local_file_name(report)