Ejemplo n.º 1
0
    def asset_exists(cls, key):
        """Check if asset with the key exists"""
        graph_ref = GraphReference()

        with graph_ref.get_session() as session:
            asset_info = GraphReference.get_asset_and_components(session, key)
            return asset_info is not None
Ejemplo n.º 2
0
    def _cpu_impact(self):
        """Keep updating *this sensor based on cpu load changes
        This function waits for the thermal event switch and exits when the connection between this sensor & cpu load
        is removed;
        """

        # avoid circular imports with the server
        from enginecore.state.api import IBMCServerStateManager

        with self._graph_ref.get_session() as session:

            asset_info = GraphReference.get_asset_and_components(
                session, self._server_key)
            server_sm = IBMCServerStateManager(asset_info)

            cpu_impact_degrees_1 = 0
            cpu_impact_degrees_2 = 0

            while True:
                self._s_thermal_event.wait()

                rel_details = GraphReference.get_cpu_thermal_rel(
                    session, self._server_key, self.name)

                # relationship was deleted
                if not rel_details:
                    return

                with self._s_file_locks.get_lock(self.name):

                    current_cpu_load = server_sm.cpu_load

                    # calculate cpu impact based on the model
                    cpu_impact_degrees_2 = self._calc_approx_value(
                        json.loads(rel_details["model"]), current_cpu_load)
                    new_calc_value = (int(self.sensor_value) +
                                      cpu_impact_degrees_2 -
                                      cpu_impact_degrees_1)

                    # meaning update is needed
                    if cpu_impact_degrees_1 != cpu_impact_degrees_2:
                        ambient = ISystemEnvironment.get_ambient()
                        self.sensor_value = (new_calc_value
                                             if new_calc_value > ambient else
                                             int(ambient))

                        logger.debug(
                            "Thermal impact of CPU load at (%s%%) updated: (%s°)->(%s°)",
                            current_cpu_load,
                            cpu_impact_degrees_1,
                            cpu_impact_degrees_2,
                        )

                    cpu_impact_degrees_1 = cpu_impact_degrees_2
                    time.sleep(5)
Ejemplo n.º 3
0
    def get_state_manager_by_key(cls, key, supported_assets=None):
        """Infer asset manager from key"""
        from enginecore.state.hardware.room import Asset

        if not supported_assets:
            supported_assets = Asset.get_supported_assets()

        graph_ref = GraphReference()

        with graph_ref.get_session() as session:
            asset_info = GraphReference.get_asset_and_components(session, key)

        sm_mro = supported_assets[asset_info["type"]].StateManagerCls.mro()

        module = ".".join(__name__.split(".")[:-1])  # api module
        return next(filter(lambda x: x.__module__.startswith(module),
                           sm_mro))(asset_info)