def get_ceph_store(self) -> CephStore: """Establish a connection to the CEPH.""" s3 = CephStore( key_id=self._KEY_ID, secret_key=self._SECRET_KEY, prefix=self._PREFIX, host=self._HOST, bucket=self._BUCKET ) s3.connect() return s3
def get_ceph_connection_error_status() -> None: """Check connection to Ceph instance.""" ceph_storage = CephStore( key_id=Configuration.CEPH_ACCESS_KEY_ID, secret_key=Configuration.CEPH_ACCESS_SECRET_KEY, prefix=Configuration.CEPH_BUCKET_PREFIX, host=Configuration.S3_ENDPOINT_URL, bucket=Configuration.CEPH_BUCKET, ) try: ceph_storage.connect() except Exception as excptn: metrics.ceph_connection_error_status.set(0) _LOGGER.exception(excptn) else: metrics.ceph_connection_error_status.set(1)
class WorkflowLogsStore(StorageBase): """Access logs stored by Argo Workflows.""" def __init__( self, deployment_name: Optional[str] = None, *, host: Optional[str] = None, key_id: Optional[str] = None, secret_key: Optional[str] = None, bucket: Optional[str] = None, region: Optional[str] = None, prefix: Optional[str] = None, ): """Initialize the adapter.""" self.deployment_name = deployment_name or os.environ[ "THOTH_DEPLOYMENT_NAME"] self.prefix = "{}/{}/argo/artifacts".format( prefix or os.environ["THOTH_CEPH_BUCKET_PREFIX"], self.deployment_name, ) self.ceph = CephStore(self.prefix, host=host, key_id=key_id, secret_key=secret_key, bucket=bucket, region=region) def get_log(self, workflow_id: str) -> str: """Obtain log from the given workflow.""" results = list(self.ceph.get_document_listing(workflow_id)) if len(results) > 1: raise MultipleFoundError( f"Multiple results match the given workflow_id ({workflow_id!r}) provided: {results!r}" ) # Make sure users do not use workflow id prefix. if not results or not results[0].startswith(f"{workflow_id}/"): raise NotFoundError(f"No log entry found for {workflow_id!r}") return self.ceph.retrieve_blob(results[0]).decode() def connect(self) -> None: """Connect to Ceph.""" self.ceph.connect()
def get_ceph_store() -> CephStore: """Establish a connection to the CEPH.""" s3 = CephStore(prefix=PREFIX, host=HOST, bucket=BUCKET) s3.connect() return s3