class CloudstackEventReader(object):
    def __init__(self, region):
        self.region = region
        self.acs = CloudstackClientFactory.get_instance(region)
        host = os.getenv(region.upper() + '_EVENT_QUEUE_HOST')
        port = int(os.getenv(region.upper() + '_EVENT_QUEUE_PORT', 5672))
        username = os.getenv(region.upper() + '_EVENT_QUEUE_USER')
        password = os.getenv(region.upper() + '_EVENT_QUEUE_PASSWORD')
        self.rabbit_client = RabbitMQClient(host, port, username, password)

    def read_events(self):
        self.log("Event processing started")
        self.rabbit_client.start_consuming(self._save_event)
        self.log("Event processing ended")

    def _save_event(self, event_json_string):
        try:
            event_data = json.loads(event_json_string)
            if event_data['status'] == 'Completed':
                self.log("Saving event %s" % event_json_string, 'debug')

                if self._verify_eventdata(event_data):
                    event = self._create_event(event_data, event_json_string)
                    db.session.add(event)
                    db.session.commit()
        except Exception, e:
            self.log("Error when trying to save event: %s" % event_json_string,
                     'error')
            raise e
Esempio n. 2
0
class CloudstackEventReader(object):

    def __init__(self, region):
        self.region = region
        self.acs = CloudstackClientFactory.get_instance(region)
        host = os.getenv(region.upper() + '_EVENT_QUEUE_HOST')
        port = int(os.getenv(region.upper() + '_EVENT_QUEUE_PORT', 5672))
        username = os.getenv(region.upper() + '_EVENT_QUEUE_USER')
        password = os.getenv(region.upper() + '_EVENT_QUEUE_PASSWORD')
        self.rabbit_client = RabbitMQClient(host, port, username, password)

    def read_events(self):
        self.log("Event processing started")
        self.rabbit_client.start_consuming(self._save_event)
        self.log("Event processing ended")

    def _save_event(self, event_json_string):
        try:
            event_data = json.loads(event_json_string)
            if event_data['status'] == 'Completed':
                self.log("Saving event %s" % event_json_string, 'debug')

                event = self._create_event(event_data, event_json_string)
                db.session.add(event)
                db.session.commit()
        except Exception, e:
            self.log("Error when trying to save event: %s" % event_json_string,  'error')
            raise e
 def __init__(self, region):
     self.region = region
     self.acs = CloudstackClientFactory.get_instance(region)
     host = os.getenv(region.upper() + '_EVENT_QUEUE_HOST')
     port = int(os.getenv(region.upper() + '_EVENT_QUEUE_PORT', 5672))
     username = os.getenv(region.upper() + '_EVENT_QUEUE_USER')
     password = os.getenv(region.upper() + '_EVENT_QUEUE_PASSWORD')
     self.rabbit_client = RabbitMQClient(host, port, username, password)
Esempio n. 4
0
 def __init__(self, region):
     self.region = region
     self.acs = CloudstackClientFactory.get_instance(region)
     host = os.getenv(region.upper() + '_EVENT_QUEUE_HOST')
     port = int(os.getenv(region.upper() + '_EVENT_QUEUE_PORT', 5672))
     username = os.getenv(region.upper() + '_EVENT_QUEUE_USER')
     password = os.getenv(region.upper() + '_EVENT_QUEUE_PASSWORD')
     self.rabbit_client = RabbitMQClient(host, port, username, password)