From bc48d5148c2d0b65f90e393184a213dc202ecc70 Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Thu, 2 Nov 2006 18:32:55 +0000 Subject: [PATCH] unset None fields, if allowed --- PLC/Addresses.py | 4 ++-- PLC/ConfFiles.py | 8 ++++---- PLC/Method.py | 8 +++++++- PLC/NodeGroups.py | 4 ++-- PLC/NodeNetworks.py | 25 ++++++++++++++----------- PLC/Nodes.py | 4 ++-- PLC/PCUs.py | 12 ++++++------ PLC/Parameter.py | 8 ++++++-- PLC/Persons.py | 10 +++++----- PLC/Sites.py | 6 +++--- PLC/Slices.py | 4 ++-- 11 files changed, 53 insertions(+), 40 deletions(-) diff --git a/PLC/Addresses.py b/PLC/Addresses.py index 667aa849..1a6ab50c 100644 --- a/PLC/Addresses.py +++ b/PLC/Addresses.py @@ -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), diff --git a/PLC/ConfFiles.py b/PLC/ConfFiles.py index 7eedcd0e..a80c96a3 100644 --- a/PLC/ConfFiles.py +++ b/PLC/ConfFiles.py @@ -4,7 +4,7 @@ # Mark Huang # 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), diff --git a/PLC/Method.py b/PLC/Method.py index ec0a244b..4cda6bb0 100644 --- a/PLC/Method.py +++ b/PLC/Method.py @@ -4,7 +4,7 @@ # Mark Huang # 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): diff --git a/PLC/NodeGroups.py b/PLC/NodeGroups.py index 23ab4f1c..b27c3a03 100644 --- a/PLC/NodeGroups.py +++ b/PLC/NodeGroups.py @@ -4,7 +4,7 @@ # Mark Huang # 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"), } diff --git a/PLC/NodeNetworks.py b/PLC/NodeNetworks.py index 0bdf8c49..47cda57b 100644 --- a/PLC/NodeNetworks.py +++ b/PLC/NodeNetworks.py @@ -4,7 +4,7 @@ # Mark Huang # 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: diff --git a/PLC/Nodes.py b/PLC/Nodes.py index c2af870d..16c63cba 100644 --- a/PLC/Nodes.py +++ b/PLC/Nodes.py @@ -4,7 +4,7 @@ # Mark Huang # 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), diff --git a/PLC/PCUs.py b/PLC/PCUs.py index 57ec44cf..aa047c04 100644 --- a/PLC/PCUs.py +++ b/PLC/PCUs.py @@ -4,7 +4,7 @@ # Mark Huang # 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), } diff --git a/PLC/Parameter.py b/PLC/Parameter.py index 9ae64869..53c32196 100644 --- a/PLC/Parameter.py +++ b/PLC/Parameter.py @@ -4,7 +4,7 @@ # Mark Huang # 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) diff --git a/PLC/Persons.py b/PLC/Persons.py index 9f7c1fc2..39f52528 100644 --- a/PLC/Persons.py +++ b/PLC/Persons.py @@ -4,7 +4,7 @@ # Mark Huang # 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), diff --git a/PLC/Sites.py b/PLC/Sites.py index b345a04f..00fc9647 100644 --- a/PLC/Sites.py +++ b/PLC/Sites.py @@ -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"), diff --git a/PLC/Slices.py b/PLC/Slices.py index fe728631..8eec3084 100644 --- a/PLC/Slices.py +++ b/PLC/Slices.py @@ -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), -- 2.47.0