Exemplo n.º 1
0
    def run(self):
        if self.setup['daemon']:
            self._daemonize()

        hostname, port = urlparse(self.setup['location'])[1].split(':')
        server_address = socket.getaddrinfo(hostname,
                                            port,
                                            socket.AF_UNSPEC,
                                            socket.SOCK_STREAM)[0][4]
        try:
            server = XMLRPCServer(self.setup['listen_all'],
                                  server_address,
                                  keyfile=self.setup['key'],
                                  certfile=self.setup['cert'],
                                  register=False,
                                  timeout=1,
                                  ca=self.setup['ca'],
                                  protocol=self.setup['protocol'])
        except:
            err = sys.exc_info()[1]
            self.logger.error("Server startup failed: %s" % err)
            os._exit(1)
        server.register_instance(self)

        try:
            server.serve_forever()
        finally:
            server.server_close()
        self.shutdown()
Exemplo n.º 2
0
Arquivo: Proxy.py Projeto: rcuza/bcfg2
def ComponentProxy(url,
                   user=None,
                   password=None,
                   key=None,
                   cert=None,
                   ca=None,
                   allowedServerCNs=None,
                   timeout=90,
                   retries=3,
                   delay=1):
    """Constructs proxies to components.

    Arguments:
    component_name -- name of the component to connect to

    Additional arguments are passed to the ServerProxy constructor.

    """
    xmlrpclib._Method.max_retries = retries
    xmlrpclib._Method.retry_delay = delay

    if user and password:
        method, path = urlparse(url)[:2]
        newurl = "%s://%s:%s@%s" % (method, quote_plus(
            user, ''), quote_plus(password, ''), path)
    else:
        newurl = url
    ssl_trans = XMLRPCTransport(key,
                                cert,
                                ca,
                                allowedServerCNs,
                                timeout=float(timeout))
    return xmlrpclib.ServerProxy(newurl, allow_none=True, transport=ssl_trans)
Exemplo n.º 3
0
    def run(self):
        hostname, port = urlparse(self.setup['location'])[1].split(':')
        if self.setup['listen_all']:
            hostname = '0.0.0.0'

        config = {'engine.autoreload.on': False,
                  'server.socket_port': int(port)}
        if self.setup['cert'] and self.setup['key']:
            config.update({'server.ssl_module': 'pyopenssl',
                           'server.ssl_certificate': self.setup['cert'],
                           'server.ssl_private_key': self.setup['key']})
        if self.setup['debug']:
            config['log.screen'] = True
        cherrypy.config.update(config)
        cherrypy.quickstart(self, config={'/': self.setup})
Exemplo n.º 4
0
 def _run(self):
     """ Create :attr:`server` to start the server listening. """
     hostname, port = urlparse(Bcfg2.Options.setup.server)[1].split(':')
     server_address = socket.getaddrinfo(hostname, port, socket.AF_UNSPEC,
                                         socket.SOCK_STREAM)[0][4]
     try:
         self.server = XMLRPCServer(Bcfg2.Options.setup.listen_all,
                                    server_address,
                                    keyfile=Bcfg2.Options.setup.key,
                                    certfile=Bcfg2.Options.setup.cert,
                                    register=False,
                                    ca=Bcfg2.Options.setup.ca)
     except:  # pylint: disable=W0702
         err = sys.exc_info()[1]
         self.logger.error("Server startup failed: %s" % err)
         self.context.close()
         return False
     return True
Exemplo n.º 5
0
    def _run(self):
        """ Start the server listening. """
        hostname, port = urlparse(self.setup['location'])[1].split(':')
        if self.setup['listen_all']:
            hostname = '0.0.0.0'

        config = {'engine.autoreload.on': False,
                  'server.socket_port': int(port),
                  'server.socket_host': hostname}
        if self.setup['cert'] and self.setup['key']:
            config.update({'server.ssl_module': 'pyopenssl',
                           'server.ssl_certificate': self.setup['cert'],
                           'server.ssl_private_key': self.setup['key']})
        if self.setup['debug']:
            config['log.screen'] = True
        cherrypy.config.update(config)
        cherrypy.tree.mount(self, '/', {'/': self.setup})
        cherrypy.engine.start()
        return True
