unset None fields, if allowed
authorMark Huang <mlhuang@cs.princeton.edu>
Thu, 2 Nov 2006 18:32:55 +0000 (18:32 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Thu, 2 Nov 2006 18:32:55 +0000 (18:32 +0000)
PLC/Addresses.py
PLC/ConfFiles.py
PLC/Method.py
PLC/NodeGroups.py
PLC/NodeNetworks.py
PLC/Nodes.py
PLC/PCUs.py
PLC/Parameter.py
PLC/Persons.py
PLC/Sites.py
PLC/Slices.py

index 667aa84..1a6ab50 100644 (file)
@@ -15,8 +15,8 @@ class Address(Row):
     fields = {
         'address_id': Parameter(int, "Address identifier"),
         'line1': Parameter(str, "Address line 1", max = 254),
-        'line2': Parameter(str, "Address line 2", max = 254),
-        'line3': Parameter(str, "Address line 3", max = 254),
+        'line2': Parameter(str, "Address line 2", max = 254, nullok = True),
+        'line3': Parameter(str, "Address line 3", max = 254, nullok = True),
         'city': Parameter(str, "City", max = 254),
         'state': Parameter(str, "State or province", max = 254),
         'postalcode': Parameter(str, "Postal code", max = 64),
index 7eedcd0..a80c96a 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: ConfFiles.py,v 1.4 2006/10/24 20:02:22 mlhuang Exp $
+# $Id: ConfFiles.py,v 1.5 2006/10/25 14:29:13 mlhuang Exp $
 #
 
 from PLC.Faults import *
@@ -30,9 +30,9 @@ class ConfFile(Row):
         'file_permissions': Parameter(str, "chmod(1) permissions", max = 20),
         'file_owner': Parameter(str, "chown(1) owner", max = 50),
         'file_group': Parameter(str, "chgrp(1) owner", max = 50),
-        'preinstall_cmd': Parameter(str, "Shell command to execute prior to installing", max = 1024),
-        'postinstall_cmd': Parameter(str, "Shell command to execute after installing", max = 1024),
-        'error_cmd': Parameter(str, "Shell command to execute if any error occurs", max = 1024),
+        'preinstall_cmd': Parameter(str, "Shell command to execute prior to installing", max = 1024, nullok = True),
+        'postinstall_cmd': Parameter(str, "Shell command to execute after installing", max = 1024, nullok = True),
+        'error_cmd': Parameter(str, "Shell command to execute if any error occurs", max = 1024, nullok = True),
         'ignore_cmd_errors': Parameter(bool, "Install file anyway even if an error occurs"),
         'always_update': Parameter(bool, "Always attempt to install file even if unchanged"),
         'node_ids': Parameter(int, "List of nodes linked to this file", ro = True),
index ec0a244..4cda6bb 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: Method.py,v 1.13 2006/10/25 19:33:52 mlhuang Exp $
+# $Id: Method.py,v 1.14 2006/10/31 21:47:21 mlhuang Exp $
 #
 
 import xmlrpclib
@@ -278,13 +278,19 @@ class Method:
         if isinstance(expected, Parameter):
             min = expected.min
             max = expected.max
+            nullok = expected.nullok
             expected = expected.type
         else:
             min = None
             max = None
+            nullok = False
 
         expected_type = python_type(expected)
 
+        # If value can be NULL
+        if value is None and nullok:
+            return
+
         # Strings are a special case. Accept either unicode or str
         # types if a string is expected.
         if expected_type in StringTypes and isinstance(value, StringTypes):
index 23ab4f1..b27c3a0 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: NodeGroups.py,v 1.14 2006/10/24 20:02:22 mlhuang Exp $
+# $Id: NodeGroups.py,v 1.15 2006/10/25 14:29:13 mlhuang Exp $
 #
 
 from types import StringTypes
@@ -28,7 +28,7 @@ class NodeGroup(Row):
     fields = {
         'nodegroup_id': Parameter(int, "Node group identifier"),
         'name': Parameter(str, "Node group name", max = 50),
-        'description': Parameter(str, "Node group description", max = 200),
+        'description': Parameter(str, "Node group description", max = 200, nullok = True),
         'node_ids': Parameter([int], "List of nodes in this node group"),
         'conf_file_ids': Parameter([int], "List of configuration files specific to this node group"),
         }
index 0bdf8c4..47cda57 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: NodeNetworks.py,v 1.10 2006/10/24 20:02:22 mlhuang Exp $
+# $Id: NodeNetworks.py,v 1.11 2006/10/25 14:29:13 mlhuang Exp $
 #
 
 from types import StringTypes
@@ -51,16 +51,16 @@ class NodeNetwork(Row):
         'nodenetwork_id': Parameter(int, "Node interface identifier"),
         'method': Parameter(str, "Addressing method (e.g., 'static' or 'dhcp')"),
         'type': Parameter(str, "Address type (e.g., 'ipv4')"),
-        'ip': Parameter(str, "IP address"),
-        'mac': Parameter(str, "MAC address"),
-        'gateway': Parameter(str, "IP address of primary gateway"),
-        'network': Parameter(str, "Subnet address"),
-        'broadcast': Parameter(str, "Network broadcast address"),
-        'netmask': Parameter(str, "Subnet mask"),
-        'dns1': Parameter(str, "IP address of primary DNS server"),
-        'dns2': Parameter(str, "IP address of secondary DNS server"),
-        'bwlimit': Parameter(int, "Bandwidth limit", min = 0),
-        'hostname': Parameter(str, "(Optional) Hostname"),
+        'ip': Parameter(str, "IP address", nullok = True),
+        'mac': Parameter(str, "MAC address", nullok = True),
+        'gateway': Parameter(str, "IP address of primary gateway", nullok = True),
+        'network': Parameter(str, "Subnet address", nullok = True),
+        'broadcast': Parameter(str, "Network broadcast address", nullok = True),
+        'netmask': Parameter(str, "Subnet mask", nullok = True),
+        'dns1': Parameter(str, "IP address of primary DNS server", nullok = True),
+        'dns2': Parameter(str, "IP address of secondary DNS server", nullok = True),
+        'bwlimit': Parameter(int, "Bandwidth limit", min = 0, nullok = True),
+        'hostname': Parameter(str, "(Optional) Hostname", nullok = True),
         'node_id': Parameter(int, "Node associated with this interface"),
         'is_primary': Parameter(bool, "Is the primary interface for this node"),
         }
@@ -81,6 +81,9 @@ class NodeNetwork(Row):
         return ip
 
     def validate_mac(self, mac):
+        if not mac:
+            return mac
+
         try:
             bytes = mac.split(":")
             if len(bytes) < 6:
index c2af870..16c63cb 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: Nodes.py,v 1.14 2006/10/25 14:29:13 mlhuang Exp $
+# $Id: Nodes.py,v 1.15 2006/10/27 15:32:43 mlhuang Exp $
 #
 
 from types import StringTypes
@@ -42,7 +42,7 @@ class Node(Row):
         'hostname': Parameter(str, "Fully qualified hostname", max = 255),
         'site_id': Parameter(int, "Site at which this node is located"),
         'boot_state': Parameter(str, "Boot state", max = 20),
-        'model': Parameter(str, "Make and model of the actual machine", max = 255),
+        'model': Parameter(str, "Make and model of the actual machine", max = 255, nullok = True),
         'boot_nonce': Parameter(str, "(Admin only) Random value generated by the node at last boot", max = 128),
         'version': Parameter(str, "Apparent Boot CD version", max = 64),
         'ssh_rsa_key': Parameter(str, "Last known SSH host key", max = 1024),
index 57ec44c..aa047c0 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: PCUs.py,v 1.5 2006/10/24 20:02:22 mlhuang Exp $
+# $Id: PCUs.py,v 1.6 2006/10/25 14:29:13 mlhuang Exp $
 #
 
 from PLC.Faults import *
@@ -28,11 +28,11 @@ class PCU(Row):
         'site_id': Parameter(int, "Identifier of site where PCU is located"),
         'hostname': Parameter(str, "PCU hostname", max = 254),
         'ip': Parameter(str, "PCU IP address", max = 254),
-        'protocol': Parameter(str, "PCU protocol, e.g. ssh, https, telnet", max = 16),
-        'username': Parameter(str, "PCU username", max = 254),
-        'password': Parameter(str, "PCU username", max = 254),
-        'notes': Parameter(str, "Miscellaneous notes", max = 254),
-        'model': Parameter(str, "PCU model string", max = 32),
+        'protocol': Parameter(str, "PCU protocol, e.g. ssh, https, telnet", max = 16, nullok = True),
+        'username': Parameter(str, "PCU username", max = 254, nullok = True),
+        'password': Parameter(str, "PCU username", max = 254, nullok = True),
+        'notes': Parameter(str, "Miscellaneous notes", max = 254, nullok = True),
+        'model': Parameter(str, "PCU model string", max = 32, nullok = True),
         'node_ids': Parameter([int], "List of nodes that this PCU controls", ro = True),
         'ports': Parameter([int], "List of the port numbers that each node is connected to", ro = True),
         }
