def _makeHTTPService(self): """Create the HTTP service.""" from provisioningserver.rackdservices.http import HTTPResource from twisted.application.internet import StreamServerEndpointService from twisted.internet.endpoints import AdoptedStreamServerEndpoint from provisioningserver.utils.twisted import SiteNoLog port = 5249 s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) except socket_error as e: if e.errno != ENOPROTOOPT: raise e s.bind(('::', port)) # Use a backlog of 50, which seems to be fairly common. s.listen(50) # Adopt this socket into Twisted's reactor. site_endpoint = AdoptedStreamServerEndpoint(reactor, s.fileno(), s.family) site_endpoint.port = port # Make it easy to get the port number. site_endpoint.socket = s # Prevent garbage collection. http_service = StreamServerEndpointService(site_endpoint, SiteNoLog(HTTPResource())) http_service.setName("http_service") return http_service
def _makeHTTPService(self, port, path, prefix=None): from twisted.internet.endpoints import AdoptedStreamServerEndpoint from provisioningserver.http import ( create_reuse_socket, EndpointService, ) # Create the HTTP socket binded to the provided port. s = create_reuse_socket() s.bind(('::', port)) # Use a backlog of 50, which seems to be fairly common. s.listen(50) # Adopt this socket into Twisted's reactor. site_endpoint = AdoptedStreamServerEndpoint( reactor, s.fileno(), s.family) site_endpoint.port = port # Make it easy to get the port number. site_endpoint.socket = s # Prevent garbage collection. # Setup the endpoing with the resource path. service = EndpointService( resource_root=path, endpoint=site_endpoint, prefix=prefix) service.setName("http_endpoint") return service
def _makeImageService(self, resource_root): from provisioningserver.rackdservices.image import ( BootImageEndpointService) from twisted.internet.endpoints import AdoptedStreamServerEndpoint port = 5248 # config["port"] # Make a socket with SO_REUSEPORT set so that we can run multiple we # applications. This is easier to do from outside of Twisted as there's # not yet official support for setting socket options. s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) except socket_error as e: # Python's socket module was compiled using modern headers # thus defining SO_REUSEPORT would cause issues as it might # running in older kernel that does not support SO_REUSEPORT. # XXX andreserl 2015-04-08 bug=1441684: We need to add a warning # log message when we see this error, and a test for it. if e.errno != ENOPROTOOPT: raise e s.bind(('::', port)) # Use a backlog of 50, which seems to be fairly common. s.listen(50) # Adopt this socket into Twisted's reactor. site_endpoint = AdoptedStreamServerEndpoint(reactor, s.fileno(), s.family) site_endpoint.port = port # Make it easy to get the port number. site_endpoint.socket = s # Prevent garbage collection. image_service = BootImageEndpointService(resource_root=resource_root, endpoint=site_endpoint) image_service.setName("image_service") return image_service
def _makeEndpoint(self): """Make the endpoint for the webapp.""" # Make a socket with SO_REUSEPORT set so that we can run multiple web # applications. This is easier to do from outside of Twisted as there's # not yet official support for setting socket options. s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) # N.B, using the IPv6 INADDR_ANY means that getpeername() returns # something like: ('::ffff:192.168.133.32', 40588, 0, 0) s.bind(("::", self.port)) # Use a backlog of 50, which seems to be fairly common. s.listen(50) # Adopt this socket into Twisted's reactor setting the endpoint. endpoint = AdoptedStreamServerEndpoint(reactor, s.fileno(), s.family) endpoint.port = self.port # Make it easy to get the port number. endpoint.socket = s # Prevent garbage collection. return endpoint
def make_WebApplicationService(postgresListener, statusWorker): from maasserver.webapp import WebApplicationService site_port = DEFAULT_PORT # config["port"] # Make a socket with SO_REUSEPORT set so that we can run multiple web # applications. This is easier to do from outside of Twisted as there's # not yet official support for setting socket options. s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) # N.B, using the IPv6 INADDR_ANY means that getpeername() returns something # like: ('::ffff:192.168.133.32', 40588, 0, 0) s.bind(('::', site_port)) # Use a backlog of 50, which seems to be fairly common. s.listen(50) # Adopt this socket into Twisted's reactor. site_endpoint = AdoptedStreamServerEndpoint(reactor, s.fileno(), s.family) site_endpoint.port = site_port # Make it easy to get the port number. site_endpoint.socket = s # Prevent garbage collection. site_service = WebApplicationService(site_endpoint, postgresListener, statusWorker) return site_service