Exemplo n.º 6
0
    def _run(self):
        """ Start the server listening. """
        hostname, port = urlparse(Bcfg2.Options.setup.server)[1].split(':')
        if Bcfg2.Options.setup.listen_all:
            hostname = '0.0.0.0'

        config = {'engine.autoreload.on': False,
                  'server.socket_port': int(port),
                  'server.socket_host': hostname}
        if Bcfg2.Options.setup.cert and Bcfg2.Options.setup.key:
            config.update({'server.ssl_module': 'pyopenssl',
                           'server.ssl_certificate': Bcfg2.Options.setup.cert,
                           'server.ssl_private_key': Bcfg2.Options.setup.key})
        if Bcfg2.Options.setup.debug:
            config['log.screen'] = True
        cherrypy.config.update(config)
        cherrypy.tree.mount(self, '/', {'/': Bcfg2.Options.setup})
        cherrypy.engine.start()
        return True
Exemplo n.º 7
0
    def __init__(self):
        RetryMethod.max_retries = Bcfg2.Options.setup.retries
        RetryMethod.retry_delay = Bcfg2.Options.setup.retry_delay

        if Bcfg2.Options.setup.user and Bcfg2.Options.setup.password:
            method, path = urlparse(Bcfg2.Options.setup.server)[:2]
            url = "%s://%s:%s@%s" % (
                method, quote_plus(Bcfg2.Options.setup.user, ''),
                quote_plus(Bcfg2.Options.setup.password, ''), path)
        else:
            url = Bcfg2.Options.setup.server
        ssl_trans = XMLRPCTransport(Bcfg2.Options.setup.key,
                                    Bcfg2.Options.setup.cert,
                                    Bcfg2.Options.setup.ca,
                                    Bcfg2.Options.setup.ssl_cns,
                                    Bcfg2.Options.setup.client_timeout)
        xmlrpclib.ServerProxy.__init__(self,
                                       url,
                                       allow_none=True,
                                       transport=ssl_trans)
Exemplo n.º 8
0
 def _run(self):
     """ Create :attr:`server` to start the server listening. """
     hostname, port = urlparse(self.setup['location'])[1].split(':')
     server_address = socket.getaddrinfo(hostname, port, socket.AF_UNSPEC,
                                         socket.SOCK_STREAM)[0][4]
     try:
         self.server = XMLRPCServer(self.setup['listen_all'],
                                    server_address,
                                    keyfile=self.setup['key'],
                                    certfile=self.setup['cert'],
                                    register=False,
                                    timeout=1,
                                    ca=self.setup['ca'],
                                    protocol=self.setup['protocol'])
     except:  # pylint: disable=W0702
         err = sys.exc_info()[1]
         self.logger.error("Server startup failed: %s" % err)
         self.context.close()
         return False
     return True
Exemplo n.º 9
0
 def _run(self):
     """ Create :attr:`server` to start the server listening. """
     hostname, port = urlparse(Bcfg2.Options.setup.server)[1].split(':')
     server_address = socket.getaddrinfo(hostname,
                                         port,
                                         socket.AF_UNSPEC,
                                         socket.SOCK_STREAM)[0][4]
     try:
         self.server = XMLRPCServer(Bcfg2.Options.setup.listen_all,
                                    server_address,
                                    keyfile=Bcfg2.Options.setup.key,
                                    certfile=Bcfg2.Options.setup.cert,
                                    register=False,
                                    ca=Bcfg2.Options.setup.ca)
     except:  # pylint: disable=W0702
         err = sys.exc_info()[1]
         self.logger.error("Server startup failed: %s" % err)
         self.context.close()
         return False
     return True