index 9ae6486..53c3219 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: Parameter.py,v 1.3 2006/10/02 18:32:31 mlhuang Exp $
+# $Id: Parameter.py,v 1.4 2006/10/25 14:27:12 mlhuang Exp $
 #
 
 class Parameter:
@@ -17,7 +17,8 @@ class Parameter:
     def __init__(self, type, doc = "",
                  min = None, max = None,
                  optional = None,
-                 ro = False):
+                 ro = False,
+                 nullok = False):
         # Basic type of the parameter. May be a builtin type or Mixed.
         self.type = type
 
@@ -37,6 +38,9 @@ class Parameter:
         # Whether the DB field is read-only.
         self.ro = ro
 
+        # Whether the DB field can be NULL.
+        self.nullok = nullok
+
     def __repr__(self):
         return repr(self.type)
 
index 9f7c1fc..39f5252 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: Persons.py,v 1.14 2006/10/25 14:29:13 mlhuang Exp $
+# $Id: Persons.py,v 1.15 2006/10/27 15:32:56 mlhuang Exp $
 #
 
 from types import StringTypes
@@ -35,11 +35,11 @@ class Person(Row):
         'person_id': Parameter(int, "Account identifier"),
         'first_name': Parameter(str, "Given name", max = 128),
         'last_name': Parameter(str, "Surname", max = 128),
