예제 #1
0
def cleanup_rde_artifacts(logger=NULL_LOGGER):
    """Cleanup all defined entity related artifacts.

    Deletes the following -
    - CSE interface
    - Native entity type
    """
    try:
        rde_version_in_use = rde_utils.get_runtime_rde_version_by_vcd_api_version(
            CLIENT.get_api_version())  # noqa: E501
        rde_metadata = rde_utils.get_rde_metadata(rde_version_in_use)
        cloudapi_client = pyvcloud_utils.get_cloudapi_client_from_vcd_client(
            client=CLIENT,
            logger_debug=logger,
            logger_wire=SERVER_CLOUDAPI_WIRE_LOGGER)
        schema_svc = def_schema_svc.DefSchemaService(
            cloudapi_client=cloudapi_client)  # noqa: E501
        if rde_constants.RDEMetadataKey.ENTITY_TYPE in rde_metadata:
            # delete entity_type
            entity_type: common_models.DefEntityType = \
                rde_metadata[rde_constants.RDEMetadataKey.ENTITY_TYPE]
            schema_svc.delete_entity_type(entity_type.get_id())
            logger.debug(f"Deleted entity type: {entity_type.name}")
        if rde_constants.RDEMetadataKey.INTERFACES in rde_metadata:
            # delete interface
            interfaces: List[common_models.DefInterface] = \
                rde_metadata[rde_constants.RDEMetadataKey.INTERFACES]
            for i in interfaces:
                interface_id = i.get_id()
                if interface_id != common_models.K8Interface.VCD_INTERFACE.value.get_id(
                ):  # noqa: E501
                    schema_svc.delete_interface(interface_id)
                    logger.debug(f"Deleted interface: {i.name}")
    except Exception as e:
        logger.warning(f"Failed to clean up RDE artifacts: {e}")
 def __init__(self, client):
     logger_wire = logger.NULL_LOGGER
     if os.getenv(cli_constants.ENV_CSE_CLIENT_WIRE_LOGGING):
         logger_wire = logger.CLIENT_WIRE_LOGGER
     self._cloudapi_client = \
         vcd_utils.get_cloudapi_client_from_vcd_client(
             client=client, logger_debug=logger.CLIENT_LOGGER,
             logger_wire=logger_wire)
     self._native_cluster_api = NativeClusterApi(client)
     self._client = client
     schema_service = def_schema_svc.DefSchemaService(self._cloudapi_client)
     self._server_rde_version = \
         schema_service.get_latest_registered_schema_version()
예제 #3
0
 def __init__(self, client):
     logger_wire = logger.CLIENT_WIRE_LOGGER \
         if core_utils.str_to_bool(
             os.getenv(cli_constants.ENV_CSE_CLIENT_WIRE_LOGGING)
         ) \
         else logger.NULL_LOGGER
     self._client = client
     self._cloudapi_client = \
         vcd_utils.get_cloudapi_client_from_vcd_client(
             client=client,
             logger_debug=logger.CLIENT_LOGGER,
             logger_wire=logger_wire
         )
     self._nativeCluster = DEClusterNative(client)
     self._tkgCluster = DEClusterTKGS(client)
     schema_svc = def_schema_svc.DefSchemaService(self._cloudapi_client)
     self._server_rde_version = \
         schema_svc.get_latest_registered_schema_version()
예제 #4
0
    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()