Exemple #1
0
    def register_engine_listeners(self):
        self.tokens = {}

        class TopicProxy():
            @staticmethod
            def authorize_vnc_console(context, **kwargs):
                print "Received a token: %s" % kwargs
                self.tokens[kwargs['token']] =  \
                    {'args': kwargs, 'last_activity': time.time()}

        self.conn = rpc.create_connection(new=True)
        self.conn.create_consumer(
                'vncproxy',
                TopicProxy)

        def delete_expired_tokens():
            now = time.time()
            to_delete = []
            for k, v in self.tokens.items():
                if now - v['last_activity'] > FLAGS.vnc_proxy_idle_timeout:
                    to_delete.append(k)

            for k in to_delete:
                del self.tokens[k]

        self.conn.consume_in_thread()
        utils.LoopingCall(delete_expired_tokens).start(1)
Exemple #2
0
    def register_engine_listeners(self):
        self.tokens = {}

        class TopicProxy():
            @staticmethod
            def authorize_vnc_console(context, **kwargs):
                print "Received a token: %s" % kwargs
                self.tokens[kwargs['token']] =  \
                    {'args': kwargs, 'last_activity': time.time()}

        self.conn = rpc.create_connection(new=True)
        self.conn.create_consumer('vncproxy', TopicProxy)

        def delete_expired_tokens():
            now = time.time()
            to_delete = []
            for k, v in self.tokens.items():
                if now - v['last_activity'] > FLAGS.vnc_proxy_idle_timeout:
                    to_delete.append(k)

            for k in to_delete:
                del self.tokens[k]

        self.conn.consume_in_thread()
        utils.LoopingCall(delete_expired_tokens).start(1)
Exemple #3
0
    def test_rpc_consumer_isolation(self):
        class NeverCalled(object):

            def __getattribute__(*args):
                assert False, "I should never get called."

        connection = rpc.create_connection(new=True)
        proxy = NeverCalled()
        connection.create_consumer('compute', proxy, fanout=False)
        connection.consume_in_thread()
    def start(self):
        vcs_string = version.version_string_with_vcs()
        logging.audit(_('Starting %(topic)s node (version %(vcs_string)s)'),
                      {'topic': self.topic, 'vcs_string': vcs_string})
        self.manager.init_host()
        self.model_disconnected = False
        ctxt = context.get_admin_context()
        try:
            service_ref = db.service_get_by_args(ctxt,
                                                 self.host,
                                                 self.binary)
            self.service_id = service_ref['id']
        except exception.NotFound:
            self._create_service_ref(ctxt)

        if 'engine-compute' == self.binary:
            self.manager.update_available_resource(ctxt)

        self.conn = rpc.create_connection(new=True)
        logging.debug("Creating Consumer connection for Service %s" %
                      self.topic)

        # Share this same connection for these Consumers
        self.conn.create_consumer(self.topic, self, fanout=False)

        node_topic = '%s.%s' % (self.topic, self.host)
        self.conn.create_consumer(node_topic, self, fanout=False)

        self.conn.create_consumer(self.topic, self, fanout=True)

        # Consume from all consumers in a thread
        self.conn.consume_in_thread()

        if self.report_interval:
            pulse = utils.LoopingCall(self.report_state)
            pulse.start(interval=self.report_interval, now=False)
            self.timers.append(pulse)

        if self.periodic_interval:
            periodic = utils.LoopingCall(self.periodic_tasks)
            periodic.start(interval=self.periodic_interval, now=False)
            self.timers.append(periodic)