def port_manager(): """An instance of port manager""" PortManager._instance = None p = PortManager.instance() p.console_host = "127.0.0.1" return p
def allocate_udp_port(request, response): pm = ProjectManager.instance() project = pm.get_project(request.match_info["project_id"]) m = PortManager.instance() udp_port = m.get_free_udp_port(project) response.set_status(201) response.json({"udp_port": udp_port})
def _getDebugData(): try: addrs = [ "* {}: {}".format(key, val) for key, val in psutil.net_if_addrs().items() ] except UnicodeDecodeError: addrs = ["INVALID ADDR WITH UNICODE CHARACTERS"] data = """Version: {version} OS: {os} Python: {python} CPU: {cpu} Memory: {memory} Networks: {addrs} """.format(version=__version__, os=platform.platform(), python=platform.python_version(), memory=psutil.virtual_memory(), cpu=psutil.cpu_times(), addrs="\n".join(addrs)) try: connections = psutil.net_connections() # You need to be root for OSX except psutil.AccessDenied: connections = None if connections: data += "\n\nConnections:\n" for port in PortManager.instance().tcp_ports: found = False for open_port in connections: if open_port.laddr[1] == port: found = True data += "TCP {}: {}\n".format(port, found) for port in PortManager.instance().udp_ports: found = False for open_port in connections: if open_port.laddr[1] == port: found = True data += "UDP {}: {}\n".format(port, found) return data
def _getDebugData(): try: addrs = ["* {}: {}".format(key, val) for key, val in psutil.net_if_addrs().items()] except UnicodeDecodeError: addrs = ["INVALID ADDR WITH UNICODE CHARACTERS"] data = """Version: {version} OS: {os} Python: {python} CPU: {cpu} Memory: {memory} Networks: {addrs} """.format( version=__version__, os=platform.platform(), python=platform.python_version(), memory=psutil.virtual_memory(), cpu=psutil.cpu_times(), addrs="\n".join(addrs) ) try: connections = psutil.net_connections() # You need to be root for OSX except psutil.AccessDenied: connections = None if connections: data += "\n\nConnections:\n" for port in PortManager.instance().tcp_ports: found = False for open_port in connections: if open_port.laddr[1] == port: found = True data += "TCP {}: {}\n".format(port, found) for port in PortManager.instance().udp_ports: found = False for open_port in connections: if open_port.laddr[1] == port: found = True data += "UDP {}: {}\n".format(port, found) return data
def compute(request, response): response.template("compute.html", port_manager=PortManager.instance(), project_manager=ProjectManager.instance())
def network_ports(request, response): m = PortManager.instance() response.json(m)