Ejemplo n.º 1
0
    def send(self, msg, event_data=None):
        """
        @param msg: Message to send to the server
        @param event_data: additional fields for 'outgoing_message' event
        """
        event = {'event': 'outgoing_message',
                 'message': msg,
                 'target_server': self}

        if event_data:
            event.update(event_data)
        self.role.farm.event_mgr.notify(events.Event(**event))

        LOG.debug('Outgoing message %s to %s', msg.name, self.id)
        xml_data = msg.toxml()
        LOG.debug(' * data: %s', xml_data)
        crypto_key = binascii.a2b_base64(self.crypto_key)
        encrypted_data = crypto.encrypt(xml_data, crypto_key)
        signature, timestamp = crypto.sign(encrypted_data, crypto_key)

        url = 'http://{0}:8013/control'.format(self.public_ip)
        req = urllib2.Request(url, encrypted_data, {
            'Content-type': 'application/xml',
            'Date': timestamp,
            'X-Signature': signature,
            'X-Server-Id': self.id})
        opener = urllib2.build_opener(urllib2.HTTPRedirectHandler())
        opener.open(req)
Ejemplo n.º 2
0
    def on_message(self, msg):
        server_id = msg.meta['server_id']
        LOG.debug('Incoming message  "%s" from %s', msg.name, server_id)
        server = self.servers(sid=server_id)[0]

        self.event_mgr.notify(events.Event(event='incoming_message',
                                        message=msg, server=server))

        kwds = dict(trigger_message=msg, trigger_server=server)

        if msg.name == 'HostInit':
            server.status = 'initializing'
            server.public_ip = msg.body['remote_ip']
            server.private_ip = msg.body['local_ip']
            server.crypto_key = msg.body['crypto_key'].strip()
            time.sleep(1)  # It's important gap for Scalarizr

            server.send(Message('HostInitResponse'), event_data=kwds)

        if msg.name in ('HostInit', 'BeforeHostUp', 'HostUp'):
            if msg.name == 'HostUp':
                server.status = 'running'
            # Send copy of original message to every server in the farm
            msg_copy = msg.copy()
            msg_copy.scripts = []
            self.servers(status=lambda s: s not in ('pending', 'terminated')).send(msg_copy, event_data=kwds)

        elif msg.name == 'HostDown':
            pass
        elif msg.name == 'BeforeHostDown':
            pass
        elif msg.name in ('OperationDefinition', 'OperationProgress', 'OperationResult'):
            pass
Ejemplo n.º 3
0
 def set_status(self, new_status):
     old_status = self._status
     self._status = new_status
     self.role.farm.event_mgr.notify(events.Event(event='server_status_changed',
                                     old_status=old_status,
                                     new_status=new_status,
                                     server=self))
Ejemplo n.º 4
0
    def run(self, operation, fields, server):
        try:
            method_name = operation.replace('-', '_')
            self.LOG.debug('run %s', operation)
            response = etree.Element('response')
            if hasattr(self, method_name):
                response.append(getattr(self, method_name)(fields, server))

            self.habibi.event_mgr.notify(events.Event(event='queryenv', method_name=method_name,
                                         response=response, server=server))

            return etree.tostring(response)
        except:
            exc_info = sys.exc_info()
            LOG.error('Queryenv error', exc_info=exc_info)
            raise