示例#1
0
    def __init__(
            self,
            cmc_names,
            message_bus,  # pylint: disable=r0913
            sidecar_url,
            cycle,
            verbose=False):
        self.cycle = cycle
        self.verbose = verbose

        # get miscell config
        self.ping_timeout = float(Config().value('networking', 'ping_timeout'))
        self.ssh_timeout = float(Config().value('networking', 'ssh_timeout'))
        self.log_period = float(Config().value('monitor', 'log_period'))

        # websockets
        self.reconnectable = \
            ReconnectableSidecar(sidecar_url, 'nodes')

        # the nodes part
        nodes = [Node(cmc_name, message_bus) for cmc_name in cmc_names]
        self.monitor_nodes = [
            MonitorNode(node=node,
                        reconnectable=self.reconnectable,
                        verbose=verbose) for node in nodes
        ]
示例#2
0
class MonitorLeases:  # pylint: disable=r0902
    def __init__(
            self,
            message_bus,
            sidecar_url,  # pylint: disable=r0913
            verbose=False):
        self.message_bus = message_bus
        self.sidecar_url = sidecar_url
        self.verbose = verbose

        # websockets
        self.reconnectable = \
            ReconnectableSidecar(sidecar_url, 'leases')

        self.cycle = float(Config().value('monitor', 'cycle_leases'))
        self.step = float(Config().value('monitor', 'step_leases'))

    def on_back_channel(self, umbrella):
        # when anything is received on the backchannel, we go to fast track
        logger.info(f"MonitorLeases.on_back_channel, umbrella={umbrella}")
        self.fast_track = True  # pylint: disable=w0201

    async def mainloop(self):
        leases = Leases(self.message_bus)
        if self.verbose:
            logger.info("Entering monitor on leases")
        while True:
            self.fast_track = False  # pylint: disable=w0201
            trigger = time.time() + self.cycle
            # check for back_channel every 50 ms
            while not self.fast_track and time.time() < trigger:
                await asyncio.sleep(self.step)

            try:
                if self.verbose:
                    logger.info("monitorleases mainloop")
                await leases.refresh()
                # xxx this is fragile
                omf_leases = leases.resources
                logger.info("advertising {} leases".format(len(omf_leases)))
                await self.reconnectable.emit_infos(omf_leases)
                if self.verbose:
                    logger.info("Leases details: {}".format(omf_leases))
            except Exception:
                logger.exception("monitornodes could not get leases")

    async def run_forever(self):
        def closure(umbrella):
            return self.on_back_channel(umbrella)

        await asyncio.gather(
            self.mainloop(), self.reconnectable.keep_connected(),
            self.reconnectable.watch_back_channel('leases', closure))
示例#3
0
    def __init__(self, verbose, sidecar_url, cycle):
        self.verbose = verbose

        phone_specs = InventoryPhones().all_phones()

        self.reconnectable = ReconnectableSidecar(sidecar_url, 'phones')
        # xxx this is fragile
        # we rely on the fact that the items in the inventory
        # match the args of MonitorPhone's constructor
        self.phones = [
            MonitorPhone(reconnectable=self.reconnectable,
                         verbose=verbose,
                         cycle=cycle,
                         **spec) for spec in phone_specs
        ]
示例#4
0
    def __init__(
            self,
            message_bus,
            sidecar_url,  # pylint: disable=r0913
            verbose=False):
        self.message_bus = message_bus
        self.sidecar_url = sidecar_url
        self.verbose = verbose

        # websockets
        self.reconnectable = \
            ReconnectableSidecar(sidecar_url, 'leases')

        self.cycle = float(Config().value('monitor', 'cycle_leases'))
        self.step = float(Config().value('monitor', 'step_leases'))
示例#5
0
class MonitorNodes:  # pylint: disable=r0902
    def __init__(
            self,
            cmc_names,
            message_bus,  # pylint: disable=r0913
            sidecar_url,
            cycle,
            verbose=False):
        self.cycle = cycle
        self.verbose = verbose

        # get miscell config
        self.ping_timeout = float(Config().value('networking', 'ping_timeout'))
        self.ssh_timeout = float(Config().value('networking', 'ssh_timeout'))
        self.log_period = float(Config().value('monitor', 'log_period'))

        # websockets
        self.reconnectable = \
            ReconnectableSidecar(sidecar_url, 'nodes')

        # the nodes part
        nodes = [Node(cmc_name, message_bus) for cmc_name in cmc_names]
        self.monitor_nodes = [
            MonitorNode(node=node,
                        reconnectable=self.reconnectable,
                        verbose=verbose) for node in nodes
        ]

    async def log(self):
        previous = 0
        while True:
            line = "".join(
                [one_char_summary(mnode.info) for mnode in self.monitor_nodes])
            current = self.reconnectable.counter
            delta = f"+ {current-previous}"
            line += f" {current} emits ({delta})"
            previous = current
            logger.info(line)
            await asyncio.sleep(self.log_period)

    async def run_forever(self):
        logger.info(f"Starting nodes on {len(self.monitor_nodes)} nodes")
        return asyncio.gather(
            *[
                monitor_node.probe_forever(self.cycle,
                                           ping_timeout=self.ping_timeout,
                                           ssh_timeout=self.ssh_timeout)
                for monitor_node in self.monitor_nodes
            ],
            self.reconnectable.keep_connected(),
            self.log(),
        )
示例#6
0
class MonitorPhones:  # pylint:disable=r0903
    def __init__(self, verbose, sidecar_url, cycle):
        self.verbose = verbose

        phone_specs = InventoryPhones().all_phones()

        self.reconnectable = ReconnectableSidecar(sidecar_url, 'phones')
        # xxx this is fragile
        # we rely on the fact that the items in the inventory
        # match the args of MonitorPhone's constructor
        self.phones = [
            MonitorPhone(reconnectable=self.reconnectable,
                         verbose=verbose,
                         cycle=cycle,
                         **spec) for spec in phone_specs
        ]

    async def run_forever(self):
        await asyncio.gather(*[phone.probe_forever() for phone in self.phones],
                             self.reconnectable.keep_connected())