From 2cd57935fb39398e28281b9e8a6714453d430376 Mon Sep 17 00:00:00 2001 From: Steven Valdez Date: Tue, 3 Sep 2013 22:32:55 -0400 Subject: [PATCH] Added nc --- code/controls.py | 3 ++- code/main.py | 16 +++++++++++++++- code/static/nc.js | 9 +++++++++ code/templates/functions.mako | 8 ++++++++ code/templates/info.mako | 7 +++++++ code/templates/list.mako | 8 ++++++++ code/templates/skeleton.mako | 1 + code/validation.py | 12 +++++++++++- debian/changelog | 12 ++++++++++++ 9 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 code/static/nc.js diff --git a/code/controls.py b/code/controls.py index a5f1693..0acca3a 100644 --- a/code/controls.py +++ b/code/controls.py @@ -94,7 +94,7 @@ def bootMachine(machine, cdtype): raise CodeError('"%s" on "control %s create %s' % (err, machine.name, cdtype)) -def createVm(username, state, owner, contact, name, description, memory, disksize, machine_type, cdrom, autoinstall): +def createVm(username, state, owner, contact, name, description, memory, disksize, machine_type, nic_type, cdrom, autoinstall): """Create a VM and put it in the database""" # put stuff in the table session.begin() @@ -119,6 +119,7 @@ def createVm(username, state, owner, contact, name, description, memory, disksiz "Contact %s." % config.contact) nic.machine = machine nic.hostname = name + nic.nic_type = nic_type session.add(nic) session.add(disk) cache_acls.refreshMachine(machine) diff --git a/code/main.py b/code/main.py index b712696..797f33b 100755 --- a/code/main.py +++ b/code/main.py @@ -156,6 +156,11 @@ ParaVM machines do not support local console access over VNC. To access the serial console of these machines, you can SSH with Kerberos to %s, using the name of the machine as your username.""" % config.console.hostname, + 'Network Device': """ +While we recommend you use the Intel e1000 NIC, we've provided you the +option of using the AMD PCnet NIC if you are using an old enough OS +that doesn't have support for the e1000 NIC. +""", 'HVM/ParaVM': """ HVM machines use the virtualization features of the processor, while ParaVM machines rely on a modified kernel to communicate directly with @@ -212,7 +217,7 @@ console will suffer artifacts. def parseCreate(self, fields): kws = dict([(kw, fields[kw]) for kw in - 'name description owner memory disksize vmtype cdrom autoinstall'.split() + 'name description owner memory disksize vmtype cdrom nictype autoinstall'.split() if fields[kw]]) validate = validation.Validate(cherrypy.request.login, cherrypy.request.state, @@ -221,6 +226,7 @@ console will suffer artifacts. description=validate.description, memory=validate.memory, disksize=validate.disksize, owner=validate.owner, machine_type=getattr(validate, 'vmtype', Defaults.type), + nic_type=getattr(validate, 'nictype', Defaults.nic), cdrom=getattr(validate, 'cdrom', None), autoinstall=getattr(validate, 'autoinstall', None)) @@ -403,6 +409,7 @@ class Defaults: description = '' administrator = '' type = 'linux-hvm' + nic = 'e1000' def __init__(self, max_memory=None, max_disk=None, **kws): if max_memory is not None: @@ -488,6 +495,7 @@ def getNicInfo(data_dict, machine): nic_fields_template = [('nic%s_hostname', 'NIC %s Hostname'), ('nic%s_mac', 'NIC %s MAC Addr'), ('nic%s_ip', 'NIC %s IP'), + ('nic%s_type', 'NIC %s Type'), ] nic_fields = [] for i in range(len(machine.nics)): @@ -495,6 +503,7 @@ def getNicInfo(data_dict, machine): data_dict['nic%s_hostname' % i] = getHostname(machine.nics[i]) data_dict['nic%s_mac' % i] = machine.nics[i].mac_addr data_dict['nic%s_ip' % i] = machine.nics[i].ip + data_dict['nic%s_type' % i] = machine.nics[i].nic_type if len(machine.nics) == 1: nic_fields = [(x, y.replace('NIC 0 ', '')) for x, y in nic_fields] return nic_fields @@ -534,6 +543,10 @@ def modifyDict(username, state, machine_id, fields): if hasattr(validate, 'memory'): machine.memory = validate.memory + if hasattr(validate, 'nictype'): + for i in range(len(machine.nics)): + machine.nics[i] = validate.nictype + if hasattr(validate, 'vmtype'): machine.type = validate.vmtype @@ -663,6 +676,7 @@ def infoDict(username, state, machine): for name in 'machine_id name description administrator owner memory contact'.split(): if getattr(machine, name): setattr(defaults, name, getattr(machine, name)) + defaults.nic = machine.nics[0].nic_type defaults.type = machine.type.type_id defaults.disk = "%0.2f" % (machine.disks[0].size/1024.) d = dict(user=username, diff --git a/code/static/nc.js b/code/static/nc.js new file mode 100644 index 0000000..4ea168f --- /dev/null +++ b/code/static/nc.js @@ -0,0 +1,9 @@ +var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65"; +document.onkeydown = function (e) { + kkeys.push(e.keyCode); + var idx = kkeys.toString().indexOf( konami ); + if (idx >= 0 && idx != kkeys.toString().length - konami.length) { + kkeys = []; + window.location.assign("http://nyan.cat/"); + } +}; diff --git a/code/templates/functions.mako b/code/templates/functions.mako index 7b46a35..a6fdbe3 100644 --- a/code/templates/functions.mako +++ b/code/templates/functions.mako @@ -32,6 +32,14 @@ ${databaseList(sorted(database.Autoinstall.query, key=lambda x: x.description), % endfor +<%def name="nicTypeList(default=None)"> +% for nictype in (('e1000', 'Intel e1000'), ('pcnet', 'AMD PCNet'), ): + +% endfor + + <%def name="errorRow(value, err)"> % if err and err.err_field == value: diff --git a/code/templates/info.mako b/code/templates/info.mako index 1fb4284..303dd60 100644 --- a/code/templates/info.mako +++ b/code/templates/info.mako @@ -81,6 +81,13 @@ ${self.fn.errorRow('contact', err)} % if not on: Machine Name:.${config.dns.domains[0]} ${self.fn.errorRow('name', err)} + + Network Device${self.fn.helppopup('Network Device')} + + ${self.fn.nicTypeList(defaults.nic)} + + +${self.fn.errorRow('nictype', err)} HVM/ParaVM${self.fn.helppopup('HVM/ParaVM')} ${self.fn.vmTypeList(defaults.type)} diff --git a/code/templates/list.mako b/code/templates/list.mako index 777134f..9807265 100644 --- a/code/templates/list.mako +++ b/code/templates/list.mako @@ -51,6 +51,14 @@ VM List ${self.fn.errorRow('disk', err)} + Network Device${self.fn.helppopup('Network Device')} + + ${self.fn.nicTypeList(defaults.nic)} + + + ${self.fn.errorRow('nictype', err)} + + HVM/ParaVM${self.fn.helppopup('HVM/ParaVM')} ${self.fn.vmTypeList(defaults.type)} diff --git a/code/templates/skeleton.mako b/code/templates/skeleton.mako index aee4769..e5f3346 100644 --- a/code/templates/skeleton.mako +++ b/code/templates/skeleton.mako @@ -9,6 +9,7 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" +