Exemplo n.º 10
0
    def __init__(self):
        RetryMethod.max_retries = Bcfg2.Options.setup.retries
        RetryMethod.retry_delay = Bcfg2.Options.setup.retry_delay

        if Bcfg2.Options.setup.user and Bcfg2.Options.setup.password:
            method, path = urlparse(Bcfg2.Options.setup.server)[:2]
            url = "%s://%s:%s@%s" % (
                method,
                quote_plus(Bcfg2.Options.setup.user, ''),
                quote_plus(Bcfg2.Options.setup.password, ''),
                path)
        else:
            url = Bcfg2.Options.setup.server
        ssl_trans = XMLRPCTransport(Bcfg2.Options.setup.key,
                                    Bcfg2.Options.setup.cert,
                                    Bcfg2.Options.setup.ca,
                                    Bcfg2.Options.setup.ssl_cns,
                                    Bcfg2.Options.setup.client_timeout)
        xmlrpclib.ServerProxy.__init__(self, url,
                                       allow_none=True, transport=ssl_trans)
Exemplo n.º 11
0
 def _run(self):
     hostname, port = urlparse(self.setup['location'])[1].split(':')
     server_address = socket.getaddrinfo(hostname,
                                         port,
                                         socket.AF_UNSPEC,
                                         socket.SOCK_STREAM)[0][4]
     try:
         self.server = XMLRPCServer(self.setup['listen_all'],
                                    server_address,
                                    keyfile=self.setup['key'],
                                    certfile=self.setup['cert'],
                                    register=False,
                                    timeout=1,
                                    ca=self.setup['ca'],
                                    protocol=self.setup['protocol'])
     except:  # pylint: disable=W0702
         err = sys.exc_info()[1]
         self.logger.error("Server startup failed: %s" % err)
         self.context.close()
         return False
     self.server.register_instance(self)
     return True
Exemplo n.º 12
0
def ComponentProxy(url, user=None, password=None, key=None, cert=None, ca=None,
                   allowedServerCNs=None, timeout=90, retries=3, delay=1):

    """Constructs proxies to components.

    Arguments:
    component_name -- name of the component to connect to

    Additional arguments are passed to the ServerProxy constructor.

    """
    xmlrpclib._Method.max_retries = retries
    xmlrpclib._Method.retry_delay = delay

    if user and password:
        method, path = urlparse(url)[:2]
        newurl = "%s://%s:%s@%s" % (method, user, password, path)
    else:
        newurl = url
    ssl_trans = XMLRPCTransport(key, cert, ca,
                                allowedServerCNs, timeout=float(timeout))
    return xmlrpclib.ServerProxy(newurl, allow_none=True, transport=ssl_trans)
Exemplo n.º 13
0
    def _run(self):
        hostname, port = urlparse(self.setup['location'])[1].split(':')
        if self.setup['listen_all']:
            hostname = '0.0.0.0'

        config = {
            'engine.autoreload.on': False,
            'server.socket_port': int(port),
            'server.socket_host': hostname
        }
        if self.setup['cert'] and self.setup['key']:
            config.update({
                'server.ssl_module': 'pyopenssl',
                'server.ssl_certificate': self.setup['cert'],
                'server.ssl_private_key': self.setup['key']
            })
        if self.setup['debug']:
            config['log.screen'] = True
        cherrypy.config.update(config)
        cherrypy.tree.mount(self, '/', {'/': self.setup})
        cherrypy.engine.start()
        return True
Exemplo n.º 14
0
    def _run(self):
        """ Start the server listening. """
        hostname, port = urlparse(Bcfg2.Options.setup.server)[1].split(':')
        if Bcfg2.Options.setup.listen_all:
            hostname = '0.0.0.0'

        config = {
            'engine.autoreload.on': False,
            'server.socket_port': int(port),
            'server.socket_host': hostname
        }
        if Bcfg2.Options.setup.cert and Bcfg2.Options.setup.key:
            config.update({
                'server.ssl_module': 'pyopenssl',
                'server.ssl_certificate': Bcfg2.Options.setup.cert,
                'server.ssl_private_key': Bcfg2.Options.setup.key
            })
        if Bcfg2.Options.setup.debug:
            config['log.screen'] = True
        cherrypy.config.update(config)
        cherrypy.tree.mount(self, '/', {'/': Bcfg2.Options.setup})
        cherrypy.engine.start()
        return True