Added nc
[invirt/packages/invirt-web.git] / code / validation.py
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.