Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

HTTP Port + working Python3 #147

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pypxe/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def __init__(self, **server_settings):
import_safe[packed_mac] = imported[lease]
self.leases.update(import_safe)
self.logger.info('Loaded leases from {0}'.format(self.save_leases_file))
except IOError, ValueError:
except IOError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for splitting these up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically I should have made those proper functions but this gets by the Python3 test for exception changes.

pass
except ValueError:
pass

signal.signal(signal.SIGINT, self.export_leases)
Expand Down
23 changes: 16 additions & 7 deletions pypxe/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import threading
import os
import io
import sys
import json
import logging
Expand Down Expand Up @@ -48,6 +49,7 @@
'NBD_COPY_TO_RAM':False,
'NBD_SERVER_IP':'0.0.0.0',
'NBD_PORT':10809,
'HTTP_PORT':80,
'MODE_DEBUG':'',
'MODE_VERBOSE':''}

Expand Down Expand Up @@ -113,6 +115,9 @@ def parse_cli_arguments():
tftp_group = parser.add_argument_group(title = 'TFTP', description = 'Arguments relevant to the TFTP server')
tftp_group.add_argument('--tftp-server-ip', action = 'store', dest = 'TFTP_SERVER_IP', help = 'TFTP Server IP', default = SETTINGS['TFTP_SERVER_IP'])

# HTTP server arguments
http_group = parser.add_argument_group(title = 'HTTP', description = 'Arguments relevant to the HTTP server')
http_group.add_argument('--http-port', action = 'store', dest = 'HTTP_PORT', help = 'HTTP Server Port', default = SETTINGS['HTTP_PORT'])

return parser.parse_args()

Expand Down Expand Up @@ -141,12 +146,12 @@ def main():
del settings['DUMP_CONFIG']
del settings['DUMP_CONFIG_MERGED']
del settings['JSON_CONFIG']
print json.dumps(settings, sort_keys=True, indent=4)
print(json.dumps(settings, sort_keys=True, indent=4))
sys.exit()

if args.JSON_CONFIG: # load from configuration file if specified
try:
config_file = open(args.JSON_CONFIG, 'rb')
config_file = io.open(args.JSON_CONFIG, 'r')
except IOError:
sys.exit('Failed to open {0}'.format(args.JSON_CONFIG))
try:
Expand All @@ -161,15 +166,14 @@ def main():
args = parse_cli_arguments() # re-parse, CLI options take precedence

# warn the user that they are starting PyPXE as non-root user
if os.getuid() != 0:
print >> sys.stderr, '\nWARNING: Not root. Servers will probably fail to bind.\n'

if os.geteuid() != 0:
print("You need to have root privileges to run this script.\n Servers will probably fail to bind")

# ideally this would be in dhcp itself, but the chroot below *probably*
# breaks the ability to open the config file.
if args.STATIC_CONFIG:
try:
static_config = open(args.STATIC_CONFIG, 'rb')
static_config = io.open(args.STATIC_CONFIG, 'r')
except IOError:
sys.exit("Failed to open {0}".format(args.STATIC_CONFIG))
try:
Expand Down Expand Up @@ -285,7 +289,12 @@ def main():
sys_logger.info('Starting HTTP server...')

# setup the thread
http_server = http.HTTPD(mode_debug = do_debug('http'), mode_verbose = do_debug('http'), logger = http_logger, netboot_directory = args.NETBOOT_DIR)
http_server = http.HTTPD(
mode_debug = do_debug('http'),
mode_verbose = do_debug('http'),
logger = http_logger,
port = args.HTTP_PORT,
netboot_directory = args.NETBOOT_DIR)
httpd = threading.Thread(target = http_server.listen)
httpd.daemon = True
httpd.start()
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
deps = []

# Python 3 unsupported
if version_info >= (3,):
print "Sorry, PyPXE doesn't support Python 3."
exit(1)

# require argparse on Python <2.7
if version_info[0] == 2 and version_info[1] < 7:
Expand Down