-        'title': Parameter(str, "Title", max = 128),
+        'title': Parameter(str, "Title", max = 128, nullok = True),
         'email': Parameter(str, "Primary e-mail address", max = 254),
-        'phone': Parameter(str, "Telephone number", max = 64),
-        'url': Parameter(str, "Home page", max = 254),
-        'bio': Parameter(str, "Biography", max = 254),
+        'phone': Parameter(str, "Telephone number", max = 64, nullok = True),
+        'url': Parameter(str, "Home page", max = 254, nullok = True),
+        'bio': Parameter(str, "Biography", max = 254, nullok = True),
         'enabled': Parameter(bool, "Has been enabled"),
         'password': Parameter(str, "Account password in crypt() form", max = 254),
         'last_updated': Parameter(int, "Date and time of last update", ro = True),
index b345a04..00fc964 100644 (file)
@@ -27,9 +27,9 @@ class Site(Row):
         'abbreviated_name': Parameter(str, "Abbreviated site name", max = 50),
         'login_base': Parameter(str, "Site slice prefix", max = 20),
         'is_public': Parameter(bool, "Publicly viewable site"),
-        'latitude': Parameter(float, "Decimal latitude of the site", min = -90.0, max = 90.0),
-        'longitude': Parameter(float, "Decimal longitude of the site", min = -180.0, max = 180.0),
-        'url': Parameter(str, "URL of a page that describes the site", max = 254),
+        'latitude': Parameter(float, "Decimal latitude of the site", min = -90.0, max = 90.0, nullok = True),
+        'longitude': Parameter(float, "Decimal longitude of the site", min = -180.0, max = 180.0, nullok = True),
+        'url': Parameter(str, "URL of a page that describes the site", max = 254, nullok = True),
         'date_created': Parameter(int, "Date and time when site entry was created, in seconds since UNIX epoch", ro = True),
         'last_updated': Parameter(int, "Date and time when site entry was last updated, in seconds since UNIX epoch", ro = True),
         'max_slices': Parameter(int, "Maximum number of slices that the site is able to create"),
index fe72863..8eec308 100644 (file)
@@ -25,8 +25,8 @@ class Slice(Row):
         'site_id': Parameter(int, "Identifier of the site to which this slice belongs"),
         'name': Parameter(str, "Slice name", max = 32),
         'instantiation': Parameter(str, "Slice instantiation state"),
-        'url': Parameter(str, "URL further describing this slice", max = 254),
-        'description': Parameter(str, "Slice description", max = 2048),
+        'url': Parameter(str, "URL further describing this slice", max = 254, nullok = True),
+        'description': Parameter(str, "Slice description", max = 2048, nullok = True),
         'max_nodes': Parameter(int, "Maximum number of nodes that can be assigned to this slice"),
         'creator_person_id': Parameter(int, "Identifier of the account that created this slice"),
         'created': Parameter(int, "Date and time when slice was created, in seconds since UNIX epoch", ro = True),