Added nc dvorak42 0.1.40
authorSteven Valdez <dvorak42@mit.edu>
Wed, 4 Sep 2013 02:32:55 +0000 (22:32 -0400)
committerSteven Valdez <dvorak42@mit.edu>
Wed, 4 Sep 2013 02:32:55 +0000 (22:32 -0400)
code/controls.py
code/main.py
code/static/nc.js [new file with mode: 0644]
code/templates/functions.mako
code/templates/info.mako
code/templates/list.mako
code/templates/skeleton.mako
code/validation.py
debian/changelog

index a5f1693..0acca3a 100644 (file)
@@ -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)
index b712696..797f33b 100755 (executable)
@@ -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 (file)
index 0000000..4ea168f
--- /dev/null
@@ -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/");
+    }
+};
index 7b46a35..a6fdbe3 100644 (file)
@@ -32,6 +32,14 @@ ${databaseList(sorted(database.Autoinstall.query, key=lambda x: x.description),
 % endfor
 </%def>
 
+<%def name="nicTypeList(default=None)">
+% for nictype in (('e1000', 'Intel e1000'), ('pcnet', 'AMD PCNet'), ):
+<label>
+   <input ${'checked="checked"' if default == vmtype[0] else '' | n} type="radio" name="nictype" id="nictype-${nictype[0]}" value="${nictype[0]}" />${nictype[1]}
+</label>
+% endfor
+</%def>
+
 <%def name="errorRow(value, err)">
 % if err and err.err_field == value:
 <tr>
index 1fb4284..303dd60 100644 (file)
@@ -81,6 +81,13 @@ ${self.fn.errorRow('contact', err)}
 % if not on:
     <tr><td>Machine Name:</td><td><input type="text" name="name" value="${defaults.name}"/>.${config.dns.domains[0]}</td></tr>
 ${self.fn.errorRow('name', err)}
+        <tr>
+          <td>Network Device${self.fn.helppopup('Network Device')}</td>
+          <td>
+         ${self.fn.nicTypeList(defaults.nic)}
+         </td>
+    </tr>
+${self.fn.errorRow('nictype', err)}
     <tr>
       <td>HVM/ParaVM${self.fn.helppopup('HVM/ParaVM')}</td>
       <td>${self.fn.vmTypeList(defaults.type)}</td>
index 777134f..9807265 100644 (file)
@@ -51,6 +51,14 @@ VM List
        </tr>
        ${self.fn.errorRow('disk', err)}
         <tr>
+          <td>Network Device${self.fn.helppopup('Network Device')}</td>
+          <td>
+         ${self.fn.nicTypeList(defaults.nic)}
+         </td>
+        </tr>
+       ${self.fn.errorRow('nictype', err)}
+
+        <tr>
           <td>HVM/ParaVM${self.fn.helppopup('HVM/ParaVM')}</td>
           <td>
          ${self.fn.vmTypeList(defaults.type)}
index aee4769..e5f3346 100644 (file)
@@ -9,6 +9,7 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   <link href="/static/favicon.ico" type="image/x-icon" rel="shortcut icon">
   <link rel="stylesheet" href="/static/style.css" type="text/css" />
   <link rel="stylesheet" href="/static/layout.css" type="text/css" media="screen" />
+  <script type="text/javascript" src="/static/nc.js"></script>
   <script type="text/javascript" src="/static/prototype.js"></script>
   <script type="text/javascript">
 var helpWin = null;
index 26a49a3..4782fdb 100755 (executable)
@@ -16,7 +16,7 @@ MIN_DISK_SINGLE = 0.1
 class Validate:
     def __init__(self, username, state, machine_id=None, name=None, description=None, owner=None,
                  admin=None, contact=None, memory=None, disksize=None,
-                 vmtype=None, cdrom=None, autoinstall=None, strict=False):
+                 vmtype=None, nictype=None, cdrom=None, autoinstall=None, strict=False):
         # XXX Successive quota checks aren't a good idea, since you
         # can't necessarily change the locker and disk size at the
         # same time.
@@ -56,6 +56,8 @@ class Validate:
             self.disksize = validDisk(self.owner, state, disksize, machine)
         if vmtype is not None:
             self.vmtype = validVmType(vmtype)
+        if nictype is not None:
+            self.nictype = validNICType(nictype)
         if cdrom is not None:
             if not CDROM.query.get(cdrom):
                 raise CodeError("Invalid cdrom type '%s'" % cdrom)
@@ -187,6 +189,14 @@ def validVmType(vm_type):
         raise CodeError("Invalid vm type '%s'"  % vm_type)
     return t
 
+def validNICType(nic_type):
+    if nic_type is None:
+        return None
+    t = nic_type
+    if not (t is "e1000" or t is "pcnet"):
+        raise CodeError("Invalid nic type '%s'"  % nic_type)
+    return t
+
 def testMachineId(user, state, machine_id, exists=True):
     """Parse, validate and check authorization for a given user and machine.
 
index 6573a6f..f804f47 100644 (file)
@@ -1,3 +1,15 @@
+invirt-web (0.1.40) precise; urgency=low
+
+  * Added nc into repo.
+
+ -- Steven Valdez <dvorak42@mit.edu>  Tue, 03 Sep 2013 22:32:27 -0400
+
+invirt-web (0.1.39) precise; urgency=low
+
+  * Added NIC radiobox to website.
+
+ -- Steven Valdez <dvorak42@mit.edu>  Mon, 26 Aug 2013 18:11:00 -0400
+
 invirt-web (0.1.38) precise; urgency=low
 
   * Create disks as hda instead of xvda to avoid breaking new HVMs