def __init__(self, cloudapi_client: CloudApiClient): def_utils.raise_error_if_def_not_supported(cloudapi_client) self._cloudapi_client = cloudapi_client
def _load_def_schema(self, msg_update_callback=utils.NullPrinter()): """Load cluster interface and cluster entity type to global context. If defined entity framework is supported by vCD api version, load defined entity interface and defined entity type registered during server install :param utils.NullMessagePrinter msg_update_callback: """ sysadmin_client = None try: sysadmin_client = vcd_utils.get_sys_admin_client(api_version=None) logger_wire = logger.NULL_LOGGER if utils.str_to_bool( utils.str_to_bool(self.config['service'].get( 'log_wire', False))): # noqa: E501 logger_wire = logger.SERVER_CLOUDAPI_WIRE_LOGGER cloudapi_client = \ vcd_utils.get_cloudapi_client_from_vcd_client(sysadmin_client, logger.SERVER_LOGGER, # noqa: E501 logger_wire) raise_error_if_def_not_supported(cloudapi_client) server_rde_version = server_utils.get_rde_version_in_use() msg_update_callback.general( f"Using RDE version: {server_rde_version}") # noqa: E501 schema_svc = def_schema_svc.DefSchemaService(cloudapi_client) def_metadata_dict: dict = def_utils.get_rde_metadata( server_rde_version) # noqa: E501 entity_type: common_models.DefEntityType = \ def_metadata_dict[def_constants.RDEMetadataKey.ENTITY_TYPE] # noqa: E501 interfaces: List[common_models.DefInterface] = \ def_metadata_dict[def_constants.RDEMetadataKey.INTERFACES] # noqa: E501 for interface in interfaces: # TODO change _kubernetesInterface to an array once additional # interface for CSE is added. self._kubernetesInterface = \ schema_svc.get_interface(interface.get_id()) self._nativeEntityType = \ schema_svc.get_entity_type(entity_type.get_id()) msg = f"Successfully loaded defined entity schema " \ f"{entity_type.get_id()} to global context" msg_update_callback.general(msg) logger.SERVER_LOGGER.debug(msg) except cse_exception.DefNotSupportedException: msg = "Skipping initialization of defined entity type" \ " and defined entity interface" msg_update_callback.info(msg) logger.SERVER_LOGGER.debug(msg) except cse_exception.DefSchemaServiceError as e: msg = f"Error while loading defined entity schema: {e.error_message}" # noqa: E501 msg_update_callback.error(msg) logger.SERVER_LOGGER.debug(msg) raise except Exception as e: msg = f"Failed to load defined entity schema to global context: {str(e)}" # noqa: E501 msg_update_callback.error(msg) logger.SERVER_LOGGER.error(msg) raise finally: if sysadmin_client: sysadmin_client.logout()