def process(self, ctxt, publisher_id, event_type, payload, metadata): LOG.debug("Received nova event %s for server %s", event_type, payload.get('instance_id', '<unknown>')) try: actions = { # compute.instance.update seems to be the event set as a # result of a state change etc 'compute.instance.update': self.create_or_update, 'compute.instance.exists': self.create_or_update, 'compute.instance.create.end': self.create_or_update, 'compute.instance.power_on.end': self.create_or_update, 'compute.instance.power_off.end': self.create_or_update, 'compute.instance.delete.end': self.delete, # Neutron events 'port.create.end': self.update_from_neutron, # TODO(sjmc7) Remind myself why i commented this out, # and also whether neutron events should be separate # 'port.delete.end': self.update_neutron_ports, } #import pdb #pdb.set_trace() result = actions[event_type](payload) send_notification(result) return oslo_messaging.NotificationResult.HANDLED except Exception as e: LOG.error(encodeutils.exception_to_unicode(e))
def delete(self, payload): id = payload['id'] self.engine.delete( index=self.index_name, doc_type=self.document_type, id=id ) send_notification(payload)
def create_or_update(self, payload): id = payload['id'] payload = self.serialize_notification(payload) self.engine.index( index=self.index_name, doc_type=self.document_type, body=payload, id=id ) send_notification(payload)