コード例 #1
0
ファイル: agent.py プロジェクト: BillTheBest/openvstorage
                check_output('service openvpn start', shell=True)
            elif task == 'CLOSE_TUNNEL':
                check_output('service openvpn stop', shell=True)
                check_output('rm -f /etc/openvpn/ovs_*', shell=True)
            elif task == 'UPLOAD_LOGFILES':
                logfile = check_output('ovs collect logs', shell=True).strip()
                check_output('mv {0} /tmp/{1}; curl -T /tmp/{1} ftp://{2} --user {3}:{4}; rm -f {0} /tmp/{1}'.format(
                    logfile, metadata['filename'], metadata['endpoint'], metadata['user'], metadata['password']
                ), shell=True)
            else:
                raise RuntimeError('Unknown task')
        except Exception, ex:
            logger.exception('Unexpected error while processing task {0} (data: {1}): {2}'.format(task, json.dumps(metadata), ex))
            raise
        finally:
            logger.debug('Completed')

    def run(self):
        """
        Executes a call
        """
        logger.debug('Processing heartbeat')

        try:
            request = requests.post(self._url, data={'data': json.dumps(SupportAgent.get_heartbeat_data())})
            return_data = request.json()
        except Exception, ex:
            logger.exception('Unexpected error during support call: {0}'.format(ex))
            raise

        if self._enable_support:
コード例 #2
0
            for filename in os.listdir(path):
                if os.path.isfile(os.path.join(
                        path, filename)) and filename.endswith('.py'):
                    name = filename.replace('.py', '')
                    module = imp.load_source(name,
                                             os.path.join(path, filename))
                    for member in inspect.getmembers(module):
                        if inspect.isclass(member[1]) \
                                and member[1].__module__ == name \
                                and 'object' in [base.__name__ for base in member[1].__bases__]:
                            this_mapping = member[1].mapping
                            for key in this_mapping.keys():
                                if key not in mapping:
                                    mapping[key] = []
                                mapping[key] += this_mapping[key]
            logger.debug('Event map:')
            for key in mapping:
                logger.debug('{0}: {1}'.format(mapping[key][0]['property'], [
                    current_map['task'].__name__
                    for current_map in mapping[key]
                ]))

            # Starting connection and handling
            rmq_ini = ConfigObj(
                os.path.join(Configuration.get('ovs.core.cfgdir'),
                             'rabbitmqclient.cfg'))
            rmq_nodes = rmq_ini.get('main')['nodes'] if type(
                rmq_ini.get('main')['nodes']) == list else [
                    rmq_ini.get('main')['nodes']
                ]
            this_server = '{0}:{1}'.format(
コード例 #3
0
ファイル: sender.py プロジェクト: mflu/openvstorage_centos
# limitations under the License.

"""
This script can be used for testing purposes, adding data passed in as the only argument to the
body of a new entry on the queue.
"""

import sys
import pika

from ovs.log.logHandler import LogHandler

logger = LogHandler('extensions', name='sender')

if __name__ == '__main__':
    data = sys.argv[1] if len(sys.argv) >= 2 else '{}'
    queue = sys.argv[2] if len(sys.argv) >= 3 else 'default'

    connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
    channel = connection.channel()

    channel.queue_declare(queue=queue, durable=True)

    logger.debug('Sending to {0}: {1}'.format(queue, data))
    channel.basic_publish(exchange='',
                          routing_key=queue,
                          body=data,
                          properties=pika.BasicProperties(delivery_mode=2))
    channel.close()
    connection.close()
コード例 #4
0
ファイル: consumer.py プロジェクト: BillTheBest/openvstorage
            for filename in os.listdir(path):
                if os.path.isfile(os.path.join(path, filename)) and filename.endswith(".py"):
                    name = filename.replace(".py", "")
                    module = imp.load_source(name, os.path.join(path, filename))
                    for member in inspect.getmembers(module):
                        if (
                            inspect.isclass(member[1])
                            and member[1].__module__ == name
                            and "object" in [base.__name__ for base in member[1].__bases__]
                        ):
                            this_mapping = member[1].mapping
                            for key in this_mapping.keys():
                                if key not in mapping:
                                    mapping[key] = []
                                mapping[key] += this_mapping[key]
            logger.debug("Event map:")
            for key in mapping:
                logger.debug(
                    "{0}: {1}".format(key.name, [current_map["task"].__name__ for current_map in mapping[key]])
                )

            # Starting connection and handling
            rmq_ini = RawConfigParser()
            rmq_ini.read(os.path.join(Configuration.get("ovs.core.cfgdir"), "rabbitmqclient.cfg"))
            rmq_nodes = [node.strip() for node in rmq_ini.get("main", "nodes").split(",")]
            this_server = "{0}:{1}".format(Configuration.get("ovs.grid.ip"), Configuration.get("ovs.core.broker.port"))
            rmq_servers = [this_server] + [
                server for server in map(lambda n: rmq_ini.get(n, "location"), rmq_nodes) if server != this_server
            ]
            channel = None
            server = ""