- Change .py files to use 4-space indents and no hard tab characters.
authorS.Çağlar Onur <caglar@cs.princeton.edu>
Tue, 22 Jun 2010 18:56:38 +0000 (18:56 +0000)
committerS.Çağlar Onur <caglar@cs.princeton.edu>
Tue, 22 Jun 2010 18:56:38 +0000 (18:56 +0000)
- Trim excess spaces and tabs from ends of lines, and remove empty lines at the end of files.
- Ensure the last line ends with a newline.

209 files changed:
PLC/API.py
PLC/Accessor.py
PLC/Accessors/Accessors_example_ple.py
PLC/Accessors/Accessors_omf.py
PLC/Accessors/Accessors_site.py
PLC/Accessors/Accessors_standard.py
PLC/Accessors/Accessors_wireless.py
PLC/Accessors/Factory.py
PLC/AddressTypes.py
PLC/Addresses.py
PLC/Auth.py
PLC/BootStates.py
PLC/ConfFiles.py
PLC/EventObjects.py
PLC/Events.py
PLC/Filter.py
PLC/InitScripts.py
PLC/InterfaceTags.py
PLC/Interfaces.py
PLC/KeyTypes.py
PLC/Keys.py
PLC/LeaseFilter.py
PLC/Leases.py
PLC/Messages.py
PLC/Method.py
PLC/Methods/AddAddressType.py
PLC/Methods/AddAddressTypeToAddress.py
PLC/Methods/AddBootState.py
PLC/Methods/AddConfFile.py
PLC/Methods/AddConfFileToNode.py
PLC/Methods/AddConfFileToNodeGroup.py
PLC/Methods/AddIlink.py
PLC/Methods/AddInitScript.py
PLC/Methods/AddInterface.py
PLC/Methods/AddInterfaceTag.py
PLC/Methods/AddLeases.py
PLC/Methods/AddNode.py
PLC/Methods/AddNodeGroup.py
PLC/Methods/AddNodeTag.py
PLC/Methods/AddNodeToPCU.py
PLC/Methods/AddNodeType.py
PLC/Methods/AddPCU.py
PLC/Methods/AddPCUProtocolType.py
PLC/Methods/AddPCUType.py
PLC/Methods/AddPeer.py
PLC/Methods/AddPerson.py
PLC/Methods/AddPersonTag.py
PLC/Methods/AddPersonToSlice.py
PLC/Methods/AddRole.py
PLC/Methods/AddRoleToPerson.py
PLC/Methods/AddSession.py
PLC/Methods/AddSite.py
PLC/Methods/AddSiteAddress.py
PLC/Methods/AddSiteTag.py
PLC/Methods/AddSlice.py
PLC/Methods/AddSliceTag.py
PLC/Methods/AddSliceToNodes.py
PLC/Methods/AddSliceToNodesWhitelist.py
PLC/Methods/AddTagType.py
PLC/Methods/BindObjectToPeer.py
PLC/Methods/BlacklistKey.py
PLC/Methods/BootGetNodeDetails.py
PLC/Methods/BootUpdateNode.py
PLC/Methods/DeleteAddress.py
PLC/Methods/DeleteAddressType.py
PLC/Methods/DeleteAddressTypeFromAddress.py
PLC/Methods/DeleteBootState.py
PLC/Methods/DeleteConfFile.py
PLC/Methods/DeleteConfFileFromNode.py
PLC/Methods/DeleteConfFileFromNodeGroup.py
PLC/Methods/DeleteIlink.py
PLC/Methods/DeleteInitScript.py
PLC/Methods/DeleteInterface.py
PLC/Methods/DeleteInterfaceTag.py
PLC/Methods/DeleteKey.py
PLC/Methods/DeleteKeyType.py
PLC/Methods/DeleteLeases.py
PLC/Methods/DeleteMessage.py
PLC/Methods/DeleteNetworkMethod.py
PLC/Methods/DeleteNetworkType.py
PLC/Methods/DeleteNodeFromPCU.py
PLC/Methods/DeleteNodeGroup.py
PLC/Methods/DeleteNodeTag.py
PLC/Methods/DeleteNodeType.py
PLC/Methods/DeletePCU.py
PLC/Methods/DeletePCUProtocolType.py
PLC/Methods/DeletePCUType.py
PLC/Methods/DeletePeer.py
PLC/Methods/DeletePerson.py
PLC/Methods/DeletePersonFromSite.py
PLC/Methods/DeletePersonFromSlice.py
PLC/Methods/DeletePersonTag.py
PLC/Methods/DeleteRole.py
PLC/Methods/DeleteRoleFromPerson.py
PLC/Methods/DeleteSite.py
PLC/Methods/DeleteSiteTag.py
PLC/Methods/DeleteSliceFromNodes.py
PLC/Methods/DeleteSliceFromNodesWhitelist.py
PLC/Methods/DeleteSliceTag.py
PLC/Methods/DeleteTagType.py
PLC/Methods/GenerateNodeConfFile.py
PLC/Methods/GetAddresses.py
PLC/Methods/GetBootMedium.py
PLC/Methods/GetBootStates.py
PLC/Methods/GetEventObjects.py
PLC/Methods/GetEvents.py
PLC/Methods/GetIlinks.py
PLC/Methods/GetInitScripts.py
PLC/Methods/GetInterfaceTags.py
PLC/Methods/GetInterfaces.py
PLC/Methods/GetKeys.py
PLC/Methods/GetLeases.py
PLC/Methods/GetNodeFlavour.py
PLC/Methods/GetNodeGroups.py
PLC/Methods/GetNodeTags.py
PLC/Methods/GetNodeTypes.py
PLC/Methods/GetNodes.py
PLC/Methods/GetPCUProtocolTypes.py
PLC/Methods/GetPCUTypes.py
PLC/Methods/GetPCUs.py
PLC/Methods/GetPeerData.py
PLC/Methods/GetPeers.py
PLC/Methods/GetPersonTags.py
PLC/Methods/GetPersons.py
PLC/Methods/GetPlcRelease.py
PLC/Methods/GetRoles.py
PLC/Methods/GetSession.py
PLC/Methods/GetSessions.py
PLC/Methods/GetSiteTags.py
PLC/Methods/GetSites.py
PLC/Methods/GetSliceFamily.py
PLC/Methods/GetSliceKeys.py
PLC/Methods/GetSliceTags.py
PLC/Methods/GetSliceTicket.py
PLC/Methods/GetSlices.py
PLC/Methods/GetSlivers.py
PLC/Methods/GetWhitelist.py
PLC/Methods/NotifySupport.py
PLC/Methods/RebootNode.py
PLC/Methods/RebootNodeWithPCU.py
PLC/Methods/RefreshPeer.py
PLC/Methods/ReportRunlevel.py
PLC/Methods/ResetPassword.py
PLC/Methods/ResolveSlices.py
PLC/Methods/SliceCreate.py
PLC/Methods/SliceDelete.py
PLC/Methods/SliceExtendedInfo.py
PLC/Methods/SliceGetTicket.py
PLC/Methods/SliceInfo.py
PLC/Methods/SliceListNames.py
PLC/Methods/SliceListUserSlices.py
PLC/Methods/SliceNodesAdd.py
PLC/Methods/SliceNodesDel.py
PLC/Methods/SliceNodesList.py
PLC/Methods/SliceRenew.py
PLC/Methods/SliceUpdate.py
PLC/Methods/SliceUserAdd.py
PLC/Methods/SliceUserDel.py
PLC/Methods/SliceUsersList.py
PLC/Methods/UnBindObjectFromPeer.py
PLC/Methods/UpdateAddress.py
PLC/Methods/UpdateAddressType.py
PLC/Methods/UpdateConfFile.py
PLC/Methods/UpdateIlink.py
PLC/Methods/UpdateInitScript.py
PLC/Methods/UpdateInterface.py
PLC/Methods/UpdateInterfaceTag.py
PLC/Methods/UpdateKey.py
PLC/Methods/UpdateLeases.py
PLC/Methods/UpdateMessage.py
PLC/Methods/UpdateNode.py
PLC/Methods/UpdateNodeGroup.py
PLC/Methods/UpdateNodeTag.py
PLC/Methods/UpdatePCU.py
PLC/Methods/UpdatePCUProtocolType.py
PLC/Methods/UpdatePCUType.py
PLC/Methods/UpdatePeer.py
PLC/Methods/UpdatePerson.py
PLC/Methods/UpdatePersonTag.py
PLC/Methods/UpdateSite.py
PLC/Methods/UpdateSiteTag.py
PLC/Methods/UpdateSlice.py
PLC/Methods/UpdateSliceTag.py
PLC/Methods/UpdateTagType.py
PLC/Methods/VerifyPerson.py
PLC/Namespace.py
PLC/NetworkMethods.py
PLC/NetworkTypes.py
PLC/NodeGroups.py
PLC/NodeTypes.py
PLC/Nodes.py
PLC/PCUProtocolTypes.py
PLC/PCUTypes.py
PLC/POD.py
PLC/Peers.py
PLC/PersonTags.py
PLC/Persons.py
PLC/PostgreSQL.py
PLC/PyCurl.py
PLC/Roles.py
PLC/Sessions.py
PLC/SiteTags.py
PLC/Sites.py
PLC/SliceInstantiations.py
PLC/SliceTags.py
PLC/Slices.py
PLC/Table.py
PLC/TagTypes.py
PLC/Timestamp.py

index dec2e08..783280f 100644 (file)
@@ -111,7 +111,7 @@ class PLCAPI:
                 other_methods_map[method] = fullpath
 
     all_methods = native_methods + other_methods_map.keys()
-    
+
     def __init__(self, config = "/etc/planetlab/plc_config", encoding = "utf-8"):
         self.encoding = encoding
 
@@ -121,8 +121,8 @@ class PLCAPI:
 
         # Load configuration
         self.config = Config(config)
-       
-       # Initialize database connection
+
+        # Initialize database connection
         if self.config.PLC_DB_TYPE == "postgresql":
             from PLC.PostgreSQL import PostgreSQL
             self.db = PostgreSQL(self)
@@ -144,7 +144,7 @@ class PLCAPI:
         # Look up method
         if method not in self.all_methods:
             raise PLCInvalidAPIMethod, method
-        
+
         # Get new instance of method
         try:
             classname = method.split(".")[-1]
index 8a8d16d..acf9a49 100644 (file)
@@ -29,7 +29,7 @@ This is implemented as a singleton, so we can cache results over time"""
 
     def locate_or_create_tag (self,tagname,category, description, min_role_id):
         "search tag type from tagname & create if needed"
-        
+
         # cached ?
         if self.has_cache (tagname):
             return self.get_cache(tagname)
@@ -39,7 +39,7 @@ This is implemented as a singleton, so we can cache results over time"""
             tag_type = tag_types[0]
         else:
             # not found: create it
-            tag_type_fields = {'tagname':tagname, 
+            tag_type_fields = {'tagname':tagname,
                                'category' :  category,
                                'description' : description,
                                'min_role_id': min_role_id}
index 94ef84e..77774d7 100644 (file)
@@ -16,9 +16,9 @@ import sys
 current_module = sys.modules[__name__]
 
 #### example 1 : attach vlan ids on interfaces
-# The third argument expose_in_api is a boolean flag that tells whether this tag may be handled 
+# The third argument expose_in_api is a boolean flag that tells whether this tag may be handled
 #   through the Add/Get/Update methods as a native field
-# 
+#
 #define_accessors(current_module, Interface, "Vlan", "vlan",
 #                  "interface/general", "tag for setting VLAN id",
 #                  get_roles=all_roles, set_roles=tech_roles)
@@ -35,17 +35,17 @@ current_module = sys.modules[__name__]
 #################### MySlice tags
 define_accessors(current_module, Node, "Reliability", "reliability",
                  # category
-                 "node/monitor/ui/header=R/type=int/rank=ad", 
+                 "node/monitor/ui/header=R/type=int/rank=ad",
                  # description : used to add a footnote to the table if header is set in category
                  "average reliability (% uptime) over the last week",
                   get_roles=all_roles, set_roles=tech_roles, expose_in_api=True)
 
 define_accessors(current_module, Node, "Load", "load",
-                 "node/monitor/ui/header=l/type=sortAlphaNumericBottom", 
+                 "node/monitor/ui/header=l/type=sortAlphaNumericBottom",
                  "average load (% CPU utilization) over the last week",
                   get_roles=all_roles, set_roles=tech_roles, expose_in_api=True)
 
 define_accessors(current_module, Node, "ASNumber", "asnumber",
-                 "node/location/ui/header=AS/type=sortAlphaNumericBottom/rank=z", 
+                 "node/location/ui/header=AS/type=sortAlphaNumericBottom/rank=z",
                  "Autonomous System id",
                  get_roles=all_roles, set_roles=tech_roles, expose_in_api=True)
index c491da7..ebdb5de 100644 (file)
@@ -17,4 +17,3 @@ current_module = sys.modules[__name__]
 define_accessors(current_module, Slice, "OmfControl","omf_control",
                  "slice/usertools","Pre-install and configure OMF Resource Controller in slice if set",
                  get_roles=all_roles, set_roles=all_roles, expose_in_api=True)
-
index f27cd8d..f1305c2 100644 (file)
@@ -26,9 +26,9 @@ import sys
 current_module = sys.modules[__name__]
 
 #### example : attach vlan ids on interfaces
-# The third argument expose_in_api is a boolean flag that tells whether this tag may be handled 
+# The third argument expose_in_api is a boolean flag that tells whether this tag may be handled
 #   through the Add/Get/Update methods as a native field
-# 
+#
 #define_accessors(current_module, Interface, "Vlan", "vlan",
 #                  "interface/general", "tag for setting VLAN id",
 #                  get_roles=all_roles, set_roles=tech_roles)
index 0d773b2..f97bfd4 100644 (file)
@@ -21,58 +21,58 @@ current_module = sys.modules[__name__]
 # You might wish to keep this roughly in sync with db-config.d/011-standard_tags
 #
 
-# 
+#
 ### system slices - at least planetflow - still rely on 'vref'
-# 
+#
 
-# These following accessors are mostly of interest for implementing the 
-# GetSliceFamily method, that takes into account the vref attribute, 
+# These following accessors are mostly of interest for implementing the
+# GetSliceFamily method, that takes into account the vref attribute,
 # as well as the 3 attributes below, and the PLC_FLAVOUR config category
 
-### slice vref 
-define_accessors(current_module, Slice, "Vref", "vref", 
+### slice vref
+define_accessors(current_module, Slice, "Vref", "vref",
                  "slice/config", "vserver reference image name",
                  get_roles=all_roles, set_roles=["admin"], expose_in_api=True)
 
 # xxx the accessor factory should enforce the category and descriptions provided here.
 # and BTW the tag should be created right away as far as possible, or at least when a Get is issued
 # also note that the two 'arch' instances use here will end in the same unique TagType object,
-# so you should make sure to use the same category/description for both 
-define_accessors(current_module, Slice, "Arch", "arch", 
+# so you should make sure to use the same category/description for both
+define_accessors(current_module, Slice, "Arch", "arch",
                  "node/slice/config", "node arch or slivers arch",
                  get_roles=all_roles, set_roles=["user"], expose_in_api=True)
 define_accessors(current_module, Slice, "Pldistro", "pldistro",
-                 "node/slice/config", "PlanetLab distribution to use for node or slivers", 
+                 "node/slice/config", "PlanetLab distribution to use for node or slivers",
                  get_roles=all_roles, set_roles=["admin"], expose_in_api=True)
 define_accessors(current_module, Slice, "Fcdistro", "fcdistro",
-                 "node/slice/config", "Fedora or CentOS distribution to use for node or slivers", 
+                 "node/slice/config", "Fedora or CentOS distribution to use for node or slivers",
                  get_roles=all_roles, set_roles=["admin"], expose_in_api=True)
 
 # Ditto for the GetNodeFlavour method
-define_accessors(current_module, Node, "Arch", "arch",  
+define_accessors(current_module, Node, "Arch", "arch",
                  "node/slice/config", "node arch or slivers arch",
                  get_roles=all_roles, set_roles=tech_roles, expose_in_api=True)
 define_accessors(current_module, Node, "Pldistro", "pldistro",
-                 "node/slice/config", "PlanetLab distribution to use for node or slivers", 
+                 "node/slice/config", "PlanetLab distribution to use for node or slivers",
                  get_roles=all_roles, set_roles=["admin"], expose_in_api=True)
 define_accessors(current_module, Node, "Fcdistro", "fcdistro",
-                 "node/slice/config", "Fedora or CentOS distribution to use for node or slivers", 
+                 "node/slice/config", "Fedora or CentOS distribution to use for node or slivers",
                  get_roles=all_roles, set_roles=["admin"], expose_in_api=True)
 # node deployment (alpha, beta, ...)
 define_accessors(current_module, Node, "Deployment", "deployment",
                  "node/operation", 'typically "alpha", "beta", or "production"',
                  get_roles=all_roles, set_roles=["admin"], expose_in_api=True)
 # extension
-define_accessors(current_module, Node, "Extensions", "extensions", 
+define_accessors(current_module, Node, "Extensions", "extensions",
                  "node/config", "space-separated list of extensions to install",
                  get_roles=all_roles, set_roles=["admin"],expose_in_api=True)
-# access HRN - this is the ideal definition of roles, even if AddNodeTag cannot handle this 
+# access HRN - this is the ideal definition of roles, even if AddNodeTag cannot handle this
 define_accessors(current_module, Node, "Hrn","hrn",
                  "node/sfa", "SFA human readable name",
                  get_roles=all_roles, set_roles=["admin","pi","tech"], expose_in_api=True)
 
 # test nodes perform their installation from an uncompressed bootstrapfs
-define_accessors(current_module, Node, "PlainBootstrapfs", "plain-bootstrapfs", 
+define_accessors(current_module, Node, "PlainBootstrapfs", "plain-bootstrapfs",
                  "node/config", "use uncompressed bootstrapfs when set",
                  get_roles=all_roles, set_roles=tech_roles)
 
@@ -88,18 +88,17 @@ define_accessors(current_module, Node, "Kargs", "kargs",
 define_accessors(current_module, Node, "NoHangcheck", "no-hangcheck",
                  "node/bootcd", "disable hangcheck on the boot CD if set -- see GetBootMedium")
 
-# interface 
+# interface
 # xxx - don't expose yet in api interface and slices dont know how to use that yet
-define_accessors(current_module, Interface, "Ifname", "ifname", 
+define_accessors(current_module, Interface, "Ifname", "ifname",
                  "interface/config", "linux name",
                  get_roles=all_roles, set_roles=tech_roles, expose_in_api=True)
-define_accessors(current_module, Interface, "Driver", "driver", 
+define_accessors(current_module, Interface, "Driver", "driver",
                  "interface/config", "driver name",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Alias", "alias", 
+define_accessors(current_module, Interface, "Alias", "alias",
                  "interface/config", "interface alias",
                  get_roles=all_roles, set_roles=tech_roles)
 define_accessors(current_module, Interface, "Backdoor", "backdoor",
                  "interface/hidden", "For testing new settings",
                  get_roles=all_roles, set_roles=admin_roles)
-
index 3a021f2..5af6e29 100644 (file)
@@ -13,7 +13,7 @@ import sys
 current_module = sys.modules[__name__]
 
 #### Wireless
-define_accessors(current_module, Interface, "Mode", "mode", 
+define_accessors(current_module, Interface, "Mode", "mode",
                  "interface/wifi", "Wifi operation mode - see iwconfig",
                  get_roles=all_roles, set_roles=tech_roles)
 define_accessors(current_module, Interface, "Essid", "essid",
@@ -22,39 +22,39 @@ define_accessors(current_module, Interface, "Essid", "essid",
 define_accessors(current_module, Interface, "Nw", "nw",
                  "interface/wifi", "Wireless nw - see iwconfig",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Freq", "freq", 
+define_accessors(current_module, Interface, "Freq", "freq",
                  "interface/wifi", "Wireless freq - see iwconfig",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Channel", "channel", 
+define_accessors(current_module, Interface, "Channel", "channel",
                  "interface/wifi", "Wireless channel - see iwconfig",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Sens", "sens", 
+define_accessors(current_module, Interface, "Sens", "sens",
                  "interface/wifi", "Wireless sens - see iwconfig",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Rate", "rate", 
+define_accessors(current_module, Interface, "Rate", "rate",
                  "interface/wifi", "Wireless rate - see iwconfig",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Key", "key", 
+define_accessors(current_module, Interface, "Key", "key",
                  "interface/wifi", "Wireless key - see iwconfig key",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Key1", "key1", 
+define_accessors(current_module, Interface, "Key1", "key1",
                  "interface/wifi", "Wireless key1 - see iwconfig key[1]",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Key2", "key2", 
+define_accessors(current_module, Interface, "Key2", "key2",
                  "interface/wifi", "Wireless key2 - see iwconfig key[2]",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Key3", "key3", 
+define_accessors(current_module, Interface, "Key3", "key3",
                  "interface/wifi", "Wireless key3 - see iwconfig key[3]",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Key4", "key4", 
+define_accessors(current_module, Interface, "Key4", "key4",
                  "interface/wifi", "Wireless key4 - see iwconfig key[4]",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "SecurityMode", "securitymode", 
+define_accessors(current_module, Interface, "SecurityMode", "securitymode",
                  "interface/wifi", "Wireless securitymode - see iwconfig enc",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Iwconfig", "iwconfig", 
+define_accessors(current_module, Interface, "Iwconfig", "iwconfig",
                  "interface/wifi", "Wireless iwconfig - see ifup-wireless",
                  get_roles=all_roles, set_roles=tech_roles)
-define_accessors(current_module, Interface, "Iwpriv", "iwpriv", 
+define_accessors(current_module, Interface, "Iwpriv", "iwpriv",
                  "interface/wifi", "Wireless iwpriv - see ifup-wireless",
                  get_roles=all_roles, set_roles=tech_roles)
index abd34fd..546e3d9 100644 (file)
@@ -28,19 +28,19 @@ from PLC.PersonTags import PersonTags, PersonTag
 from PLC.TagTypes import TagTypes, TagType
 
 # known classes : { class -> secondary_key }
-taggable_classes = { Node : {'table_class' : Nodes, 
+taggable_classes = { Node : {'table_class' : Nodes,
                              'joins_class' : NodeTags, 'join_class' : NodeTag,
                              'secondary_key': 'hostname'},
-                     Interface : {'table_class' : Interfaces, 
+                     Interface : {'table_class' : Interfaces,
                                   'joins_class': InterfaceTags, 'join_class': InterfaceTag,
                                   'secondary_key' : 'ip'},
-                     Slice: {'table_class' : Slices, 
+                     Slice: {'table_class' : Slices,
                              'joins_class': SliceTags, 'join_class': SliceTag,
                              'secondary_key':'name'},
-                     Site: {'table_class' : Sites, 
+                     Site: {'table_class' : Sites,
                              'joins_class': SiteTags, 'join_class': SiteTag,
                              'secondary_key':'login_base'},
-                     Person: {'table_class' : Persons, 
+                     Person: {'table_class' : Persons,
                              'joins_class': PersonTags, 'join_class': PersonTag,
                              'secondary_key':'email'},
 #                     Ilink : xxx
@@ -57,21 +57,21 @@ tech_roles = [ 'admin', 'pi', 'tech' ]
 # Set<classname><methodsuffix> (auth, id_or_name, value) -> None
 # value is always a string, no cast nor typecheck for now
 #
-# The expose_in_api flag tells whether this tag may be handled 
+# The expose_in_api flag tells whether this tag may be handled
 #   through the Add/Get/Update methods as a native field
 #
-# note: tag_min_role_id gets attached to the tagtype instance, 
+# note: tag_min_role_id gets attached to the tagtype instance,
 # while get_roles and set_roles get attached to the created methods
 # this might need a cleanup
-# 
-# in addition a convenience method like e.g. LocateNodeArch is defined 
+#
+# in addition a convenience method like e.g. LocateNodeArch is defined
 # in the Accessor class; its purpose is to retrieve the tag, or to create it if needed
 
-def define_accessors (module, objclass, methodsuffix, tagname, 
-                      category, description, 
-                      get_roles=['admin'], set_roles=['admin'], 
+def define_accessors (module, objclass, methodsuffix, tagname,
+                      category, description,
+                      get_roles=['admin'], set_roles=['admin'],
                       tag_min_role_id=10, expose_in_api = False):
-    
+
     if objclass not in taggable_classes:
         try:
             raise PLCInvalidArgument,"PLC.Accessors.Factory: unknown class %s"%objclass.__name__
@@ -95,7 +95,7 @@ def define_accessors (module, objclass, methodsuffix, tagname,
                       {"__doc__":"Accessor 'set' method designed for %s objects using tag %s"%\
                            (classname,tagname)})
 
-    # accepts 
+    # accepts
     get_accepts = [ Auth () ]
     primary_key=objclass.primary_key
     secondary_key = taggable_classes[objclass]['secondary_key']
@@ -117,7 +117,7 @@ def define_accessors (module, objclass, methodsuffix, tagname,
     setattr(set_class,'accepts',set_accepts)
     setattr(set_class,'returns', set_returns)
     setattr(set_class,'skip_typecheck',True)
-    
+
     table_class = taggable_classes[objclass]['table_class']
     joins_class = taggable_classes[objclass]['joins_class']
     join_class = taggable_classes[objclass]['join_class']
@@ -146,7 +146,7 @@ def define_accessors (module, objclass, methodsuffix, tagname,
             filter[secondary_key]=id_or_name
         joins = joins_class (self.api,filter,['value'])
         if not joins:
-            # xxx - we return None even if id_or_name is not valid 
+            # xxx - we return None even if id_or_name is not valid
             return None
         else:
             return joins[0]['value']
@@ -154,7 +154,7 @@ def define_accessors (module, objclass, methodsuffix, tagname,
     # attach it
     setattr (get_class,"call",get_call)
 
-    # body of the set method 
+    # body of the set method
     def set_call (self, auth, id_or_name, value):
         # locate the object
         if isinstance (id_or_name, int):
@@ -165,7 +165,7 @@ def define_accessors (module, objclass, methodsuffix, tagname,
         if not objs:
             raise PLCInvalidArgument, "Cannot set tag on %s %r"%(objclass.__name__,id_or_name)
         primary_id = objs[0][primary_key]
-                           
+
         # locate the tag, see above
         locator = getattr(Accessor,locator_name)
         tag_type_id = locator(AccessorSingleton(self.api))
@@ -215,4 +215,3 @@ def define_accessors (module, objclass, methodsuffix, tagname,
         methods=[]
     methods += [get_name,set_name]
     setattr(module,'methods',methods)
-
index 227b974..74bf0f7 100644 (file)
@@ -30,17 +30,17 @@ class AddressType(Row):
         }
 
     def validate_name(self, name):
-       # Make sure name is not blank
+        # Make sure name is not blank
         if not len(name):
             raise PLCInvalidArgument, "Address type must be specified"
-       
-       # Make sure address type does not already exist
-       conflicts = AddressTypes(self.api, [name])
-       for address_type_id in conflicts:
+
+        # Make sure address type does not already exist
+        conflicts = AddressTypes(self.api, [name])
+        for address_type_id in conflicts:
             if 'address_type_id' not in self or self['address_type_id'] != address_type_id:
-               raise PLCInvalidArgument, "Address type name already in use"
+                raise PLCInvalidArgument, "Address type name already in use"
 
-       return name
+        return name
 
 class AddressTypes(Table):
     """
@@ -48,7 +48,7 @@ class AddressTypes(Table):
     """
 
     def __init__(self, api, address_type_filter = None, columns = None):
-       Table.__init__(self, api, AddressType, columns)
+        Table.__init__(self, api, AddressType, columns)
 
         sql = "SELECT %s FROM address_types WHERE True" % \
               ", ".join(self.columns)
index ce5fdc7..8098ce0 100644 (file)
@@ -87,7 +87,7 @@ class Addresses(Table):
     """
 
     def __init__(self, api, address_filter = None, columns = None):
-       Table.__init__(self, api, Address, columns)
+        Table.__init__(self, api, Address, columns)
 
         sql = "SELECT %s FROM view_addresses WHERE True" % \
               ", ".join(self.columns)
index 08c9d2c..59908ce 100644 (file)
@@ -239,10 +239,10 @@ class BootAuth(Auth):
                     for interface in interfaces:
                         if interface['is_primary']:
                             break
-            
+
                 if not interface or not interface['is_primary']:
                     raise PLCAuthenticationFailure, "No primary network interface on record"
-            
+
                 if method.source is None:
                     raise PLCAuthenticationFailure, "Cannot determine IP address of requestor"
 
@@ -337,6 +337,6 @@ class PasswordAuth(Auth):
                 raise PLCAuthenticationFailure, "Password verification failed"
 
         if not set(person['roles']).intersection(method.roles):
-           raise PLCAuthenticationFailure, "Not allowed to call method"
+            raise PLCAuthenticationFailure, "Not allowed to call method"
 
         method.caller = person
index 952a2d5..416ca4d 100644 (file)
@@ -26,16 +26,16 @@ class BootState(Row):
         }
 
     def validate_boot_state(self, name):
-       # Make sure name is not blank
+        # Make sure name is not blank
         if not len(name):
             raise PLCInvalidArgument, "Boot state must be specified"
-       
-       # Make sure boot state does not alredy exist
-       conflicts = BootStates(self.api, [name])
+
+        # Make sure boot state does not alredy exist
+        conflicts = BootStates(self.api, [name])
         if conflicts:
             raise PLCInvalidArgument, "Boot state name already in use"
 
-       return name
+        return name
 
 class BootStates(Table):
     """
@@ -47,7 +47,7 @@ class BootStates(Table):
 
         sql = "SELECT %s FROM boot_states" % \
               ", ".join(BootState.fields)
-        
+
         if boot_states:
             sql += " WHERE boot_state IN (%s)" % ", ".join(map(api.db.quote, boot_states))
 
index 641908f..1db8b4a 100644 (file)
@@ -141,7 +141,7 @@ class ConfFiles(Table):
     """
 
     def __init__(self, api, conf_file_filter = None, columns = None):
-       Table.__init__(self, api, ConfFile, columns)
+        Table.__init__(self, api, ConfFile, columns)
 
         sql = "SELECT %s FROM view_conf_files WHERE True" % \
               ", ".join(self.columns)
index 7b430e7..15b89f8 100644 (file)
@@ -16,9 +16,9 @@ from PLC.Table import Row, Table
 
 class EventObject(Row):
     """
-    Representation of a row in the event_object table. 
+    Representation of a row in the event_object table.
     """
-    
+
     table_name = 'event_object'
     primary_key = 'event_id'
     fields = {
@@ -26,27 +26,27 @@ class EventObject(Row):
         'person_id': Parameter(int, "Identifier of person responsible for event, if any"),
         'node_id': Parameter(int, "Identifier of node responsible for event, if any"),
         'fault_code': Parameter(int, "Event fault code"),
-       'call_name': Parameter(str, "Call responsible for this event"),
-       'call': Parameter(str, "Call responsible for this event, including paramters"),
-       'message': Parameter(str, "High level description of this event"),
+        'call_name': Parameter(str, "Call responsible for this event"),
+        'call': Parameter(str, "Call responsible for this event, including paramters"),
+        'message': Parameter(str, "High level description of this event"),
         'runtime': Parameter(float, "Runtime of event"),
         'time': Parameter(int, "Date and time that the event took place, in seconds since UNIX epoch", ro = True),
         'object_id': Parameter(int, "ID of objects affected by this event"),
-       'object_type': Parameter(str, "What type of object is this event affecting")
-       }    
+        'object_type': Parameter(str, "What type of object is this event affecting")
+        }
 
 class EventObjects(Table):
     """
-    Representation of row(s) from the event_object table in the database. 
+    Representation of row(s) from the event_object table in the database.
     """
 
     def __init__(self, api, event_filter = None, columns = None):
         Table.__init__(self, api, EventObject, columns)
-       
-       sql = "SELECT %s FROM view_event_objects WHERE True" % \
+
+        sql = "SELECT %s FROM view_event_objects WHERE True" % \
             ", ".join(self.columns)
-        
-       if event_filter is not None:
+
+        if event_filter is not None:
             if isinstance(event_filter, (list, tuple, set)):
                 event_filter = Filter(EventObject.fields, {'event_id': event_filter})
                 sql += " AND (%s) %s" % event_filter.sql(api, "OR")
@@ -58,5 +58,5 @@ class EventObjects(Table):
                 sql += " AND (%s) %s" % event_filter.sql(api, "AND")
             else:
                 raise PLCInvalidArgument, "Wrong event object filter %r"%event_filter
-        
-       self.selectall(sql)
+
+        self.selectall(sql)
index e060949..b8ad6e8 100644 (file)
@@ -16,25 +16,25 @@ from PLC.Table import Row, Table
 
 class Event(Row):
     """
-    Representation of a row in the events table. 
+    Representation of a row in the events table.
     """
-    
+
     table_name = 'events'
     primary_key = 'event_id'
     fields = {
         'event_id': Parameter(int, "Event identifier"),
         'person_id': Parameter(int, "Identifier of person responsible for event, if any"),
         'node_id': Parameter(int, "Identifier of node responsible for event, if any"),
-       'auth_type': Parameter(int, "Type of auth used. i.e. AuthMethod"),
+        'auth_type': Parameter(int, "Type of auth used. i.e. AuthMethod"),
         'fault_code': Parameter(int, "Event fault code"),
-       'call_name': Parameter(str, "Call responsible for this event"),
-       'call': Parameter(str, "Call responsible for this event, including paramters"),
-       'message': Parameter(str, "High level description of this event"),
+        'call_name': Parameter(str, "Call responsible for this event"),
+        'call': Parameter(str, "Call responsible for this event, including paramters"),
+        'message': Parameter(str, "High level description of this event"),
         'runtime': Parameter(float, "Runtime of event"),
         'time': Parameter(int, "Date and time that the event took place, in seconds since UNIX epoch", ro = True),
         'object_ids': Parameter([int], "IDs of objects affected by this event"),
-       'object_types': Parameter([str], "What type of object were affected by this event")
-       }    
+        'object_types': Parameter([str], "What type of object were affected by this event")
+        }
 
     def add_object(self, object_type, object_id, commit = True):
         """
@@ -57,10 +57,10 @@ class Event(Row):
                 self.api.db.commit()
 
             self['object_ids'].append(object_id)
-    
+
 class Events(Table):
     """
-    Representation of row(s) from the events table in the database. 
+    Representation of row(s) from the events table in the database.
     """
 
     def __init__(self, api, event_filter = None, columns = None):
index 5d0d22d..15af715 100644 (file)
@@ -16,7 +16,7 @@ class Filter(Parameter, dict):
     """
     A type of parameter that represents a filter on one or more
     columns of a database table.
-    Special features provide support for negation, upper and lower bounds, 
+    Special features provide support for negation, upper and lower bounds,
     as well as sorting and clipping.
 
 
@@ -29,16 +29,16 @@ class Filter(Parameter, dict):
 
 
     filter should be a dictionary of field names and values
-    representing  the criteria for filtering. 
+    representing  the criteria for filtering.
     example : filter = { 'hostname' : '*.edu' , site_id : [34,54] }
 
 
-    Whether the filter represents an intersection (AND) or a union (OR) 
+    Whether the filter represents an intersection (AND) or a union (OR)
     of these criteria is determined as follows:
     * if the dictionnary has the '-AND' or the '-OR' key, this is chosen
-    * otherwise, the join_with argument, as provided to the sql method below, 
-      is expected to hold the 'AND' or 'OR' string 
-      this argument defaults to 'AND' and in most of the code, this default applies 
+    * otherwise, the join_with argument, as provided to the sql method below,
+      is expected to hold the 'AND' or 'OR' string
+      this argument defaults to 'AND' and in most of the code, this default applies
       as the join_with argument is left unspecified
 
 
@@ -63,32 +63,32 @@ class Filter(Parameter, dict):
     example :  filter = { '>time' : 1178531418 }
       in this example the integer value denotes a unix timestamp
 
-    * if a value is a sequence type, then it should represent 
+    * if a value is a sequence type, then it should represent
       a list of possible values for that field
     example : filter = { 'node_id' : [12,34,56] }
 
     * a (string) value containing either a * or a % character is
       treated as a (sql) pattern; * are replaced with % that is the
       SQL wildcard character.
-    example :  filter = { 'hostname' : '*.jp' } 
+    example :  filter = { 'hostname' : '*.jp' }
 
     * the filter's keys starting with '-' are special and relate to sorting and clipping
     * '-SORT' : a field name, or an ordered list of field names that are used for sorting
       these fields may start with + (default) or - for denoting increasing or decreasing order
     example : filter = { '-SORT' : [ '+node_id', '-hostname' ] }
     * '-OFFSET' : the number of first rows to be ommitted
-    * '-LIMIT' : the amount of rows to be returned 
+    * '-LIMIT' : the amount of rows to be returned
     example : filter = { '-OFFSET' : 100, '-LIMIT':25}
 
 
     Here are a few realistic examples
 
-    GetNodes ( { 'node_type' : 'regular' , 'hostname' : '*.edu' , 
+    GetNodes ( { 'node_type' : 'regular' , 'hostname' : '*.edu' ,
                  '-SORT' : 'hostname' , '-OFFSET' : 30 , '-LIMIT' : 25 } )
       would return regular (usual) nodes matching '*.edu' in alphabetical order from 31th to 55th
 
-    GetNodes ( { '~peer_id' : None } ) 
-      returns the foreign nodes - that have an integer peer_id 
+    GetNodes ( { '~peer_id' : None } )
+      returns the foreign nodes - that have an integer peer_id
 
     GetPersons ( { '|role_ids' : [ 20 , 40] } )
       would return all persons that have either pi (20) or tech (40) roles
@@ -110,7 +110,7 @@ class Filter(Parameter, dict):
         # Declare ourselves as a type of parameter that can take
         # either a value or a list of values for each of the specified
         # fields.
-        self.fields = dict ( [ ( field, Mixed (expected, [expected])) 
+        self.fields = dict ( [ ( field, Mixed (expected, [expected]))
                                  for (field,expected) in fields.iteritems() ] )
 
         # Null filter means no filter
@@ -121,10 +121,10 @@ class Filter(Parameter, dict):
         Returns a SQL conditional that represents this filter.
         """
 
-        if self.has_key('-AND'): 
+        if self.has_key('-AND'):
             del self['-AND']
             join_with='AND'
-        if self.has_key('-OR'): 
+        if self.has_key('-OR'):
             del self['-OR']
             join_with='OR'
 
@@ -138,20 +138,20 @@ class Filter(Parameter, dict):
         else:
             assert join_with in ("AND", "OR")
 
-        # init 
+        # init
         sorts = []
         clips = []
 
         for field, value in self.iteritems():
-           # handle negation, numeric comparisons
-           # simple, 1-depth only mechanism
+            # handle negation, numeric comparisons
+            # simple, 1-depth only mechanism
 
-           modifiers={'~' : False, 
-                      '<' : False, '>' : False,
-                      '[' : False, ']' : False,
+            modifiers={'~' : False,
+                       '<' : False, '>' : False,
+                       '[' : False, ']' : False,
                        '-' : False,
                        '&' : False, '|' : False,
-                      }
+                       }
             def check_modifiers(field):
                 if field[0] in modifiers.keys():
                     modifiers[field[0]] = True
@@ -199,7 +199,7 @@ class Filter(Parameter, dict):
                 if isinstance(value, (list, tuple, set)):
                     # handling filters like '~slice_id':[]
                     # this should return true, as it's the opposite of 'slice_id':[] which is false
-                    # prior to this fix, 'slice_id':[] would have returned ``slice_id IN (NULL) '' which is unknown 
+                    # prior to this fix, 'slice_id':[] would have returned ``slice_id IN (NULL) '' which is unknown
                     # so it worked by coincidence, but the negation '~slice_ids':[] would return false too
                     if not value:
                         if modifiers['&'] or modifiers['|']:
index de9cd75..3323dcd 100644 (file)
@@ -31,16 +31,16 @@ class InitScript(Row):
         }
 
     def validate_name(self, name):
-       """ 
-       validates the script name 
-       """
-       
-       conflicts = InitScripts(self.api, [name])
-       for initscript in conflicts:
-           if 'initscript_id' not in self or self['initscript_id'] != initscript['initscript_id']:
-               raise PLCInvalidArgument, "Initscript name already in use"
+        """
+        validates the script name
+        """
 
-       return name
+        conflicts = InitScripts(self.api, [name])
+        for initscript in conflicts:
+            if 'initscript_id' not in self or self['initscript_id'] != initscript['initscript_id']:
+                raise PLCInvalidArgument, "Initscript name already in use"
+
+        return name
 
 
 class InitScripts(Table):
@@ -49,20 +49,20 @@ class InitScripts(Table):
     """
 
     def __init__(self, api, initscript_filter = None, columns = None):
-       Table.__init__(self, api, InitScript, columns)
+        Table.__init__(self, api, InitScript, columns)
 
         sql = "SELECT %s FROM initscripts WHERE True" % \
               ", ".join(self.columns)
 
         if initscript_filter is not None:
             if isinstance(initscript_filter, (list, tuple, set)):
-               # Separate the list into integers and strings
+                # Separate the list into integers and strings
                 ints = filter(lambda x: isinstance(x, (int, long)), initscript_filter)
                 strs = filter(lambda x: isinstance(x, StringTypes), initscript_filter)
                 initscript_filter = Filter(InitScript.fields, {'initscript_id': ints, 'name': strs })
-               sql += " AND (%s) %s" % initscript_filter.sql(api, "OR")
+                sql += " AND (%s) %s" % initscript_filter.sql(api, "OR")
             elif isinstance(initscript_filter, dict):
                 initscript_filter = Filter(InitScript.fields, initscript_filter)
-               sql += " AND (%s) %s" % initscript_filter.sql(api, "AND")
+                sql += " AND (%s) %s" % initscript_filter.sql(api, "AND")
 
         self.selectall(sql)
index 1993256..87e2226 100644 (file)
@@ -30,8 +30,8 @@ class InterfaceTag(Row):
         'category': TagType.fields['category'],
         'min_role_id': TagType.fields['min_role_id'],
         'value': Parameter(str, "Interface setting value"),
-       ### relations
-       
+        ### relations
+
         }
 
 class InterfaceTags(Table):
index bd933cd..46b6f40 100644 (file)
@@ -76,13 +76,13 @@ class Interface(Row):
         network_methods = [row['method'] for row in NetworkMethods(self.api)]
         if method not in network_methods:
             raise PLCInvalidArgument, "Invalid addressing method %s"%method
-       return method
+        return method
 
     def validate_type(self, type):
         network_types = [row['type'] for row in NetworkTypes(self.api)]
         if type not in network_types:
             raise PLCInvalidArgument, "Invalid address type %s"%type
-       return type
+        return type
 
     def validate_ip(self, ip):
         if ip and not valid_ip(ip):
@@ -116,13 +116,13 @@ class Interface(Row):
     validate_dns2 = validate_ip
 
     def validate_bwlimit(self, bwlimit):
-       if not bwlimit:
-           return bwlimit
+        if not bwlimit:
+            return bwlimit
 
-       if bwlimit < 500000:
-           raise PLCInvalidArgument, 'Minimum bw is 500 kbs'
+        if bwlimit < 500000:
+            raise PLCInvalidArgument, 'Minimum bw is 500 kbs'
 
-       return bwlimit  
+        return bwlimit
 
     def validate_hostname(self, hostname):
         # Optional
@@ -224,7 +224,7 @@ class Interfaces(Table):
         for tagname in self.tag_columns:
             view= "%s left join %s using (%s)"%(view,Interface.tagvalue_view_name(tagname),
                                                 Interface.primary_key)
-            
+
         sql = "SELECT %s FROM %s WHERE True" % \
             (", ".join(self.columns.keys()+self.tag_columns.keys()),view)
 
index e491b45..1fae01b 100644 (file)
@@ -26,17 +26,17 @@ class KeyType(Row):
         }
 
     def validate_key_type(self, name):
-       # Make sure name is not blank
+        # Make sure name is not blank
         if not len(name):
             raise PLCInvalidArgument, "Key type must be specified"
-       
-       # Make sure key type does not alredy exist
-       conflicts = KeyTypes(self.api, [name])
+
+        # Make sure key type does not alredy exist
+        conflicts = KeyTypes(self.api, [name])
         if conflicts:
             raise PLCInvalidArgument, "Key type name already in use"
 
-       return name
-        
+        return name
+
 class KeyTypes(Table):
     """
     Representation of the key_types table in the database.
@@ -47,7 +47,7 @@ class KeyTypes(Table):
 
         sql = "SELECT %s FROM key_types" % \
               ", ".join(KeyType.fields)
-        
+
         if key_types:
             sql += " WHERE key_type IN (%s)" % ", ".join(map(api.db.quote, key_types))
 
index d8e54e6..5318966 100644 (file)
@@ -11,8 +11,8 @@ from PLC.KeyTypes import KeyType, KeyTypes
 
 class Key(Row):
     """
-    Representation of a row in the keys table. To use, instantiate with a 
-    dict of values. Update as you would a dict. Commit to the database 
+    Representation of a row in the keys table. To use, instantiate with a
+    dict of values. Update as you would a dict. Commit to the database
     with sync().
     """
 
@@ -32,18 +32,18 @@ class Key(Row):
         key_types = [row['key_type'] for row in KeyTypes(self.api)]
         if key_type not in key_types:
             raise PLCInvalidArgument, "Invalid key type"
-       return key_type
+        return key_type
 
     def validate_key(self, key):
-       # Key must not be blacklisted
-       rows = self.api.db.selectall("SELECT 1 from keys" \
-                                    " WHERE key = %(key)s" \
+        # Key must not be blacklisted
+        rows = self.api.db.selectall("SELECT 1 from keys" \
+                                     " WHERE key = %(key)s" \
                                      " AND is_blacklisted IS True",
                                      locals())
-       if rows:
+        if rows:
             raise PLCInvalidArgument, "Key is blacklisted and cannot be used"
 
-       return key
+        return key
 
     def validate(self):
         # Basic validation
@@ -69,13 +69,13 @@ class Key(Row):
 
     def blacklist(self, commit = True):
         """
-       Permanently blacklist key (and all other identical keys),
-       preventing it from ever being added again. Because this could
-       affect multiple keys associated with multiple accounts, it
-       should be admin only.        
-       """
+        Permanently blacklist key (and all other identical keys),
+        preventing it from ever being added again. Because this could
+        affect multiple keys associated with multiple accounts, it
+        should be admin only.
+        """
 
-       assert 'key_id' in self
+        assert 'key_id' in self
         assert 'key' in self
 
         # Get all matching keys
@@ -89,7 +89,7 @@ class Key(Row):
         self.api.db.do("UPDATE keys SET is_blacklisted = True" \
                        " WHERE key_id IN (%s)" % ", ".join(map(str, key_ids)))
 
-       # But disassociate them from all join tables
+        # But disassociate them from all join tables
         for table in self.join_tables:
             self.api.db.do("DELETE FROM %s WHERE key_id IN (%s)" % \
                            (table, ", ".join(map(str, key_ids))))
@@ -105,8 +105,8 @@ class Keys(Table):
 
     def __init__(self, api, key_filter = None, columns = None):
         Table.__init__(self, api, Key, columns)
-       
-       sql = "SELECT %s FROM view_keys WHERE is_blacklisted IS False" % \
+
+        sql = "SELECT %s FROM view_keys WHERE is_blacklisted IS False" % \
               ", ".join(self.columns)
 
         if key_filter is not None:
@@ -116,4 +116,4 @@ class Keys(Table):
                 key_filter = Filter(Key.fields, key_filter)
             sql += " AND (%s) %s" % key_filter.sql(api)
 
-       self.selectall(sql)
+        self.selectall(sql)
index 0d13f9e..9a8d0b3 100644 (file)
@@ -4,7 +4,7 @@
 # Thierry Parmentelat -- INRIA
 #
 # Utilities for filtering on leases
-# 
+#
 
 from types import StringTypes
 from PLC.Faults import *
@@ -14,7 +14,7 @@ from PLC.Timestamp import Timestamp
 
 # supersede the generic Filter class to support time intersection
 class LeaseFilter (Filter):
-    
+
     # general notes on input parameters
     # int_timestamp: number of seconds since the epoch
     # str_timestamp: see Timestamp.sql_validate
@@ -28,12 +28,12 @@ class LeaseFilter (Filter):
                                       Parameter (tuple,"timeslot: the leases alive during this timeslot")),
                      }
 
-    def __init__(self, fields = {}, filter = {}, 
+    def __init__(self, fields = {}, filter = {},
                  doc = "Lease filter -- adds the 'alive' and 'clip' capabilities for filtering on leases"):
         Filter.__init__(self,fields,filter,doc)
-        self.fields.update (LeaseFilter.local_fields) 
+        self.fields.update (LeaseFilter.local_fields)
+
 
-    
     ## canonical type
     @staticmethod
     def quote (timestamp): return Timestamp.cast_long(timestamp)
@@ -116,10 +116,10 @@ class LeaseFilter (Filter):
         return (where_part,clip_part)
 
 ######## xxx not sure where this belongs yet
-# given a set of nodes, and a timeslot, 
+# given a set of nodes, and a timeslot,
 # returns the available leases that have at least a given duration
 def free_leases (api, node_ids, t_from, t_until, min_duration):
-    
+
     # get the leases for these nodes and timeslot
     filter = {'node_id':node_ids,
               'clip': (t_from, t_until),
@@ -170,5 +170,3 @@ def node_free_leases (node_id, node_leases, t_from, t_until):
             result.append( {'node_id':node_id,'t_from':current_time,'t_until':next_time})
             current_time = next_time
             is_on=True
-
-
index cb8eed6..4b967c6 100644 (file)
@@ -58,10 +58,10 @@ class Lease(Row):
         # return a SQL string
         return Timestamp.sql_validate_utc(timestamp)
 
-    # round UP 
+    # round UP
     def validate_t_from(self,timestamp):
         return self.validate_time (timestamp, round_up=True)
-    # round DOWN 
+    # round DOWN
     def validate_t_until (self, timestamp):
         return self.validate_time (timestamp, round_up=False)
 
index 4c7299e..dfc1c9f 100644 (file)
@@ -14,9 +14,9 @@ from PLC.Filter import Filter
 
 class Message(Row):
     """
-    Representation of a row in the messages table. 
+    Representation of a row in the messages table.
     """
-    
+
     table_name = 'messages'
     primary_key = 'message_id'
     fields = {
@@ -25,15 +25,15 @@ class Message(Row):
         'template': Parameter(str, "Message template", nullok = True),
         'enabled': Parameter(bool, "Message is enabled"),
         }
-    
+
 class Messages(Table):
     """
-    Representation of row(s) from the messages table in the database. 
+    Representation of row(s) from the messages table in the database.
     """
 
     def __init__(self, api, message_filter = None, columns = None, enabled = None):
         Table.__init__(self, api, Message, columns)
-    
+
         sql = "SELECT %s from messages WHERE True" % \
               ", ".join(self.columns)
 
index ed03974..352640f 100644 (file)
@@ -73,7 +73,7 @@ class Method (object):
 
         # API may set this to a (addr, port) tuple if known
         self.source = None
-       
+
     def __call__(self, *args, **kwds):
         """
         Main entry point for all PLCAPI functions. Type checks
@@ -81,53 +81,53 @@ class Method (object):
         """
 
         try:
-           start = time.time()
+            start = time.time()
 
             # legacy code cannot be type-checked, due to the way Method.args() works
             if not hasattr(self,"skip_typecheck"):
                 (min_args, max_args, defaults) = self.args()
-                               
+
                 # Check that the right number of arguments were passed in
                 if len(args) < len(min_args) or len(args) > len(max_args):
                     raise PLCInvalidArgumentCount(len(args), len(min_args), len(max_args))
 
                 for name, value, expected in zip(max_args, args, self.accepts):
                     self.type_check(name, value, expected, args)
-       
-           result = self.call(*args, **kwds)
-           runtime = time.time() - start
-       
+
+            result = self.call(*args, **kwds)
+            runtime = time.time() - start
+
             if self.api.config.PLC_API_DEBUG or hasattr(self, 'message'):
-               self.log(None, runtime, *args)
-               
-           return result
+                self.log(None, runtime, *args)
+
+            return result
 
         except PLCFault, fault:
-       
-           caller = ""
-           if isinstance(self.caller, Person):
-               caller = 'person_id %s'  % self.caller['person_id']
+
+            caller = ""
+            if isinstance(self.caller, Person):
+                caller = 'person_id %s'  % self.caller['person_id']
             elif isinstance(self.caller, Node):
                 caller = 'node_id %s'  % self.caller['node_id']
 
             # Prepend caller and method name to expected faults
             fault.faultString = caller + ": " +  self.name + ": " + fault.faultString
-           runtime = time.time() - start
-           
-           if self.api.config.PLC_API_DEBUG:
-               self.log(fault, runtime, *args)
-            
-           raise fault
+            runtime = time.time() - start
+
+            if self.api.config.PLC_API_DEBUG:
+                self.log(fault, runtime, *args)
+
+            raise fault
 
     def log(self, fault, runtime, *args):
         """
-        Log the transaction 
-        """    
+        Log the transaction
+        """
 
-       # Do not log system or Get calls
+        # Do not log system or Get calls
         #if self.name.startswith('system') or self.name.startswith('Get'):
         #    return False
-        # Do not log ReportRunlevel 
+        # Do not log ReportRunlevel
         if self.name.startswith('system'):
             return False
         if self.name.startswith('ReportRunlevel'):
@@ -135,8 +135,8 @@ class Method (object):
 
         # Create a new event
         event = Event(self.api)
-       event['fault_code'] = 0
-       if fault:
+        event['fault_code'] = 0
+        if fault:
             event['fault_code'] = fault.faultCode
         event['runtime'] = runtime
 
@@ -163,7 +163,7 @@ class Method (object):
         # Log call representation
         # XXX Truncate to avoid DoS
         event['call'] = self.name + pprint.saferepr(newargs)
-       event['call_name'] = self.name
+        event['call_name'] = self.name
 
         # Both users and nodes can call some methods
         if isinstance(self.caller, Person):
@@ -175,16 +175,16 @@ class Method (object):
 
         if hasattr(self, 'event_objects') and isinstance(self.event_objects, dict):
             for key in self.event_objects.keys():
-               for object_id in self.event_objects[key]:
+                for object_id in self.event_objects[key]:
                     event.add_object(key, object_id, commit = False)
-       
-
-       # Set the message for this event
-       if fault:
-           event['message'] = fault.faultString
-       elif hasattr(self, 'message'):
-            event['message'] = self.message    
-       
+
+
+        # Set the message for this event
+        if fault:
+            event['message'] = fault.faultString
+        elif hasattr(self, 'message'):
+            event['message'] = self.message
+
         # Commit
         event.sync()
 
@@ -269,7 +269,7 @@ class Method (object):
         That represents the minimum and maximum sets of arguments that
         this function accepts and the defaults for the optional arguments.
         """
-        
+
         # Inspect call. Remove self from the argument list.
         max_args = self.call.func_code.co_varnames[1:self.call.func_code.co_argcount]
         defaults = self.call.func_defaults
@@ -278,7 +278,7 @@ class Method (object):
 
         min_args = max_args[0:len(max_args) - len(defaults)]
         defaults = tuple([None for arg in min_args]) + defaults
-        
+
         return (min_args, max_args, defaults)
 
     def type_check(self, name, value, expected, args):
@@ -287,7 +287,7 @@ class Method (object):
         which may be a Python type, a typed value, a Parameter, a
         Mixed type, or a list or dictionary of possibly mixed types,
         values, Parameters, or Mixed types.
-        
+
         Extraneous members of lists must be of the same type as the
         last specified type. For example, if the expected argument
         type is [int, bool], then [1, False] and [14, True, False,
index ae88e58..7ad23db 100644 (file)
@@ -26,13 +26,13 @@ class AddAddressType(Method):
         ]
 
     returns = Parameter(int, 'New address_type_id (> 0) if successful')
-        
+
 
     def call(self, auth, address_type_fields):
         address_type_fields = dict(filter(can_update, address_type_fields.items()))
         address_type = AddressType(self.api, address_type_fields)
         address_type.sync()
 
-       self.event_objects = {'AddressType' : [address_type['address_type_id']]}
-        
-       return address_type['address_type_id']
+        self.event_objects = {'AddressType' : [address_type['address_type_id']]}
+
+        return address_type['address_type_id']
index 2278110..b6d5392 100644 (file)
@@ -29,7 +29,7 @@ class AddAddressTypeToAddress(Method):
 
 
     def call(self, auth, address_type_id_or_name, address_id):
-       address_types = AddressTypes(self.api, [address_type_id_or_name])
+        address_types = AddressTypes(self.api, [address_type_id_or_name])
         if not address_types:
             raise PLCInvalidArgument, "No such address type"
         address_type = address_types[0]
@@ -44,6 +44,6 @@ class AddAddressTypeToAddress(Method):
                 raise PLCPermissionDenied, "Address must be associated with one of your sites"
 
         address.add_address_type(address_type)
-       self.event_objects = {'Address': [address['address_id']]}
+        self.event_objects = {'Address': [address['address_id']]}
 
         return 1
index 061edd4..3e11087 100644 (file)
@@ -22,7 +22,7 @@ class AddBootState(Method):
 
     returns = Parameter(int, '1 if successful')
 
-    
+
     def call(self, auth, name):
         boot_state = BootState(self.api)
         boot_state['boot_state'] = name
index f2a300d..bb11282 100644 (file)
@@ -34,6 +34,6 @@ class AddConfFile(Method):
         conf_file = ConfFile(self.api, conf_file_fields)
         conf_file.sync()
 
-       self.event_objects = {'ConfFile': [conf_file['conf_file_id']]}
+        self.event_objects = {'ConfFile': [conf_file['conf_file_id']]}
 
         return conf_file['conf_file_id']
index e592916..d7292a8 100644 (file)
@@ -27,27 +27,27 @@ class AddConfFileToNode(Method):
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth, conf_file_id, node_id_or_hostname):
-       # Get configuration file
+        # Get configuration file
         conf_files = ConfFiles(self.api, [conf_file_id])
         if not conf_files:
             raise PLCInvalidArgument, "No such configuration file"
         conf_file = conf_files[0]
 
         # Get node
-       nodes = Nodes(self.api, [node_id_or_hostname])
-       if not nodes:
-               raise PLCInvalidArgument, "No such node"
-       node = nodes[0]
+        nodes = Nodes(self.api, [node_id_or_hostname])
+        if not nodes:
+            raise PLCInvalidArgument, "No such node"
+        node = nodes[0]
 
         if node['peer_id'] is not None:
             raise PLCInvalidArgument, "Not a local node"
-       
-       # Link configuration file to node
+
+        # Link configuration file to node
         if node['node_id'] not in conf_file['node_ids']:
             conf_file.add_node(node)
 
         # Log affected objects
-        self.event_objects = {'ConfFile': [conf_file_id], 
-                             'Node': [node['node_id']] }
+        self.event_objects = {'ConfFile': [conf_file_id],
+                              'Node': [node['node_id']] }
 
         return 1
index f9166ad..cdcec88 100644 (file)
@@ -29,24 +29,24 @@ class AddConfFileToNodeGroup(Method):
 
 
     def call(self, auth, conf_file_id, nodegroup_id_or_name):
-       # Get configuration file
+        # Get configuration file
         conf_files = ConfFiles(self.api, [conf_file_id])
         if not conf_files:
             raise PLCInvalidArgument, "No such configuration file"
         conf_file = conf_files[0]
 
         # Get node
-       nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
-       if not nodegroups:
+        nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
+        if not nodegroups:
             raise PLCInvalidArgument, "No such node group"
-       nodegroup = nodegroups[0]
-       
-       # Link configuration file to node
+        nodegroup = nodegroups[0]
+
+        # Link configuration file to node
         if nodegroup['nodegroup_id'] not in conf_file['nodegroup_ids']:
             conf_file.add_nodegroup(nodegroup)
 
         # Log affected objects
-        self.event_objects = {'ConfFile': [conf_file_id], 
-                             'NodeGroup': [nodegroup['nodegroup_id']] }
+        self.event_objects = {'ConfFile': [conf_file_id],
+                              'NodeGroup': [nodegroup['nodegroup_id']] }
 
         return 1
index d132561..6316805 100644 (file)
@@ -20,7 +20,7 @@ class AddIlink(Method):
     """
     Create a link between two interfaces
     The link has a tag type, that needs be created beforehand
-    and an optional value. 
+    and an optional value.
 
     Returns the new ilink_id (> 0) if successful, faults
     otherwise.
@@ -54,7 +54,7 @@ class AddIlink(Method):
             raise PLCInvalidArgument, "AddIlink: No such tag type %r"%tag_type_id_or_name
         tag_type = tag_types[0]
 
-       # checks for existence - with the same type
+        # checks for existence - with the same type
         conflicts = Ilinks(self.api,
                            {'tag_type_id':tag_type['tag_type_id'],
                             'src_interface_id':src_if_id,
@@ -65,20 +65,20 @@ class AddIlink(Method):
             raise PLCInvalidArgument, "Ilink (%s,%d,%d) already exists and has value %r"\
                 %(tag_type['name'],src_if_id,dst_if_id,ilink['value'])
 
-       if 'admin' not in self.caller['roles']:
-#      # check permission : it not admin, is the user affiliated with the right site(s) ????
-#          # locate node
-#          node = Nodes (self.api,[node['node_id']])[0]
-#          # locate site
-#          site = Sites (self.api, [node['site_id']])[0]
-#          # check caller is affiliated with this site
-#          if self.caller['person_id'] not in site['person_ids']:
-#              raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified ilink, requires role %d",required_min_role
+        if 'admin' not in self.caller['roles']:
+#       # check permission : it not admin, is the user affiliated with the right site(s) ????
+#           # locate node
+#           node = Nodes (self.api,[node['node_id']])[0]
+#           # locate site
+#           site = Sites (self.api, [node['site_id']])[0]
+#           # check caller is affiliated with this site
+#           if self.caller['person_id'] not in site['person_ids']:
+#               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified ilink, requires role %d",required_min_role
 
         ilink = Ilink(self.api)
         ilink['tag_type_id'] = tag_type['tag_type_id']
@@ -89,6 +89,6 @@ class AddIlink(Method):
         ilink.sync()
 
         self.object_type = 'Interface'
-       self.object_ids = [src_if_id,dst_if_id]
+        self.object_ids = [src_if_id,dst_if_id]
 
         return ilink['ilink_id']
index ed3efac..850b4f4 100644 (file)
@@ -34,6 +34,6 @@ class AddInitScript(Method):
         initscript = InitScript(self.api, initscript_fields)
         initscript.sync()
 
-       self.event_objects = {'InitScript': [initscript['initscript_id']]}
+        self.event_objects = {'InitScript': [initscript['initscript_id']]}
 
         return initscript['initscript_id']
index 1b97fc3..e98d545 100644 (file)
@@ -20,7 +20,7 @@ class AddInterface(Method):
 
     Adds a new network for a node. Any values specified in
     interface_fields are used, otherwise defaults are
-    used. 
+    used.
 
     If type is static, then ip, gateway, network, broadcast, netmask,
     and dns1 must all be specified in interface_fields. If type is
@@ -46,7 +46,7 @@ class AddInterface(Method):
 
     returns = Parameter(int, 'New interface_id (> 0) if successful')
 
-    
+
     def call(self, auth, node_id_or_hostname, interface_fields):
 
         [native,tags,rejected]=Row.split_fields(interface_fields,[Interface.fields,Interface.tags])
@@ -60,7 +60,7 @@ class AddInterface(Method):
         nodes = Nodes(self.api, [node_id_or_hostname])
         if not nodes:
             raise PLCInvalidArgument, "No such node %r"%node_id_or_hostname
-       node = nodes[0]
+        node = nodes[0]
 
         # Authenticated function
         assert self.caller is not None
@@ -72,17 +72,17 @@ class AddInterface(Method):
                 raise PLCPermissionDenied, "Not allowed to add an interface to the specified node"
 
         # Add interface
-       interface = Interface(self.api, native)
+        interface = Interface(self.api, native)
         interface['node_id'] = node['node_id']
-       # if this is the first interface, make it primary
-       if not node['interface_ids']:
-               interface['is_primary'] = True
+        # if this is the first interface, make it primary
+        if not node['interface_ids']:
+            interface['is_primary'] = True
         interface.sync()
-       
-       # Logging variables
-       self.event_objects = { 'Node': [node['node_id']], 
+
+        # Logging variables
+        self.event_objects = { 'Node': [node['node_id']],
                                'Interface' : [interface['interface_id']] }
-       self.message = "Interface %d added" % interface['interface_id']
+        self.message = "Interface %d added" % interface['interface_id']
 
         for (tagname,value) in tags.iteritems():
             # the tagtype instance is assumed to exist, just check that
index 9b87e8f..23aaeaf 100644 (file)
@@ -56,7 +56,7 @@ class AddInterfaceTag(Method):
             raise PLCInvalidArgument, "No such tag type %r"%tag_type_id_or_name
         tag_type = tag_types[0]
 
-       # checks for existence - does not allow several different settings
+        # checks for existence - does not allow several different settings
         conflicts = InterfaceTags(self.api,
                                         {'interface_id':interface['interface_id'],
                                          'tag_type_id':tag_type['tag_type_id']})
@@ -65,20 +65,20 @@ class AddInterfaceTag(Method):
             raise PLCInvalidArgument, "Interface %d already has setting %d"%(interface['interface_id'],
                                                                                tag_type['tag_type_id'])
 
-       # check permission : it not admin, is the user affiliated with the right site
-       if 'admin' not in self.caller['roles']:
-           # locate node
-           node = Nodes (self.api,[interface['node_id']])[0]
-           # locate site
-           site = Sites (self.api, [node['site_id']])[0]
-           # check caller is affiliated with this site
-           if self.caller['person_id'] not in site['person_ids']:
-               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified interface setting, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the right site
+        if 'admin' not in self.caller['roles']:
+            # locate node
+            node = Nodes (self.api,[interface['node_id']])[0]
+            # locate site
+            site = Sites (self.api, [node['site_id']])[0]
+            # check caller is affiliated with this site
+            if self.caller['person_id'] not in site['person_ids']:
+                raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified interface setting, requires role %d",required_min_role
 
         interface_tag = InterfaceTag(self.api)
         interface_tag['interface_id'] = interface['interface_id']
@@ -86,6 +86,6 @@ class AddInterfaceTag(Method):
         interface_tag['value'] = value
 
         interface_tag.sync()
-       self.object_ids = [interface_tag['interface_tag_id']]
+        self.object_ids = [interface_tag['interface_tag_id']]
 
         return interface_tag['interface_tag_id']
index ea2f3ca..9450365 100644 (file)
@@ -17,12 +17,12 @@ can_update = ['name', 'instantiation', 'url', 'description', 'max_nodes']
 
 class AddLeases(Method):
     """
-    Adds a new lease. 
+    Adds a new lease.
     Mandatory arguments are node(s), slice, t_from and t_until
     times can be either integers, datetime's, or human readable (see Timestamp)
 
     PIs may only add leases associated with their own sites (i.e.,
-    to a slice that belongs to their site). 
+    to a slice that belongs to their site).
     Users may only add leases associated with their own slices.
 
     Returns the new lease_ids if successful, faults otherwise.
@@ -32,7 +32,7 @@ class AddLeases(Method):
 
     accepts = [
         Auth(),
-       Mixed(Node.fields['node_id'],[Node.fields['node_id']],
+        Mixed(Node.fields['node_id'],[Node.fields['node_id']],
               Node.fields['hostname'],[Node.fields['hostname']],),
         Mixed(Slice.fields['slice_id'],
               Slice.fields['name']),
@@ -92,7 +92,7 @@ class AddLeases(Method):
                 nodes.remove(node)
 
         self.event_objects = {'Slice': [slice['slice_id']],
-                              'Node': [node['node_id'] for node in nodes]}     
+                              'Node': [node['node_id'] for node in nodes]}
         self.message = "New leases %r on n=%r s=%s [%s -> %s]" % \
             (result_ids,[node['hostname'] for node in nodes],slice['name'],t_from,t_until)
 
index f2ff661..a1e8337 100644 (file)
@@ -76,7 +76,7 @@ class AddNode(Method):
         # since hostname was specified lets add the 'hrn' node tag
         root_auth = self.api.config.PLC_HRN_ROOT
         login_base = site['login_base']
-        tags['hrn'] = hostname_to_hrn(root_auth, login_base, node['hostname'])        
+        tags['hrn'] = hostname_to_hrn(root_auth, login_base, node['hostname'])
 
         for (tagname,value) in tags.iteritems():
             # the tagtype instance is assumed to exist, just check that
@@ -89,7 +89,7 @@ class AddNode(Method):
                 UpdateNodeTag(self.api).__call__(auth,node_tags[0]['node_tag_id'],value)
 
         self.event_objects = {'Site': [site['site_id']],
-                              'Node': [node['node_id']]}       
+                              'Node': [node['node_id']]}
         self.message = "Node %d=%s created" % (node['node_id'],node['hostname'])
-        
+
         return node['node_id']
index 88210c1..c84d9c6 100644 (file)
@@ -47,8 +47,8 @@ class AddNodeGroup(Method):
         nodegroup = NodeGroup(self.api, nodegroup_fields)
         nodegroup.sync()
 
-       # Logging variables
-       self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
-       self.message = 'Node group %d created' % nodegroup['nodegroup_id']
+        # Logging variables
+        self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
+        self.message = 'Node group %d created' % nodegroup['nodegroup_id']
+
         return nodegroup['nodegroup_id']
index 81e46c0..f02181b 100644 (file)
@@ -56,7 +56,7 @@ class AddNodeTag(Method):
             raise PLCInvalidArgument, "No such node tag type %r"%tag_type_id_or_name
         tag_type = tag_types[0]
 
-       # checks for existence - does not allow several different tags
+        # checks for existence - does not allow several different tags
         conflicts = NodeTags(self.api,
                                         {'node_id':node['node_id'],
                                          'tag_type_id':tag_type['tag_type_id']})
@@ -65,20 +65,20 @@ class AddNodeTag(Method):
             raise PLCInvalidArgument, "Node %d already has tag %d"%(node['node_id'],
                                                                                tag_type['tag_type_id'])
 
-       # check permission : it not admin, is the user affiliated with the right site
-       if 'admin' not in self.caller['roles']:
-           # locate node
-           node = Nodes (self.api,[node['node_id']])[0]
-           # locate site
-           site = Sites (self.api, [node['site_id']])[0]
-           # check caller is affiliated with this site
-           if self.caller['person_id'] not in site['person_ids']:
-               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified node tag, requires role %d"%required_min_role
+        # check permission : it not admin, is the user affiliated with the right site
+        if 'admin' not in self.caller['roles']:
+            # locate node
+            node = Nodes (self.api,[node['node_id']])[0]
+            # locate site
+            site = Sites (self.api, [node['site_id']])[0]
+            # check caller is affiliated with this site
+            if self.caller['person_id'] not in site['person_ids']:
+                raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified node tag, requires role %d"%required_min_role
 
         node_tag = NodeTag(self.api)
         node_tag['node_id'] = node['node_id']
@@ -86,6 +86,6 @@ class AddNodeTag(Method):
         node_tag['value'] = value
 
         node_tag.sync()
-       self.object_ids = [node_tag['node_tag_id']]
+        self.object_ids = [node_tag['node_tag_id']]
 
         return node_tag['node_tag_id']
index 279731d..7f9daeb 100644 (file)
@@ -22,7 +22,7 @@ class AddNodeToPCU(Method):
 
     accepts = [
         Auth(),
-       Mixed(Node.fields['node_id'],
+        Mixed(Node.fields['node_id'],
               Node.fields['hostname']),
         PCU.fields['pcu_id'],
         Parameter(int, 'PCU port number')
@@ -31,7 +31,7 @@ class AddNodeToPCU(Method):
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth, node_id_or_hostname, pcu_id, port):
-        # Get node
+         # Get node
         nodes = Nodes(self.api, [node_id_or_hostname])
         if not nodes:
             raise PLCInvalidArgument, "No such node"
@@ -55,8 +55,8 @@ class AddNodeToPCU(Method):
                     break
             if not ok:
                 raise PLCPermissionDenied, "Not allowed to update that PCU"
-       
-       # Add node to PCU
+
+        # Add node to PCU
         if node['node_id'] in pcu['node_ids']:
             raise PLCInvalidArgument, "Node already controlled by PCU"
 
@@ -68,9 +68,9 @@ class AddNodeToPCU(Method):
 
         pcu.add_node(node, port)
 
-       # Logging variables
-       self.event_objects = {'Node': [node['node_id']],
-                             'PCU': [pcu['pcu_id']]}
-       self.message = 'Node %d added to pcu %d on port %d' % \
-               (node['node_id'], pcu['pcu_id'], port)
+        # Logging variables
+        self.event_objects = {'Node': [node['node_id']],
+                              'PCU': [pcu['pcu_id']]}
+        self.message = 'Node %d added to pcu %d on port %d' % \
+                (node['node_id'], pcu['pcu_id'], port)
         return 1
index 034ed41..b390c6e 100644 (file)
@@ -22,7 +22,7 @@ class AddNodeType(Method):
 
     returns = Parameter(int, '1 if successful')
 
-    
+
     def call(self, auth, name):
         node_type = NodeType(self.api)
         node_type['node_type'] = name
index 9def186..02fb296 100644 (file)
@@ -35,7 +35,7 @@ class AddPCU(Method):
         ]
 
     returns = Parameter(int, 'New pcu_id (> 0) if successful')
-    
+
 
     def call(self, auth, site_id_or_login_base, pcu_fields):
         pcu_fields = dict(filter(can_update, pcu_fields.items()))
@@ -54,10 +54,10 @@ class AddPCU(Method):
         pcu['site_id'] = site['site_id']
         pcu.sync()
 
-       # Logging variables
-       self.event_objects = {'Site': [site['site_id']],
-                             'PCU': [pcu['pcu_id']]}
-       self.message = 'PCU %d added site %s' % \
-               (pcu['pcu_id'], site['site_id'])
+        # Logging variables
+        self.event_objects = {'Site': [site['site_id']],
+                              'PCU': [pcu['pcu_id']]}
+        self.message = 'PCU %d added site %s' % \
+                (pcu['pcu_id'], site['site_id'])
 
         return pcu['pcu_id']
index f722917..c324c5f 100644 (file)
@@ -8,7 +8,7 @@ from PLC.PCUTypes import PCUType, PCUTypes
 from PLC.Auth import Auth
 
 can_update = lambda (field, value): field in \
-            ['pcu_type_id', 'port', 'protocol', 'supported']   
+             ['pcu_type_id', 'port', 'protocol', 'supported']
 
 class AddPCUProtocolType(Method):
     """
@@ -23,35 +23,35 @@ class AddPCUProtocolType(Method):
 
     accepts = [
         Auth(),
-       Mixed(PCUType.fields['pcu_type_id'],
+        Mixed(PCUType.fields['pcu_type_id'],
               PCUType.fields['model']),
         protocol_type_fields
-       ]
+        ]
 
     returns = Parameter(int, 'New pcu_protocol_type_id (> 0) if successful')
 
     def call(self, auth, pcu_type_id_or_model, protocol_type_fields):
 
-       # Check if pcu type exists
-       pcu_types = PCUTypes(self.api, [pcu_type_id_or_model])
-       if not pcu_types:
-           raise PLCInvalidArgument, "No such pcu type"
-       pcu_type = pcu_types[0]
-
-       
-       # Check if this port is already used
-       if 'port' not in protocol_type_fields:
-           raise PLCInvalidArgument, "Must specify a port"
-       else:
-           protocol_types = PCUProtocolTypes(self.api, {'pcu_type_id': pcu_type['pcu_type_id']})
-           for protocol_type in protocol_types:
-               if protocol_type['port'] == protocol_type_fields['port']:
-                   raise PLCInvalidArgument, "Port alreay in use" 
-
-       protocol_type_fields = dict(filter(can_update, protocol_type_fields.items()))
+        # Check if pcu type exists
+        pcu_types = PCUTypes(self.api, [pcu_type_id_or_model])
+        if not pcu_types:
+            raise PLCInvalidArgument, "No such pcu type"
+        pcu_type = pcu_types[0]
+
+
+        # Check if this port is already used
+        if 'port' not in protocol_type_fields:
+            raise PLCInvalidArgument, "Must specify a port"
+        else:
+            protocol_types = PCUProtocolTypes(self.api, {'pcu_type_id': pcu_type['pcu_type_id']})
+            for protocol_type in protocol_types:
+                if protocol_type['port'] == protocol_type_fields['port']:
+                    raise PLCInvalidArgument, "Port alreay in use"
+
+        protocol_type_fields = dict(filter(can_update, protocol_type_fields.items()))
         protocol_type = PCUProtocolType(self.api, protocol_type_fields)
-       protocol_type['pcu_type_id'] = pcu_type['pcu_type_id']
-       protocol_type.sync()
-       self.event_object = {'PCUProtocolType': [protocol_type['pcu_protocol_type_id']]}        
+        protocol_type['pcu_type_id'] = pcu_type['pcu_type_id']
+        protocol_type.sync()
+        self.event_object = {'PCUProtocolType': [protocol_type['pcu_protocol_type_id']]}
 
         return protocol_type['pcu_protocol_type_id']
index 58bb80d..4383eaa 100644 (file)
@@ -7,7 +7,7 @@ from PLC.PCUTypes import PCUType, PCUTypes
 from PLC.Auth import Auth
 
 can_update = lambda (field, value): field in \
-            ['model', 'name']  
+             ['model', 'name']
 
 class AddPCUType(Method):
     """
@@ -23,15 +23,15 @@ class AddPCUType(Method):
     accepts = [
         Auth(),
         pcu_type_fields
-       ]
+        ]
 
     returns = Parameter(int, 'New pcu_type_id (> 0) if successful')
 
-    
+
     def call(self, auth, pcu_type_fields):
-       pcu_type_fields = dict(filter(can_update, pcu_type_fields.items()))
+        pcu_type_fields = dict(filter(can_update, pcu_type_fields.items()))
         pcu_type = PCUType(self.api, pcu_type_fields)
-       pcu_type.sync()
-       self.event_object = {'PCUType': [pcu_type['pcu_type_id']]}      
+        pcu_type.sync()
+        self.event_object = {'PCUType': [pcu_type['pcu_type_id']]}
 
         return pcu_type['pcu_type_id']
index e4aef4c..5a5b6fa 100644 (file)
@@ -2,7 +2,7 @@
 # $URL$
 #
 # Thierry Parmentelat - INRIA
-# 
+#
 
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
@@ -31,8 +31,8 @@ class AddPeer(Method):
     returns = Parameter(int, "New peer_id (> 0) if successful")
 
     def call(self, auth, peer_fields):
-       peer = Peer(self.api, peer_fields);
-       peer.sync()
-       self.event_objects = {'Peer': [peer['peer_id']]}
+        peer = Peer(self.api, peer_fields);
+        peer.sync()
+        self.event_objects = {'Peer': [peer['peer_id']]}
 
-       return peer['peer_id']
+        return peer['peer_id']
index a8b4e2c..7c4d67d 100644 (file)
@@ -40,6 +40,6 @@ class AddPerson(Method):
 
         # Logging variables
         self.event_objects = {'Person': [person['person_id']]}
-        self.message = 'Person %d added' % person['person_id'] 
+        self.message = 'Person %d added' % person['person_id']
 
         return person['person_id']
index 6824657..7f22bee 100644 (file)
@@ -55,7 +55,7 @@ class AddPersonTag(Method):
             raise PLCInvalidArgument, "No such tag type %r"%tag_type_id_or_name
         tag_type = tag_types[0]
 
-       # checks for existence - does not allow several different settings
+        # checks for existence - does not allow several different settings
         conflicts = PersonTags(self.api,
                                         {'person_id':person['person_id'],
                                          'tag_type_id':tag_type['tag_type_id']})
@@ -64,16 +64,16 @@ class AddPersonTag(Method):
             raise PLCInvalidArgument, "Person %d already has setting %d"%(person['person_id'],
                                                                                tag_type['tag_type_id'])
 
-       # check permission : it not admin, is the user affiliated with the same site as this person
-       if 'admin' not in self.caller['roles']:
-           # check caller is affiliated with at least one of Person's sites
-           if len(set(person['site_ids']) & set(self.caller['site_ids'])) == 0:
-               raise PLCPermissionDenied, "Not a member of the person's sites: %s"%person['site_ids']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified person setting, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the same site as this person
+        if 'admin' not in self.caller['roles']:
+            # check caller is affiliated with at least one of Person's sites
+            if len(set(person['site_ids']) & set(self.caller['site_ids'])) == 0:
+                raise PLCPermissionDenied, "Not a member of the person's sites: %s"%person['site_ids']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified person setting, requires role %d",required_min_role
 
         person_tag = PersonTag(self.api)
         person_tag['person_id'] = person['person_id']
@@ -81,6 +81,6 @@ class AddPersonTag(Method):
         person_tag['value'] = value
 
         person_tag.sync()
-       self.object_ids = [person_tag['person_tag_id']]
+        self.object_ids = [person_tag['person_tag_id']]
 
         return person_tag['person_tag_id']
index b38e111..1cee030 100644 (file)
@@ -10,7 +10,7 @@ from PLC.Auth import Auth
 class AddPersonToSlice(Method):
     """
     Adds the specified person to the specified slice. If the person is
-    already a member of the slice, no errors are returned. 
+    already a member of the slice, no errors are returned.
 
     Returns 1 if successful, faults otherwise.
     """
@@ -48,16 +48,16 @@ class AddPersonToSlice(Method):
 
         # If we are not admin, make sure the caller is a PI
         # of the site associated with the slice
-       if 'admin' not in self.caller['roles']:
+        if 'admin' not in self.caller['roles']:
             if slice['site_id'] not in self.caller['site_ids']:
                 raise PLCPermissionDenied, "Not allowed to add users to this slice"
 
-       if slice['slice_id'] not in person['slice_ids']:
+        if slice['slice_id'] not in person['slice_ids']:
             slice.add_person(person)
 
         # Logging variables
-       self.event_objects = {'Person': [person['person_id']],
-                             'Slice': [slice['slice_id']]}     
-       self.object_ids = [slice['slice_id']]
+        self.event_objects = {'Person': [person['person_id']],
+                              'Slice': [slice['slice_id']]}
+        self.object_ids = [slice['slice_id']]
 
         return 1
index 2ab69f1..d57d260 100644 (file)
@@ -29,6 +29,6 @@ class AddRole(Method):
         role['role_id'] = role_id
         role['name'] = name
         role.sync(insert = True)
-       self.event_objects = {'Role': [role['role_id']]}
+        self.event_objects = {'Role': [role['role_id']]}
 
         return 1
index 9fa85df..458b40b 100644 (file)
@@ -10,7 +10,7 @@ from PLC.Roles import Role, Roles
 class AddRoleToPerson(Method):
     """
     Grants the specified role to the person.
-    
+
     PIs can only grant the tech and user roles to users and techs at
     their sites. Admins can grant any role to any user.
 
@@ -60,9 +60,9 @@ class AddRoleToPerson(Method):
         if role['role_id'] not in person['role_ids']:
             person.add_role(role)
 
-       self.event_objects = {'Person': [person['person_id']],
-                             'Role': [role['role_id']]}
-       self.message = "Role %d granted to person %d" % \
+        self.event_objects = {'Person': [person['person_id']],
+                              'Role': [role['role_id']]}
+        self.message = "Role %d granted to person %d" % \
                        (role['role_id'], person['person_id'])
 
         return 1
index d06b7a0..c9ca5ff 100644 (file)
@@ -10,30 +10,30 @@ from PLC.Persons import Person, Persons
 
 class AddSession(Method):
     """
-    Creates and returns a new session key for the specified user. 
+    Creates and returns a new session key for the specified user.
     (Used for website 'user sudo')
     """
 
     roles = ['admin']
     accepts = [
-       Auth(),
-       Mixed(Person.fields['person_id'],
+        Auth(),
+        Mixed(Person.fields['person_id'],
               Person.fields['email'])
-       ]
+        ]
     returns = Session.fields['session_id']
-    
+
 
     def call(self, auth, person_id_or_email):
-        
-       persons = Persons(self.api, [person_id_or_email], ['person_id', 'email'])
-       
-       if not persons:
-           raise PLCInvalidArgument, "No such person"
-       
-       person = persons[0]
-       session = Session(self.api)
+
+        persons = Persons(self.api, [person_id_or_email], ['person_id', 'email'])
+
+        if not persons:
+            raise PLCInvalidArgument, "No such person"
+
+        person = persons[0]
+        session = Session(self.api)
         session['expires'] = int(time.time()) + (24 * 60 * 60)
-       session.sync(commit = False)
-       session.add_person(person, commit = True)
+        session.sync(commit = False)
+        session.add_person(person, commit = True)
 
         return session['session_id']
index 239de70..09d7507 100644 (file)
@@ -35,9 +35,9 @@ class AddSite(Method):
         site_fields = dict(filter(can_update, site_fields.items()))
         site = Site(self.api, site_fields)
         site.sync()
-       
-        # Logging variables 
+
+        # Logging variables
         self.event_objects = {'Site': [site['site_id']]}
         self.message = 'Site %d created' % site['site_id']
-       
+
         return site['site_id']
index 7a93821..9d5ecac 100644 (file)
@@ -51,10 +51,10 @@ class AddSiteAddress(Method):
         address.sync(commit = False)
         site.add_address(address, commit = True)
 
-       # Logging variables
-       self.event_objects = {'Site': [site['site_id']], 
-                             'Address': [address['address_id']]}
-       self.message = 'Address %d assigned to Site %d' % \
-               (address['address_id'], site['site_id'])
+        # Logging variables
+        self.event_objects = {'Site': [site['site_id']],
+                              'Address': [address['address_id']]}
+        self.message = 'Address %d assigned to Site %d' % \
+                (address['address_id'], site['site_id'])
 
         return address['address_id']
index dda3f57..9bc5ef7 100644 (file)
@@ -56,7 +56,7 @@ class AddSiteTag(Method):
             raise PLCInvalidArgument, "No such tag type %r"%tag_type_id_or_name
         tag_type = tag_types[0]
 
-       # checks for existence - does not allow several different settings
+        # checks for existence - does not allow several different settings
         conflicts = SiteTags(self.api,
                                         {'site_id':site['site_id'],
                                          'tag_type_id':tag_type['tag_type_id']})
@@ -65,18 +65,18 @@ class AddSiteTag(Method):
             raise PLCInvalidArgument, "Site %d already has setting %d"%(site['site_id'],
                                                                                tag_type['tag_type_id'])
 
-       # check permission : it not admin, is the user affiliated with the right site
-       if 'admin' not in self.caller['roles']:
-           # locate site
-           site = Sites (self.api, site_id)[0]
-           # check caller is affiliated with this site
-           if self.caller['person_id'] not in site['person_ids']:
-               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified site setting, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the right site
+        if 'admin' not in self.caller['roles']:
+            # locate site
+            site = Sites (self.api, site_id)[0]
+            # check caller is affiliated with this site
+            if self.caller['person_id'] not in site['person_ids']:
+                raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified site setting, requires role %d",required_min_role
 
         site_tag = SiteTag(self.api)
         site_tag['site_id'] = site['site_id']
@@ -84,6 +84,6 @@ class AddSiteTag(Method):
         site_tag['value'] = value
 
         site_tag.sync()
-       self.object_ids = [site_tag['site_tag_id']]
+        self.object_ids = [site_tag['site_tag_id']]
 
         return site_tag['site_tag_id']
index 937c551..a7fb5b9 100644 (file)
@@ -84,9 +84,9 @@ class AddSlice(Method):
                 "Site %s has reached (%d) its maximum allowable slice count (%d)"%(site['name'],
                                                                                    len(site['slice_ids']),
                                                                                    site['max_slices'])
-       if not site['enabled']:
-           raise PLCInvalidArgument, "Site %s is disabled and can cannot create slices" % (site['name'])
-        
+        if not site['enabled']:
+            raise PLCInvalidArgument, "Site %s is disabled and can cannot create slices" % (site['name'])
+
         slice = Slice(self.api, native)
         slice['creator_person_id'] = self.caller['person_id']
         slice['site_id'] = site['site_id']
@@ -104,5 +104,5 @@ class AddSlice(Method):
 
         self.event_objects = {'Slice': [slice['slice_id']]}
         self.message = "Slice %d created" % slice['slice_id']
-    
+
         return slice['slice_id']
index b9f51bd..e55aa7c 100644 (file)
@@ -35,11 +35,11 @@ class AddSliceTag(Method):
         Mixed(SliceTag.fields['tag_type_id'],
               SliceTag.fields['tagname']),
         Mixed(SliceTag.fields['value'],
-             InitScript.fields['name']),
+              InitScript.fields['name']),
         Mixed(Node.fields['node_id'],
               Node.fields['hostname'],
-             None),
-       Mixed(NodeGroup.fields['nodegroup_id'],
+              None),
+        Mixed(NodeGroup.fields['nodegroup_id'],
               NodeGroup.fields['groupname'])
         ]
 
@@ -73,12 +73,12 @@ class AddSliceTag(Method):
             node_role_id = 20
             if tag_type['min_role_id'] is not None and node_role_id > tag_type['min_role_id']:
                 raise PLCPermissionDenied, "Not allowed to set the specified slice attribute"
-            
-       # if initscript is specified, validate value
-       if tag_type['tagname'] in ['initscript']:
-           initscripts = InitScripts(self.api, {'enabled': True, 'name': value})
-           if not initscripts: 
-               raise PLCInvalidArgument, "No such plc initscript %r"%value
+
+        # if initscript is specified, validate value
+        if tag_type['tagname'] in ['initscript']:
+            initscripts = InitScripts(self.api, {'enabled': True, 'name': value})
+            if not initscripts:
+                raise PLCInvalidArgument, "No such plc initscript %r"%value
 
         slice_tag = SliceTag(self.api)
         slice_tag['slice_id'] = slice['slice_id']
@@ -99,30 +99,30 @@ class AddSliceTag(Method):
                 node = nodes[0]
                 if node_id <> None and node_id <> node['node_id']:
                     raise PLCPermissionDenied, "Not allowed to set another node's sliver attribute"
-                else:                    
+                else:
                     node_id = node['node_id']
-            
+
             system_slice_tags = SliceTags(self.api, {'tagname': 'system', 'value': '1'}).dict('slice_id')
             system_slice_ids = system_slice_tags.keys()
-           if slice['slice_id'] not in system_slice_ids and node_id not in slice['node_ids']:
+            if slice['slice_id'] not in system_slice_ids and node_id not in slice['node_ids']:
                 raise PLCInvalidArgument, "AddSliceTag: slice %s not on specified node %s nor is it a system slice (%r)"%(slice['name'],node['hostname'],system_slice_ids)
             slice_tag['node_id'] = node['node_id']
 
-       # Sliver attribute shared accross nodes if nodegroup is sepcified
-       if nodegroup_id_or_name is not None:
+        # Sliver attribute shared accross nodes if nodegroup is sepcified
+        if nodegroup_id_or_name is not None:
             if isinstance(self.caller, Node):
-                    raise PLCPermissionDenied, "Not allowed to set nodegroup slice attributes"
-                
-           nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
-           if not nodegroups:
-               raise PLCInvalidArgument, "No such nodegroup %r"%nodegroup_id_or_name
-           nodegroup = nodegroups[0]
-       
-           slice_tag['nodegroup_id'] = nodegroup['nodegroup_id']
-
-       # Check if slice attribute alreay exists
-        slice_tags_check = SliceTags(self.api, {'slice_id': slice['slice_id'], 
-                                                            'tagname': tag_type['tagname'], 
+                raise PLCPermissionDenied, "Not allowed to set nodegroup slice attributes"
+
+            nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
+            if not nodegroups:
+                raise PLCInvalidArgument, "No such nodegroup %r"%nodegroup_id_or_name
+            nodegroup = nodegroups[0]
+
+            slice_tag['nodegroup_id'] = nodegroup['nodegroup_id']
+
+        # Check if slice attribute alreay exists
+        slice_tags_check = SliceTags(self.api, {'slice_id': slice['slice_id'],
+                                                            'tagname': tag_type['tagname'],
                                                             'value': value})
         for slice_tag_check in slice_tags_check:
             # do not compare between slice tag and sliver tag
@@ -132,13 +132,13 @@ class AddSliceTag(Method):
             if 'node_id' in slice_tag and slice_tag['node_id'] is not None and slice_tag_check['node_id'] is None:
                 continue
             if 'node_id' in slice_tag and slice_tag['node_id'] == slice_tag_check['node_id']:
-               raise PLCInvalidArgument, "Sliver attribute already exists"
-           if 'nodegroup_id' in slice_tag and slice_tag['nodegroup_id'] == slice_tag_check['nodegroup_id']:
-               raise PLCInvalidArgument, "Slice attribute already exists for this nodegroup"
+                raise PLCInvalidArgument, "Sliver attribute already exists"
+            if 'nodegroup_id' in slice_tag and slice_tag['nodegroup_id'] == slice_tag_check['nodegroup_id']:
+                raise PLCInvalidArgument, "Slice attribute already exists for this nodegroup"
             if node_id_or_hostname is None and nodegroup_id_or_name is None:
                 raise PLCInvalidArgument, "Slice attribute already exists"
 
         slice_tag.sync()
-       self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}
+        self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}
 
         return slice_tag['slice_tag_id']
index 57724cb..0601ac5 100644 (file)
@@ -25,7 +25,7 @@ class AddSliceToNodes(Method):
         Auth(),
         Mixed(Slice.fields['slice_id'],
               Slice.fields['name']),
-       [Mixed(Node.fields['node_id'],
+        [Mixed(Node.fields['node_id'],
                Node.fields['hostname'])]
         ]
 
@@ -48,26 +48,26 @@ class AddSliceToNodes(Method):
                 raise PLCPermissionDenied, "Not a member of the specified slice"
             elif slice['site_id'] not in self.caller['site_ids']:
                 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
-       
-        # Get specified nodes, add them to the slice         
+
+        # Get specified nodes, add them to the slice
         nodes = Nodes(self.api, node_id_or_hostname_list, ['node_id', 'hostname', 'slice_ids', 'slice_ids_whitelist', 'site_id'])
-       
-       for node in nodes:
-           # check the slice whitelist on each node first
-           # allow  users at site to add node to slice, ignoring whitelist
-           if node['slice_ids_whitelist'] and \
-              slice['slice_id'] not in node['slice_ids_whitelist'] and \
-              not set(self.caller['site_ids']).intersection([node['site_id']]):
-               raise PLCInvalidArgument, "%s is not allowed on %s (not on the whitelist)" % \
-                 (slice['name'], node['hostname'])
+
+        for node in nodes:
+            # check the slice whitelist on each node first
+            # allow  users at site to add node to slice, ignoring whitelist
+            if node['slice_ids_whitelist'] and \
+               slice['slice_id'] not in node['slice_ids_whitelist'] and \
+               not set(self.caller['site_ids']).intersection([node['site_id']]):
+                raise PLCInvalidArgument, "%s is not allowed on %s (not on the whitelist)" % \
+                  (slice['name'], node['hostname'])
             if slice['slice_id'] not in node['slice_ids']:
                 slice.add_node(node, commit = False)
 
         slice.sync()
 
         nodeids = [node['node_id'] for node in nodes]
-       self.event_objects = {'Node': nodeids,
-                             'Slice': [slice['slice_id']]}
+        self.event_objects = {'Node': nodeids,
+                              'Slice': [slice['slice_id']]}
         self.message = 'Slice %d added to nodes %s' % (slice['slice_id'], nodeids)
 
         return 1
index 5b0dc91..77fcfe6 100644 (file)
@@ -24,7 +24,7 @@ class AddSliceToNodesWhitelist(Method):
         Auth(),
         Mixed(Slice.fields['slice_id'],
               Slice.fields['name']),
-       [Mixed(Node.fields['node_id'],
+        [Mixed(Node.fields['node_id'],
                Node.fields['hostname'])]
         ]
 
@@ -40,17 +40,17 @@ class AddSliceToNodesWhitelist(Method):
         if slice['peer_id'] is not None:
             raise PLCInvalidArgument, "Not a local slice"
 
-        # Get specified nodes, add them to the slice         
+        # Get specified nodes, add them to the slice
         nodes = Nodes(self.api, node_id_or_hostname_list)
-       for node in nodes:
-           if node['peer_id'] is not None:
+        for node in nodes:
+            if node['peer_id'] is not None:
                 raise PLCInvalidArgument, "%s not a local node" % node['hostname']
             if slice['slice_id'] not in node['slice_ids_whitelist']:
                 slice.add_to_node_whitelist(node, commit = False)
-           
+
         slice.sync()
 
-       self.event_objects = {'Node': [node['node_id'] for node in nodes],
-                             'Slice': [slice['slice_id']]}
+        self.event_objects = {'Node': [node['node_id'] for node in nodes],
+                              'Slice': [slice['slice_id']]}
 
         return 1
index 3de86b0..336edb3 100644 (file)
@@ -42,6 +42,6 @@ class AddTagType(Method):
         tag_type = TagType(self.api, tag_type_fields)
         tag_type.sync()
 
-       self.object_ids = [tag_type['tag_type_id']]
+        self.object_ids = [tag_type['tag_type_id']]
 
         return tag_type['tag_type_id']
index 70f24c3..14feeea 100644 (file)
@@ -12,14 +12,14 @@ from PLC.Slices import Slices
 from PLC.Keys import Keys
 from PLC.Peers import Peers
 from PLC.Faults import *
+
 class BindObjectToPeer(Method):
     """
     This method is a hopefully temporary hack to let the sfa correctly
     attach the objects it creates to a remote peer object. This is
     needed so that the sfa federation link can work in parallel with
     RefreshPeer, as RefreshPeer depends on remote objects being
-    correctly marked. 
+    correctly marked.
 
     BindRemoteObjectToPeer is allowed to admins only.
     """
@@ -63,11 +63,11 @@ class BindObjectToPeer(Method):
 
         peer=peers[0]
         object = self.locate_object (object_type, object_id)
-        
-        # There is no need to continue if the object is already bound to this peer  
+
+        # There is no need to continue if the object is already bound to this peer
         if object['peer_id'] in [peer['peer_id']]:
             return 1
-        
+
         adder_name = 'add_'+object_type
         add_function = getattr(type(peer),adder_name)
         add_function(peer,object,remote_object_id)
index 298e4e3..afe1d93 100644 (file)
@@ -25,7 +25,7 @@ class BlacklistKey(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-   
+
     def call(self, auth, key_id):
         # Get associated key details
         keys = Keys(self.api, [key_id])
@@ -36,9 +36,9 @@ class BlacklistKey(Method):
         # N.B.: Can blacklist any key, even foreign ones
 
         key.blacklist()
-       
-       # Logging variables
-       self.event_objects = {'Key': [key['key_id']]}
-       self.message = 'Key %d blacklisted' % key['key_id']
+
+        # Logging variables
+        self.event_objects = {'Key': [key['key_id']]}
+        self.message = 'Key %d blacklisted' % key['key_id']
 
         return 1
index ae338f9..c376f45 100644 (file)
@@ -51,7 +51,6 @@ class BootGetNodeDetails(Method):
                         else:
                             network[field] = ""
 
-       self.message = "Node request boot_state (%s) and networks" % \
-               (details['boot_state'])
+        self.message = "Node request boot_state (%s) and networks" % \
+                (details['boot_state'])
         return details
-
index d69f162..f89bf27 100644 (file)
@@ -59,7 +59,7 @@ class BootUpdateNode(Method):
 
         # Update primary interface state
         if node_fields.has_key('primary_network'):
-            primary_network = node_fields['primary_network'] 
+            primary_network = node_fields['primary_network']
 
             if 'interface_id' not in primary_network:
                 raise PLCInvalidArgument, "Interface not specified"
index 0b0924d..bc6ba5e 100644 (file)
@@ -23,7 +23,7 @@ class DeleteAddress(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-    
+
 
     def call(self, auth, address_id):
         # Get associated address details
@@ -38,8 +38,8 @@ class DeleteAddress(Method):
 
         address.delete()
 
-       # Logging variables
+        # Logging variables
         self.event_objects = {'Address': [address['address_id']]}
-       self.message = 'Address %d deleted' % address['address_id']     
+        self.message = 'Address %d deleted' % address['address_id']
 
         return 1
index 3a43d70..dae2858 100644 (file)
@@ -30,6 +30,6 @@ class DeleteAddressType(Method):
             raise PLCInvalidArgument, "No such address type"
         address_type = address_types[0]
         address_type.delete()
-       self.event_objects = {'AddressType': [address_type['address_type_id']]}
+        self.event_objects = {'AddressType': [address_type['address_type_id']]}
 
         return 1
index 4115759..2ddd753 100644 (file)
@@ -26,7 +26,7 @@ class DeleteAddressTypeFromAddress(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-    
+
 
     def call(self, auth, address_type_id_or_name, address_id):
         address_types = AddressTypes(self.api, [address_type_id_or_name])
@@ -44,7 +44,7 @@ class DeleteAddressTypeFromAddress(Method):
                 raise PLCPermissionDenied, "Address must be associated with one of your sites"
 
         address.remove_address_type(address_type)
-       self.event_objects = {'Address' : [address['address_id']],
-                             'AddressType': [address_type['address_type_id']]} 
+        self.event_objects = {'Address' : [address['address_id']],
+                              'AddressType': [address_type['address_type_id']]}
 
         return 1
index 2339778..5f47755 100644 (file)
@@ -33,5 +33,5 @@ class DeleteBootState(Method):
         boot_state = boot_states[0]
 
         boot_state.delete()
-       
+
         return 1
index 2d7183b..f3d0471 100644 (file)
@@ -21,7 +21,7 @@ class DeleteConfFile(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-    
+
 
     def call(self, auth, conf_file_id):
         conf_files = ConfFiles(self.api, [conf_file_id])
@@ -30,6 +30,6 @@ class DeleteConfFile(Method):
 
         conf_file = conf_files[0]
         conf_file.delete()
-       self.event_objects = {'ConfFile': [conf_file['conf_file_id']]}
+        self.event_objects = {'ConfFile': [conf_file['conf_file_id']]}
 
         return 1
index 838755f..b8541c3 100644 (file)
@@ -27,24 +27,24 @@ class DeleteConfFileFromNode(Method):
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth, conf_file_id, node_id_or_hostname):
-       # Get configuration file
+        # Get configuration file
         conf_files = ConfFiles(self.api, [conf_file_id])
         if not conf_files:
             raise PLCInvalidArgument, "No such configuration file"
         conf_file = conf_files[0]
 
         # Get node
-       nodes = Nodes(self.api, [node_id_or_hostname])
-       if not nodes:
-               raise PLCInvalidArgument, "No such node"
-       node = nodes[0]
-       
-       # Link configuration file to node
+        nodes = Nodes(self.api, [node_id_or_hostname])
+        if not nodes:
+            raise PLCInvalidArgument, "No such node"
+        node = nodes[0]
+
+        # Link configuration file to node
         if node['node_id'] in conf_file['node_ids']:
             conf_file.remove_node(node)
 
         # Log affected objects
-        self.event_objects = {'ConfFile': [conf_file_id], 
-                             'Node': [node['node_id']]}
+        self.event_objects = {'ConfFile': [conf_file_id],
+                              'Node': [node['node_id']]}
 
         return 1
index 3e0ba48..f621bac 100644 (file)
@@ -28,24 +28,24 @@ class DeleteConfFileFromNodeGroup(Method):
 
 
     def call(self, auth, conf_file_id, nodegroup_id_or_name):
-       # Get configuration file
+        # Get configuration file
         conf_files = ConfFiles(self.api, [conf_file_id])
         if not conf_files:
             raise PLCInvalidArgument, "No such configuration file"
         conf_file = conf_files[0]
 
         # Get nodegroup
-       nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
-       if not nodegroups:
-               raise PLCInvalidArgument, "No such nodegroup"
-       nodegroup = nodegroups[0]
-       
-       # Link configuration file to nodegroup
+        nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
+        if not nodegroups:
+            raise PLCInvalidArgument, "No such nodegroup"
+        nodegroup = nodegroups[0]
+
+        # Link configuration file to nodegroup
         if nodegroup['nodegroup_id'] in conf_file['nodegroup_ids']:
             conf_file.remove_nodegroup(nodegroup)
 
         # Log affected objects
-        self.event_objects = {'ConfFile': [conf_file_id], 
-                             'NodeGroup': [nodegroup['nodegroup_id']]}
+        self.event_objects = {'ConfFile': [conf_file_id],
+                              'NodeGroup': [nodegroup['nodegroup_id']]}
 
         return 1
index 163a7b5..40780ad 100644 (file)
@@ -21,7 +21,7 @@ class DeleteIlink(Method):
     """
     Deletes the specified ilink
 
-    Attributes may require the caller to have a particular 
+    Attributes may require the caller to have a particular
     role in order to be deleted, depending on the related tag type.
     Admins may delete attributes of any slice or sliver.
 
@@ -50,26 +50,26 @@ class DeleteIlink(Method):
         tag_type = TagTypes (self.api,[tag_type_id])[0]
         required_min_role = tag_type ['min_role_id']
 
-       # check permission : it not admin, is the user affiliated with the right site<S>
-       if 'admin' not in self.caller['roles']:
+        # check permission : it not admin, is the user affiliated with the right site<S>
+        if 'admin' not in self.caller['roles']:
             for key in ['src_interface_id','dst_interface_id']:
                 # locate interface
                 interface_id=ilink[key]
                 interface = Interfaces (self.api,interface_id)[0]
                 node_id=interface['node_id']
                 node = Nodes (self.api,node_id) [0]
-               # locate site
+                # locate site
                 site_id = node['site_id']
                 site = Sites (self.api, [site_id]) [0]
-               # check caller is affiliated with this site
+                # check caller is affiliated with this site
                 if self.caller['person_id'] not in site['person_ids']:
                     raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
+
                 if required_min_role is not None and \
                         min(self.caller['role_ids']) > required_min_role:
                     raise PLCPermissionDenied, "Not allowed to modify the specified ilink, requires role %d",required_min_role
 
         ilink.delete()
-       self.object_ids = [ilink['src_interface_id'],ilink['dst_interface_id']]
+        self.object_ids = [ilink['src_interface_id'],ilink['dst_interface_id']]
 
         return 1
index 1363874..1b29cee 100644 (file)
@@ -8,9 +8,9 @@ from PLC.Auth import Auth
 
 class DeleteInitScript(Method):
     """
-    Deletes an existing initscript.  
-    
-    Returns 1 if successful, faults otherwise. 
+    Deletes an existing initscript.
+
+    Returns 1 if successful, faults otherwise.
     """
 
     roles = ['admin']
@@ -22,7 +22,7 @@ class DeleteInitScript(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-    
+
 
     def call(self, auth, initscript_id_or_name):
         initscripts = InitScripts(self.api, [initscript_id_or_name])
@@ -31,6 +31,6 @@ class DeleteInitScript(Method):
 
         initscript = initscripts[0]
         initscript.delete()
-       self.event_objects = {'InitScript':  [initscript['initscript_id']]}
+        self.event_objects = {'InitScript':  [initscript['initscript_id']]}
 
         return 1
index 6b888c7..4475f5d 100644 (file)
@@ -21,7 +21,7 @@ class DeleteInterface(Method):
 
     accepts = [
         Auth(),
-       Interface.fields['interface_id']
+        Interface.fields['interface_id']
         ]
 
     returns = Parameter(int, '1 if successful')
@@ -33,16 +33,16 @@ class DeleteInterface(Method):
         interfaces = Interfaces(self.api, [interface_id])
         if not interfaces:
             raise PLCInvalidArgument, "No such interface %r"%interface_id
-       interface = interfaces[0]
-       
-       # Get node information
-       nodes = Nodes(self.api, [interface['node_id']])
-       if not nodes:
-               raise PLCInvalidArgument, "No such node %r"%node_id
-       node = nodes[0]
+        interface = interfaces[0]
+
+        # Get node information
+        nodes = Nodes(self.api, [interface['node_id']])
+        if not nodes:
+            raise PLCInvalidArgument, "No such node %r"%node_id
+        node = nodes[0]
 
         # Authenticated functino
-       assert self.caller is not None
+        assert self.caller is not None
 
         # If we are not an admin, make sure that the caller is a
         # member of the site at which the node is located.
@@ -52,8 +52,8 @@ class DeleteInterface(Method):
 
         interface.delete()
 
-       # Logging variables
-       self.event_objects = {'Interface': [interface['interface_id']]}
-       self.message = "Interface %d deleted" % interface['interface_id']
+        # Logging variables
+        self.event_objects = {'Interface': [interface['interface_id']]}
+        self.message = "Interface %d deleted" % interface['interface_id']
 
         return 1
index bbf2a51..67b2bbb 100644 (file)
@@ -54,22 +54,22 @@ class DeleteInterfaceTag(Method):
 
         assert interface_tag['interface_tag_id'] in interface['interface_tag_ids']
 
-       # check permission : it not admin, is the user affiliated with the right site
-       if 'admin' not in self.caller['roles']:
-           # locate node
-           node = Nodes (self.api,[interface['node_id']])[0]
-           # locate site
-           site = Sites (self.api, [node['site_id']])[0]
-           # check caller is affiliated with this site
-           if self.caller['person_id'] not in site['person_ids']:
-               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified interface setting, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the right site
+        if 'admin' not in self.caller['roles']:
+            # locate node
+            node = Nodes (self.api,[interface['node_id']])[0]
+            # locate site
+            site = Sites (self.api, [node['site_id']])[0]
+            # check caller is affiliated with this site
+            if self.caller['person_id'] not in site['person_ids']:
+                raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified interface setting, requires role %d",required_min_role
 
         interface_tag.delete()
-       self.object_ids = [interface_tag['interface_tag_id']]
+        self.object_ids = [interface_tag['interface_tag_id']]
 
         return 1
index e4203fc..e4632ae 100644 (file)
@@ -40,7 +40,7 @@ class DeleteKey(Method):
                 raise PLCPermissionDenied, "Key must be associated with your account"
 
         key.delete()
-       
+
         # Logging variables
         self.event_objects = {'Key': [key['key_id']]}
         self.message = 'Key %d deleted' % key['key_id']
index 95d3bea..d227368 100644 (file)
@@ -23,8 +23,8 @@ class DeleteKeyType(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-    
-    
+
+
     def call(self, auth, name):
         key_types = KeyTypes(self.api, [name])
         if not key_types:
index ff021b7..ed450d6 100644 (file)
@@ -11,7 +11,7 @@ class DeleteLeases(Method):
     """
     Deletes a lease.
 
-    Users may only delete leases attached to their slices. 
+    Users may only delete leases attached to their slices.
     PIs may delete any of the leases for slices at their sites, or any
     slices of which they are members. Admins may delete any lease.
 
@@ -54,7 +54,7 @@ class DeleteLeases(Method):
                 slice['verified']=True
 
             lease.delete()
-       
+
         # Logging variables
         self.event_objects = {'Lease': lease_ids }
         self.message = 'Leases %r deleted' % lease_ids
index f316998..857ce91 100644 (file)
@@ -21,7 +21,7 @@ class DeleteMessage(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-       
+
 
     def call(self, auth, message_id):
         # Get message information
@@ -31,6 +31,6 @@ class DeleteMessage(Method):
         message = messages[0]
 
         message.delete()
-       self.event_objects = {'Message': [message['message_id']]}
+        self.event_objects = {'Message': [message['message_id']]}
 
         return 1
index aeeef52..7dccbde 100644 (file)
@@ -24,7 +24,7 @@ class DeleteNetworkMethod(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-   
+
 
     def call(self, auth, name):
         network_methods = NetworkMethods(self.api, [name])
index 424628e..db6d0f3 100644 (file)
@@ -24,7 +24,7 @@ class DeleteNetworkType(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-    
+
 
     def call(self, auth, name):
         network_types = NetworkTypes(self.api, [name])
index 5cf00f7..3f408da 100644 (file)
@@ -21,7 +21,7 @@ class DeleteNodeFromPCU(Method):
 
     accepts = [
         Auth(),
-       Mixed(Node.fields['node_id'],
+        Mixed(Node.fields['node_id'],
               Node.fields['hostname']),
         PCU.fields['pcu_id']
         ]
@@ -29,7 +29,7 @@ class DeleteNodeFromPCU(Method):
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth, node_id_or_hostname, pcu_id):
-        # Get node
+         # Get node
         nodes = Nodes(self.api, [node_id_or_hostname])
         if not nodes:
             raise PLCInvalidArgument, "No such node"
@@ -52,16 +52,16 @@ class DeleteNodeFromPCU(Method):
                     break
             if not ok:
                 raise PLCPermissionDenied, "Not allowed to update that PCU"
-       
-       # Removed node from PCU
-       
+
+        # Removed node from PCU
+
         if node['node_id'] in pcu['node_ids']:
             pcu.remove_node(node)
 
-       # Logging variables
-       self.event_objects = {'PCU': [pcu['pcu_id']],
-                             'Node': [node['node_id']]}        
-       self.message = 'Node %d removed from PCU %d' % \
-               (node['node_id'], pcu['pcu_id']) 
-       
-       return 1
+        # Logging variables
+        self.event_objects = {'PCU': [pcu['pcu_id']],
+                              'Node': [node['node_id']]}
+        self.message = 'Node %d removed from PCU %d' % \
+                (node['node_id'], pcu['pcu_id'])
+
+        return 1
index ae66dc7..680e718 100644 (file)
@@ -20,7 +20,7 @@ class DeleteNodeGroup(Method):
     accepts = [
         Auth(),
         Mixed(NodeGroup.fields['nodegroup_id'],
-             NodeGroup.fields['groupname'])
+              NodeGroup.fields['groupname'])
         ]
 
     returns = Parameter(int, '1 if successful')
@@ -36,8 +36,8 @@ class DeleteNodeGroup(Method):
 
         nodegroup.delete()
 
-       # Logging variables
-       self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
-       self.message  = 'Node group %d deleted' % nodegroup['nodegroup_id']
+        # Logging variables
+        self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
+        self.message  = 'Node group %d deleted' % nodegroup['nodegroup_id']
+
         return 1
index 8ad9072..9b3fdb8 100644 (file)
@@ -54,22 +54,22 @@ class DeleteNodeTag(Method):
 
         assert node_tag['node_tag_id'] in node['node_tag_ids']
 
-       # check permission : it not admin, is the user affiliated with the right site
-       if 'admin' not in self.caller['roles']:
-           # locate node
-           node = Nodes (self.api,[node['node_id']])[0]
-           # locate site
-           site = Sites (self.api, [node['site_id']])[0]
-           # check caller is affiliated with this site
-           if self.caller['person_id'] not in site['person_ids']:
-               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified node tag, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the right site
+        if 'admin' not in self.caller['roles']:
+            # locate node
+            node = Nodes (self.api,[node['node_id']])[0]
+            # locate site
+            site = Sites (self.api, [node['site_id']])[0]
+            # check caller is affiliated with this site
+            if self.caller['person_id'] not in site['person_ids']:
+                raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified node tag, requires role %d",required_min_role
 
         node_tag.delete()
-       self.object_ids = [node_tag['node_tag_id']]
+        self.object_ids = [node_tag['node_tag_id']]
 
         return 1
index 1b6fd38..d5bc58d 100644 (file)
@@ -33,5 +33,5 @@ class DeleteNodeType(Method):
         node_type = node_types[0]
 
         node_type.delete()
-       
+
         return 1
index 6b6c45f..caff26b 100644 (file)
@@ -37,9 +37,9 @@ class DeletePCU(Method):
                 raise PLCPermissionDenied, "Not allowed to update that PCU"
 
         pcu.delete()
-       
-       # Logging variables
-       self.event_objects = {'PCU': [pcu['pcu_id']]}
-       self.message = 'PCU %d deleted' % pcu['pcu_id']
+
+        # Logging variables
+        self.event_objects = {'PCU': [pcu['pcu_id']]}
+        self.message = 'PCU %d deleted' % pcu['pcu_id']
 
         return 1
index b4c0ac7..f64d64a 100644 (file)
@@ -10,7 +10,7 @@ class DeletePCUProtocolType(Method):
     """
     Deletes a PCU protocol type.
 
-    Returns 1 if successful, faults otherwise. 
+    Returns 1 if successful, faults otherwise.
     """
 
     roles = ['admin']
@@ -21,7 +21,7 @@ class DeletePCUProtocolType(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-    
+
 
     def call(self, auth, protocol_type_id):
         protocol_types = PCUProtocolTypes(self.api, [protocol_type_id])
@@ -30,6 +30,6 @@ class DeletePCUProtocolType(Method):
 
         protocol_type = protocol_types[0]
         protocol_type.delete()
-       self.event_objects = {'PCUProtocolType': [protocol_type['pcu_protocol_type_id']]}
+        self.event_objects = {'PCUProtocolType': [protocol_type['pcu_protocol_type_id']]}
 
         return 1
index f27e117..166c628 100644 (file)
@@ -10,7 +10,7 @@ class DeletePCUType(Method):
     """
     Deletes a PCU type.
 
-    Returns 1 if successful, faults otherwise. 
+    Returns 1 if successful, faults otherwise.
     """
 
     roles = ['admin']
@@ -21,7 +21,7 @@ class DeletePCUType(Method):
         ]
 
     returns = Parameter(int, '1 if successful')
-    
+
 
     def call(self, auth, pcu_type_id):
         pcu_types = PCUTypes(self.api, [pcu_type_id])
@@ -30,6 +30,6 @@ class DeletePCUType(Method):
 
         pcu_type = pcu_types[0]
         pcu_type.delete()
-       self.event_objects = {'PCUType': [pcu_type['pcu_type_id']]}
+        self.event_objects = {'PCUType': [pcu_type['pcu_type_id']]}
 
         return 1
index f5ba75d..673e449 100644 (file)
@@ -35,6 +35,6 @@ class DeletePeer(Method):
         peer.delete()
 
         # Log affected objects
-       self.event_objects = {'Peer': [peer['peer_id']]}
+        self.event_objects = {'Peer': [peer['peer_id']]}
 
-       return 1
+        return 1
index a199aec..91267ca 100644 (file)
@@ -45,7 +45,7 @@ class DeletePerson(Method):
             raise PLCPermissionDenied, "Not allowed to delete specified account"
 
         person.delete()
-       
+
         # Logging variables
         self.event_objects = {'Person': [person['person_id']]}
         self.message = 'Person %d deleted' % person['person_id']
index 0345100..8b9ed0c 100644 (file)
@@ -52,8 +52,8 @@ class DeletePersonFromSite(Method):
 
         # Logging variables
         self.event_objects = {'Site': [site['site_id']],
-                              'Person': [person['person_id']]} 
-        self.message = 'Person %d deleted from site %d ' % \
+                              'Person': [person['person_id']]}
+        self.message = 'Person %d deleted from site %d  ' % \
                         (person['person_id'], site['site_id'])
 
         return 1
index d36a1c3..9cdfb16 100644 (file)
@@ -10,7 +10,7 @@ from PLC.Auth import Auth
 class DeletePersonFromSlice(Method):
     """
     Deletes the specified person from the specified slice. If the person is
-    not a member of the slice, no errors are returned. 
+    not a member of the slice, no errors are returned.
 
     Returns 1 if successful, faults otherwise.
     """
@@ -48,14 +48,14 @@ class DeletePersonFromSlice(Method):
 
         # If we are not admin, make sure the caller is a pi
         # of the site associated with the slice
-       if 'admin' not in self.caller['roles']:
-               if slice['site_id'] not in self.caller['site_ids']:
-                       raise PLCPermissionDenied, "Not allowed to delete users from this slice"
+        if 'admin' not in self.caller['roles']:
+            if slice['site_id'] not in self.caller['site_ids']:
+                raise PLCPermissionDenied, "Not allowed to delete users from this slice"
 
-       if slice['slice_id'] in person['slice_ids']:
+        if slice['slice_id'] in person['slice_ids']:
             slice.remove_person(person)
-       
-       self.event_objects = {'Slice': [slice['slice_id']],
-                             'Person': [person['person_id']]}  
+
+        self.event_objects = {'Slice': [slice['slice_id']],
+                              'Person': [person['person_id']]}
 
         return 1
index 51a1432..e4abcdd 100644 (file)
@@ -54,18 +54,18 @@ class DeletePersonTag(Method):
 
         assert person_tag['person_tag_id'] in person['person_tag_ids']
 
-       # check permission : it not admin, is the user affiliated with the right person
-       if 'admin' not in self.caller['roles']:
-           # check caller is affiliated with this person's site
-           if len(set(person['site_ids']) & set(self.caller['site_ids'])) == 0:
-               raise PLCPermissionDenied, "Not a member of the person's sites: %s"%person['site_ids']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified person setting, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the right person
+        if 'admin' not in self.caller['roles']:
+            # check caller is affiliated with this person's site
+            if len(set(person['site_ids']) & set(self.caller['site_ids'])) == 0:
+                raise PLCPermissionDenied, "Not a member of the person's sites: %s"%person['site_ids']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified person setting, requires role %d",required_min_role
 
         person_tag.delete()
-       self.object_ids = [person_tag['person_tag_id']]
+        self.object_ids = [person_tag['person_tag_id']]
 
         return 1
index fb5a515..a75ebc5 100644 (file)
@@ -27,7 +27,7 @@ class DeleteRole(Method):
 
     returns = Parameter(int, '1 if successful')
 
-    
+
     def call(self, auth, role_id_or_name):
         roles = Roles(self.api, [role_id_or_name])
         if not roles:
@@ -35,6 +35,6 @@ class DeleteRole(Method):
         role = roles[0]
 
         role.delete()
-       self.event_objects = {'Role': [role['role_id']]}
+        self.event_objects = {'Role': [role['role_id']]}
 
         return 1
index 1506e9f..28dedfb 100644 (file)
@@ -10,7 +10,7 @@ from PLC.Roles import Role, Roles
 class DeleteRoleFromPerson(Method):
     """
     Deletes the specified role from the person.
-    
+
     PIs can only revoke the tech and user roles from users and techs
     at their sites. ins can revoke any role from any user.
 
@@ -59,11 +59,11 @@ class DeleteRoleFromPerson(Method):
 
         if role['role_id'] in person['role_ids']:
             person.remove_role(role)
-       
-       # Logging variables
-       self.event_objects = {'Person': [person['person_id']],
-                             'Role': [role['role_id']]}        
-       self.message = "Role %d revoked from person %d" % \
+
+        # Logging variables
+        self.event_objects = {'Person': [person['person_id']],
+                              'Role': [role['role_id']]}
+        self.message = "Role %d revoked from person %d" % \
                        (role['role_id'], person['person_id'])
 
         return 1
index 8c7feb3..9776275 100644 (file)
@@ -40,10 +40,10 @@ class DeleteSite(Method):
             raise PLCInvalidArgument, "Not a local site"
 
         site.delete()
-       
+
         # Logging variables
         self.event_objects = {'Site': [site['site_id']]}
-        self.message = 'Site %d deleted' % site['site_id']     
+        self.message = 'Site %d deleted' % site['site_id']
+
 
-        
         return 1
index f1e06aa..ab22400 100644 (file)
@@ -54,18 +54,18 @@ class DeleteSiteTag(Method):
 
         assert site_tag['site_tag_id'] in site['site_tag_ids']
 
-       # check permission : it not admin, is the user affiliated with the right site
-       if 'admin' not in self.caller['roles']:
-           # check caller is affiliated with this site
-           if self.caller['person_id'] not in site['person_ids']:
-               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified site setting, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the right site
+        if 'admin' not in self.caller['roles']:
+            # check caller is affiliated with this site
+            if self.caller['person_id'] not in site['person_ids']:
+                raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified site setting, requires role %d",required_min_role
 
         site_tag.delete()
-       self.object_ids = [site_tag['site_tag_id']]
+        self.object_ids = [site_tag['site_tag_id']]
 
         return 1
index 22117e0..946fe43 100644 (file)
@@ -10,7 +10,7 @@ from PLC.Auth import Auth
 class DeleteSliceFromNodes(Method):
     """
     Deletes the specified slice from the specified nodes. If the slice is
-    not associated with a node, no errors are returned. 
+    not associated with a node, no errors are returned.
 
     Returns 1 if successful, faults otherwise.
     """
@@ -21,7 +21,7 @@ class DeleteSliceFromNodes(Method):
         Auth(),
        Mixed(Slice.fields['slice_id'],
               Slice.fields['name']),
-       [Mixed(Node.fields['node_id'],
+        [Mixed(Node.fields['node_id'],
                Node.fields['hostname'])]
         ]
 
@@ -41,20 +41,20 @@ class DeleteSliceFromNodes(Method):
                 raise PLCPermissionDenied, "Not a member of the specified slice"
             elif slice['site_id'] not in self.caller['site_ids']:
                 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
-       
-       # Remove slice from all nodes found
 
-       # Get specified nodes
+        # Remove slice from all nodes found
+
+        # Get specified nodes
         nodes = Nodes(self.api, node_id_or_hostname_list)
-       for node in nodes:
-           if slice['peer_id'] is not None and node['peer_id'] is not None:
-               raise PLCPermissionDenied, "Not allowed to remove peer slice from peer node"
+        for node in nodes:
+            if slice['peer_id'] is not None and node['peer_id'] is not None:
+                raise PLCPermissionDenied, "Not allowed to remove peer slice from peer node"
             if slice['slice_id'] in node['slice_ids']:
                 slice.remove_node(node, commit = False)
 
         slice.sync()
-       
-       self.event_objects = {'Node': [node['node_id'] for node in nodes],
-                             'Slice': [slice['slice_id']]}      
+
+        self.event_objects = {'Node': [node['node_id'] for node in nodes],
+                              'Slice': [slice['slice_id']]}
 
         return 1
index 2d95851..ca6ccd8 100644 (file)
@@ -24,7 +24,7 @@ class DeleteSliceFromNodesWhitelist(Method):
         Auth(),
         Mixed(Slice.fields['slice_id'],
               Slice.fields['name']),
-       [Mixed(Node.fields['node_id'],
+        [Mixed(Node.fields['node_id'],
                Node.fields['hostname'])]
         ]
 
@@ -40,17 +40,17 @@ class DeleteSliceFromNodesWhitelist(Method):
         if slice['peer_id'] is not None:
             raise PLCInvalidArgument, "Not a local slice"
 
-        # Get specified nodes, add them to the slice         
+        # Get specified nodes, add them to the slice
         nodes = Nodes(self.api, node_id_or_hostname_list)
-       for node in nodes:
+        for node in nodes:
             if node['peer_id'] is not None:
                 raise PLCInvalidArgument, "%s not a local node" % node['hostname']
-           if slice['slice_id'] in node['slice_ids_whitelist']:
+            if slice['slice_id'] in node['slice_ids_whitelist']:
                 slice.delete_from_node_whitelist(node, commit = False)
 
         slice.sync()
 
-       self.event_objects = {'Node': [node['node_id'] for node in nodes],
-                             'Slice': [slice['slice_id']]}
+        self.event_objects = {'Node': [node['node_id'] for node in nodes],
+                              'Slice': [slice['slice_id']]}
 
         return 1
index 7a574a3..9e2ad06 100644 (file)
@@ -56,6 +56,6 @@ class DeleteSliceTag(Method):
                 raise PLCPermissioinDenied, "Not allowed to delete the specified attribute"
 
         slice_tag.delete()
-       self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}
+        self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}
 
         return 1
index 69c7bba..4d4169d 100644 (file)
@@ -36,6 +36,6 @@ class DeleteTagType(Method):
         tag_type = tag_types[0]
 
         tag_type.delete()
-       self.object_ids = [tag_type['tag_type_id']]
+        self.object_ids = [tag_type['tag_type_id']]
 
         return 1
index ece5fd1..dc34ae2 100644 (file)
@@ -28,7 +28,7 @@ class GenerateNodeConfFile(Method):
         Auth(),
         Mixed(Node.fields['node_id'],
               Node.fields['hostname']),
-       Parameter(bool, "True if you want to regenerate node key")
+        Parameter(bool, "True if you want to regenerate node key")
         ]
 
     returns = Parameter(str, "Node configuration file")
@@ -49,7 +49,7 @@ class GenerateNodeConfFile(Method):
             if node['site_id'] not in self.caller['site_ids']:
                 raise PLCPermissionDenied, "Not allowed to generate a configuration file for that node"
 
-       # Get interfaces for this node
+        # Get interfaces for this node
         primary = None
         interfaces = Interfaces(self.api, node['interface_ids'])
         for interface in interfaces:
@@ -66,7 +66,7 @@ class GenerateNodeConfFile(Method):
         host = parts[0]
         domain = parts[1]
 
-       if regenerate_node_key:
+        if regenerate_node_key:
             # Generate 32 random bytes
             bytes = random.sample(xrange(0, 256), 32)
             # Base64 encode their string representation
index a45cc87..7ebc80b 100644 (file)
@@ -26,7 +26,7 @@ class GetAddresses(Method):
         ]
 
     returns = [Address.fields]
-    
+
 
     def call(self, auth, address_filter = None, return_fields = None):
         return Addresses(self.api, address_filter, return_fields)
index 64458e2..848796d 100644 (file)
@@ -16,13 +16,13 @@ from PLC.Interfaces import Interface, Interfaces
 from PLC.InterfaceTags import InterfaceTag, InterfaceTags
 from PLC.NodeTags import NodeTag, NodeTags
 
-from PLC.Accessors.Accessors_standard import *                 # import node accessors
+from PLC.Accessors.Accessors_standard import *                  # import node accessors
 
 # could not define this in the class..
 # create a dict with the allowed actions for each type of node
 # reservable nodes being more recent, we do not support the floppy stuff anymore
 allowed_actions = {
-    'regular' : 
+    'regular' :
     [ 'node-preview',
       'node-floppy',
       'node-iso',
@@ -30,7 +30,7 @@ allowed_actions = {
       'generic-iso',
       'generic-usb',
       ],
-    'reservable': 
+    'reservable':
     [ 'node-preview',
       'node-iso',
       'node-usb',
@@ -50,18 +50,18 @@ def compute_key():
 
 class GetBootMedium(Method):
     """
-    This method is a redesign based on former, supposedly dedicated, 
+    This method is a redesign based on former, supposedly dedicated,
     AdmGenerateNodeConfFile
 
-    As compared with its ancestor, this method provides a much more 
+    As compared with its ancestor, this method provides a much more
     detailed interface, that allows to
-    (*) either just preview the node config file -- in which case 
+    (*) either just preview the node config file -- in which case
         the node key is NOT recomputed, and NOT provided in the output
-    (*) or regenerate the node config file for storage on a floppy 
-        that is, exactly what the ancestor method used todo, 
+    (*) or regenerate the node config file for storage on a floppy
+        that is, exactly what the ancestor method used todo,
         including renewing the node's key
     (*) or regenerate the config file and bundle it inside an ISO or USB image
-    (*) or just provide the generic ISO or USB boot images 
+    (*) or just provide the generic ISO or USB boot images
         in which case of course the node_id_or_hostname parameter is not used
 
     action is expected among the following string constants according the
@@ -77,34 +77,34 @@ class GetBootMedium(Method):
 
     Apart for the preview mode, this method generates a new node key for the
     specified node, effectively invalidating any old boot medium.
-    Note that 'reservable' nodes do not support 'node-floppy', 
+    Note that 'reservable' nodes do not support 'node-floppy',
     'generic-iso' nor 'generic-usb'.
 
     In addition, two return mechanisms are supported.
-    (*) The default behaviour is that the file's content is returned as a 
+    (*) The default behaviour is that the file's content is returned as a
         base64-encoded string. This is how the ancestor method used to work.
         To use this method, pass an empty string as the file parameter.
 
-    (*) Or, for efficiency -- this makes sense only when the API is used 
-        by the web pages that run on the same host -- the caller may provide 
-        a filename, in which case the resulting file is stored in that location instead. 
-        The filename argument can use the following markers, that are expanded 
+    (*) Or, for efficiency -- this makes sense only when the API is used
+        by the web pages that run on the same host -- the caller may provide
+        a filename, in which case the resulting file is stored in that location instead.
+        The filename argument can use the following markers, that are expanded
         within the method
         - %d : default root dir (some builtin dedicated area under /var/tmp/)
                Using this is recommended, and enforced for non-admin users
-        - %n : the node's name when this makes sense, or a mktemp-like name when 
+        - %n : the node's name when this makes sense, or a mktemp-like name when
                generic media is requested
         - %s : a file suffix appropriate in the context (.txt, .iso or the like)
         - %v : the bootcd version string (e.g. 4.0)
         - %p : the PLC name
         - %f : the nodefamily
         - %a : arch
-        With the file-based return mechanism, the method returns the full pathname 
-        of the result file; 
+        With the file-based return mechanism, the method returns the full pathname
+        of the result file;
         ** WARNING **
         It is the caller's responsability to remove this file after use.
 
-    Options: an optional array of keywords. 
+    Options: an optional array of keywords.
         options are not supported for generic images
       Currently supported are
         - 'partition' - for USB actions only
@@ -115,19 +115,19 @@ class GetBootMedium(Method):
         tty - baudrate - parity - bits
         e.g. ttyS0:115200:n:8
         - 'variant:<variantname>'
-        passed to build.sh as -V <variant> 
+        passed to build.sh as -V <variant>
         variants are used to run a different kernel on the bootCD
         see kvariant.sh for how to create a variant
         - 'no-hangcheck' - disable hangcheck
 
     Tags: the following tags are taken into account when attached to the node:
         'serial', 'cramfs', 'kvariant', 'kargs', 'no-hangcheck'
-        
+
     Security:
         - Non-admins can only generate files for nodes at their sites.
         - Non-admins, when they provide a filename, *must* specify it in the %d area
 
-   Housekeeping: 
+   Housekeeping:
         Whenever needed, the method stores intermediate files in a
         private area, typically not located under the web server's
         accessible area, and are cleaned up by the method.
@@ -165,7 +165,7 @@ class GetBootMedium(Method):
         if len(parts) < 2:
             raise PLCInvalidArgument, "Node hostname %s is invalid"%node['hostname']
         return parts
-        
+
     # Generate the node (plnode.txt) configuration content.
     #
     # This function will create the configuration file a node
@@ -234,7 +234,7 @@ class GetBootMedium(Method):
         for setting in settings:
             if setting['category'] is not None:
                 categories.add(setting['category'])
-        
+
         for category in categories:
             category_settings = InterfaceTags(self.api,{'interface_id':interface['interface_id'],
                                                               'category':category})
@@ -259,9 +259,9 @@ class GetBootMedium(Method):
         arch = self.api.config.PLC_FLAVOUR_NODE_ARCH
         if not node:
             return (pldistro,fcdistro,arch)
-        
+
         node_id=node['node_id']
-        
+
         # no support for deployment-based BootCD's, use kvariants instead
         node_pldistro = GetNodePldistro (self.api).call(auth, node_id)
         if node_pldistro: pldistro = node_pldistro
@@ -271,7 +271,7 @@ class GetBootMedium(Method):
 
         node_arch = GetNodeArch (self.api).call(auth,node_id)
         if node_arch: arch = node_arch
-        
+
         return (pldistro,fcdistro,arch)
 
     def bootcd_version (self):
@@ -279,7 +279,7 @@ class GetBootMedium(Method):
             return file(self.BOOTCDDIR + "/build/version.txt").readline().strip()
         except:
             raise Exception,"Unknown boot cd version - probably wrong bootcd dir : %s"%self.BOOTCDDIR
-    
+
     def cleantrash (self):
         for file in self.trash:
             if self.DEBUG:
@@ -288,7 +288,7 @@ class GetBootMedium(Method):
                 os.unlink(file)
 
     ### handle filename
-    # build the filename string 
+    # build the filename string
     # check for permissions and concurrency
     # returns the filename
     def handle_filename (self, filename, nodename, suffix, arch):
@@ -316,7 +316,7 @@ class GetBootMedium(Method):
             if os.path.exists(filename):
                 raise PLCInvalidArgument, "Resulting file %s already exists"%filename
 
-            ### we can now safely create the file, 
+            ### we can now safely create the file,
             ### either we are admin or under a controlled location
             filedir=os.path.dirname(filename)
             # dirname does not return "." for a local filename like its shell counterpart
@@ -340,13 +340,13 @@ class GetBootMedium(Method):
         if node_type in [ 'regular', 'reservable' ]:
 
             build_sh_options=""
-            if "cramfs" in build_sh_spec: 
+            if "cramfs" in build_sh_spec:
                 type += "_cramfs"
-            if "serial" in build_sh_spec: 
+            if "serial" in build_sh_spec:
                 build_sh_options += " -s %s"%build_sh_spec['serial']
             if "variant" in build_sh_spec:
                 build_sh_options += " -V %s"%build_sh_spec['variant']
-            
+
             for karg in build_sh_spec['kargs']:
                 build_sh_options += ' -k "%s"'%karg
 
@@ -362,7 +362,7 @@ class GetBootMedium(Method):
         if self.DEBUG:
             print "The build command line is %s" % command
 
-        return command 
+        return command
 
     def call(self, auth, node_id_or_hostname, action, filename, options = []):
 
@@ -399,12 +399,12 @@ class GetBootMedium(Method):
             if options:
                 raise PLCInvalidArgument, "Options are not supported for node configs"
         else:
-            # create a dict for build.sh 
+            # create a dict for build.sh
             build_sh_spec={'kargs':[]}
             # use node tags as defaults
             # check for node tag equivalents
-            tags = NodeTags(self.api, 
-                            {'node_id': node['node_id'], 
+            tags = NodeTags(self.api,
+                            {'node_id': node['node_id'],
                              'tagname': ['serial', 'cramfs', 'kvariant', 'kargs', 'no-hangcheck']},
                             ['tagname', 'value'])
             if tags:
@@ -456,9 +456,9 @@ class GetBootMedium(Method):
         # apply on globals
         for attr in [ "BOOTCDDIR", "BOOTCDBUILD", "GENERICDIR" ]:
             setattr(self,attr,getattr(self,attr).replace("@NODEFAMILY@",self.nodefamily))
-            
+
         filename = self.handle_filename(filename, nodename, suffix, arch)
-        
+
         # log call
         if node:
             self.message='GetBootMedium on node %s - action=%s'%(nodename,action)
@@ -511,7 +511,7 @@ class GetBootMedium(Method):
 
             ### check we've got required material
             version = self.bootcd_version()
-            
+
             if not os.path.isfile(self.BOOTCDBUILD):
                 raise PLCAPIError, "Cannot locate bootcd/build.sh script %s"%self.BOOTCDBUILD
 
@@ -522,7 +522,7 @@ class GetBootMedium(Method):
                     os.chmod(self.WORKDIR,0777)
                 except:
                     raise PLCPermissionDenied, "Could not create dir %s"%self.WORKDIR
-            
+
             try:
                 # generate floppy config
                 floppy_text = self.floppy_contents(node,True)
@@ -552,7 +552,7 @@ class GetBootMedium(Method):
 
                 if not os.path.isfile (node_image):
                     raise PLCAPIError,"Unexpected location of build.sh output - %s"%node_image
-            
+
                 # handle result
                 if filename:
                     ret=os.system('mv "%s" "%s"'%(node_image,filename))
@@ -570,7 +570,6 @@ class GetBootMedium(Method):
             except:
                 self.cleantrash()
                 raise
-                
+
         # we're done here, or we missed something
         raise PLCAPIError,'Unhandled action %s'%action
-
index 2e458bb..9105d12 100644 (file)
@@ -18,7 +18,7 @@ class GetBootStates(Method):
         ]
 
     returns = [BootState.fields['boot_state']]
-    
+
 
     def call(self, auth):
         return [boot_state['boot_state'] for boot_state in BootStates(self.api)]
index 432ae04..2cee70b 100644 (file)
@@ -28,4 +28,3 @@ class GetEventObjects(Method):
 
     def call(self, auth, event_filter = None, return_fields = None):
         return EventObjects(self.api, event_filter, return_fields)
-
index 845eb3a..6b88618 100644 (file)
@@ -29,4 +29,3 @@ class GetEvents(Method):
 
     def call(self, auth, event_filter = None, return_fields = None):
         return Events(self.api, event_filter, return_fields)
-
index 9b63fe2..93a208a 100644 (file)
@@ -37,7 +37,7 @@ class GetIlinks(Method):
         ]
 
     returns = [Ilink.fields]
-    
+
 
     def call(self, auth, ilink_filter = None, return_fields = None):
 
index ffc75e6..e9a3226 100644 (file)
@@ -9,10 +9,10 @@ from PLC.Auth import Auth
 
 class GetInitScripts(Method):
     """
-    Returns an array of structs containing details about initscripts. 
-    If initscript_filter is specified and is an array of initscript 
-    identifiers, or a struct of initscript attributes, only initscripts 
-    matching the filter will be returned. If return_fields is specified, 
+    Returns an array of structs containing details about initscripts.
+    If initscript_filter is specified and is an array of initscript
+    identifiers, or a struct of initscript attributes, only initscripts
+    matching the filter will be returned. If return_fields is specified,
     only the specified details will be returned.
     """
 
@@ -21,7 +21,7 @@ class GetInitScripts(Method):
     accepts = [
         Auth(),
         Mixed([Mixed(InitScript.fields['initscript_id'],
-                    InitScript.fields['name'])],
+                     InitScript.fields['name'])],
               Filter(InitScript.fields)),
         Parameter([str], "List of fields to return", nullok = True)
         ]
index 6daa3f9..131d3e5 100644 (file)
@@ -37,7 +37,7 @@ class GetInterfaceTags(Method):
         ]
 
     returns = [InterfaceTag.fields]
-    
+
 
     def call(self, auth, interface_tag_filter = None, return_fields = None):
 
index 2c6b6b4..a5a7689 100644 (file)
@@ -31,6 +31,6 @@ class GetInterfaces(Method):
         ]
 
     returns = [Interface.fields]
-    
+
     def call(self, auth, interface_filter = None, return_fields = None):
         return Interfaces(self.api, interface_filter, return_fields)
index 9895710..0451f45 100644 (file)
@@ -26,16 +26,16 @@ class GetKeys(Method):
         Auth(),
         Mixed([Mixed(Key.fields['key_id'])],
               Filter(Key.fields)),
-        Parameter([str], "List of fields to return", nullok = True)        
+        Parameter([str], "List of fields to return", nullok = True)
         ]
 
     returns = [Key.fields]
 
 
     def call(self, auth, key_filter = None, return_fields = None):
-       keys = Keys(self.api, key_filter, return_fields)
+        keys = Keys(self.api, key_filter, return_fields)
 
-       # If we are not admin, make sure to only return our own keys       
+        # If we are not admin, make sure to only return our own keys
         if isinstance(self.caller, Person) and \
            'admin' not in self.caller['roles']:
             keys = filter(lambda key: key['key_id'] in self.caller['key_ids'], keys)
index f3dfa78..80e272b 100644 (file)
@@ -35,7 +35,7 @@ class GetLeases(Method):
         Auth(),
         Mixed(Lease.fields['lease_id'],
               [Lease.fields['lease_id']],
-              LeaseFilter(Lease.fields)),    
+              LeaseFilter(Lease.fields)),
         Parameter([str], "List of fields to return", nullok = True)
         ]
 
@@ -55,7 +55,7 @@ class GetLeases(Method):
         # Remove lease_id if not specified
         if added_fields:
             for lease in leases:
-               if 'lease_id' in lease:
-                   del lease['lease_id']
+                if 'lease_id' in lease:
+                    del lease['lease_id']
 
         return leases
index 4146c0a..6ebcc12 100644 (file)
@@ -6,17 +6,17 @@ from PLC.Faults import *
 from PLC.Parameter import *
 from PLC.Nodes import Node, Nodes
 
-from PLC.Accessors.Accessors_standard import *                 # import node accessors
+from PLC.Accessors.Accessors_standard import *                  # import node accessors
 
 class GetNodeFlavour(Method):
     """
     Returns detailed information on a given node's flavour, i.e. its
-    base installation. 
+    base installation.
 
     This depends on the global PLC settings in the PLC_FLAVOUR area,
     optionnally overridden by any of the following tags if set on that node:
 
-    'arch', 'pldistro', 'fcdistro', 
+    'arch', 'pldistro', 'fcdistro',
     'deployment', 'extensions',
     """
 
@@ -28,25 +28,25 @@ class GetNodeFlavour(Method):
               Node.fields['hostname']),
         ]
 
-    returns = { 
+    returns = {
         'nodefamily' : Parameter (str, "the nodefamily this node should be based upon"),
         'fcdistro': Parameter (str, "the fcdistro this node should be based upon"),
         'extensions' : [ Parameter (str, "extensions to add to the base install") ],
         'plain' : Parameter (bool, "use plain bootstrapfs image if set (for tests)" ) ,
         }
 
-    
+
     ########## nodefamily
     def nodefamily (self, auth, node_id, fcdistro, arch):
 
         # the deployment tag, if set, wins
-        # xxx Thierry: this probably is wrong; we need fcdistro to be set anyway 
+        # xxx Thierry: this probably is wrong; we need fcdistro to be set anyway
         # for generating the proper yum config....
         deployment = GetNodeDeployment (self.api).call(auth,node_id)
         if deployment: return deployment
 
         pldistro = GetNodePldistro (self.api).call(auth, node_id)
-        if not pldistro: 
+        if not pldistro:
             pldistro = self.api.config.PLC_FLAVOUR_NODE_PLDISTRO
             SetNodePldistro(self.api).call(auth,node_id,pldistro)
 
@@ -72,12 +72,12 @@ class GetNodeFlavour(Method):
 
         arch = GetNodeArch (self.api).call(auth,node_id)
         # if not set, use the global default and tag the node, in case the global default changes later on
-        if not arch: 
+        if not arch:
             arch = self.api.config.PLC_FLAVOUR_NODE_ARCH
             SetNodeArch (self.api).call(auth,node_id,arch)
 
         fcdistro = GetNodeFcdistro (self.api).call(auth, node_id)
-        if not fcdistro: 
+        if not fcdistro:
             fcdistro = self.api.config.PLC_FLAVOUR_NODE_FCDISTRO
             SetNodeFcdistro (self.api).call (auth, node_id, fcdistro)
 
index 6428f80..d5cb8eb 100644 (file)
@@ -27,6 +27,6 @@ class GetNodeGroups(Method):
         ]
 
     returns = [NodeGroup.fields]
-  
+
     def call(self, auth, nodegroup_filter = None, return_fields = None):
-       return NodeGroups(self.api, nodegroup_filter, return_fields)
+        return NodeGroups(self.api, nodegroup_filter, return_fields)
index e7710c6..41dfd8b 100644 (file)
@@ -37,7 +37,7 @@ class GetNodeTags(Method):
         ]
 
     returns = [NodeTag.fields]
-    
+
 
     def call(self, auth, node_tag_filter = None, return_fields = None):
 
index 6f90469..c8f1aeb 100644 (file)
@@ -18,7 +18,7 @@ class GetNodeTypes(Method):
         ]
 
     returns = [NodeType.fields['node_type']]
-    
+
 
     def call(self, auth):
         return [node_type['node_type'] for node_type in NodeTypes(self.api)]
index a49cac1..7dc62ea 100644 (file)
@@ -15,7 +15,7 @@ class GetNodes(Method):
     Returns an array of structs containing details about nodes. If
     node_filter is specified and is an array of node identifiers or
     hostnames, or a struct of node attributes, only nodes matching the
-    filter will be returned. 
+    filter will be returned.
 
     If return_fields is specified, only the specified details will be
     returned. NOTE that if return_fields is unspecified, the complete
@@ -31,7 +31,7 @@ class GetNodes(Method):
         Auth(),
         Mixed([Mixed(Node.fields['node_id'],
                      Node.fields['hostname'])],
-             Parameter(str,"hostname"),
+              Parameter(str,"hostname"),
               Parameter(int,"node_id"),
               Filter(Node.fields)),
         Parameter([str], "List of fields to return", nullok = True),
@@ -41,51 +41,51 @@ class GetNodes(Method):
 
 
     def call(self, auth, node_filter = None, return_fields = None):
-        
-       # Must query at least slice_ids_whitelist
-       if return_fields is not None:
-           added_fields = set(['slice_ids_whitelist', 'site_id']).difference(return_fields)
-           return_fields += added_fields
-       else:
-           added_fields =[]    
-
-       # Get node information
+
+        # Must query at least slice_ids_whitelist
+        if return_fields is not None:
+            added_fields = set(['slice_ids_whitelist', 'site_id']).difference(return_fields)
+            return_fields += added_fields
+        else:
+            added_fields =[]
+
+        # Get node information
         nodes = Nodes(self.api, node_filter, return_fields)
 
         # Remove admin only fields
         if not isinstance(self.caller, Person) or \
            'admin' not in self.caller['roles']:
-           slice_ids = set()
-           site_ids = set()
-           
-           if self.caller:
-               slice_ids.update(self.caller['slice_ids'])
-               if isinstance(self.caller, Node):
-                   site_ids.update([self.caller['site_id']])
-               else:  
-                   site_ids.update(self.caller['site_ids'])
-
-           # if node has whitelist, only return it if users is at
-           # the same site or user has a slice on the whitelist 
+            slice_ids = set()
+            site_ids = set()
+
+            if self.caller:
+                slice_ids.update(self.caller['slice_ids'])
+                if isinstance(self.caller, Node):
+                    site_ids.update([self.caller['site_id']])
+                else:
+                    site_ids.update(self.caller['site_ids'])
+
+            # if node has whitelist, only return it if users is at
+            # the same site or user has a slice on the whitelist
             for node in nodes[:]:
-               if 'site_id' in node and \
-                  site_ids.intersection([node['site_id']]):
-                   continue    
-               if 'slice_ids_whitelist' in node and \
-                  node['slice_ids_whitelist'] and \
-                  not slice_ids.intersection(node['slice_ids_whitelist']):
-                   nodes.remove(node)
-
-           # remove remaining admin only fields
-            for node in nodes:    
-               for field in admin_only:
+                if 'site_id' in node and \
+                   site_ids.intersection([node['site_id']]):
+                    continue
+                if 'slice_ids_whitelist' in node and \
+                   node['slice_ids_whitelist'] and \
+                   not slice_ids.intersection(node['slice_ids_whitelist']):
+                    nodes.remove(node)
+
+            # remove remaining admin only fields
+            for node in nodes:
+                for field in admin_only:
                     if field in node:
                         del node[field]
-       
-       # remove added fields if not specified
-       if added_fields:
-           for node in nodes:
-               for field in added_fields:
-                   del node[field]     
+
+        # remove added fields if not specified
+        if added_fields:
+            for node in nodes:
+                for field in added_fields:
+                    del node[field]
 
         return nodes
index a75a6b0..72fe26a 100644 (file)
@@ -16,27 +16,27 @@ class GetPCUProtocolTypes(Method):
 
     accepts = [
         Auth(),
-       Mixed([PCUProtocolType.fields['pcu_type_id']],
+        Mixed([PCUProtocolType.fields['pcu_type_id']],
                Filter(PCUProtocolType.fields)),
         Parameter([str], "List of fields to return", nullok = True)
         ]
 
     returns = [PCUProtocolType.fields]
-    
+
 
     def call(self, auth, protocol_type_filter = None, return_fields = None):
 
-       #Must query at least pcu_type_id
-       if return_fields is not None and 'pcu_protocol_type_id' not in return_fields:
-           return_fields.append('pcu_protocol_type_id')
-           added_fields = ['pcu_protocol_type_id']
-       else:
-           added_fields = []
+        #Must query at least pcu_type_id
+        if return_fields is not None and 'pcu_protocol_type_id' not in return_fields:
+            return_fields.append('pcu_protocol_type_id')
+            added_fields = ['pcu_protocol_type_id']
+        else:
+            added_fields = []
+
+        protocol_types = PCUProtocolTypes(self.api, protocol_type_filter, return_fields)
 
-       protocol_types = PCUProtocolTypes(self.api, protocol_type_filter, return_fields)
+        for added_field in added_fields:
+            for protocol_type in protocol_types:
+                del protocol_type[added_field]
 
-       for added_field in added_fields:
-           for protocol_type in protocol_types:
-               del protocol_type[added_field]
-               
-        return protocol_types 
+        return protocol_types
index 7d50821..58d8fcd 100644 (file)
@@ -16,37 +16,37 @@ class GetPCUTypes(Method):
 
     accepts = [
         Auth(),
-       Mixed([Mixed(PCUType.fields['pcu_type_id'],
+        Mixed([Mixed(PCUType.fields['pcu_type_id'],
                      PCUType.fields['model'])],
-              Parameter(str, 'model'),
-              Parameter(int, 'node_id'),               
+               Parameter(str, 'model'),
+               Parameter(int, 'node_id'),
                Filter(PCUType.fields)),
         Parameter([str], "List of fields to return", nullok = True)
         ]
 
     returns = [PCUType.fields]
-    
+
 
     def call(self, auth, pcu_type_filter = None, return_fields = None):
 
-       #Must query at least pcu_type_id
-       if return_fields is not None:
-           added_fields = []
-           if 'pcu_type_id' not in return_fields:
-               return_fields.append('pcu_type_id')
-               added_fields.append('pcu_type_id')
-           if 'pcu_protocol_types' in return_fields and \
-              'pcu_protocol_type_ids' not in return_fields:
-               return_fields.append('pcu_protocol_type_ids')
-               added_fields.append('pcu_protocol_type_ids') 
-       else:
-           added_fields = []
-
-       pcu_types = PCUTypes(self.api, pcu_type_filter, return_fields)
-
-       # remove added fields and protocol_types
-       for added_field in added_fields:
-           for pcu_type in pcu_types:
-               del pcu_type[added_field]
-               
-        return pcu_types 
+        #Must query at least pcu_type_id
+        if return_fields is not None:
+            added_fields = []
+            if 'pcu_type_id' not in return_fields:
+                return_fields.append('pcu_type_id')
+                added_fields.append('pcu_type_id')
+            if 'pcu_protocol_types' in return_fields and \
+               'pcu_protocol_type_ids' not in return_fields:
+                return_fields.append('pcu_protocol_type_ids')
+                added_fields.append('pcu_protocol_type_ids')
+        else:
+            added_fields = []
+
+        pcu_types = PCUTypes(self.api, pcu_type_filter, return_fields)
+
+        # remove added fields and protocol_types
+        for added_field in added_fields:
+            for pcu_type in pcu_types:
+                del pcu_type[added_field]
+
+        return pcu_types
index aee8f4a..298094c 100644 (file)
@@ -34,7 +34,7 @@ class GetPCUs(Method):
     returns = [PCU.fields]
 
     def call(self, auth, pcu_filter = None, return_fields = None):
-       # If we are not admin
+        # If we are not admin
         if not (isinstance(self.caller, Person) and 'admin' in self.caller['roles']):
             # Return only the PCUs at our site
             valid_pcu_ids = []
@@ -69,7 +69,7 @@ class GetPCUs(Method):
         # Remove pcu_id if not specified
         if added_fields:
             for pcu in pcus:
-               if 'pcu_id' in pcu:
-                   del pcu['pcu_id']
+                if 'pcu_id' in pcu:
+                    del pcu['pcu_id']
 
         return pcus
index 43a77aa..f26322e 100644 (file)
@@ -1,6 +1,6 @@
 #
 # Thierry Parmentelat - INRIA
-# 
+#
 # $Id$
 # $URL$
 
@@ -26,7 +26,7 @@ class GetPeerData(Method):
     database as foreign objects. Also returns the list of foreign
     nodes in this database, for which the calling peer is
     authoritative, to assist in synchronization of slivers.
-    
+
     See the implementation of RefreshPeer for how this data is used.
     """
 
@@ -52,8 +52,8 @@ class GetPeerData(Method):
                              Node.fields)
         nodes = Nodes(self.api, {'peer_id': None}, node_fields);
         # filter out whitelisted nodes
-        nodes = [ n for n in nodes if not n['slice_ids_whitelist']] 
-        
+        nodes = [ n for n in nodes if not n['slice_ids_whitelist']]
+
 
         person_fields = filter(lambda field: field not in \
                                ['password', 'verification_key', 'verification_expires'],
@@ -62,16 +62,16 @@ class GetPeerData(Method):
         # XXX Optimize to return only those Persons, Keys, and Slices
         # necessary for slice creation on the calling peer's nodes.
 
-       # filter out special person
-       persons = Persons(self.api, {'~email':[self.api.config.PLC_API_MAINTENANCE_USER,
-                                              self.api.config.PLC_ROOT_USER],
-                                    'peer_id': None}, person_fields)
+        # filter out special person
+        persons = Persons(self.api, {'~email':[self.api.config.PLC_API_MAINTENANCE_USER,
+                                               self.api.config.PLC_ROOT_USER],
+                                     'peer_id': None}, person_fields)
 
-       # filter out system slices
+        # filter out system slices
         system_slice_ids = SliceTags(self.api, {'name': 'system', 'value': '1'}).dict('slice_id')
-       slices = Slices(self.api, {'peer_id': None,
-                                  '~slice_id':system_slice_ids.keys()})
-       
+        slices = Slices(self.api, {'peer_id': None,
+                                   '~slice_id':system_slice_ids.keys()})
+
         result = {
             'Sites': Sites(self.api, {'peer_id': None}),
             'Keys': Keys(self.api, {'peer_id': None}),
index 97f96d0..bce911e 100644 (file)
@@ -2,7 +2,7 @@
 # $URL$
 #
 # Thierry Parmentelat - INRIA
-# 
+#
 
 from PLC.Faults import *
 from PLC.Method import Method
@@ -29,20 +29,20 @@ class GetPeers (Method):
         Mixed([Mixed(Peer.fields['peer_id'],
                      Peer.fields['peername'])],
               Filter(Peer.fields)),
-        Parameter([str], "List of fields to return", nullok = True)        
+        Parameter([str], "List of fields to return", nullok = True)
         ]
 
     returns = [Peer.fields]
 
     def call (self, auth, peer_filter = None, return_fields = None):
-        
+
         peers = Peers(self.api, peer_filter, return_fields)
 
         # Remove admin only fields
         if not isinstance(self.caller, Person) or \
                 'admin' not in self.caller['roles']:
-            for peer in peers:    
-               for field in ['key', 'cacert']:
+            for peer in peers:
+                for field in ['key', 'cacert']:
                     if field in peer:
                         del peer[field]
 
index 516638f..44fbdea 100644 (file)
@@ -35,7 +35,7 @@ class GetPersonTags(Method):
         ]
 
     returns = [PersonTag.fields]
-    
+
 
     def call(self, auth, person_tag_filter = None, return_fields = None):
 
index 7ef68b2..3ebf871 100644 (file)
@@ -29,8 +29,8 @@ class GetPersons(Method):
         Auth(),
         Mixed([Mixed(Person.fields['person_id'],
                      Person.fields['email'])],
-             Parameter(str,"email"),
-              Parameter(int,"person_id"), 
+              Parameter(str,"email"),
+              Parameter(int,"person_id"),
               Filter(Person.fields)),
         Parameter([str], "List of fields to return", nullok = True)
         ]
@@ -39,9 +39,9 @@ class GetPersons(Method):
     return_fields = dict(filter(lambda (field, value): field not in hidden_fields,
                                 Person.fields.items()))
     returns = [return_fields]
-    
+
     def call(self, auth, person_filter = None, return_fields = None):
-       # If we are not admin, make sure to only return viewable accounts
+        # If we are not admin, make sure to only return viewable accounts
         if isinstance(self.caller, Person) and \
            'admin' not in self.caller['roles']:
             # Get accounts that we are able to view
@@ -61,8 +61,8 @@ class GetPersons(Method):
         if return_fields:
             return_fields = filter(lambda field: field not in hidden_fields,
                                    return_fields)
-       else:
-           return_fields = self.return_fields.keys()
+        else:
+            return_fields = self.return_fields.keys()
 
         # Must query at least person_id, site_ids, and role_ids (see
         # Person.can_view() and below).
@@ -83,7 +83,7 @@ class GetPersons(Method):
         if added_fields:
             for person in persons:
                 for field in added_fields:
-                   if field in person:
-                       del person[field]
+                    if field in person:
+                        del person[field]
 
         return persons
index 9f4ca94..77f2fb0 100644 (file)
@@ -6,10 +6,10 @@ from PLC.Faults import *
 
 import re
 
-comment_regexp = '\A\s*#.|\A\s*\Z|\Axxxxx' 
+comment_regexp = '\A\s*#.|\A\s*\Z|\Axxxxx'
 
 regexps = { 'build'   : '\A[bB]uild\s+(?P<key>[^:]+)\s*:\s*(?P<value>.*)\Z',
-           'tags'    : '\A(?P<key>[^:]+)\s*:=\s*(?P<value>.*)\Z',
+            'tags'    : '\A(?P<key>[^:]+)\s*:=\s*(?P<value>.*)\Z',
 # spaces not part of key : ungreedy
             'rpms'    : '\A(?P<key>[^:]+?)\s*::\s*(?P<value>.*)\Z',
 }
@@ -27,35 +27,35 @@ class GetPlcRelease(Method):
 
     # for now only return /etc/myplc-release verbatim
     returns = { 'build' : 'information about the build',
-               'tags' : 'describes the codebase location and tags used for building',
-               'rpms' : 'details the rpm installed in the myplc chroot jail' }
+                'tags' : 'describes the codebase location and tags used for building',
+                'rpms' : 'details the rpm installed in the myplc chroot jail' }
 
     def call(self, auth):
 
-       comment_matcher = re.compile(comment_regexp)
-
-       matchers = {}
-       result = {} 
-       for field in regexps.keys():
-           matchers[field] = re.compile(regexps[field])
-           result[field]={}
-
-       try:
-           release = open('/etc/myplc-release')
-           for line in release.readlines():
-               line=line.strip()
-               if comment_matcher.match(line):
-                   continue
-               for field in regexps.keys():
-                   m=matchers[field].match(line)
-                   if m:
-                       (key,value)=m.groups(['key','value'])
-                       result[field][key]=value
-                       break
-               else:
-                   if not result.has_key('unexpected'):
-                       result['unexpected']=""
-                   result['unexpected'] += (line+"\n")
-       except:
-           raise PLCNotImplemented, 'Cannot open /etc/myplc-release'
-       return result
+        comment_matcher = re.compile(comment_regexp)
+
+        matchers = {}
+        result = {}
+        for field in regexps.keys():
+            matchers[field] = re.compile(regexps[field])
+            result[field]={}
+
+        try:
+            release = open('/etc/myplc-release')
+            for line in release.readlines():
+                line=line.strip()
+                if comment_matcher.match(line):
+                    continue
+                for field in regexps.keys():
+                    m=matchers[field].match(line)
+                    if m:
+                        (key,value)=m.groups(['key','value'])
+                        result[field][key]=value
+                        break
+                else:
+                    if not result.has_key('unexpected'):
+                        result['unexpected']=""
+                    result['unexpected'] += (line+"\n")
+        except:
+            raise PLCNotImplemented, 'Cannot open /etc/myplc-release'
+        return result
index ae1c314..b660471 100644 (file)
@@ -18,6 +18,6 @@ class GetRoles(Method):
         ]
 
     returns = [Role.fields]
-    
+
     def call(self, auth):
-       return Roles(self.api)
+        return Roles(self.api)
index 70f39b4..1e713fe 100644 (file)
@@ -18,7 +18,7 @@ class GetSession(Method):
     roles = ['admin', 'pi', 'user', 'tech', 'node']
     accepts = [Auth()]
     returns = Session.fields['session_id']
-    
+
 
     def call(self, auth):
         # Authenticated with a session key, just return it
index e80fb50..5e84017 100644 (file)
@@ -16,7 +16,7 @@ class GetSessions(Method):
     filter will be returned. If return_fields is specified, only the
     specified details will be returned.
 
-    
+
     """
 
     roles = ['admin']
@@ -29,9 +29,9 @@ class GetSessions(Method):
         ]
 
     returns = [Session.fields]
-    
+
     def call(self, auth, session_filter = None):
 
         sessions = Sessions(self.api, session_filter)
-       
-       return sessions
+
+        return sessions
index 4663e8a..83b208c 100644 (file)
@@ -36,7 +36,7 @@ class GetSiteTags(Method):
         ]
 
     returns = [SiteTag.fields]
-    
+
 
     def call(self, auth, site_tag_filter = None, return_fields = None):
 
index 5a5d657..a97386c 100644 (file)
@@ -21,10 +21,10 @@ class GetSites(Method):
         Auth(),
         Mixed([Mixed(Site.fields['site_id'],
                      Site.fields['login_base'])],
-             Parameter(str,"login_base"),
+              Parameter(str,"login_base"),
               Parameter(int,"site_id"),
               Filter(Site.fields)),
-        Parameter([str], "List of fields to return", nullok = True)        
+        Parameter([str], "List of fields to return", nullok = True)
         ]
 
     returns = [Site.fields]
index 512cbb1..f1f8dcc 100644 (file)
@@ -6,8 +6,8 @@ from PLC.Faults import *
 from PLC.Parameter import *
 from PLC.Slices import Slice, Slices
 
-from PLC.Accessors.Accessors_standard import *                 # import slice accessors
-from PLC.Accessors.Accessors_omf import *                      # import slice accessors
+from PLC.Accessors.Accessors_standard import *                  # import slice accessors
+from PLC.Accessors.Accessors_omf import *                       # import slice accessors
 
 class GetSliceFamily(Method):
     """
@@ -28,9 +28,9 @@ class GetSliceFamily(Method):
 
     returns = Parameter (str, "the slicefamily this slice should be based upon")
 
-    # 
+    #
     ### system slices - at least planetflow - still rely on 'vref'
-    # 
+    #
     def call(self, auth, slice_id_or_name):
         # Get slice information
         slices = Slices(self.api, [slice_id_or_name])
@@ -59,7 +59,7 @@ class GetSliceFamily(Method):
 
         # xxx would make sense to check the corresponding vserver rpms are available
         # in all node-families yum repos (and yumgroups, btw)
-        if vref: 
+        if vref:
             return "%s-%s-%s"%(vref,fcdistro,arch)
         else:
             return "%s-%s-%s"%(pldistro,fcdistro,arch)
index 7306a01..8ac2716 100644 (file)
@@ -11,11 +11,11 @@ from PLC.Keys import Key, Keys
 
 class GetSliceKeys(Method):
     """
-    Returns an array of structs containing public key info for users in 
-    the specified slices. If slice_filter is specified and is an array 
-    of slice identifiers or slice names, or a struct of slice 
-    attributes, only slices matching the filter will be returned. If 
-    return_fields is specified, only the specified details will be 
+    Returns an array of structs containing public key info for users in
+    the specified slices. If slice_filter is specified and is an array
+    of slice identifiers or slice names, or a struct of slice
+    attributes, only slices matching the filter will be returned. If
+    return_fields is specified, only the specified details will be
     returned.
 
     Users may only query slices of which they are members. PIs may
@@ -35,21 +35,21 @@ class GetSliceKeys(Method):
         ]
 
     returns = [
-       {
-       'slice_id': Slice.fields['slice_id'],
-       'name': Slice.fields['name'], 
-       'person_id': Person.fields['person_id'], 
-       'email': Person.fields['email'],
-       'key': Key.fields['key']
-       }]
+        {
+        'slice_id': Slice.fields['slice_id'],
+        'name': Slice.fields['name'],
+        'person_id': Person.fields['person_id'],
+        'email': Person.fields['email'],
+        'key': Key.fields['key']
+        }]
 
     def call(self, auth, slice_filter = None, return_fields = None):
-       slice_fields = ['slice_id', 'name']
-       person_fields = ['person_id', 'email']
-       key_fields = ['key']
+        slice_fields = ['slice_id', 'name']
+        person_fields = ['person_id', 'email']
+        key_fields = ['key']
 
-       # If we are not admin, make sure to return only viewable
-       # slices.
+        # If we are not admin, make sure to return only viewable
+        # slices.
         if isinstance(self.caller, Person) and \
            'admin' not in self.caller['roles']:
             # Get slices that we are able to view
@@ -65,72 +65,71 @@ class GetSliceKeys(Method):
             if slice_filter is None:
                 slice_filter = valid_slice_ids
 
-       if return_fields:
-           slice_return_fields = filter(lambda field: field in slice_fields, return_fields)
-           person_return_fields = filter(lambda field: field in person_fields, return_fields)
-           key_return_fields = filter(lambda field: field in key_fields, return_fields)
-       else:
-           slice_return_fields = slice_fields
-           person_return_fields = person_fields
-           key_return_fields = key_fields
-
-       # Must query at least Slice.slice_id, Slice.person_ids, 
-       # and Person.person_id and Person.key_ids so we can join data correctly
+        if return_fields:
+            slice_return_fields = filter(lambda field: field in slice_fields, return_fields)
+            person_return_fields = filter(lambda field: field in person_fields, return_fields)
+            key_return_fields = filter(lambda field: field in key_fields, return_fields)
+        else:
+            slice_return_fields = slice_fields
+            person_return_fields = person_fields
+            key_return_fields = key_fields
+
+        # Must query at least Slice.slice_id, Slice.person_ids,
+        # and Person.person_id and Person.key_ids so we can join data correctly
         slice_added_fields = set(['slice_id', 'person_ids']).difference(slice_return_fields)
         slice_return_fields += slice_added_fields
-       person_added_fields = set(['person_id', 'key_ids']).difference(person_return_fields)
-       person_return_fields += person_added_fields
-       key_added_fields = set(['key_id']).difference(key_return_fields)
-       key_return_fields += key_added_fields
+        person_added_fields = set(['person_id', 'key_ids']).difference(person_return_fields)
+        person_return_fields += person_added_fields
+        key_added_fields = set(['key_id']).difference(key_return_fields)
+        key_return_fields += key_added_fields
 
-       # Get the slices
+        # Get the slices
         all_slices = Slices(self.api, slice_filter, slice_return_fields).dict('slice_id')
-       slice_ids = all_slices.keys()
-       slices = all_slices.values()
+        slice_ids = all_slices.keys()
+        slices = all_slices.values()
 
-       # Filter out slices that are not viewable
+        # Filter out slices that are not viewable
         if isinstance(self.caller, Person) and \
            'admin' not in self.caller['roles']:
             slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices)
-       
-       # Get the persons
-       person_ids = set()
-       for slice in slices:
-           person_ids.update(slice['person_ids'])
-
-       all_persons = Persons(self.api, list(person_ids), person_return_fields).dict('person_id')
-       person_ids = all_persons.keys()
-       persons = all_persons.values()
-       
-       # Get the keys
-       key_ids = set()
-       for person in persons:
-           key_ids.update(person['key_ids'])
-       
-       all_keys = Keys(self.api, list(key_ids), key_return_fields).dict('key_id')
-       key_ids = all_keys.keys()
-       keys = all_keys.values()
-
-       # Create slice_keys list
-       slice_keys = []
-       slice_fields = list(set(slice_return_fields).difference(slice_added_fields))
-       person_fields = list(set(person_return_fields).difference(person_added_fields))
-       key_fields = list(set(key_return_fields).difference(key_added_fields))
-
-       for slice in slices:
-            slice_key = dict.fromkeys(slice_fields + person_fields + key_fields)
-           if not slice['person_ids']:
-               continue
-           for person_id in slice['person_ids']:
-               person = all_persons[person_id]
-               if not person['key_ids']:
-                   continue
-               for key_id in person['key_ids']:
-                   key = all_keys[key_id]
-                   slice_key.update(dict(filter(lambda (k, v): k in slice_fields, slice.items())))
-                   slice_key.update(dict(filter(lambda (k, v): k in person_fields, person.items())))
-                   slice_key.update(dict(filter(lambda (k, v): k in key_fields, key.items())))
-                   slice_keys.append(slice_key.copy())
-
-       return slice_keys       
 
+        # Get the persons
+        person_ids = set()
+        for slice in slices:
+            person_ids.update(slice['person_ids'])
+
+        all_persons = Persons(self.api, list(person_ids), person_return_fields).dict('person_id')
+        person_ids = all_persons.keys()
+        persons = all_persons.values()
+
+        # Get the keys
+        key_ids = set()
+        for person in persons:
+            key_ids.update(person['key_ids'])
+
+        all_keys = Keys(self.api, list(key_ids), key_return_fields).dict('key_id')
+        key_ids = all_keys.keys()
+        keys = all_keys.values()
+
+        # Create slice_keys list
+        slice_keys = []
+        slice_fields = list(set(slice_return_fields).difference(slice_added_fields))
+        person_fields = list(set(person_return_fields).difference(person_added_fields))
+        key_fields = list(set(key_return_fields).difference(key_added_fields))
+
+        for slice in slices:
+            slice_key = dict.fromkeys(slice_fields + person_fields + key_fields)
+            if not slice['person_ids']:
+                continue
+            for person_id in slice['person_ids']:
+                person = all_persons[person_id]
+                if not person['key_ids']:
+                    continue
+                for key_id in person['key_ids']:
+                    key = all_keys[key_id]
+                    slice_key.update(dict(filter(lambda (k, v): k in slice_fields, slice.items())))
+                    slice_key.update(dict(filter(lambda (k, v): k in person_fields, person.items())))
+                    slice_key.update(dict(filter(lambda (k, v): k in key_fields, key.items())))
+                    slice_keys.append(slice_key.copy())
+
+        return slice_keys
index 41ed3e9..45a445f 100644 (file)
@@ -36,11 +36,11 @@ class GetSliceTags(Method):
         ]
 
     returns = [SliceTag.fields]
-    
+
 
     def call(self, auth, slice_tag_filter = None, return_fields = None):
-       # If we are not admin, make sure to only return our own slice
-       # and sliver attributes.
+        # If we are not admin, make sure to only return our own slice
+        # and sliver attributes.
         if isinstance(self.caller, Person) and \
            'admin' not in self.caller['roles']:
             # Get slices that we are able to view
@@ -84,7 +84,7 @@ class GetSliceTags(Method):
         # Remove slice_tag_id if not specified
         if added_fields:
             for slice_tag in slice_tags:
-               if 'slice_tag_id' in slice_tag:
-                   del slice_tag['slice_tag_id']
+                if 'slice_tag_id' in slice_tag:
+                    del slice_tag['slice_tag_id']
 
         return slice_tags
index cbf4d95..90c0f63 100644 (file)
@@ -57,12 +57,12 @@ class GetSliceTicket(Method):
 
         # Tickets are the canonicalized XML-RPC methodResponse
         # representation of a partial GetSlivers() response, i.e.,
-       
-       initscripts = InitScripts(self.api, {'enabled': True})
+
+        initscripts = InitScripts(self.api, {'enabled': True})
 
         data = {
             'timestamp': int(time.time()),
-           'initscripts': initscripts,
+            'initscripts': initscripts,
             'slivers': get_slivers(self.api, auth, [slice['slice_id']]),
             }
 
index ab4cdf6..22e5e1e 100644 (file)
@@ -37,8 +37,8 @@ class GetSlices(Method):
     returns = [Slice.fields]
 
     def call(self, auth, slice_filter = None, return_fields = None):
-       # If we are not admin, make sure to return only viewable
-       # slices.
+        # If we are not admin, make sure to return only viewable
+        # slices.
         if isinstance(self.caller, Person) and \
            'admin' not in self.caller['roles']:
             # Get slices that we are able to view
@@ -71,8 +71,7 @@ class GetSlices(Method):
         # Remove slice_id if not specified
         if added_fields:
             for slice in slices:
-               if 'slice_id' in slice:
-                   del slice['slice_id']
+                if 'slice_id' in slice:
+                    del slice['slice_id']
 
         return slices
-
index 28dee1e..951b352 100644 (file)
@@ -77,7 +77,7 @@ def get_slivers(api, auth, slice_filter, node = None):
         # Per-node sliver attributes take precedence over global
         # slice attributes, so set them first.
         # Then comes nodegroup slice attributes
-       # Followed by global slice attributes
+        # Followed by global slice attributes
         sliver_attributes = []
 
         if node is not None:
@@ -86,14 +86,14 @@ def get_slivers(api, auth, slice_filter, node = None):
                 attributes.append({'tagname': sliver_attribute['tagname'],
                                    'value': sliver_attribute['value']})
 
-           # set nodegroup slice attributes
-           for slice_tag in [ a for a in slice_tags if a['nodegroup_id'] in node['nodegroup_ids'] ]:
-               # Do not set any nodegroup slice attributes for
+            # set nodegroup slice attributes
+            for slice_tag in [ a for a in slice_tags if a['nodegroup_id'] in node['nodegroup_ids'] ]:
+                # Do not set any nodegroup slice attributes for
                 # which there is at least one sliver attribute
                 # already set.
-               if slice_tag not in slice_tags:
-                   attributes.append({'tagname': slice_tag['tagname'],
-                                  'value': slice_tag['value']})
+                if slice_tag not in slice_tags:
+                    attributes.append({'tagname': slice_tag['tagname'],
+                                   'value': slice_tag['value']})
 
         for slice_tag in [ a for a in slice_tags if a['node_id'] is None ]:
             # Do not set any global slice attributes for
@@ -149,7 +149,7 @@ class GetSlivers(Method):
         'interfaces': [Interface.fields],
         'groups': [NodeGroup.fields['groupname']],
         'conf_files': [ConfFile.fields],
-       'initscripts': [InitScript.fields],
+        'initscripts': [InitScript.fields],
         'accounts': [{
             'name': Parameter(str, "unix style account name", max = 254),
             'keys': [{
@@ -222,7 +222,7 @@ class GetSlivers(Method):
         for conf_file in all_conf_files.values():
             if not conf_file['node_ids'] and not conf_file['nodegroup_ids']:
                 conf_files[conf_file['dest']] = conf_file
-        
+
         # Node group configuration files take precedence over global
         # ones. If a node belongs to multiple node groups for which
         # the same configuration file is defined, it is undefined
@@ -232,28 +232,28 @@ class GetSlivers(Method):
                 if conf_file_id in all_conf_files:
                     conf_file = all_conf_files[conf_file_id]
                     conf_files[conf_file['dest']] = conf_file
-        
+
         # Node configuration files take precedence over node group
         # configuration files.
         for conf_file_id in node['conf_file_ids']:
             if conf_file_id in all_conf_files:
                 conf_file = all_conf_files[conf_file_id]
-                conf_files[conf_file['dest']] = conf_file            
+                conf_files[conf_file['dest']] = conf_file
 
-       # Get all (enabled) initscripts
-       initscripts = InitScripts(self.api, {'enabled': True})  
+        # Get all (enabled) initscripts
+        initscripts = InitScripts(self.api, {'enabled': True})
 
         # Get system slices
         system_slice_tags = SliceTags(self.api, {'tagname': 'system', 'value': '1'}).dict('slice_id')
         system_slice_ids = system_slice_tags.keys()
-       
-       # Get nm-controller slices
+
+        # Get nm-controller slices
         # xxx Thierry: should these really be exposed regardless of their mapping to nodes ?
-       controller_and_delegated_slices = Slices(self.api, {'instantiation': ['nm-controller', 'delegated']}, ['slice_id']).dict('slice_id')
-       controller_and_delegated_slice_ids = controller_and_delegated_slices.keys()
-       slice_ids = system_slice_ids + controller_and_delegated_slice_ids + node['slice_ids']
+        controller_and_delegated_slices = Slices(self.api, {'instantiation': ['nm-controller', 'delegated']}, ['slice_id']).dict('slice_id')
+        controller_and_delegated_slice_ids = controller_and_delegated_slices.keys()
+        slice_ids = system_slice_ids + controller_and_delegated_slice_ids + node['slice_ids']
 
-       slivers = get_slivers(self.api, auth, slice_ids, node)
+        slivers = get_slivers(self.api, auth, slice_ids, node)
 
         # get the special accounts and keys needed for the node
         # root
@@ -270,19 +270,19 @@ class GetSlivers(Method):
         # power users are pis and techs
         def get_site_power_user_keys(api,site_id_or_name):
             site = Sites (api,site_id_or_name,['person_ids'])[0]
-            key_ids = reduce (reduce_flatten_list, 
+            key_ids = reduce (reduce_flatten_list,
                               [ p['key_ids'] for p in \
-                                    Persons(api,{ 'person_id':site['person_ids'], 
-                                                  'enabled':True, '|role_ids' : [20, 40] }, 
+                                    Persons(api,{ 'person_id':site['person_ids'],
+                                                  'enabled':True, '|role_ids' : [20, 40] },
                                             ['key_ids']) ],
                               [])
             return [ key['key'] for key in Keys (api, key_ids) if key['key_type']=='ssh']
 
         # all admins regardless of their site
         def get_all_admin_keys(api):
-            key_ids = reduce (reduce_flatten_list, 
+            key_ids = reduce (reduce_flatten_list,
                               [ p['key_ids'] for p in \
-                                    Persons(api, {'peer_id':None, 'enabled':True, '|role_ids':[10] }, 
+                                    Persons(api, {'peer_id':None, 'enabled':True, '|role_ids':[10] },
                                             ['key_ids']) ],
                               [])
             return [ key['key'] for key in Keys (api, key_ids) if key['key_type']=='ssh']
@@ -308,7 +308,7 @@ class GetSlivers(Method):
         except:
             xmpp={'server':None,'user':None,'password':None}
 
-       node.update_last_contact()
+        node.update_last_contact()
 
         # expose leases & reservation policy
         # in a first implementation we only support none and lease_or_idle
@@ -319,7 +319,7 @@ class GetSlivers(Method):
         else:
             reservation_policy='lease_or_idle'
             # expose the leases for the next 24 hours
-            leases = [ dict ( [ (k,l[k]) for k in lease_exposed_fields ] ) 
+            leases = [ dict ( [ (k,l[k]) for k in lease_exposed_fields ] )
                        for l in Leases (self.api, {'node_id':node['node_id'],
                                                    'clip': (timestamp, timestamp+24*Duration.HOUR),
                                                    '-SORT': 't_from',
@@ -333,7 +333,7 @@ class GetSlivers(Method):
             'interfaces': interfaces,
             'groups': groups,
             'conf_files': conf_files.values(),
-           'initscripts': initscripts,
+            'initscripts': initscripts,
             'slivers': slivers,
             'accounts': accounts,
             'xmpp':xmpp,
index 852a7af..ca3bbae 100644 (file)
@@ -10,7 +10,7 @@ from PLC.Auth import Auth
 
 class GetWhitelist(Method):
     """
-    Returns an array of structs containing details about the specified nodes 
+    Returns an array of structs containing details about the specified nodes
     whitelists. If node_filter is specified and is an array of node identifiers or
     hostnames, or a struct of node attributes, only nodes matching the
     filter will be returned. If return_fields is specified, only the
@@ -33,43 +33,43 @@ class GetWhitelist(Method):
 
 
     def call(self, auth, node_filter = None, return_fields = None):
-        
-       # Must query at least slice_ids_whitelist
-       if return_fields is not None:
-           added_fields = set(['slice_ids_whitelist']).difference(return_fields)
-           return_fields += added_fields
-       else:
-           added_fields =[]    
 
-       # Get node information
+        # Must query at least slice_ids_whitelist
+        if return_fields is not None:
+            added_fields = set(['slice_ids_whitelist']).difference(return_fields)
+            return_fields += added_fields
+        else:
+            added_fields =[]
+
+        # Get node information
         nodes = Nodes(self.api, node_filter, return_fields)
 
-       # Remove all nodes without a whitelist
-       for node in nodes[:]:
-           if not node['slice_ids_whitelist']:
-               nodes.remove(node)
+        # Remove all nodes without a whitelist
+        for node in nodes[:]:
+            if not node['slice_ids_whitelist']:
+                nodes.remove(node)
 
         # Remove admin only fields
         if not isinstance(self.caller, Person) or \
            'admin' not in self.caller['roles']:
-           slice_ids = set()
-           if self.caller:
-               slice_ids.update(self.caller['slice_ids'])
-           #if node has whitelist, make sure the user has a slice on the whitelist 
+            slice_ids = set()
+            if self.caller:
+                slice_ids.update(self.caller['slice_ids'])
+            #if node has whitelist, make sure the user has a slice on the whitelist
             for node in nodes[:]:
-               if 'slice_ids_whitelist' in node and \
-                  node['slice_ids_whitelist'] and \
-                  not slice_ids.intersection(node['slice_ids_whitelist']):
-                   nodes.remove(node)
-           for node in nodes:   
+                if 'slice_ids_whitelist' in node and \
+                   node['slice_ids_whitelist'] and \
+                   not slice_ids.intersection(node['slice_ids_whitelist']):
+                    nodes.remove(node)
+            for node in nodes:
                 for field in ['boot_nonce', 'key', 'session', 'root_person_ids']:
                     if field in node:
                         del node[field]
 
-       # remove added fields if not specified
-       if added_fields:
-           for node in nodes:
-               for field in added_fields:
-                   del node[field]     
+        # remove added fields if not specified
+        if added_fields:
+            for node in nodes:
+                for field in added_fields:
+                    del node[field]
 
         return nodes
index bf71520..84b599f 100644 (file)
@@ -7,7 +7,7 @@ from PLC.sendmail import sendmail
 
 class NotifySupport(Method):
     """
-    Sends an e-mail message to the configured support address. 
+    Sends an e-mail message to the configured support address.
 
     Returns 1 if successful.
     """
index 7f0d1b5..956d342 100644 (file)
@@ -69,7 +69,7 @@ class RebootNode(Method):
             # Ignore socket errors
             pass
 
-       self.event_objects = {'Node': [node['node_id']]}
-       self.message = "RebootNode called"
-               
+        self.event_objects = {'Node': [node['node_id']]}
+        self.message = "RebootNode called"
+
         return 1
index ac5b6b6..2a31e2b 100644 (file)
@@ -11,22 +11,22 @@ from PLC.Nodes import Node, Nodes
 from PLC.PCUs import PCU, PCUs
 
 try:
-       from pcucontrol import reboot
-       external_dependency = True
+    from pcucontrol import reboot
+    external_dependency = True
 except:
-       external_dependency = False
+    external_dependency = False
 
 class RebootNodeWithPCU(Method):
     """
-       Uses the associated PCU to attempt to reboot the given Node.
+        Uses the associated PCU to attempt to reboot the given Node.
 
     Admins can reboot any node. Techs and PIs can only reboot nodes at
     their site.
 
     Returns 1 if the reboot proceeded without error (Note: this does not guarantee
-       that the reboot is successful).
-       Returns -1 if external dependencies for this call are not available.
-       Returns "error string" if the reboot failed with a specific message.
+        that the reboot is successful).
+        Returns -1 if external dependencies for this call are not available.
+        Returns "error string" if the reboot failed with a specific message.
     """
 
     roles = ['admin', 'pi', 'tech']
@@ -41,7 +41,7 @@ class RebootNodeWithPCU(Method):
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth, node_id_or_hostname, testrun=None):
-        # Get account information
+    # Get account information
         nodes = Nodes(self.api, [node_id_or_hostname])
         if not nodes:
             raise PLCInvalidArgument, "No such node"
@@ -60,22 +60,22 @@ class RebootNodeWithPCU(Method):
             if node['site_id'] not in self.caller['site_ids']:
                 raise PLCPermissionDenied, "Not allowed to reboot nodes from specified site"
 
-       # Verify that the node has pcus associated with it.
-       pcus = PCUs(self.api, {'pcu_id' : node['pcu_ids']} )
+        # Verify that the node has pcus associated with it.
+        pcus = PCUs(self.api, {'pcu_id' : node['pcu_ids']} )
         if not pcus:
             raise PLCInvalidArgument, "No PCUs associated with Node"
 
-       pcu = pcus[0]
+        pcu = pcus[0]
 
-       if not external_dependency:
+        if not external_dependency:
             raise PLCNotImplemented, "Could not load external module to attempt reboot"
 
-       # model, hostname, port, 
-       # i = pcu['node_ids'].index(node['node_id'])
-       # p = pcu['ports'][i]
-       ret = reboot.reboot_api(node, pcu, testrun)
+        # model, hostname, port,
+        # i = pcu['node_ids'].index(node['node_id'])
+        # p = pcu['ports'][i]
+        ret = reboot.reboot_api(node, pcu, testrun)
 
         self.event_objects = {'Node': [node['node_id']]}
         self.message = "RebootNodeWithPCU called"
-               
+
         return ret
index fe81e39..4a5a6cc 100644 (file)
@@ -1,6 +1,6 @@
 #
 # Thierry Parmentelat - INRIA
-# 
+#
 # $Id$
 # $URL$
 
@@ -108,24 +108,24 @@ class RefreshPeer(Method):
         file_lock.unlock()
         return ret_val
 
-        
+
     def real_call(self, auth, peer_id_or_peername):
         # Get peer
-       peers = Peers(self.api, [peer_id_or_peername])
+        peers = Peers(self.api, [peer_id_or_peername])
         if not peers:
             raise PLCInvalidArgument, "No such peer '%s'" % unicode(peer_id_or_peername)
         peer = peers[0]
         peer_id = peer['peer_id']
 
-       # Connect to peer API
+        # Connect to peer API
         peer.connect()
 
         timers = {}
 
         # Get peer data
         start = time.time()
-       message('RefreshPeer starting up (commit_mode=%r)'%commit_mode)
-       message('Issuing GetPeerData')
+        message('RefreshPeer starting up (commit_mode=%r)'%commit_mode)
+        message('Issuing GetPeerData')
         peer_tables = peer.GetPeerData()
         # for smooth federation with 4.2 - ignore fields that are useless anyway, and rewrite boot_state
         boot_state_rewrite={'dbg':'safeboot','diag':'safeboot','disable':'disabled',
@@ -172,7 +172,7 @@ class RefreshPeer(Method):
             def trace (message):
                 if classname == trace_type and peer_object_id in trace_ids:
                     message_verbose('TRACE>>'+message)
-                
+
             # Add/update new/existing objects
             for peer_object_id, peer_object in peer_objects.iteritems():
                 message_verbose ('DBG %s peer_object_id=%d (%d/%d)'%(classname,peer_object_id,count,total))
@@ -333,10 +333,10 @@ class RefreshPeer(Method):
         # Keyed on foreign person_id
         old_peer_persons = Persons(self.api, {'peer_id': peer_id}, columns).dict('peer_person_id')
 
-       # artificially attach the persons returned by GetPeerData to the new peer 
-       # this is because validate_email needs peer_id to be correct when checking for duplicates 
-       for person in peer_tables['Persons']: 
-           person['peer_id']=peer_id
+        # artificially attach the persons returned by GetPeerData to the new peer
+        # this is because validate_email needs peer_id to be correct when checking for duplicates
+        for person in peer_tables['Persons']:
+            person['peer_id']=peer_id
         persons_at_peer = dict([(peer_person['person_id'], peer_person) \
                                 for peer_person in peer_tables['Persons']])
 
@@ -345,9 +345,9 @@ class RefreshPeer(Method):
         # Synchronize new set (still keyed on foreign person_id)
         peer_persons = sync(old_peer_persons, persons_at_peer, Person)
 
-       # transcoder : retrieve a local key_id from a peer_key_id
-       key_transcoder = dict ( [ (key['key_id'],peer_key_id) \
-                                 for peer_key_id,key in peer_keys.iteritems()])
+        # transcoder : retrieve a local key_id from a peer_key_id
+        key_transcoder = dict ( [ (key['key_id'],peer_key_id) \
+                                  for peer_key_id,key in peer_keys.iteritems()])
 
         for peer_person_id, person in peer_persons.iteritems():
             # Bind any newly cached users to peer
@@ -359,24 +359,24 @@ class RefreshPeer(Method):
 
             # User as viewed by peer
             peer_person = persons_at_peer[peer_person_id]
-            
+
             # Foreign keys currently belonging to the user
-           old_person_key_ids = [key_transcoder[key_id] for key_id in person['key_ids'] \
-                                 if key_transcoder[key_id] in peer_keys]
+            old_person_key_ids = [key_transcoder[key_id] for key_id in person['key_ids'] \
+                                  if key_transcoder[key_id] in peer_keys]
 
             # Foreign keys that should belong to the user
-           # this is basically peer_person['key_ids'], we just check it makes sense 
-           # (e.g. we might have failed importing it)
-           person_key_ids = [ key_id for key_id in peer_person['key_ids'] if key_id in peer_keys]
+            # this is basically peer_person['key_ids'], we just check it makes sense
+            # (e.g. we might have failed importing it)
+            person_key_ids = [ key_id for key_id in peer_person['key_ids'] if key_id in peer_keys]
 
             # Remove stale keys from user
-           for key_id in (set(old_person_key_ids) - set(person_key_ids)):
-               person.remove_key(peer_keys[key_id], commit = commit_mode)
+            for key_id in (set(old_person_key_ids) - set(person_key_ids)):
+                person.remove_key(peer_keys[key_id], commit = commit_mode)
                 message ("%s Key %d removed from person %s"%(peer['peername'], key_id, person['email']))
 
             # Add new keys to user
-           for key_id in (set(person_key_ids) - set(old_person_key_ids)):
-               person.add_key(peer_keys[key_id], commit = commit_mode)
+            for key_id in (set(person_key_ids) - set(old_person_key_ids)):
+                person.add_key(peer_keys[key_id], commit = commit_mode)
                 message ("%s Key %d added into person %s"%(peer['peername'],key_id, person['email']))
 
         timers['persons'] = time.time() - start
@@ -508,11 +508,11 @@ class RefreshPeer(Method):
         peer_slices = sync(old_peer_slices, slices_at_peer, Slice)
 
         message('Dealing with Slices (2)')
-       # transcoder : retrieve a local node_id from a peer_node_id
-       node_transcoder = dict ( [ (node['node_id'],peer_node_id) \
-                                  for peer_node_id,node in peer_nodes.iteritems()])
-       person_transcoder = dict ( [ (person['person_id'],peer_person_id) \
-                                    for peer_person_id,person in peer_persons.iteritems()])
+        # transcoder : retrieve a local node_id from a peer_node_id
+        node_transcoder = dict ( [ (node['node_id'],peer_node_id) \
+                                   for peer_node_id,node in peer_nodes.iteritems()])
+        person_transcoder = dict ( [ (person['person_id'],peer_person_id) \
+                                     for peer_person_id,person in peer_persons.iteritems()])
 
         for peer_slice_id, slice in peer_slices.iteritems():
             # Bind any newly cached foreign slices to peer
@@ -527,11 +527,11 @@ class RefreshPeer(Method):
             peer_slice = slices_at_peer[peer_slice_id]
 
             # Nodes that are currently part of the slice
-           old_slice_node_ids = [ node_transcoder[node_id] for node_id in slice['node_ids'] \
-                                  if node_id in node_transcoder and node_transcoder[node_id] in peer_nodes]
+            old_slice_node_ids = [ node_transcoder[node_id] for node_id in slice['node_ids'] \
+                                   if node_id in node_transcoder and node_transcoder[node_id] in peer_nodes]
 
             # Nodes that should be part of the slice
-           slice_node_ids = [ node_id for node_id in peer_slice['node_ids'] if node_id in peer_nodes]
+            slice_node_ids = [ node_id for node_id in peer_slice['node_ids'] if node_id in peer_nodes]
 
             # Remove stale nodes from slice
             for node_id in (set(old_slice_node_ids) - set(slice_node_ids)):
@@ -547,22 +547,22 @@ class RefreshPeer(Method):
             # by hand, are removed. In other words, don't do this.
 
             # Foreign users that are currently part of the slice
-           #old_slice_person_ids = [ person_transcoder[person_id] for person_id in slice['person_ids'] \
-           #                if person_transcoder[person_id] in peer_persons]
-           # An issue occurred with a user who registered on both sites (same email)
-           # So the remote person could not get cached locally
-           # The one-line map/filter style is nicer but ineffective here
-           old_slice_person_ids = []
-           for person_id in slice['person_ids']:
-               if not person_transcoder.has_key(person_id):
+            #old_slice_person_ids = [ person_transcoder[person_id] for person_id in slice['person_ids'] \
+            #                if person_transcoder[person_id] in peer_persons]
+            # An issue occurred with a user who registered on both sites (same email)
+            # So the remote person could not get cached locally
+            # The one-line map/filter style is nicer but ineffective here
+            old_slice_person_ids = []
+            for person_id in slice['person_ids']:
+                if not person_transcoder.has_key(person_id):
                     message ('WARNING : person_id %d in %s not transcodable (1) - skipped'%(person_id,slice['name']))
-               elif person_transcoder[person_id] not in peer_persons:
+                elif person_transcoder[person_id] not in peer_persons:
                     message('WARNING : person_id %d in %s not transcodable (2) - skipped'%(person_id,slice['name']))
-               else:
-                   old_slice_person_ids += [person_transcoder[person_id]]
+                else:
+                    old_slice_person_ids += [person_transcoder[person_id]]
 
             # Foreign users that should be part of the slice
-           slice_person_ids = [ person_id for person_id in peer_slice['person_ids'] if person_id in peer_persons ]
+            slice_person_ids = [ person_id for person_id in peer_slice['person_ids'] if person_id in peer_persons ]
 
             # Remove stale users from slice
             for person_id in (set(old_slice_person_ids) - set(slice_person_ids)):
@@ -581,5 +581,5 @@ class RefreshPeer(Method):
 
         # Update peer itself and commit
         peer.sync(commit = True)
-        
+
         return timers
index e903122..1d3dc29 100644 (file)
@@ -49,7 +49,7 @@ class ReportRunlevel(Method):
                 node.update({field : report_fields[field]})
 
         node.sync(commit=True)
-        
+
         # skip logging in this case
         if former_level and 'run_level' in node and node['run_level'] == former_level:
             pass
index b066529..61abd45 100644 (file)
@@ -37,14 +37,14 @@ class ResetPassword(Method):
         Auth(),
         Mixed(Person.fields['person_id'],
               Person.fields['email']),
-       Person.fields['verification_key'],
+        Person.fields['verification_key'],
         Person.fields['verification_expires']
         ]
 
     returns = Parameter(int, '1 if verification_key is valid')
 
     def call(self, auth, person_id_or_email, verification_key = None, verification_expires = None):
-       # Get account information
+        # Get account information
         # we need to search in local objects only
         if isinstance (person_id_or_email,StringTypes):
             filter={'email':person_id_or_email}
@@ -123,7 +123,7 @@ class ResetPassword(Method):
         else:
             print >> log, "Warning: No message template '%s'" % message_id
 
-       # Logging variables
+        # Logging variables
         self.event_objects = {'Person': [person['person_id']]}
         self.message = message_id
 
index 2a33ef2..7f5fb92 100644 (file)
@@ -19,7 +19,7 @@ class ResolveSlices(Method):
 
     roles = ['admin', 'pi', 'user', 'tech', 'anonymous' ]
 
-    applicable_fields = { 
+    applicable_fields = {
         'slice_id' : Slice.fields['slice_id'],
         'name' : Slice.fields['name'],
         }
index 72f8c9c..4be4ee0 100644 (file)
@@ -13,13 +13,13 @@ class SliceCreate(AddSlice):
     """
 
     status = "deprecated"
-    
+
     accepts = [
         Auth(),
         Slice.fields['name'],
         AddSlice.accepts[1]
         ]
-    
+
     returns = Parameter(int, 'New slice_id (> 0) if successful')
 
     def call(self, auth, name, slice_fields = {}):
index 453b707..c0f73c7 100644 (file)
@@ -28,4 +28,4 @@ class SliceDelete(DeleteSlice):
 
     def call(self, auth, slice_name):
 
-       return DeleteSlice.call(self, auth, slice_name)
+        return DeleteSlice.call(self, auth, slice_name)
index 5469e81..19228ea 100644 (file)
@@ -14,8 +14,8 @@ class SliceExtendedInfo(Method):
     """
     Deprecated. Can be implemented with GetSlices.
 
-    Returns an array of structs containing details about slices. 
-    The summary can optionally include the list of nodes in and 
+    Returns an array of structs containing details about slices.
+    The summary can optionally include the list of nodes in and
     users of each slice.
 
     Users may only query slices of which they are members. PIs may
@@ -32,18 +32,18 @@ class SliceExtendedInfo(Method):
         Auth(),
         [Slice.fields['name']],
         Parameter(bool, "Whether or not to return users for the slices", nullok = True),
-       Parameter(bool, "Whether or not to return nodes for the slices", nullok = True)
+        Parameter(bool, "Whether or not to return nodes for the slices", nullok = True)
         ]
 
     returns = [Slice.fields]
-    
+
 
     def call(self, auth, slice_name_list=None, return_users=None, return_nodes=None, return_attributes=None):
-       # If we are not admin, make sure to return only viewable
-       # slices.
-       slice_filter = slice_name_list
-       slices = Slices(self.api, slice_filter)
-       if not slices:
+        # If we are not admin, make sure to return only viewable
+        # slices.
+        slice_filter = slice_name_list
+        slices = Slices(self.api, slice_filter)
+        if not slices:
             raise PLCInvalidArgument, "No such slice"
 
         if 'admin' not in self.caller['roles']:
@@ -56,31 +56,31 @@ class SliceExtendedInfo(Method):
 
             if not valid_slice_ids:
                 return []
-         
-           slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices)
 
-       for slice in slices:
-           index = slices.index(slice)
+            slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices)
+
+        for slice in slices:
+            index = slices.index(slice)
             node_ids = slices[index].pop('node_ids')
             person_ids = slices[index].pop('person_ids')
-           attribute_ids = slices[index].pop('slice_tag_ids')
+            attribute_ids = slices[index].pop('slice_tag_ids')
             if return_users or return_users is None:
                 persons = Persons(self.api, person_ids)
-                person_info = [{'email': person['email'], 
-                               'person_id': person['person_id']} \
-                              for person in persons]
+                person_info = [{'email': person['email'],
+                                'person_id': person['person_id']} \
+                               for person in persons]
                 slices[index]['users'] = person_info
             if return_nodes or return_nodes is None:
                 nodes = Nodes(self.api, node_ids)
-                node_info = [{'hostname': node['hostname'], 
-                             'node_id': node['node_id']} \
-                            for node in nodes]
+                node_info = [{'hostname': node['hostname'],
+                              'node_id': node['node_id']} \
+                             for node in nodes]
                 slices[index]['nodes'] = node_info
-           if return_attributes or return_attributes is None:
-               attributes = SliceTags(self.api, attribute_ids)
-               attribute_info = [{'name': attribute['name'],
-                                  'value': attribute['value']} \
-                                 for attribute in attributes]
-               slices[index]['attributes'] = attribute_info
-       
+            if return_attributes or return_attributes is None:
+                attributes = SliceTags(self.api, attribute_ids)
+                attribute_info = [{'name': attribute['name'],
+                                   'value': attribute['value']} \
+                                  for attribute in attributes]
+                slices[index]['attributes'] = attribute_info
+
         return slices
index d687cf8..59c67bb 100644 (file)
@@ -113,7 +113,7 @@ class SliceGetTicket(GetSliceTicket):
                          {'id': str(slice['slice_id']),
                           'name': unicode(slice['name']),
                           'expiry': unicode(int(slice['expires']))})
-        
+
         # <nodes>
         xml.startElement('nodes', {})
         for node_id in slice['node_ids']:
index 15b1665..9f36f65 100644 (file)
@@ -14,8 +14,8 @@ class SliceInfo(Method):
     """
     Deprecated. Can be implemented with GetSlices.
 
-    Returns an array of structs containing details about slices. 
-    The summary can optionally include the list of nodes in and 
+    Returns an array of structs containing details about slices.
+    The summary can optionally include the list of nodes in and
     users of each slice.
 
     Users may only query slices of which they are members. PIs may
@@ -32,18 +32,18 @@ class SliceInfo(Method):
         Auth(),
         [Mixed(Slice.fields['name'])],
         Parameter(bool, "Whether or not to return users for the slices", nullok = True),
-       Parameter(bool, "Whether or not to return nodes for the slices", nullok = True)
+        Parameter(bool, "Whether or not to return nodes for the slices", nullok = True)
         ]
 
     returns = [Slice.fields]
-    
+
 
     def call(self, auth, slice_name_list=None, return_users=None, return_nodes=None):
-       # If we are not admin, make sure to return only viewable
-       # slices.
-       slice_filter = slice_name_list
-       slices = Slices(self.api, slice_filter)
-       if not slices:
+        # If we are not admin, make sure to return only viewable
+        # slices.
+        slice_filter = slice_name_list
+        slices = Slices(self.api, slice_filter)
+        if not slices:
             raise PLCInvalidArgument, "No such slice"
 
         if 'admin' not in self.caller['roles']:
@@ -56,22 +56,22 @@ class SliceInfo(Method):
 
             if not valid_slice_ids:
                 return []
-       
-           slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices)
-
-
-       for slice in slices:
-           index = slices.index(slice)
-           node_ids = slices[index].pop('node_ids')
-           person_ids = slices[index].pop('person_ids')
-           if return_users or return_users is None:
-               persons = Persons(self.api, person_ids)
-               emails = [person['email'] for person in persons]
-               slices[index]['users'] = emails
-           if return_nodes or return_nodes is None:
-               nodes = Nodes(self.api, node_ids)
-               hostnames = [node['hostname'] for node in nodes]
-               slices[index]['nodes'] = hostnames
-               
-       
+
+            slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices)
+
+
+        for slice in slices:
+            index = slices.index(slice)
+            node_ids = slices[index].pop('node_ids')
+            person_ids = slices[index].pop('person_ids')
+            if return_users or return_users is None:
+                persons = Persons(self.api, person_ids)
+                emails = [person['email'] for person in persons]
+                slices[index]['users'] = emails
+            if return_nodes or return_nodes is None:
+                nodes = Nodes(self.api, node_ids)
+                hostnames = [node['hostname'] for node in nodes]
+                slices[index]['nodes'] = hostnames
+
+
         return slices
index 0f8df16..8db20a8 100644 (file)
@@ -29,19 +29,19 @@ class SliceListNames(GetSlices):
         ]
 
     returns = [Slice.fields['name']]
-    
+
 
     def call(self, auth, prefix=None):
 
-       slice_filter = None
+        slice_filter = None
         if prefix:
             slice_filter = {'name': prefix+'*'}
-       
+
         slices = GetSlices.call(self, auth, slice_filter)
-       
+
         if not slices:
             raise PLCInvalidArgument, "No such slice"
-       
-       slice_names = [slice['name'] for slice in slices]
+
+        slice_names = [slice['name'] for slice in slices]
 
         return slice_names
index 91936c2..185800b 100644 (file)
@@ -31,19 +31,19 @@ class SliceListUserSlices(GetSlices, GetPersons):
         ]
 
     returns = [Slice.fields['name']]
-    
+
 
     def call(self, auth, email):
 
-       persons = GetPersons.call(self, auth, [email])
-       if not persons:
-               return []
-       person = persons[0]
-       slice_ids = person['slice_ids']
-       if not slice_ids:
-               return []
-       
-       slices = GetSlices.call(self, auth, slice_ids)
-       slice_names = [slice['name'] for slice in slices]
+        persons = GetPersons.call(self, auth, [email])
+        if not persons:
+            return []
+        person = persons[0]
+        slice_ids = person['slice_ids']
+        if not slice_ids:
+            return []
+
+        slices = GetSlices.call(self, auth, slice_ids)
+        slice_names = [slice['name'] for slice in slices]
 
         return slice_names
index ef3f287..1043524 100644 (file)
@@ -28,4 +28,4 @@ class SliceNodesAdd(AddSliceToNodes):
 
     def call(self, auth, slice_name, nodes_list):
 
-       return AddSliceToNodes.call(self, auth, slice_name, nodes_list)
+        return AddSliceToNodes.call(self, auth, slice_name, nodes_list)
index b810fe8..662b831 100644 (file)
@@ -28,4 +28,4 @@ class SliceNodesDel(DeleteSliceFromNodes):
 
     def call(self, auth, slice_name, nodes_list):
 
-       return DeleteSliceFromNodes.call(self, auth, slice_name, nodes_list)
+        return DeleteSliceFromNodes.call(self, auth, slice_name, nodes_list)
index 590181a..f7a739d 100644 (file)
@@ -14,7 +14,7 @@ class SliceNodesList(GetSlices, GetNodes):
     Deprecated. Can be implemented with GetSlices and GetNodes.
 
     """
-  
+
     status = "deprecated"
 
     roles = ['admin', 'pi', 'user']
@@ -25,18 +25,18 @@ class SliceNodesList(GetSlices, GetNodes):
         ]
 
     returns = [Node.fields['hostname']]
-    
+
 
     def call(self, auth, slice_name):
-       slices = GetSlices.call(self, auth, [slice_name])
-       if not slices:
-           return []
-
-       slice = slices[0]
-       nodes = GetNodes.call(self, auth, slice['node_ids'])
-       if not nodes:
-           return []
-       
-       node_hostnames = [node['hostname'] for node in nodes]           
-       
+        slices = GetSlices.call(self, auth, [slice_name])
+        if not slices:
+            return []
+
+        slice = slices[0]
+        nodes = GetNodes.call(self, auth, slice['node_ids'])
+        if not nodes:
+            return []
+
+        node_hostnames = [node['hostname'] for node in nodes]
+
         return node_hostnames
index cfed340..a495629 100644 (file)
@@ -7,11 +7,11 @@ from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Slices import Slice, Slices
 from PLC.Auth import Auth
-from PLC.Methods.UpdateSlice import UpdateSlice 
+from PLC.Methods.UpdateSlice import UpdateSlice
 
 class SliceRenew(UpdateSlice):
     """
-    Deprecated. See UpdateSlice.    
+    Deprecated. See UpdateSlice.
 
     """
 
@@ -22,15 +22,14 @@ class SliceRenew(UpdateSlice):
     accepts = [
         Auth(),
         Slice.fields['name'],
-       Slice.fields['expires']
+        Slice.fields['expires']
         ]
 
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth, slice_name, slice_expires):
 
-       slice_fields = {}
-       slice_fields['expires'] = slice_expires
-       
-       return UpdateSlice.call(self, auth, slice_name, slice_fields)
+        slice_fields = {}
+        slice_fields['expires'] = slice_expires
+
+        return UpdateSlice.call(self, auth, slice_name, slice_fields)
index 420ccc7..fd3ad4f 100644 (file)
@@ -12,7 +12,7 @@ from PLC.Methods.UpdateSlice import UpdateSlice
 class SliceUpdate(UpdateSlice):
     """
     Deprecated. See UpdateSlice.
-   
+
     """
 
     status = 'deprecated'
@@ -30,10 +30,10 @@ class SliceUpdate(UpdateSlice):
 
     def call(self, auth, slice_name, url, description):
 
-       slice_fields = {}
-       slice_fields['url'] = url
-       slice_fields['description'] = description
-       
-       return UpdateSlice.call(self, auth, slice_name, slice_fields)
+        slice_fields = {}
+        slice_fields['url'] = url
+        slice_fields['description'] = description
+
+        return UpdateSlice.call(self, auth, slice_name, slice_fields)
 
         return 1
index fb8ac72..c0ca278 100644 (file)
@@ -28,7 +28,7 @@ class SliceUserAdd(AddPersonToSlice):
 
     def call(self, auth, slice_name, user_list):
 
-       for user in user_list:
-           AddPersonToSlice.call(self, auth, user, slice_name)
+        for user in user_list:
+            AddPersonToSlice.call(self, auth, user, slice_name)
 
         return 1
index 0cebd66..9426611 100644 (file)
@@ -13,7 +13,7 @@ class SliceUserDel(Method):
     Deprecated. Can be implemented with DeletePersonFromSlice.
 
     Removes the specified users from the specified slice. If the person is
-    already a member of the slice, no errors are returned. 
+    already a member of the slice, no errors are returned.
 
     Returns 1 if successful, faults otherwise.
     """
@@ -31,7 +31,7 @@ class SliceUserDel(Method):
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth, slice_name, user_list):
-       for user in user_list:
-           DeletePersonFromSlice.call(self, auth, user, slice_name)
+        for user in user_list:
+            DeletePersonFromSlice.call(self, auth, user, slice_name)
 
         return 1
index 2c39925..9626993 100644 (file)
@@ -17,7 +17,7 @@ class SliceUsersList(GetSlices, GetPersons):
 
     Users may only query slices of which they are members. PIs may
     query any of the slices at their sites. Admins may query any
-    slice. If a slice that cannot be queried is specified details 
+    slice. If a slice that cannot be queried is specified details
     about that slice will not be returned.
     """
 
@@ -28,20 +28,20 @@ class SliceUsersList(GetSlices, GetPersons):
     accepts = [
         Auth(),
         Slice.fields['name']
-       ]
+        ]
 
     returns = [Person.fields['email']]
-    
+
 
     def call(self, auth, slice_name):
 
-       slice_filter = [slice_name]
+        slice_filter = [slice_name]
         slices = GetSlices.call(self, auth, slice_filter)
-       if not slices:
+        if not slices:
             return []
-       slice = slices[0]
-     
-       persons = GetPersons.call(self, auth, slice['person_ids'])
-       person_emails = [person['email'] for person in persons]
+        slice = slices[0]
+
+        persons = GetPersons.call(self, auth, slice['person_ids'])
+        person_emails = [person['email'] for person in persons]
 
         return person_emails
index 1e5c4f5..8b125fd 100644 (file)
@@ -12,14 +12,14 @@ from PLC.Slices import Slices
 from PLC.Keys import Keys
 from PLC.Peers import Peers
 from PLC.Faults import *
+
 class UnBindObjectFromPeer(Method):
     """
     This method is a hopefully temporary hack to let the sfa correctly
     detach the objects it creates from a remote peer object. This is
     needed so that the sfa federation link can work in parallel with
     RefreshPeer, as RefreshPeer depends on remote objects being
-    correctly marked. 
+    correctly marked.
 
     UnBindObjectFromPeer is allowed to admins only.
     """
index 4586f64..4150972 100644 (file)
@@ -47,10 +47,10 @@ class UpdateAddress(Method):
 
         address.update(address_fields)
         address.sync()
-       
-       # Logging variables
-       self.event_objects = {'Address': [address['address_id']]}
-       self.message = 'Address %d updated: %s' % \
-               (address['address_id'], ", ".join(address_fields.keys()))
-        
-       return 1
+
+        # Logging variables
+        self.event_objects = {'Address': [address['address_id']]}
+        self.message = 'Address %d updated: %s' % \
+                (address['address_id'], ", ".join(address_fields.keys()))
+
+        return 1
index 6110de2..bfd1b78 100644 (file)
@@ -39,6 +39,6 @@ class UpdateAddressType(Method):
 
         address_type.update(address_type_fields)
         address_type.sync()
-       self.event_objects = {'AddressType': [address_type['address_type_id']]}
+        self.event_objects = {'AddressType': [address_type['address_type_id']]}
 
         return 1
index 1148f58..812d73a 100644 (file)
@@ -39,6 +39,6 @@ class UpdateConfFile(Method):
         conf_file = conf_files[0]
         conf_file.update(conf_file_fields)
         conf_file.sync()
-       self.event_objects = {'ConfFile': [conf_file['conf_file_id']]}  
+        self.event_objects = {'ConfFile': [conf_file['conf_file_id']]}
 
         return 1
index 9e86831..dae4633 100644 (file)
@@ -49,5 +49,5 @@ class UpdateIlink(Method):
         ilink['value'] = value
         ilink.sync()
 
-       self.object_ids = [ilink['src_interface_id'],ilink['dst_interface_id']]
+        self.object_ids = [ilink['src_interface_id'],ilink['dst_interface_id']]
         return 1
index 32b8730..d220ddc 100644 (file)
@@ -39,6 +39,6 @@ class UpdateInitScript(Method):
         initscript = initscripts[0]
         initscript.update(initscript_fields)
         initscript.sync()
-       self.event_objects = {'InitScript': [initscript['initscript_id']]}      
+        self.event_objects = {'InitScript': [initscript['initscript_id']]}
 
         return 1
index 61c4557..966128a 100644 (file)
@@ -23,10 +23,10 @@ class UpdateInterface(Method):
     static, then ip, gateway, network, broadcast, netmask, and dns1
     must all be specified in interface_fields. If type is dhcp,
     these parameters, even if specified, are ignored.
-    
+
     PIs and techs may only update interfaces associated with their own
     nodes. Admins may update any interface network.
+
     Returns 1 if successful, faults otherwise.
     """
 
@@ -37,8 +37,8 @@ class UpdateInterface(Method):
 
     accepts = [
         Auth(),
-       Interface.fields['interface_id'],
-       accepted_fields
+        Interface.fields['interface_id'],
+        accepted_fields
         ]
 
     returns = Parameter(int, '1 if successful')
@@ -52,17 +52,17 @@ class UpdateInterface(Method):
         if rejected:
             raise PLCInvalidArgument, "Cannot update Interface column(s) %r"%rejected
 
-       # Get interface information
-       interfaces = Interfaces(self.api, [interface_id])
-       if not interfaces:
+        # Get interface information
+        interfaces = Interfaces(self.api, [interface_id])
+        if not interfaces:
             raise PLCInvalidArgument, "No such interface"
 
-       interface = interfaces[0]
-               
+        interface = interfaces[0]
+
         # Authenticated function
         assert self.caller is not None
 
-       # If we are not an admin, make sure that the caller is a
+        # If we are not an admin, make sure that the caller is a
         # member of the site where the node exists.
         if 'admin' not in self.caller['roles']:
             nodes = Nodes(self.api, [interface['node_id']])
@@ -72,9 +72,9 @@ class UpdateInterface(Method):
             if node['site_id'] not in self.caller['site_ids']:
                 raise PLCPermissionDenied, "Not allowed to update interface"
 
-       interface.update(native)
+        interface.update(native)
         interface.sync()
-       
+
         for (tagname,value) in tags.iteritems():
             # the tagtype instance is assumed to exist, just check that
             if not TagTypes(self.api,{'tagname':tagname}):
@@ -85,7 +85,7 @@ class UpdateInterface(Method):
             else:
                 UpdateInterfaceTag(self.api).__call__(auth,interface_tags[0]['interface_tag_id'],value)
 
-       self.event_objects = {'Interface': [interface['interface_id']]}
+        self.event_objects = {'Interface': [interface['interface_id']]}
         if 'ip' in interface:
             self.message = "Interface %s updated"%interface['ip']
         else:
index 6d7e424..4a3f02f 100644 (file)
@@ -52,23 +52,23 @@ class UpdateInterfaceTag(Method):
 
         assert interface_tag['interface_tag_id'] in interface['interface_tag_ids']
 
-       # check permission : it not admin, is the user affiliated with the right site
-       if 'admin' not in self.caller['roles']:
-           # locate node
-           node = Nodes (self.api,[interface['node_id']])[0]
-           # locate site
-           site = Sites (self.api, [node['site_id']])[0]
-           # check caller is affiliated with this site
-           if self.caller['person_id'] not in site['person_ids']:
-               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified interface setting, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the right site
+        if 'admin' not in self.caller['roles']:
+            # locate node
+            node = Nodes (self.api,[interface['node_id']])[0]
+            # locate site
+            site = Sites (self.api, [node['site_id']])[0]
+            # check caller is affiliated with this site
+            if self.caller['person_id'] not in site['person_ids']:
+                raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified interface setting, requires role %d",required_min_role
 
         interface_tag['value'] = value
         interface_tag.sync()
 
-       self.object_ids = [interface_tag['interface_tag_id']]
+        self.object_ids = [interface_tag['interface_tag_id']]
         return 1
index 1294fc0..a21f591 100644 (file)
@@ -49,9 +49,9 @@ class UpdateKey(Method):
 
         key.update(key_fields)
         key.sync()
-       
-       # Logging variables
-       self.event_objects = {'Key': [key['key_id']]}
-       self.message = 'key %d updated: %s' % \
-               (key['key_id'], ", ".join(key_fields.keys()))
+
+        # Logging variables
+        self.event_objects = {'Key': [key['key_id']]}
+        self.message = 'key %d updated: %s' % \
+                (key['key_id'], ", ".join(key_fields.keys()))
         return 1
index 6e8ebca..e66be38 100644 (file)
@@ -19,7 +19,7 @@ class UpdateLeases(Method):
     As a convenience you may, in addition to the t_from and t_until fields,
     you can also set the 'duration' field.
 
-    Users may only update leases attached to their slices. 
+    Users may only update leases attached to their slices.
     PIs may update any of the leases for slices at their sites, or any
     slices of which they are members. Admins may update any lease.
 
@@ -87,7 +87,7 @@ class UpdateLeases(Method):
                     # all arithmetics on longs..
                     duration=Duration.validate(input_fields['duration'])
                     # specify 'duration':0 to keep duration unchanged
-                    if not duration: 
+                    if not duration:
                         duration = Timestamp.cast_long(lease['t_until'])-Timestamp.cast_long(lease['t_from'])
                     if 't_from' in input_fields:
                         lease_fields={'t_from':input_fields['t_from'],
@@ -97,20 +97,20 @@ class UpdateLeases(Method):
                                       't_until':input_fields['t_until']}
                     else:
                         lease_fields={'t_until':Timestamp.cast_long(lease['t_from'])+duration}
-                if UpdateLeases.debug: 
+                if UpdateLeases.debug:
                     print 'lease_fields',lease_fields
                     for k in [ 't_from', 't_until'] :
                         if k in lease_fields: print k,'aka',Timestamp.sql_validate_utc(lease_fields[k])
-                
+
                 lease.update(lease_fields)
                 lease.sync()
                 updated_ids.append(lease['lease_id'])
             except Exception,e:
                 errors.append("Could not update lease %d - check new time limits ? -- %r"%(lease['lease_id'],e))
-       
-       # Logging variables
-       self.event_objects = {'Lease': updated_ids}
-       self.message = 'lease %r updated: %s' %  (lease_ids, ", ".join(input_fields.keys()))
+
+        # Logging variables
+        self.event_objects = {'Lease': updated_ids}
+        self.message = 'lease %r updated: %s' %  (lease_ids, ", ".join(input_fields.keys()))
 
         return {'updated_ids' : updated_ids,
                 'errors' : errors }
index 0848f65..cc955f9 100644 (file)
@@ -40,6 +40,6 @@ class UpdateMessage(Method):
 
         message.update(message_fields)
         message.sync()
-       self.event_objects = {'Message': [message['message_id']]}
+        self.event_objects = {'Message': [message['message_id']]}
 
         return 1
index 136983f..a74db92 100644 (file)
@@ -15,13 +15,13 @@ from PLC.Methods.AddNodeTag import AddNodeTag
 from PLC.Methods.UpdateNodeTag import UpdateNodeTag
 
 admin_only = [ 'key', 'session', 'boot_nonce', 'site_id']
-can_update = ['hostname', 'node_type', 'boot_state', 'model', 'version'] + admin_only 
+can_update = ['hostname', 'node_type', 'boot_state', 'model', 'version'] + admin_only
 
 class UpdateNode(Method):
     """
     Updates a node. Only the fields specified in node_fields are
     updated, all other fields are left untouched.
-    
+
     PIs and techs can update only the nodes at their sites. Only
     admins can update the key, session, and boot_nonce fields.
 
@@ -45,8 +45,8 @@ class UpdateNode(Method):
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth, node_id_or_hostname, node_fields):
-        
-        # split provided fields 
+
+        # split provided fields
         [native,related,tags,rejected] = Row.split_fields(node_fields,[Node.fields,Node.related_fields,Node.tags])
 
         # type checking
@@ -85,7 +85,7 @@ class UpdateNode(Method):
         node.update(native)
         node.update_last_updated(commit=False)
         node.sync(commit=True)
-        
+
         # if hostname was modifed make sure to update the hrn
         # tag
         if 'hostname' in native:
@@ -94,8 +94,8 @@ class UpdateNode(Method):
             sites = Sites(self.api, node['site_id'], ['login_base'])
             site = sites[0]
             login_base = site['login_base']
-            tags['hrn'] = hostname_to_hrn(root_auth, login_base, node['hostname']) 
-            
+            tags['hrn'] = hostname_to_hrn(root_auth, login_base, node['hostname'])
+
         for (tagname,value) in tags.iteritems():
             # the tagtype instance is assumed to exist, just check that
             if not TagTypes(self.api,{'tagname':tagname}):
index b968766..4c7cec9 100644 (file)
@@ -6,12 +6,12 @@ from PLC.Parameter import Parameter, Mixed
 from PLC.NodeGroups import NodeGroup, NodeGroups
 from PLC.Auth import Auth
 
-can_update = lambda (field, value): field in ['groupname','value'] 
+can_update = lambda (field, value): field in ['groupname','value']
 
 class UpdateNodeGroup(Method):
     """
     Updates a custom node group.
-     
+
     Returns 1 if successful, faults otherwise.
     """
 
@@ -22,7 +22,7 @@ class UpdateNodeGroup(Method):
     accepts = [
         Auth(),
         Mixed(NodeGroup.fields['nodegroup_id'],
-             NodeGroup.fields['groupname']),
+              NodeGroup.fields['groupname']),
         nodegroup_fields
         ]
 
@@ -31,17 +31,17 @@ class UpdateNodeGroup(Method):
     def call(self, auth, nodegroup_id_or_name, nodegroup_fields):
         nodegroup_fields = dict(filter(can_update, nodegroup_fields.items()))
 
-       # Get nodegroup information
-       nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
-       if not nodegroups:
+        # Get nodegroup information
+        nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
+        if not nodegroups:
             raise PLCInvalidArgument, "No such nodegroup %r"%nodegroup_id_or_name
-       nodegroup = nodegroups[0]
+        nodegroup = nodegroups[0]
 
-       nodegroup.update(nodegroup_fields)
+        nodegroup.update(nodegroup_fields)
         nodegroup.sync()
-       
-       # Logging variables
-       self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
-       self.message = 'Node group %d updated: %s' % \
-               (nodegroup['nodegroup_id'], ", ".join(nodegroup_fields.keys()))  
+
+        # Logging variables
+        self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
+        self.message = 'Node group %d updated: %s' % \
+                (nodegroup['nodegroup_id'], ", ".join(nodegroup_fields.keys()))
         return 1
index 4750556..6b45aac 100644 (file)
@@ -50,23 +50,23 @@ class UpdateNodeTag(Method):
 
         assert node_tag['node_tag_id'] in node['node_tag_ids']
 
-       # check permission : it not admin, is the user affiliated with the right site
-       if 'admin' not in self.caller['roles']:
-           # locate node
-           node = Nodes (self.api,[node['node_id']])[0]
-           # locate site
-           site = Sites (self.api, [node['site_id']])[0]
-           # check caller is affiliated with this site
-           if self.caller['person_id'] not in site['person_ids']:
-               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified node tag, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the right site
+        if 'admin' not in self.caller['roles']:
+            # locate node
+            node = Nodes (self.api,[node['node_id']])[0]
+            # locate site
+            site = Sites (self.api, [node['site_id']])[0]
+            # check caller is affiliated with this site
+            if self.caller['person_id'] not in site['person_ids']:
+                raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified node tag, requires role %d",required_min_role
 
         node_tag['value'] = value
         node_tag.sync()
 
-       self.object_ids = [node_tag['node_tag_id']]
+        self.object_ids = [node_tag['node_tag_id']]
         return 1
index b8a1b63..2a1fe3b 100644 (file)
@@ -46,9 +46,9 @@ class UpdatePCU(Method):
 
         pcu.update(pcu_fields)
         pcu.sync()
-       
-       # Logging variables
-       self.event_objects = {'PCU': [pcu['pcu_id']]}
-       self.message = 'PCU %d updated: %s' % \
-               (pcu['pcu_id'], ", ".join(pcu_fields.keys()))
+
+        # Logging variables
+        self.event_objects = {'PCU': [pcu['pcu_id']]}
+        self.message = 'PCU %d updated: %s' % \
+                (pcu['pcu_id'], ", ".join(pcu_fields.keys()))
         return 1
index 70b62d1..9e22035 100644 (file)
@@ -39,5 +39,5 @@ class UpdatePCUProtocolType(Method):
         protocol_type = protocol_types[0]
         protocol_type.update(protocol_type_fields)
         protocol_type.sync()
-       self.event_objects = {'PCUProtocolType': [protocol_type['pcu_protocol_type_id']]}       
+        self.event_objects = {'PCUProtocolType': [protocol_type['pcu_protocol_type_id']]}
         return 1
index 47a2346..dcc705a 100644 (file)
@@ -39,6 +39,6 @@ class UpdatePCUType(Method):
         pcu_type = pcu_types[0]
         pcu_type.update(pcu_type_fields)
         pcu_type.sync()
-       self.event_objects = {'PCUType': [pcu_type['pcu_type_id']]}     
+        self.event_objects = {'PCUType': [pcu_type['pcu_type_id']]}
 
         return 1
index e0ac792..ce5a211 100644 (file)
@@ -47,6 +47,6 @@ class UpdatePeer(Method):
         peer.sync()
 
         # Log affected objects
-       self.event_objects = {'Peer': [peer['peer_id']]}
+        self.event_objects = {'Peer': [peer['peer_id']]}
 
-       return 1
+        return 1
index 9ca8c58..0795151 100644 (file)
@@ -17,7 +17,7 @@ class UpdatePerson(Method):
     """
     Updates a person. Only the fields specified in person_fields are
     updated, all other fields are left untouched.
-    
+
     Users and techs can only update themselves. PIs can only update
     themselves and other non-PIs at their sites.
 
@@ -55,38 +55,38 @@ class UpdatePerson(Method):
         # Check if we can update this account
         if not self.caller.can_update(person):
             raise PLCPermissionDenied, "Not allowed to update specified account"
-       
-       # Make requested associations
+
+        # Make requested associations
         for field in related_fields:
             if field in person_fields:
                 person.associate(auth, field, person_fields[field])
                 person_fields.pop(field)
 
         person.update(person_fields)
-       person.update_last_updated(False)
+        person.update_last_updated(False)
         person.sync()
 
-       if 'enabled' in person_fields:
-           To = [("%s %s" % (person['first_name'], person['last_name']), person['email'])]
-           Cc = []     
-           if person['enabled']:
-               Subject = "%s account enabled" % (self.api.config.PLC_NAME)
-               Body = "Your %s account has been enabled. Please visit %s to access your account." % (self.api.config.PLC_NAME, self.api.config.PLC_WWW_HOST) 
-           else:
-               Subject = "%s account disabled" % (self.api.config.PLC_NAME)
-               Body = "Your %s account has been disabled. Please contact your PI or PlanetLab support for more information" % (self.api.config.PLC_NAME)
-           sendmail(self.api, To = To, Cc = Cc, Subject = Subject, Body = Body)                
-
-                               
-       # Logging variables
-       self.event_objects = {'Person': [person['person_id']]}
+        if 'enabled' in person_fields:
+            To = [("%s %s" % (person['first_name'], person['last_name']), person['email'])]
+            Cc = []
+            if person['enabled']:
+                Subject = "%s account enabled" % (self.api.config.PLC_NAME)
+                Body = "Your %s account has been enabled. Please visit %s to access your account." % (self.api.config.PLC_NAME, self.api.config.PLC_WWW_HOST)
+            else:
+                Subject = "%s account disabled" % (self.api.config.PLC_NAME)
+                Body = "Your %s account has been disabled. Please contact your PI or PlanetLab support for more information" % (self.api.config.PLC_NAME)
+            sendmail(self.api, To = To, Cc = Cc, Subject = Subject, Body = Body)
+
+
+        # Logging variables
+        self.event_objects = {'Person': [person['person_id']]}
 
         # Redact password
         if 'password' in person_fields:
             person_fields['password'] = "Removed by API"
         self.message = 'Person %d updated: %s.' % \
                        (person['person_id'], person_fields.keys())
-       if 'enabled' in person_fields:
-            self.message += ' Person enabled'  
+        if 'enabled' in person_fields:
+            self.message += ' Person enabled'
 
         return 1
index 928b54f..e07f873 100644 (file)
@@ -50,19 +50,19 @@ class UpdatePersonTag(Method):
 
         assert person_tag['person_tag_id'] in person['person_tag_ids']
 
-       # check permission : it not admin, is the user affiliated with the right person
-       if 'admin' not in self.caller['roles']:
-           # check caller is affiliated with this person's person
-           if len(set(person['person_ids']) & set(self.caller['person_ids'])) == 0:
-               raise PLCPermissionDenied, "Not a member of the person's persons: %s"%person['person_ids']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified person setting, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the right person
+        if 'admin' not in self.caller['roles']:
+            # check caller is affiliated with this person's person
+            if len(set(person['person_ids']) & set(self.caller['person_ids'])) == 0:
+                raise PLCPermissionDenied, "Not a member of the person's persons: %s"%person['person_ids']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified person setting, requires role %d",required_min_role
 
         person_tag['value'] = value
         person_tag.sync()
 
-       self.object_ids = [person_tag['person_tag_id']]
+        self.object_ids = [person_tag['person_tag_id']]
         return 1
index b59894f..8a47cd3 100644 (file)
@@ -11,14 +11,14 @@ can_update = lambda (field, value): field in \
              ['name', 'abbreviated_name', 'login_base',
               'is_public', 'latitude', 'longitude', 'url',
               'max_slices', 'max_slivers', 'enabled', 'ext_consortium_id'] + \
-             related_fields    
+              related_fields
 
 class UpdateSite(Method):
     """
     Updates a site. Only the fields specified in update_fields are
     updated, all other fields are left untouched.
 
-    PIs can only update sites they are a member of. Only admins can 
+    PIs can only update sites they are a member of. Only admins can
     update max_slices, max_slivers, and login_base.
 
     Returns 1 if successful, faults otherwise.
@@ -63,19 +63,19 @@ class UpdateSite(Method):
                 if key in site_fields:
                     del site_fields[key]
 
-       # Make requested associations
-       for field in related_fields:
-           if field in site_fields:
-               site.associate(auth, field, site_fields[field])
-               site_fields.pop(field)  
-       
+        # Make requested associations
+        for field in related_fields:
+            if field in site_fields:
+                site.associate(auth, field, site_fields[field])
+                site_fields.pop(field)
+
         site.update(site_fields)
-       site.update_last_updated(False)
-       site.sync()
-       
-       # Logging variables
-       self.event_objects = {'Site': [site['site_id']]}
-       self.message = 'Site %d updated: %s' % \
-               (site['site_id'], ", ".join(site_fields.keys()))        
-       
-       return 1
+        site.update_last_updated(False)
+        site.sync()
+
+        # Logging variables
+        self.event_objects = {'Site': [site['site_id']]}
+        self.message = 'Site %d updated: %s' % \
+                (site['site_id'], ", ".join(site_fields.keys()))
+
+        return 1
index c7f63a3..06919bf 100644 (file)
@@ -50,19 +50,19 @@ class UpdateSiteTag(Method):
 
         assert site_tag['site_tag_id'] in site['site_tag_ids']
 
-       # check permission : it not admin, is the user affiliated with the right site
-       if 'admin' not in self.caller['roles']:
-           # check caller is affiliated with this site
-           if self.caller['person_id'] not in site['person_ids']:
-               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
-           
-           required_min_role = tag_type ['min_role_id']
-           if required_min_role is not None and \
-                   min(self.caller['role_ids']) > required_min_role:
-               raise PLCPermissionDenied, "Not allowed to modify the specified site setting, requires role %d",required_min_role
+        # check permission : it not admin, is the user affiliated with the right site
+        if 'admin' not in self.caller['roles']:
+            # check caller is affiliated with this site
+            if self.caller['person_id'] not in site['person_ids']:
+                raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
+
+            required_min_role = tag_type ['min_role_id']
+            if required_min_role is not None and \
+                    min(self.caller['role_ids']) > required_min_role:
+                raise PLCPermissionDenied, "Not allowed to modify the specified site setting, requires role %d",required_min_role
 
         site_tag['value'] = value
         site_tag.sync()
 
-       self.object_ids = [site_tag['site_tag_id']]
+        self.object_ids = [site_tag['site_tag_id']]
         return 1
index 39b052b..9034102 100644 (file)
@@ -15,7 +15,7 @@ from PLC.SliceTags import SliceTags
 from PLC.Methods.AddSliceTag import AddSliceTag
 from PLC.Methods.UpdateSliceTag import UpdateSliceTag
 
-can_update = ['instantiation', 'url', 'description', 'max_nodes', 'expires'] 
+can_update = ['instantiation', 'url', 'description', 'max_nodes', 'expires']
 
 class UpdateSlice(Method):
     """
@@ -51,15 +51,15 @@ class UpdateSlice(Method):
 
     def call(self, auth, slice_id_or_name, slice_fields):
 
-        # split provided fields 
+        # split provided fields
         [native,related,tags,rejected] = Row.split_fields(slice_fields,[Slice.fields,Slice.related_fields,Slice.tags])
-        
+
         # type checking
         native = Row.check_fields (native, self.accepted_fields)
         if rejected:
             raise PLCInvalidArgument, "Cannot update Slice column(s) %r"%rejected
 
-       slices = Slices(self.api, [slice_id_or_name])
+        slices = Slices(self.api, [slice_id_or_name])
         if not slices:
             raise PLCInvalidArgument, "No such slice %r"%slice_id_or_name
         slice = slices[0]
@@ -95,28 +95,28 @@ class UpdateSlice(Method):
             if 'admin' not in self.caller['roles'] and slice_fields['expires'] > max_expires:
                 raise PLCInvalidArgument, "Cannot renew a slice beyond 8 weeks from now"
 
-           # XXX Make this a configurable policy
+            # XXX Make this a configurable policy
             if slice['description'] is None or not slice['description'].strip():
-               if 'description' not in slice_fields or slice_fields['description'] is None or \
-                  not slice_fields['description'].strip():
-                    raise PLCInvalidArgument, "Cannot renew a slice with an empty description or URL"  
-               
-           if slice['url'] is None or not slice['url'].strip():
-               if 'url' not in slice_fields or slice_fields['url'] is None or \
-                  not slice_fields['url'].strip():
+                if 'description' not in slice_fields or slice_fields['description'] is None or \
+                   not slice_fields['description'].strip():
+                    raise PLCInvalidArgument, "Cannot renew a slice with an empty description or URL"
+
+            if slice['url'] is None or not slice['url'].strip():
+                if 'url' not in slice_fields or slice_fields['url'] is None or \
+                   not slice_fields['url'].strip():
                     raise PLCInvalidArgument, "Cannot renew a slice with an empty description or URL"
             renewing=True
-           
+
         if 'max_nodes' in slice_fields and slice_fields['max_nodes'] != slice['max_nodes']:
             if 'admin' not in self.caller['roles'] and \
                'pi' not in self.caller['roles']:
                 raise PLCInvalidArgument, "Only admins and PIs may update max_nodes"
 
-       # Make requested associations
+        # Make requested associations
         for (k,v) in related.iteritems():
             slice.associate(auth,k,v)
 
-       slice.update(slice_fields)
+        slice.update(slice_fields)
         slice.sync(commit=True)
 
         for (tagname,value) in tags.iteritems():
@@ -129,7 +129,7 @@ class UpdateSlice(Method):
             else:
                 UpdateSliceTag(self.api).__call__(auth,slice_tags[0]['slice_tag_id'],value)
 
-       self.event_objects = {'Slice': [slice['slice_id']]}
+        self.event_objects = {'Slice': [slice['slice_id']]}
         if 'name' in slice:
             self.message='Slice %s updated'%slice['name']
         else:
index 7b8aed2..76a6354 100644 (file)
@@ -26,7 +26,7 @@ class UpdateSliceTag(Method):
     accepts = [
         Auth(),
         SliceTag.fields['slice_tag_id'],
-       Mixed(SliceTag.fields['value'],
+        Mixed(SliceTag.fields['value'],
               InitScript.fields['name'])
         ]
 
@@ -62,13 +62,13 @@ class UpdateSliceTag(Method):
             node_role_id = 20
             if slice_tag['min_role_id'] is not None and node_role_id > slice_tag['min_role_id']:
                 raise PLCPermissionDenied, "Not allowed to update the specified slice attribute"
-       
-       if slice_tag['tagname'] in ['initscript']:
+
+        if slice_tag['tagname'] in ['initscript']:
             initscripts = InitScripts(self.api, {'enabled': True, 'name': value})
             if not initscripts:
-                raise PLCInvalidArgument, "No such plc initscript"     
+                raise PLCInvalidArgument, "No such plc initscript"
 
         slice_tag['value'] = unicode(value)
         slice_tag.sync()
-       self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}
+        self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}
         return 1
index 83655c4..adec78e 100644 (file)
@@ -45,6 +45,6 @@ class UpdateTagType(Method):
 
         tag_type.update(tag_type_fields)
         tag_type.sync()
-       self.object_ids = [tag_type['tag_type_id']]
+        self.object_ids = [tag_type['tag_type_id']]
 
         return 1
index 9aae067..a9ea22e 100644 (file)
@@ -38,14 +38,14 @@ class VerifyPerson(Method):
         Auth(),
         Mixed(Person.fields['person_id'],
               Person.fields['email']),
-       Person.fields['verification_key'],
+        Person.fields['verification_key'],
         Person.fields['verification_expires']
         ]
 
     returns = Parameter(int, '1 if verification_key is valid')
 
     def call(self, auth, person_id_or_email, verification_key = None, verification_expires = None):
-       # Get account information
+        # Get account information
         persons = Persons(self.api, [person_id_or_email])
         if not persons:
             raise PLCInvalidArgument, "No such account %r"%person_id_or_email
@@ -70,9 +70,9 @@ class VerifyPerson(Method):
         random_key = base64.b64encode("".join(map(chr, bytes)))
 
         if verification_key is None or \
-       (verification_key is not None and person['verification_expires'] and \
-       person['verification_expires'] < time.time()):
-           # Only allow one verification at a time
+        (verification_key is not None and person['verification_expires'] and \
+        person['verification_expires'] < time.time()):
+            # Only allow one verification at a time
             if person['verification_expires'] is not None and \
                person['verification_expires'] > time.time():
                 raise PLCPermissionDenied, "Verification request already pending"
@@ -91,12 +91,12 @@ class VerifyPerson(Method):
             message_id = 'Verify account'
 
 
-       elif verification_key is not None:
+        elif verification_key is not None:
             if person['verification_key'] is None or \
                person['verification_expires'] is None:
                 raise PLCPermissionDenied, "Invalid Verification key"
             elif person['verification_key'] != verification_key:
-               raise PLCPermissionDenied, "Verification key incorrect"
+                raise PLCPermissionDenied, "Verification key incorrect"
             else:
                 person['verification_key'] = None
                 person['verification_expires'] = None
@@ -147,12 +147,12 @@ class VerifyPerson(Method):
         else:
             print >> log, "Warning: No message template '%s'" % message_id
 
-       # Logging variables
+        # Logging variables
         self.event_objects = {'Person': [person['person_id']]}
         self.message = message_id
-       
-       if verification_key is not None and person['verification_expires'] and \
+
+        if verification_key is not None and person['verification_expires'] and \
         person['verification_expires'] < time.time():
-           raise PLCPermissionDenied, "Verification key has expired. Another email has been sent."
+            raise PLCPermissionDenied, "Verification key has expired. Another email has been sent."
 
         return 1
index 2d41fea..1332ea2 100644 (file)
@@ -1,5 +1,5 @@
-### $Id: Namespace.py 
-### $URL: 
+### $Id: Namespace.py
+### $URL:
 
 URN_PREFIX = "urn:publicid:IDN"
 
@@ -43,10 +43,10 @@ def slicename_to_hrn(auth_hrn, slicename):
 def email_to_hrn(auth_hrn, email):
     parts = email.split("@")
     username = parts[0]
-    username = username.replace(".", "_") 
+    username = username.replace(".", "_")
     person_hrn = ".".join([auth_hrn, username])
-    
-    return person_hrn 
+
+    return person_hrn
 
 def urn_to_hrn(urn):
     """
@@ -60,24 +60,24 @@ def urn_to_hrn(urn):
 
     name = urn[len(URN_PREFIX):]
     hrn_parts = name.split("+")
-    
+
     # type is always the second to last element in the list
     type = hrn_parts.pop(-2)
 
-    # convert hrn_parts (list) into hrn (str) by doing the following    
+    # convert hrn_parts (list) into hrn (str) by doing the following
     # remove blank elements
     # replace ':' with '.'
     # join list elements using '.'
-    hrn = '.'.join([part.replace(':', '.') for part in hrn_parts if part]) 
-   
-    return str(hrn), str(type) 
-    
-    
+    hrn = '.'.join([part.replace(':', '.') for part in hrn_parts if part])
+
+    return str(hrn), str(type)
+
+
 def hrn_to_urn(hrn, type=None):
     """
     convert an hrn and type to a urn string
     """
-    # if  this is already a urn dont do anything 
+    # if  this is already a urn dont do anything
     if not hrn or hrn.startswith(URN_PREFIX):
         return hrn
 
index c6f5864..4a68297 100644 (file)
@@ -26,16 +26,16 @@ class NetworkMethod(Row):
         }
 
     def validate_method(self, name):
-       # Make sure name is not blank
+        # Make sure name is not blank
         if not len(name):
             raise PLCInvalidArgument, "Network method must be specified"
-       
-       # Make sure network method does not alredy exist
-       conflicts = NetworkMethods(self.api, [name])
+
+        # Make sure network method does not alredy exist
+        conflicts = NetworkMethods(self.api, [name])
         if conflicts:
             raise PLCInvalidArgument, "Network method name already in use"
 
-       return name
+        return name
 
 class NetworkMethods(Table):
     """
@@ -47,7 +47,7 @@ class NetworkMethods(Table):
 
         sql = "SELECT %s FROM network_methods" % \
               ", ".join(NetworkMethod.fields)
-        
+
         if methods:
             sql += " WHERE method IN (%s)" % ", ".join(map(api.db.quote, methods))
 
index 2b5ff4d..7e9187c 100644 (file)
@@ -26,16 +26,16 @@ class NetworkType(Row):
         }
 
     def validate_type(self, name):
-       # Make sure name is not blank
+        # Make sure name is not blank
         if not len(name):
             raise PLCInvalidArgument, "Network type must be specified"
-       
-       # Make sure network type does not alredy exist
-       conflicts = NetworkTypes(self.api, [name])
+
+        # Make sure network type does not alredy exist
+        conflicts = NetworkTypes(self.api, [name])
         if conflicts:
             raise PLCInvalidArgument, "Network type name already in use"
 
-       return name
+        return name
 
 class NetworkTypes(Table):
     """
@@ -47,7 +47,7 @@ class NetworkTypes(Table):
 
         sql = "SELECT %s FROM network_types" % \
               ", ".join(NetworkType.fields)
-        
+
         if types:
             sql += " WHERE type IN (%s)" % ", ".join(map(api.db.quote, types))
 
index fc3e940..3705644 100644 (file)
@@ -36,22 +36,22 @@ class NodeGroup(Row):
         'tagname' : Parameter(str, "Tag name that the nodegroup definition is based upon"),
         'conf_file_ids': Parameter([int], "List of configuration files specific to this node group"),
         'node_ids' : Parameter([int], "List of node_ids that belong to this nodegroup"),
-       }
+        }
     related_fields = {
         }
 
     def validate_name(self, name):
-       # Make sure name is not blank
+        # Make sure name is not blank
         if not len(name):
-                raise PLCInvalidArgument, "Invalid node group name"
-       
-       # Make sure node group does not alredy exist
-       conflicts = NodeGroups(self.api, [name])
-       for nodegroup in conflicts:
+            raise PLCInvalidArgument, "Invalid node group name"
+
+        # Make sure node group does not alredy exist
+        conflicts = NodeGroups(self.api, [name])
+        for nodegroup in conflicts:
             if 'nodegroup_id' not in self or self['nodegroup_id'] != nodegroup['nodegroup_id']:
-               raise PLCInvalidArgument, "Node group name already in use"
+                raise PLCInvalidArgument, "Node group name already in use"
 
-       return name
+        return name
 
     def associate_conf_files(self, auth, field, value):
         """
@@ -72,10 +72,10 @@ class NodeGroup(Row):
             stale_conf_files = set(self['conf_file_ids']).difference(conf_file_ids)
 
             for new_conf_file in new_conf_files:
-                AddConfFileToNodeGroup.__call__(AddConfFileToNodeGroup(self.api), 
+                AddConfFileToNodeGroup.__call__(AddConfFileToNodeGroup(self.api),
                                                 auth, new_conf_file, self['nodegroup_id'])
             for stale_conf_file in stale_conf_files:
-                DeleteConfFileFromNodeGroup.__call__(DeleteConfFileFromNodeGroup(self.api), 
+                DeleteConfFileFromNodeGroup.__call__(DeleteConfFileFromNodeGroup(self.api),
                                                      auth, stale_conf_file, self['nodegroup_id'])
 
 
index 5b20697..896d7eb 100644 (file)
@@ -23,16 +23,16 @@ class NodeType(Row):
         }
 
     def validate_node_type(self, name):
-       # Make sure name is not blank
+        # Make sure name is not blank
         if not len(name):
             raise PLCInvalidArgument, "Node type must be specified"
-       
-       # Make sure node type does not alredy exist
-       conflicts = NodeTypes(self.api, [name])
+
+        # Make sure node type does not alredy exist
+        conflicts = NodeTypes(self.api, [name])
         if conflicts:
             raise PLCInvalidArgument, "Node type name already in use"
 
-       return name
+        return name
 
 class NodeTypes(Table):
     """
@@ -44,7 +44,7 @@ class NodeTypes(Table):
 
         sql = "SELECT %s FROM node_types" % \
               ", ".join(NodeType.fields)
-        
+
         if node_types:
             sql += " WHERE node_type IN (%s)" % ", ".join(map(api.db.quote, node_types))
 
index 8f25e28..9cf0edf 100644 (file)
@@ -40,8 +40,8 @@ class Node(Row):
 
     table_name = 'nodes'
     primary_key = 'node_id'
-    join_tables = [ 'slice_node', 'peer_node', 'slice_tag', 
-                    'node_session', 'node_slice_whitelist', 
+    join_tables = [ 'slice_node', 'peer_node', 'slice_tag',
+                    'node_session', 'node_slice_whitelist',
                     'node_tag', 'conf_file_node', 'pcu_node', 'leases', ]
     fields = {
         'node_id': Parameter(int, "Node identifier"),
@@ -56,7 +56,7 @@ class Node(Row):
         'ssh_rsa_key': Parameter(str, "Last known SSH host key", max = 1024),
         'date_created': Parameter(int, "Date and time when node entry was created", ro = True),
         'last_updated': Parameter(int, "Date and time when node entry was created", ro = True),
-       'last_contact': Parameter(int, "Date and time when node last contacted plc", ro = True), 
+        'last_contact': Parameter(int, "Date and time when node last contacted plc", ro = True),
         'verified': Parameter(bool, "Whether the node configuration is verified correct", ro=False),
         'key': Parameter(str, "(Admin only) Node key", max = 256),
         'session': Parameter(str, "(Admin only) Node session value", max = 256, ro = True),
@@ -64,7 +64,7 @@ class Node(Row):
         'conf_file_ids': Parameter([int], "List of configuration files specific to this node"),
         # 'root_person_ids': Parameter([int], "(Admin only) List of people who have root access to this node"),
         'slice_ids': Parameter([int], "List of slices on this node"),
-       'slice_ids_whitelist': Parameter([int], "List of slices allowed on this node"),
+        'slice_ids_whitelist': Parameter([int], "List of slices allowed on this node"),
         'pcu_ids': Parameter([int], "List of PCUs that control this node"),
         'ports': Parameter([int], "List of PCU ports that this node is connected to"),
         'peer_id': Parameter(int, "Peer to which this node belongs", nullok = True),
@@ -73,14 +73,14 @@ class Node(Row):
         'nodegroup_ids': Parameter([int], "List of node groups that this node is in"),
         }
     related_fields = {
-       'interfaces': [Mixed(Parameter(int, "Interface identifier"),
+        'interfaces': [Mixed(Parameter(int, "Interface identifier"),
                              Filter(Interface.fields))],
-       'conf_files': [Parameter(int, "ConfFile identifier")],
-       'slices': [Mixed(Parameter(int, "Slice identifier"),
+        'conf_files': [Parameter(int, "ConfFile identifier")],
+        'slices': [Mixed(Parameter(int, "Slice identifier"),
                          Parameter(str, "Slice name"))],
-       'slices_whitelist': [Mixed(Parameter(int, "Slice identifier"),
+        'slices_whitelist': [Mixed(Parameter(int, "Slice identifier"),
                                    Parameter(str, "Slice name"))]
-       }
+        }
 
     view_tags_name = "view_node_tags"
     # tags are used by the Add/Get/Update methods to expose tags
@@ -115,16 +115,16 @@ class Node(Row):
     validate_last_contact = Row.validate_timestamp
 
     def update_last_contact(self, commit = True):
-       """
-       Update last_contact field with current time
-       """
-       
-       assert 'node_id' in self
-       assert self.table_name
+        """
+        Update last_contact field with current time
+        """
 
-       self.api.db.do("UPDATE %s SET last_contact = CURRENT_TIMESTAMP " % (self.table_name) + \
-                      " where node_id = %d" % ( self['node_id']) )
-       self.sync(commit)
+        assert 'node_id' in self
+        assert self.table_name
+
+        self.api.db.do("UPDATE %s SET last_contact = CURRENT_TIMESTAMP " % (self.table_name) + \
+                       " where node_id = %d" % ( self['node_id']) )
+        self.sync(commit)
 
 
     def update_last_updated(self, commit = True):
@@ -153,13 +153,13 @@ class Node(Row):
             if not node_tags:
                 AddNodeTag(self.api).__call__(shell.auth,node['node_id'],tagname,value)
             else:
-                UpdateNodeTag(self.api).__call__(shell.auth,node_tags[0]['node_tag_id'],value) 
-    
+                UpdateNodeTag(self.api).__call__(shell.auth,node_tags[0]['node_tag_id'],value)
+
     def associate_interfaces(self, auth, field, value):
         """
-        Delete interfaces not found in value list (using DeleteInterface)      
+        Delete interfaces not found in value list (using DeleteInterface)
         Add interfaces found in value list (using AddInterface)
-        Updates interfaces found w/ interface_id in value list (using UpdateInterface) 
+        Updates interfaces found w/ interface_id in value list (using UpdateInterface)
         """
 
         assert 'interface_ids' in self
@@ -177,70 +177,70 @@ class Node(Row):
                 DeleteInterface.__call__(DeleteInterface(self.api), auth, stale_interface['interface_id'])
 
     def associate_conf_files(self, auth, field, value):
-       """
-       Add conf_files found in value list (AddConfFileToNode)
-       Delets conf_files not found in value list (DeleteConfFileFromNode)
-       """
-       
-       assert 'conf_file_ids' in self
-       assert 'node_id' in self
-       assert isinstance(value, list)
-       
-       conf_file_ids = self.separate_types(value)[0]
-       
-       if self['conf_file_ids'] != conf_file_ids:
-           from PLC.Methods.AddConfFileToNode import AddConfFileToNode
-           from PLC.Methods.DeleteConfFileFromNode import DeleteConfFileFromNode
-           new_conf_files = set(conf_file_ids).difference(self['conf_file_ids'])
-           stale_conf_files = set(self['conf_file_ids']).difference(conf_file_ids)
-       
-           for new_conf_file in new_conf_files:
-               AddConfFileToNode.__call__(AddConfFileToNode(self.api), auth, new_conf_file, self['node_id'])
-           for stale_conf_file in stale_conf_files:
-               DeleteConfFileFromNode.__call__(DeleteConfFileFromNode(self.api), auth, stale_conf_file, self['node_id'])
+        """
+        Add conf_files found in value list (AddConfFileToNode)
+        Delets conf_files not found in value list (DeleteConfFileFromNode)
+        """
+
+        assert 'conf_file_ids' in self
+        assert 'node_id' in self
+        assert isinstance(value, list)
+
+        conf_file_ids = self.separate_types(value)[0]
+
+        if self['conf_file_ids'] != conf_file_ids:
+            from PLC.Methods.AddConfFileToNode import AddConfFileToNode
+            from PLC.Methods.DeleteConfFileFromNode import DeleteConfFileFromNode
+            new_conf_files = set(conf_file_ids).difference(self['conf_file_ids'])
+            stale_conf_files = set(self['conf_file_ids']).difference(conf_file_ids)
+
+            for new_conf_file in new_conf_files:
+                AddConfFileToNode.__call__(AddConfFileToNode(self.api), auth, new_conf_file, self['node_id'])
+            for stale_conf_file in stale_conf_files:
+                DeleteConfFileFromNode.__call__(DeleteConfFileFromNode(self.api), auth, stale_conf_file, self['node_id'])
 
     def associate_slices(self, auth, field, value):
-       """
-       Add slices found in value list to (AddSliceToNode)
-       Delete slices not found in value list (DeleteSliceFromNode)
-       """
-       
-       from PLC.Slices import Slices
-       
-       assert 'slice_ids' in self
-       assert 'node_id' in self
-       assert isinstance(value, list)
-       
-       (slice_ids, slice_names) = self.separate_types(value)[0:2]
-
-       if slice_names:
-           slices = Slices(self.api, slice_names, ['slice_id']).dict('slice_id')
-           slice_ids += slices.keys()
-
-       if self['slice_ids'] != slice_ids:
-           from PLC.Methods.AddSliceToNodes import AddSliceToNodes
-           from PLC.Methods.DeleteSliceFromNodes import DeleteSliceFromNodes
-           new_slices = set(slice_ids).difference(self['slice_ids'])
-           stale_slices = set(self['slice_ids']).difference(slice_ids)
-       
-       for new_slice in new_slices:
-           AddSliceToNodes.__call__(AddSliceToNodes(self.api), auth, new_slice, [self['node_id']])
-       for stale_slice in stale_slices:
-           DeleteSliceFromNodes.__call__(DeleteSliceFromNodes(self.api), auth, stale_slice, [self['node_id']])                         
+        """
+        Add slices found in value list to (AddSliceToNode)
+        Delete slices not found in value list (DeleteSliceFromNode)
+        """
+
+        from PLC.Slices import Slices
+
+        assert 'slice_ids' in self
+        assert 'node_id' in self
+        assert isinstance(value, list)
+
+        (slice_ids, slice_names) = self.separate_types(value)[0:2]
+
+        if slice_names:
+            slices = Slices(self.api, slice_names, ['slice_id']).dict('slice_id')
+            slice_ids += slices.keys()
+
+        if self['slice_ids'] != slice_ids:
+            from PLC.Methods.AddSliceToNodes import AddSliceToNodes
+            from PLC.Methods.DeleteSliceFromNodes import DeleteSliceFromNodes
+            new_slices = set(slice_ids).difference(self['slice_ids'])
+            stale_slices = set(self['slice_ids']).difference(slice_ids)
+
+        for new_slice in new_slices:
+            AddSliceToNodes.__call__(AddSliceToNodes(self.api), auth, new_slice, [self['node_id']])
+        for stale_slice in stale_slices:
+            DeleteSliceFromNodes.__call__(DeleteSliceFromNodes(self.api), auth, stale_slice, [self['node_id']])
 
     def associate_slices_whitelist(self, auth, field, value):
-       """
-       Add slices found in value list to whitelist (AddSliceToNodesWhitelist)
-       Delete slices not found in value list from whitelist (DeleteSliceFromNodesWhitelist)
-       """
+        """
+        Add slices found in value list to whitelist (AddSliceToNodesWhitelist)
+        Delete slices not found in value list from whitelist (DeleteSliceFromNodesWhitelist)
+        """
 
-       from PLC.Slices import Slices
+        from PLC.Slices import Slices
 
-       assert 'slice_ids_whitelist' in self
+        assert 'slice_ids_whitelist' in self
         assert 'node_id' in self
         assert isinstance(value, list)
 
-       (slice_ids, slice_names) = self.separate_types(value)[0:2]
+        (slice_ids, slice_names) = self.separate_types(value)[0:2]
 
         if slice_names:
             slices = Slices(self.api, slice_names, ['slice_id']).dict('slice_id')
@@ -255,8 +255,8 @@ class Node(Row):
         for new_slice in new_slices:
             AddSliceToNodesWhitelist.__call__(AddSliceToNodesWhitelist(self.api), auth, new_slice, [self['node_id']])
         for stale_slice in stale_slices:
-            DeleteSliceFromNodesWhitelist.__call__(DeleteSliceFromNodesWhitelist(self.api), auth, stale_slice, [self['node_id']]) 
-               
+            DeleteSliceFromNodesWhitelist.__call__(DeleteSliceFromNodesWhitelist(self.api), auth, stale_slice, [self['node_id']])
+
 
     def delete(self, commit = True):
         """
@@ -265,7 +265,7 @@ class Node(Row):
 
         assert 'node_id' in self
 
-       # we need to clean up InterfaceTags, so handling interfaces as part of join_tables does not work
+        # we need to clean up InterfaceTags, so handling interfaces as part of join_tables does not work
         # federated nodes don't have interfaces though so for smooth transition from 4.2 to 4.3
         if 'peer_id' in self and self['peer_id']:
             pass
@@ -299,7 +299,7 @@ class Nodes(Table):
         for tagname in self.tag_columns:
             view= "%s left join %s using (%s)"%(view,Node.tagvalue_view_name(tagname),
                                                 Node.primary_key)
-            
+
         sql = "SELECT %s FROM %s WHERE deleted IS False" % \
               (", ".join(self.columns.keys()+self.tag_columns.keys()),view)
 
index 8fea231..dc3cb03 100644 (file)
@@ -23,27 +23,27 @@ class PCUProtocolType(Row):
     primary_key = 'pcu_protocol_type_id'
     join_tables = []
     fields = {
-       'pcu_protocol_type_id': Parameter(int, "PCU protocol type identifier"),
-       'pcu_type_id': Parameter(int, "PCU type identifier"), 
-       'port': Parameter(int, "PCU port"),
-       'protocol': Parameter(str, "Protocol"),
-       'supported': Parameter(bool, "Is the port/protocol supported by PLC") 
+        'pcu_protocol_type_id': Parameter(int, "PCU protocol type identifier"),
+        'pcu_type_id': Parameter(int, "PCU type identifier"),
+        'port': Parameter(int, "PCU port"),
+        'protocol': Parameter(str, "Protocol"),
+        'supported': Parameter(bool, "Is the port/protocol supported by PLC")
         }
 
     def validate_port(self, port):
-       # make sure port is not blank
-       
-       if not port:
+        # make sure port is not blank
+
+        if not port:
             raise PLCInvalidArgument, "Port must be specified"
-       
-       return port
+
+        return port
 
     def validate_protocol(self, protocol):
         # make sure port is not blank
         if not len(protocol):
             raise PLCInvalidArgument, "protocol must be specified"
 
-       return protocol
+        return protocol
 
 class PCUProtocolTypes(Table):
     """
@@ -55,8 +55,8 @@ class PCUProtocolTypes(Table):
 
         sql = "SELECT %s FROM pcu_protocol_type WHERE True" % \
               ", ".join(self.columns)
-        
-       if protocol_type_filter is not None:
+
+        if protocol_type_filter is not None:
             if isinstance(protocol_type_filter, (list, tuple, set)):
                 # Separate the list into integers and strings
                 ints = filter(lambda x: isinstance(x, (int, long)), protocol_type_filter)
@@ -70,7 +70,7 @@ class PCUProtocolTypes(Table):
 
                 sql += " AND (%s) %s" % protocol_type_filter.sql(api, "AND")
             else:
-                raise PLCInvalidArgument, "Wrong pcu_protocol_type filter %r"%protocol_type_filter     
+                raise PLCInvalidArgument, "Wrong pcu_protocol_type filter %r"%protocol_type_filter
 
 
         self.selectall(sql)
index 3268b79..0839f5b 100644 (file)
@@ -25,24 +25,24 @@ class PCUType(Row):
     join_tables = ['pcu_protocol_type']
     fields = {
         'pcu_type_id': Parameter(int, "PCU Type Identifier"),
-       'model': Parameter(str, "PCU model", max = 254),
-       'name': Parameter(str, "PCU full name", max = 254),
+        'model': Parameter(str, "PCU model", max = 254),
+        'name': Parameter(str, "PCU full name", max = 254),
         'pcu_protocol_type_ids': Parameter([int], "PCU Protocol Type Identifiers"),
-       'pcu_protocol_types': Parameter([dict], "PCU Protocol Type List")
+        'pcu_protocol_types': Parameter([dict], "PCU Protocol Type List")
         }
 
     def validate_model(self, model):
-       # Make sure name is not blank
+        # Make sure name is not blank
         if not len(model):
             raise PLCInvalidArgument, "Model must be specified"
-       
-       # Make sure boot state does not alredy exist
-       conflicts = PCUTypes(self.api, [model])
+
+        # Make sure boot state does not alredy exist
+        conflicts = PCUTypes(self.api, [model])
         for pcu_type in conflicts:
-           if 'pcu_type_id' not in self or self['pcu_type_id'] != pcu_type['pcu_type_id']: 
-               raise PLCInvalidArgument, "Model already in use"
+            if 'pcu_type_id' not in self or self['pcu_type_id'] != pcu_type['pcu_type_id']:
+                raise PLCInvalidArgument, "Model already in use"
 
-       return model
+        return model
 
 class PCUTypes(Table):
     """
@@ -51,22 +51,22 @@ class PCUTypes(Table):
 
     def __init__(self, api, pcu_type_filter = None, columns = None):
 
-       # Remove pcu_protocol_types from query since its not really a field
-       # in the db. We will add it later
-       if columns == None:
-           columns = PCUType.fields.keys()
-       if 'pcu_protocol_types' in columns:
-           removed_fields = ['pcu_protocol_types']
-           columns.remove('pcu_protocol_types')
-       else:
-           removed_fields = []
+        # Remove pcu_protocol_types from query since its not really a field
+        # in the db. We will add it later
+        if columns == None:
+            columns = PCUType.fields.keys()
+        if 'pcu_protocol_types' in columns:
+            removed_fields = ['pcu_protocol_types']
+            columns.remove('pcu_protocol_types')
+        else:
+            removed_fields = []
 
         Table.__init__(self, api, PCUType, columns)
 
         sql = "SELECT %s FROM view_pcu_types WHERE True" % \
               ", ".join(self.columns)
-        
-       if pcu_type_filter is not None:
+
+        if pcu_type_filter is not None:
             if isinstance(pcu_type_filter, (list, tuple, set)):
                 # Separate the list into integers and strings
                 ints = filter(lambda x: isinstance(x, (int, long)), pcu_type_filter)
@@ -83,21 +83,21 @@ class PCUTypes(Table):
                 pcu_type_filter = Filter(PCUType.fields, {'pcu_type_id':[pcu_type_filter]})
                 sql += " AND (%s) %s" % pcu_type_filter.sql(api, "AND")
             else:
-                raise PLCInvalidArgument, "Wrong pcu_type filter %r"%pcu_type_filter   
+                raise PLCInvalidArgument, "Wrong pcu_type filter %r"%pcu_type_filter
 
 
         self.selectall(sql)
 
-        # return a list of protocol type objects for each port type
+         # return a list of protocol type objects for each port type
         if 'pcu_protocol_types' in removed_fields:
-           from PLC.PCUProtocolTypes import PCUProtocolTypes
+            from PLC.PCUProtocolTypes import PCUProtocolTypes
             protocol_type_ids = set()
             for pcu_type in self:
                 protocol_type_ids.update(pcu_type['pcu_protocol_type_ids'])
 
             protocol_return_fields = ['pcu_protocol_type_id', 'port', 'protocol', 'supported']
             all_protocol_types = PCUProtocolTypes(self.api, list(protocol_type_ids), \
-                                                 protocol_return_fields).dict('pcu_protocol_type_id')
+                                                  protocol_return_fields).dict('pcu_protocol_type_id')
 
             for pcu_type in self:
                 pcu_type['pcu_protocol_types'] = []
index ed71236..4caddda 100644 (file)
@@ -71,7 +71,7 @@ def icmp_pod(host,key):
     if uid <> 0:
         print "must be root to send icmp pod"
         return
-    
+
     s = socket(AF_INET, SOCK_RAW, getprotobyname("icmp"))
     packet = _construct(0, key) # make a ping packet
     addr = (host,1)
index e2f91d5..1acba4a 100644 (file)
@@ -2,7 +2,7 @@
 # $URL$
 #
 # Thierry Parmentelat - INRIA
-# 
+#
 
 import re
 from types import StringTypes
@@ -25,7 +25,7 @@ from PLC.Slices import Slice, Slices
 
 class Peer(Row):
     """
-    Stores the list of peering PLCs in the peers table. 
+    Stores the list of peering PLCs in the peers table.
     See the Row class for more details
     """
 
@@ -46,7 +46,7 @@ class Peer(Row):
         'key_ids': Parameter([int], "List of keys for which this peer is authoritative"),
         'node_ids': Parameter([int], "List of nodes for which this peer is authoritative"),
         'slice_ids': Parameter([int], "List of slices for which this peer is authoritative"),
-       }
+        }
 
     def validate_peername(self, peername):
         if not len(peername):
@@ -69,8 +69,8 @@ class Peer(Row):
             raise PLCInvalidArgument, "Peer URL scheme must be https"
         if path[-1] != '/':
             raise PLCInvalidArgument, "Peer URL should end with /"
-        
-       return url
+
+        return url
 
     def delete(self, commit = True):
         """
@@ -109,7 +109,7 @@ class Peer(Row):
         """
         Unassociate a site with this peer.
         """
-        
+
         remove = Row.remove_object(Site, 'peer_site')
         remove(self, site, commit)
 
@@ -124,12 +124,12 @@ class Peer(Row):
              'person_id': person['person_id'],
              'peer_person_id': peer_person_id},
             commit = commit)
-    
+
     def remove_person(self, person, commit = True):
         """
         Unassociate a site with this peer.
         """
-    
+
         remove = Row.remove_object(Person, 'peer_person')
         remove(self, person, commit)
 
@@ -149,7 +149,7 @@ class Peer(Row):
         """
         Unassociate a key with this peer.
         """
-    
+
         remove = Row.remove_object(Key, 'peer_key')
         remove(self, key, commit)
 
@@ -178,7 +178,7 @@ class Peer(Row):
         """
         Unassociate a node with this peer.
         """
-    
+
         remove = Row.remove_object(Node, 'peer_node')
         remove(self, node, commit)
         # attempt to manually update the 'hrn' tag
@@ -274,14 +274,14 @@ class Peer(Row):
             raise AttributeError, "type object 'Peer' has no attribute '%s'" % attr
 
 class Peers (Table):
-    """ 
+    """
     Maps to the peers table in the database
     """
-    
+
     def __init__ (self, api, peer_filter = None, columns = None):
         Table.__init__(self, api, Peer, columns)
 
-       sql = "SELECT %s FROM view_peers WHERE deleted IS False" % \
+        sql = "SELECT %s FROM view_peers WHERE deleted IS False" % \
               ", ".join(self.columns)
 
         if peer_filter is not None:
@@ -295,4 +295,4 @@ class Peers (Table):
                 peer_filter = Filter(Peer.fields, peer_filter)
                 sql += " AND (%s) %s" % peer_filter.sql(api, "AND")
 
-       self.selectall(sql)
+        self.selectall(sql)
index d3c788a..fb9acc0 100644 (file)
@@ -28,8 +28,8 @@ class PersonTag(Row):
         'category': TagType.fields['category'],
         'min_role_id': TagType.fields['min_role_id'],
         'value': Parameter(str, "Person setting value"),
-       ### relations
-       
+        ### relations
+
         }
 
 class PersonTags(Table):
index 5a02403..f4346ce 100644 (file)
@@ -49,8 +49,8 @@ class Person(Row):
         'enabled': Parameter(bool, "Has been enabled"),
         'password': Parameter(str, "Account password in crypt() form", max = 254),
         'verification_key': Parameter(str, "Reset password key", max = 254, nullok = True),
-       'verification_expires': Parameter(int, "Date and time when verification_key expires", nullok = True),
-       'last_updated': Parameter(int, "Date and time of last update", ro = True),
+        'verification_expires': Parameter(int, "Date and time when verification_key expires", nullok = True),
+        'last_updated': Parameter(int, "Date and time of last update", ro = True),
         'date_created': Parameter(int, "Date and time when account was created", ro = True),
         'role_ids': Parameter([int], "List of role identifiers"),
         'roles': Parameter([str], "List of roles"),
@@ -62,15 +62,15 @@ class Person(Row):
         'person_tag_ids' : Parameter ([int], "List of tags attached to this person"),
         }
     related_fields = {
-       'roles': [Mixed(Parameter(int, "Role identifier"),
-                       Parameter(str, "Role name"))],
-       'sites': [Mixed(Parameter(int, "Site identifier"),
-                       Parameter(str, "Site name"))],
-       'keys': [Mixed(Parameter(int, "Key identifier"),
-                      Filter(Key.fields))],
-       'slices': [Mixed(Parameter(int, "Slice identifier"),
-                        Parameter(str, "Slice name"))]
-       }       
+        'roles': [Mixed(Parameter(int, "Role identifier"),
+                        Parameter(str, "Role name"))],
+        'sites': [Mixed(Parameter(int, "Site identifier"),
+                        Parameter(str, "Site name"))],
+        'keys': [Mixed(Parameter(int, "Key identifier"),
+                       Filter(Key.fields))],
+        'slices': [Mixed(Parameter(int, "Slice identifier"),
+                         Parameter(str, "Slice name"))]
+        }
     view_tags_name = "view_person_tags"
     # tags are used by the Add/Get/Update methods to expose tags
     # this is initialized here and updated by the accessors factory
@@ -90,14 +90,14 @@ class Person(Row):
         if not email_re.match(email):
             raise invalid_email
 
-               # check only against users on the same peer  
+        # check only against users on the same peer
         if 'peer_id' in self:
             namespace_peer_id = self['peer_id']
         else:
             namespace_peer_id = None
-         
-        conflicts = Persons(self.api, {'email':email,'peer_id':namespace_peer_id}) 
-       
+
+        conflicts = Persons(self.api, {'email':email,'peer_id':namespace_peer_id})
+
         for person in conflicts:
             if 'person_id' not in self or self['person_id'] != person['person_id']:
                 raise PLCInvalidArgument, "E-mail address already in use"
@@ -118,7 +118,7 @@ class Person(Row):
         else:
             # Generate a somewhat unique 8 character salt string
             salt = str(time.time()) + str(Random().random())
-            salt = md5(salt).hexdigest()[:8] 
+            salt = md5(salt).hexdigest()[:8]
             return crypt.crypt(password.encode(self.api.encoding), magic + salt + "$")
 
     validate_date_created = Row.validate_timestamp
@@ -211,42 +211,42 @@ class Person(Row):
         """
         Update last_updated field with current time
         """
-       
-       assert 'person_id' in self
-       assert self.table_name
-       
-       self.api.db.do("UPDATE %s SET last_updated = CURRENT_TIMESTAMP " % (self.table_name) + \
+
+        assert 'person_id' in self
+        assert self.table_name
+
+        self.api.db.do("UPDATE %s SET last_updated = CURRENT_TIMESTAMP " % (self.table_name) + \
                        " where person_id = %d" % (self['person_id']) )
         self.sync(commit)
 
     def associate_roles(self, auth, field, value):
-       """
-       Adds roles found in value list to this person (using AddRoleToPerson).
-       Deletes roles not found in value list from this person (using DeleteRoleFromPerson).
-       """
-       
-       assert 'role_ids' in self
-       assert 'person_id' in self
-       assert isinstance(value, list)
-       
-       (role_ids, role_names) = self.separate_types(value)[0:2]
-       
-       # Translate roles into role_ids
-       if role_names:
-           roles = Roles(self.api, role_names).dict('role_id')
-           role_ids += roles.keys()
-       
-       # Add new ids, remove stale ids
-       if self['role_ids'] != role_ids:
-           from PLC.Methods.AddRoleToPerson import AddRoleToPerson
-           from PLC.Methods.DeleteRoleFromPerson import DeleteRoleFromPerson
-           new_roles = set(role_ids).difference(self['role_ids'])
-           stale_roles = set(self['role_ids']).difference(role_ids)
-
-           for new_role in new_roles:
-               AddRoleToPerson.__call__(AddRoleToPerson(self.api), auth, new_role, self['person_id'])
-           for stale_role in stale_roles:
-               DeleteRoleFromPerson.__call__(DeleteRoleFromPerson(self.api), auth, stale_role, self['person_id'])
+        """
+        Adds roles found in value list to this person (using AddRoleToPerson).
+        Deletes roles not found in value list from this person (using DeleteRoleFromPerson).
+        """
+
+        assert 'role_ids' in self
+        assert 'person_id' in self
+        assert isinstance(value, list)
+
+        (role_ids, role_names) = self.separate_types(value)[0:2]
+
+        # Translate roles into role_ids
+        if role_names:
+            roles = Roles(self.api, role_names).dict('role_id')
+            role_ids += roles.keys()
+
+        # Add new ids, remove stale ids
+        if self['role_ids'] != role_ids:
+            from PLC.Methods.AddRoleToPerson import AddRoleToPerson
+            from PLC.Methods.DeleteRoleFromPerson import DeleteRoleFromPerson
+            new_roles = set(role_ids).difference(self['role_ids'])
+            stale_roles = set(self['role_ids']).difference(role_ids)
+
+            for new_role in new_roles:
+                AddRoleToPerson.__call__(AddRoleToPerson(self.api), auth, new_role, self['person_id'])
+            for stale_role in stale_roles:
+                DeleteRoleFromPerson.__call__(DeleteRoleFromPerson(self.api), auth, stale_role, self['person_id'])
 
 
     def associate_sites(self, auth, field, value):
@@ -255,7 +255,7 @@ class Person(Row):
         Deletes person from site not found in value list (using DeletePersonFromSite).
         """
 
-       from PLC.Sites import Sites
+        from PLC.Sites import Sites
 
         assert 'site_ids' in self
         assert 'person_id' in self
@@ -282,44 +282,44 @@ class Person(Row):
 
 
     def associate_keys(self, auth, field, value):
-       """
+        """
         Deletes key_ids not found in value list (using DeleteKey).
         Adds key if key_fields w/o key_id is found (using AddPersonKey).
         Updates key if key_fields w/ key_id is found (using UpdateKey).
         """
-       assert 'key_ids' in self
-       assert 'person_id' in self
-       assert isinstance(value, list)
-       
-       (key_ids, blank, keys) = self.separate_types(value)
-       
-       if self['key_ids'] != key_ids:
-           from PLC.Methods.DeleteKey import DeleteKey
-           stale_keys = set(self['key_ids']).difference(key_ids)
-       
-           for stale_key in stale_keys:
-               DeleteKey.__call__(DeleteKey(self.api), auth, stale_key) 
-
-       if keys:
-           from PLC.Methods.AddPersonKey import AddPersonKey
-           from PLC.Methods.UpdateKey import UpdateKey         
-           updated_keys = filter(lambda key: 'key_id' in key, keys)
-           added_keys = filter(lambda key: 'key_id' not in key, keys)
-               
-           for key in added_keys:
-               AddPersonKey.__call__(AddPersonKey(self.api), auth, self['person_id'], key)
-           for key in updated_keys:
-               key_id = key.pop('key_id')
-               UpdateKey.__call__(UpdateKey(self.api), auth, key_id, key)
-                 
-       
+        assert 'key_ids' in self
+        assert 'person_id' in self
+        assert isinstance(value, list)
+
+        (key_ids, blank, keys) = self.separate_types(value)
+
+        if self['key_ids'] != key_ids:
+            from PLC.Methods.DeleteKey import DeleteKey
+            stale_keys = set(self['key_ids']).difference(key_ids)
+
+            for stale_key in stale_keys:
+                DeleteKey.__call__(DeleteKey(self.api), auth, stale_key)
+
+        if keys:
+            from PLC.Methods.AddPersonKey import AddPersonKey
+            from PLC.Methods.UpdateKey import UpdateKey
+            updated_keys = filter(lambda key: 'key_id' in key, keys)
+            added_keys = filter(lambda key: 'key_id' not in key, keys)
+
+            for key in added_keys:
+                AddPersonKey.__call__(AddPersonKey(self.api), auth, self['person_id'], key)
+            for key in updated_keys:
+                key_id = key.pop('key_id')
+                UpdateKey.__call__(UpdateKey(self.api), auth, key_id, key)
+
+
     def associate_slices(self, auth, field, value):
         """
         Adds person to slices found in value list (using AddPersonToSlice).
         Deletes person from slices found in value list (using DeletePersonFromSlice).
         """
 
-       from PLC.Slices import Slices
+        from PLC.Slices import Slices
 
         assert 'slice_ids' in self
         assert 'person_id' in self
@@ -343,7 +343,7 @@ class Person(Row):
                 AddPersonToSlice.__call__(AddPersonToSlice(self.api), auth, self['person_id'], new_slice)
             for stale_slice in stale_slices:
                 DeletePersonFromSlice.__call__(DeletePersonFromSlice(self.api), auth, self['person_id'], stale_slice)
-    
+
 
     def delete(self, commit = True):
         """
@@ -377,7 +377,7 @@ class Persons(Table):
         for tagname in self.tag_columns:
             view= "%s left join %s using (%s)"%(view,Person.tagvalue_view_name(tagname),
                                                 Person.primary_key)
-            
+
         sql = "SELECT %s FROM %s WHERE deleted IS False" % \
             (", ".join(self.columns.keys()+self.tag_columns.keys()),view)
 
index 09132e2..965d5f9 100644 (file)
@@ -110,13 +110,13 @@ class PostgreSQL:
         return self.rowcount
 
     def next_id(self, table_name, primary_key):
-       sequence = "%(table_name)s_%(primary_key)s_seq" % locals()      
-       sql = "SELECT nextval('%(sequence)s')" % locals()
-       rows = self.selectall(sql, hashref = False)
-       if rows: 
-           return rows[0][0]
-               
-       return None 
+        sequence = "%(table_name)s_%(primary_key)s_seq" % locals()
+        sql = "SELECT nextval('%(sequence)s')" % locals()
+        rows = self.selectall(sql, hashref = False)
+        if rows:
+            return rows[0][0]
+
+        return None
 
     def last_insert_id(self, table_name, primary_key):
         if isinstance(self.lastrowid, int):
@@ -128,7 +128,7 @@ class PostgreSQL:
 
         return None
 
-    # modified for psycopg2-2.0.7 
+    # modified for psycopg2-2.0.7
     # executemany is undefined for SELECT's
     # see http://www.python.org/dev/peps/pep-0249/
     # accepts either None, a single dict, a tuple of single dict - in which case it execute's
index f688bc0..d661148 100644 (file)
@@ -52,7 +52,7 @@ class PyCurlTransport(xmlrpclib.Transport):
         self.body = ""
         def body(buf):
             self.body += buf
-        self.curl.setopt(pycurl.WRITEFUNCTION, body)        
+        self.curl.setopt(pycurl.WRITEFUNCTION, body)
 
     def request(self, host, handler, request_body, verbose = 1):
         # Set verbosity
@@ -74,7 +74,7 @@ class PyCurlTransport(xmlrpclib.Transport):
         if errcode == 60:
             raise Exception, "PyCurl: SSL certificate validation failed"
         elif errcode != 200:
-           raise Exception, "PyCurl: HTTP error %d -- %r" % (errcode,errmsg)
+            raise Exception, "PyCurl: HTTP error %d -- %r" % (errcode,errmsg)
 
         # Parse response
         p, u = self.getparser()
index d85444f..28fae35 100644 (file)
@@ -29,24 +29,24 @@ class Role(Row):
         }
 
     def validate_role_id(self, role_id):
-       # Make sure role does not already exist
-       conflicts = Roles(self.api, [role_id])
+        # Make sure role does not already exist
+        conflicts = Roles(self.api, [role_id])
         if conflicts:
             raise PLCInvalidArgument, "Role ID already in use"
 
         return role_id
 
     def validate_name(self, name):
-       # Make sure name is not blank
+        # Make sure name is not blank
         if not len(name):
             raise PLCInvalidArgument, "Role must be specified"
-       
-       # Make sure role does not already exist
-       conflicts = Roles(self.api, [name])
+
+        # Make sure role does not already exist
+        conflicts = Roles(self.api, [name])
         if conflicts:
             raise PLCInvalidArgument, "Role name already in use"
 
-       return name
+        return name
 
 class Roles(Table):
     """
@@ -58,7 +58,7 @@ class Roles(Table):
 
         sql = "SELECT %s FROM roles WHERE True" % \
               ", ".join(Role.fields)
-        
+
         if role_filter is not None:
             if isinstance(role_filter, (list, tuple, set)):
                 # Separate the list into integers and strings
index 33fd3b1..3e4355d 100644 (file)
@@ -67,21 +67,21 @@ class Sessions(Table):
     """
 
     def __init__(self, api, session_filter = None, expires = int(time.time())):
-       Table.__init__(self, api, Session)
+        Table.__init__(self, api, Session)
 
         sql = "SELECT %s FROM view_sessions WHERE True" % \
               ", ".join(Session.fields)
 
-       if session_filter is not None:
-           if isinstance(session_filter, (list, tuple, set)):
-               # Separate the list into integers and strings
+        if session_filter is not None:
+            if isinstance(session_filter, (list, tuple, set)):
+                # Separate the list into integers and strings
                 ints = filter(lambda x: isinstance(x, (int, long)), session_filter)
                 strs = filter(lambda x: isinstance(x, StringTypes), session_filter)
                 session_filter = Filter(Session.fields, {'person_id': ints, 'session_id': strs})
                 sql += " AND (%s) %s" % session_filter.sql(api, "OR")
-           elif isinstance(session_filter, dict):
-               session_filter = Filter(Session.fields, session_filter)
-               sql += " AND (%s) %s" % session_filter.sql(api, "AND")
+            elif isinstance(session_filter, dict):
+                session_filter = Filter(Session.fields, session_filter)
+                sql += " AND (%s) %s" % session_filter.sql(api, "AND")
 
         if expires is not None:
             if expires >= 0:
index 603b3c6..6ae4ded 100644 (file)
@@ -28,8 +28,8 @@ class SiteTag(Row):
         'category': TagType.fields['category'],
         'min_role_id': TagType.fields['min_role_id'],
         'value': Parameter(str, "Site setting value"),
-       ### relations
-       
+        ### relations
+
         }
 
 class SiteTags(Table):
index ef9f02a..dafa8cb 100644 (file)
@@ -31,7 +31,7 @@ class Site(Row):
         'login_base': Parameter(str, "Site slice prefix", max = 20),
         'is_public': Parameter(bool, "Publicly viewable site"),
         'enabled': Parameter(bool, "Has been enabled"),
-       'latitude': Parameter(float, "Decimal latitude of the site", min = -90.0, max = 90.0, nullok = True),
+        '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),
@@ -46,14 +46,14 @@ class Site(Row):
         'peer_id': Parameter(int, "Peer to which this site belongs", nullok = True),
         'peer_site_id': Parameter(int, "Foreign site identifier at peer", nullok = True),
         'site_tag_ids' : Parameter ([int], "List of tags attached to this site"),
-       'ext_consortium_id': Parameter(int, "external consortium id", nullok = True)
+        'ext_consortium_id': Parameter(int, "external consortium id", nullok = True)
         }
     related_fields = {
-       'persons': [Mixed(Parameter(int, "Person identifier"),
+        'persons': [Mixed(Parameter(int, "Person identifier"),
                           Parameter(str, "Email address"))],
-       'addresses': [Mixed(Parameter(int, "Address identifer"),
+        'addresses': [Mixed(Parameter(int, "Address identifer"),
                             Filter(Address.fields))]
-       }
+        }
     view_tags_name = "view_site_tags"
     # tags are used by the Add/Get/Update methods to expose tags
     # this is initialized here and updated by the accessors factory
@@ -114,54 +114,54 @@ class Site(Row):
 
         self.api.db.do("UPDATE %s SET last_updated = CURRENT_TIMESTAMP " % (self.table_name) + \
                        " where site_id = %d" % (self['site_id']) )
-        self.sync(commit)    
+        self.sync(commit)
 
 
     def associate_persons(self, auth, field, value):
-       """
-       Adds persons found in value list to this site (using AddPersonToSite).
-       Deletes persons not found in value list from this site (using DeletePersonFromSite).
-       """
-       
-       assert 'person_ids' in self
-       assert 'site_id' in self
-       assert isinstance(value, list)
-
-       (person_ids, emails) = self.separate_types(value)[0:2]
-
-       # Translate emails into person_ids
-       if emails:
-           persons = Persons(self.api, emails, ['person_id']).dict('person_id')
-           person_ids += persons.keys()
-
-       # Add new ids, remove stale ids
-       if self['person_ids'] != person_ids:
-           from PLC.Methods.AddPersonToSite import AddPersonToSite
-           from PLC.Methods.DeletePersonFromSite import DeletePersonFromSite
-           new_persons = set(person_ids).difference(self['person_ids'])
-           stale_persons = set(self['person_ids']).difference(person_ids)
-        
-           for new_person in new_persons:
-               AddPersonToSite.__call__(AddPersonToSite(self.api), auth, new_person, self['site_id'])
-           for stale_person in stale_persons:
-               DeletePersonFromSite.__call__(DeletePersonFromSite(self.api), auth, stale_person, self['site_id'])              
+        """
+        Adds persons found in value list to this site (using AddPersonToSite).
+        Deletes persons not found in value list from this site (using DeletePersonFromSite).
+        """
+
+        assert 'person_ids' in self
+        assert 'site_id' in self
+        assert isinstance(value, list)
+
+        (person_ids, emails) = self.separate_types(value)[0:2]
+
+        # Translate emails into person_ids
+        if emails:
+            persons = Persons(self.api, emails, ['person_id']).dict('person_id')
+            person_ids += persons.keys()
+
+        # Add new ids, remove stale ids
+        if self['person_ids'] != person_ids:
+            from PLC.Methods.AddPersonToSite import AddPersonToSite
+            from PLC.Methods.DeletePersonFromSite import DeletePersonFromSite
+            new_persons = set(person_ids).difference(self['person_ids'])
+            stale_persons = set(self['person_ids']).difference(person_ids)
+
+            for new_person in new_persons:
+                AddPersonToSite.__call__(AddPersonToSite(self.api), auth, new_person, self['site_id'])
+            for stale_person in stale_persons:
+                DeletePersonFromSite.__call__(DeletePersonFromSite(self.api), auth, stale_person, self['site_id'])
 
     def associate_addresses(self, auth, field, value):
-       """
-       Deletes addresses_ids not found in value list (using DeleteAddress).  
-       Adds address if slice_fields w/o address_id found in value list (using AddSiteAddress).
-       Update address if slice_fields w/ address_id found in value list (using UpdateAddress).
-       """
-       
-       assert 'address_ids' in self
-       assert 'site_id' in self
+        """
+        Deletes addresses_ids not found in value list (using DeleteAddress).
+        Adds address if slice_fields w/o address_id found in value list (using AddSiteAddress).
+        Update address if slice_fields w/ address_id found in value list (using UpdateAddress).
+        """
+
+        assert 'address_ids' in self
+        assert 'site_id' in self
         assert isinstance(value, list)
 
         (address_ids, blank, addresses) = self.separate_types(value)
 
-       for address in addresses:
-           if 'address_id' in address:
-               address_ids.append(address['address_id'])               
+        for address in addresses:
+            if 'address_id' in address:
+                address_ids.append(address['address_id'])
 
         # Add new ids, remove stale ids
         if self['address_ids'] != address_ids:
@@ -169,20 +169,20 @@ class Site(Row):
             stale_addresses = set(self['address_ids']).difference(address_ids)
 
             for stale_address in stale_addresses:
-                DeleteAddress.__call__(DeleteAddress(self.api), auth, stale_address)   
-       
-       if addresses:
-           from PLC.Methods.AddSiteAddress import AddSiteAddress
-           from PLC.Methods.UpdateAddress import UpdateAddress
-               
-           updated_addresses = filter(lambda address: 'address_id' in address, addresses)
-           added_addresses = filter(lambda address: 'address_id' not in address, addresses)
-               
-           for address in added_addresses:
-               AddSiteAddress.__call__(AddSiteAddress(self.api), auth, self['site_id'], address)       
-           for address in updated_addresses:
-               address_id = address.pop('address_id')
-               UpdateAddress.__call__(UpdateAddress(self.api), auth, address_id, address)
+                DeleteAddress.__call__(DeleteAddress(self.api), auth, stale_address)
+
+        if addresses:
+            from PLC.Methods.AddSiteAddress import AddSiteAddress
+            from PLC.Methods.UpdateAddress import UpdateAddress
+
+            updated_addresses = filter(lambda address: 'address_id' in address, addresses)
+            added_addresses = filter(lambda address: 'address_id' not in address, addresses)
+
+            for address in added_addresses:
+                AddSiteAddress.__call__(AddSiteAddress(self.api), auth, self['site_id'], address)
+            for address in updated_addresses:
+                address_id = address.pop('address_id')
+                UpdateAddress.__call__(UpdateAddress(self.api), auth, address_id, address)
 
     def delete(self, commit = True):
         """
@@ -243,12 +243,12 @@ class Sites(Table):
 
     def __init__(self, api, site_filter = None, columns = None):
         Table.__init__(self, api, Site, columns)
-       
+
         view = "view_sites"
         for tagname in self.tag_columns:
             view= "%s left join %s using (%s)"%(view,Site.tagvalue_view_name(tagname),
                                                 Site.primary_key)
-            
+
         sql = "SELECT %s FROM %s WHERE deleted IS False" % \
             (", ".join(self.columns.keys()+self.tag_columns.keys()),view)
 
index 1087e32..f03b119 100644 (file)
@@ -26,17 +26,17 @@ class SliceInstantiation(Row):
         }
 
     def validate_instantiation(self, instantiation):
-       # Make sure name is not blank
+        # Make sure name is not blank
         if not len(instantiation):
             raise PLCInvalidArgument, "Slice instantiation state name must be specified"
-       
-       # Make sure slice instantiation does not alredy exist
-       conflicts = SliceInstantiations(self.api, [instantiation])
+
+        # Make sure slice instantiation does not alredy exist
+        conflicts = SliceInstantiations(self.api, [instantiation])
         if conflicts:
             raise PLCInvalidArgument, "Slice instantiation state name already in use"
 
-       return instantiation
-        
+        return instantiation
+
 class SliceInstantiations(Table):
     """
     Representation of the slice_instantiations table in the database.
@@ -47,7 +47,7 @@ class SliceInstantiations(Table):
 
         sql = "SELECT %s FROM slice_instantiations" % \
               ", ".join(SliceInstantiation.fields)
-        
+
         if instantiations:
             sql += " WHERE instantiation IN (%s)" % ", ".join(map(api.db.quote, instantiations))
 
index 4b412b6..11adfd6 100644 (file)
@@ -23,7 +23,7 @@ class SliceTag(Row):
         'slice_id': Parameter(int, "Slice identifier"),
         'name': Parameter(str, "Slice name"),
         'node_id': Node.fields['node_id'],
-       'nodegroup_id': NodeGroup.fields['nodegroup_id'],
+        'nodegroup_id': NodeGroup.fields['nodegroup_id'],
         'tag_type_id': TagType.fields['tag_type_id'],
         'tagname': TagType.fields['tagname'],
         'description': TagType.fields['description'],
index 81da51d..59a592b 100644 (file)
@@ -44,11 +44,11 @@ class Slice(Row):
         'peer_slice_id': Parameter(int, "Foreign slice identifier at peer", nullok = True),
         }
     related_fields = {
-       'persons': [Mixed(Parameter(int, "Person identifier"),
-                         Parameter(str, "Email address"))],
-       'nodes': [Mixed(Parameter(int, "Node identifier"),
-                       Parameter(str, "Fully qualified hostname"))]
-       }
+        'persons': [Mixed(Parameter(int, "Person identifier"),
+                          Parameter(str, "Email address"))],
+        'nodes': [Mixed(Parameter(int, "Node identifier"),
+                        Parameter(str, "Fully qualified hostname"))]
+        }
 
     view_tags_name="view_slice_tags"
     tags = {}
@@ -101,21 +101,21 @@ class Slice(Row):
     def associate_persons(self, auth, field, value):
         """
         Adds persons found in value list to this slice (using AddPersonToSlice).
-       Deletes persons not found in value list from this slice (using DeletePersonFromSlice).
+        Deletes persons not found in value list from this slice (using DeletePersonFromSlice).
         """
-       
-       assert 'person_ids' in self
-       assert 'slice_id' in self
+
+        assert 'person_ids' in self
+        assert 'slice_id' in self
         assert isinstance(value, list)
 
-       (person_ids, emails) = self.separate_types(value)[0:2]
+        (person_ids, emails) = self.separate_types(value)[0:2]
 
-       # Translate emails into person_ids      
-       if emails:
-           persons = Persons(self.api, emails, ['person_id']).dict('person_id')
-           person_ids += persons.keys()
-       
-       # Add new ids, remove stale ids
+        # Translate emails into person_ids
+        if emails:
+            persons = Persons(self.api, emails, ['person_id']).dict('person_id')
+            person_ids += persons.keys()
+
+        # Add new ids, remove stale ids
         if self['person_ids'] != person_ids:
             from PLC.Methods.AddPersonToSlice import AddPersonToSlice
             from PLC.Methods.DeletePersonFromSlice import DeletePersonFromSlice
@@ -128,97 +128,97 @@ class Slice(Row):
                 DeletePersonFromSlice.__call__(DeletePersonFromSlice(self.api), auth, stale_person, self['slice_id'])
 
     def associate_nodes(self, auth, field, value):
-       """
-       Adds nodes found in value list to this slice (using AddSliceToNodes).
-       Deletes nodes not found in value list from this slice (using DeleteSliceFromNodes).
-       """
+        """
+        Adds nodes found in value list to this slice (using AddSliceToNodes).
+        Deletes nodes not found in value list from this slice (using DeleteSliceFromNodes).
+        """
 
         from PLC.Nodes import Nodes
 
-       assert 'node_ids' in self
-       assert 'slice_id' in self
-       assert isinstance(value, list)
-       
-       (node_ids, hostnames) = self.separate_types(value)[0:2]
-       
-       # Translate hostnames into node_ids
-       if hostnames:
-           nodes = Nodes(self.api, hostnames, ['node_id']).dict('node_id')
-           node_ids += nodes.keys()
-       
-       # Add new ids, remove stale ids
-       if self['node_ids'] != node_ids:
-           from PLC.Methods.AddSliceToNodes import AddSliceToNodes
-           from PLC.Methods.DeleteSliceFromNodes import DeleteSliceFromNodes
-           new_nodes = set(node_ids).difference(self['node_ids'])
-           stale_nodes = set(self['node_ids']).difference(node_ids)
-           
-           if new_nodes:
-               AddSliceToNodes.__call__(AddSliceToNodes(self.api), auth, self['slice_id'], list(new_nodes))
-           if stale_nodes:
-               DeleteSliceFromNodes.__call__(DeleteSliceFromNodes(self.api), auth, self['slice_id'], list(stale_nodes))                        
+        assert 'node_ids' in self
+        assert 'slice_id' in self
+        assert isinstance(value, list)
+
+        (node_ids, hostnames) = self.separate_types(value)[0:2]
+
+        # Translate hostnames into node_ids
+        if hostnames:
+            nodes = Nodes(self.api, hostnames, ['node_id']).dict('node_id')
+            node_ids += nodes.keys()
+
+        # Add new ids, remove stale ids
+        if self['node_ids'] != node_ids:
+            from PLC.Methods.AddSliceToNodes import AddSliceToNodes
+            from PLC.Methods.DeleteSliceFromNodes import DeleteSliceFromNodes
+            new_nodes = set(node_ids).difference(self['node_ids'])
+            stale_nodes = set(self['node_ids']).difference(node_ids)
+
+            if new_nodes:
+                AddSliceToNodes.__call__(AddSliceToNodes(self.api), auth, self['slice_id'], list(new_nodes))
+            if stale_nodes:
+                DeleteSliceFromNodes.__call__(DeleteSliceFromNodes(self.api), auth, self['slice_id'], list(stale_nodes))
     def associate_slice_tags(self, auth, fields, value):
-       """
-       Deletes slice_tag_ids not found in value list (using DeleteSliceTag). 
-       Adds slice_tags if slice_fields w/o slice_id is found (using AddSliceTag).
-       Updates slice_tag if slice_fields w/ slice_id is found (using UpdateSlceiAttribute).  
-       """
-       
-       assert 'slice_tag_ids' in self
-       assert isinstance(value, list)
-
-       (attribute_ids, blank, attributes) = self.separate_types(value)
-       
-       # There is no way to add attributes by id. They are
-       # associated with a slice when they are created.
-       # So we are only looking to delete here 
-       if self['slice_tag_ids'] != attribute_ids:
-           from PLC.Methods.DeleteSliceTag import DeleteSliceTag
-           stale_attributes = set(self['slice_tag_ids']).difference(attribute_ids)
-       
-           for stale_attribute in stale_attributes:
-               DeleteSliceTag.__call__(DeleteSliceTag(self.api), auth, stale_attribute['slice_tag_id'])                
-       
-       # If dictionary exists, we are either adding new
+        """
+        Deletes slice_tag_ids not found in value list (using DeleteSliceTag).
+        Adds slice_tags if slice_fields w/o slice_id is found (using AddSliceTag).
+        Updates slice_tag if slice_fields w/ slice_id is found (using UpdateSlceiAttribute).
+        """
+
+        assert 'slice_tag_ids' in self
+        assert isinstance(value, list)
+
+        (attribute_ids, blank, attributes) = self.separate_types(value)
+
+        # There is no way to add attributes by id. They are
+        # associated with a slice when they are created.
+        # So we are only looking to delete here
+        if self['slice_tag_ids'] != attribute_ids:
+            from PLC.Methods.DeleteSliceTag import DeleteSliceTag
+            stale_attributes = set(self['slice_tag_ids']).difference(attribute_ids)
+
+            for stale_attribute in stale_attributes:
+                DeleteSliceTag.__call__(DeleteSliceTag(self.api), auth, stale_attribute['slice_tag_id'])
+
+        # If dictionary exists, we are either adding new
         # attributes or updating existing ones.
         if attributes:
             from PLC.Methods.AddSliceTag import AddSliceTag
             from PLC.Methods.UpdateSliceTag import UpdateSliceTag
-       
-           added_attributes = filter(lambda x: 'slice_tag_id' not in x, attributes)
-           updated_attributes = filter(lambda x: 'slice_tag_id' in x, attributes)
-
-           for added_attribute in added_attributes:
-               if 'tag_type' in added_attribute:
-                   type = added_attribute['tag_type']
-               elif 'tag_type_id' in added_attribute:
-                   type = added_attribute['tag_type_id']
-               else:
-                   raise PLCInvalidArgument, "Must specify tag_type or tag_type_id"
-
-               if 'value' in added_attribute:
-                   value = added_attribute['value']
-               else:
-                   raise PLCInvalidArgument, "Must specify a value"
-               
-               if 'node_id' in added_attribute:
-                   node_id = added_attribute['node_id']
-               else:
-                   node_id = None
-
-               if 'nodegroup_id' in added_attribute:
-                   nodegroup_id = added_attribute['nodegroup_id']
-               else:
-                   nodegroup_id = None 
-               AddSliceTag.__call__(AddSliceTag(self.api), auth, self['slice_id'], type, value, node_id, nodegroup_id)
-           for updated_attribute in updated_attributes:
-               attribute_id = updated_attribute.pop('slice_tag_id')
-               if attribute_id not in self['slice_tag_ids']:
-                   raise PLCInvalidArgument, "Attribute doesnt belong to this slice" 
-               else:
-                   UpdateSliceTag.__call__(UpdateSliceTag(self.api), auth, attribute_id, updated_attribute)             
-       
+
+            added_attributes = filter(lambda x: 'slice_tag_id' not in x, attributes)
+            updated_attributes = filter(lambda x: 'slice_tag_id' in x, attributes)
+
+            for added_attribute in added_attributes:
+                if 'tag_type' in added_attribute:
+                    type = added_attribute['tag_type']
+                elif 'tag_type_id' in added_attribute:
+                    type = added_attribute['tag_type_id']
+                else:
+                    raise PLCInvalidArgument, "Must specify tag_type or tag_type_id"
+
+                if 'value' in added_attribute:
+                    value = added_attribute['value']
+                else:
+                    raise PLCInvalidArgument, "Must specify a value"
+
+                if 'node_id' in added_attribute:
+                    node_id = added_attribute['node_id']
+                else:
+                    node_id = None
+
+                if 'nodegroup_id' in added_attribute:
+                    nodegroup_id = added_attribute['nodegroup_id']
+                else:
+                    nodegroup_id = None
+
+                AddSliceTag.__call__(AddSliceTag(self.api), auth, self['slice_id'], type, value, node_id, nodegroup_id)
+            for updated_attribute in updated_attributes:
+                attribute_id = updated_attribute.pop('slice_tag_id')
+                if attribute_id not in self['slice_tag_ids']:
+                    raise PLCInvalidArgument, "Attribute doesnt belong to this slice"
+                else:
+                    UpdateSliceTag.__call__(UpdateSliceTag(self.api), auth, attribute_id, updated_attribute)
+
     def sync(self, commit = True):
         """
         Add or update a slice.
@@ -264,7 +264,7 @@ class Slices(Table):
         for tagname in self.tag_columns:
             view= "%s left join %s using (%s)"%(view,Slice.tagvalue_view_name(tagname),
                                                 Slice.primary_key)
-            
+
         sql = "SELECT %s FROM %s WHERE is_deleted IS False" % \
               (", ".join(self.columns.keys()+self.tag_columns.keys()),view)
 
index c3cf0ec..b811c62 100644 (file)
@@ -68,35 +68,35 @@ class Row(dict):
             if value is not None and hasattr(self, 'validate_' + key):
                 validate = getattr(self, 'validate_' + key)
                 self[key] = validate(value)
-       
+
     def separate_types(self, items):
-       """
-       Separate a list of different typed objects. 
-       Return a list for each type (ints, strs and dicts)
-       """
-       
-       if isinstance(items, (list, tuple, set)):
-           ints = filter(lambda x: isinstance(x, (int, long)), items)
-           strs = filter(lambda x: isinstance(x, StringTypes), items)
-           dicts = filter(lambda x: isinstance(x, dict), items)
-           return (ints, strs, dicts)          
-       else:
-           raise PLCInvalidArgument, "Can only separate list types" 
-               
+        """
+        Separate a list of different typed objects.
+        Return a list for each type (ints, strs and dicts)
+        """
+
+        if isinstance(items, (list, tuple, set)):
+            ints = filter(lambda x: isinstance(x, (int, long)), items)
+            strs = filter(lambda x: isinstance(x, StringTypes), items)
+            dicts = filter(lambda x: isinstance(x, dict), items)
+            return (ints, strs, dicts)
+        else:
+            raise PLCInvalidArgument, "Can only separate list types"
+
 
     def associate(self, *args):
-       """
-       Provides a means for high level api calls to associate objects
+        """
+        Provides a means for high level api calls to associate objects
         using low level calls.
-       """
+        """
 
-       if len(args) < 3:
-           raise PLCInvalidArgumentCount, "auth, field, value must be specified"
-       elif hasattr(self, 'associate_' + args[1]):
-           associate = getattr(self, 'associate_'+args[1])
-           associate(*args)
-       else:
-           raise PLCInvalidArguemnt, "No such associate function associate_%s" % args[1]
+        if len(args) < 3:
+            raise PLCInvalidArgumentCount, "auth, field, value must be specified"
+        elif hasattr(self, 'associate_' + args[1]):
+            associate = getattr(self, 'associate_'+args[1])
+            associate(*args)
+        else:
+            raise PLCInvalidArguemnt, "No such associate function associate_%s" % args[1]
 
     def validate_timestamp (self, timestamp):
         return Timestamp.sql_validate(timestamp)
@@ -119,7 +119,7 @@ class Row(dict):
             assert isinstance(obj, classobj)
             assert isinstance(obj, Row)
             assert obj.primary_key in obj
-           assert join_table in obj.join_tables
+            assert join_table in obj.join_tables
 
             # By default, just insert the primary keys of each object
             # into the join table.
@@ -137,7 +137,7 @@ class Row(dict):
 
             if commit:
                 self.api.db.commit()
-    
+
         return add
 
     add_object = classmethod(add_object)
@@ -152,7 +152,7 @@ class Row(dict):
             """
             Disassociate from the specified object.
             """
-    
+
             assert isinstance(self, Row)
             assert self.primary_key in self
             assert join_table in self.join_tables
@@ -160,10 +160,10 @@ class Row(dict):
             assert isinstance(obj, Row)
             assert obj.primary_key in obj
             assert join_table in obj.join_tables
-    
+
             self_id = self[self.primary_key]
             obj_id = obj[obj.primary_key]
-    
+
             self.api.db.do("DELETE FROM %s WHERE %s = %s AND %s = %s" % \
                            (join_table,
                             self.primary_key, self.api.db.param('self_id', self_id),
@@ -207,10 +207,10 @@ class Row(dict):
         Return the fields of obj that are mentioned in tags
         """
         if obj is None: obj=self
-        
-        return dict ( [ (key,value) for (key,value) in obj.iteritems() 
+
+        return dict ( [ (key,value) for (key,value) in obj.iteritems()
                         if key in self.tags and Row.is_writable(key,value,self.tags) ] )
-    
+
     # takes as input a list of columns, sort native fields from tags
     # returns 2 dicts and one list : fields, tags, rejected
     @classmethod
@@ -261,7 +261,7 @@ class Row(dict):
                 if field in candidate_dict.keys():
                     result[i][field]=value
                     found=True
-                    break 
+                    break
             if not found: rejected[field]=value
         result.append(rejected)
         return result
@@ -274,13 +274,13 @@ class Row(dict):
     @classmethod
     def tagvalue_view_create_sql (cls,tagname):
         """
-        returns a SQL sentence that creates a view named after the primary_key and tagname, 
+        returns a SQL sentence that creates a view named after the primary_key and tagname,
         with 2 columns
-        (*) column 1: primary_key 
+        (*) column 1: primary_key
         (*) column 2: actual tag value, renamed into tagname
         """
 
-        if not cls.view_tags_name: 
+        if not cls.view_tags_name:
             raise Exception, 'WARNING: class %s needs to set view_tags_name'%cls.__name__
 
         table_name=cls.table_name
@@ -336,15 +336,15 @@ class Row(dict):
         if not self.has_key(self.primary_key) or \
            keys == [self.primary_key] or \
            insert is True:
-           
-           # If primary key id is a serial int and it isnt included, get next id
-           if self.fields[self.primary_key].type in (IntType, LongType) and \
-              self.primary_key not in self:
-               pk_id = self.api.db.next_id(self.table_name, self.primary_key)
-               self[self.primary_key] = pk_id
-               db_fields[self.primary_key] = pk_id
-               keys = db_fields.keys()
-               values = [self.api.db.param(key, value) for (key, value) in db_fields.items()]
+
+            # If primary key id is a serial int and it isnt included, get next id
+            if self.fields[self.primary_key].type in (IntType, LongType) and \
+               self.primary_key not in self:
+                pk_id = self.api.db.next_id(self.table_name, self.primary_key)
+                self[self.primary_key] = pk_id
+                db_fields[self.primary_key] = pk_id
+                keys = db_fields.keys()
+                values = [self.api.db.param(key, value) for (key, value) in db_fields.items()]
             # Insert new row
             sql = "INSERT INTO %s (%s) VALUES (%s)" % \
                   (self.table_name, ", ".join(keys), ", ".join(values))
index a7a3f4e..209b61e 100644 (file)
@@ -1,4 +1,84 @@
 # $Id$
+# $Id$
+# $URL$
+#
+# Thierry Parmentelat - INRIA
+#
+from types import StringTypes
+
+from PLC.Faults import *
+from PLC.Parameter import Parameter
+from PLC.Filter import Filter
+from PLC.Table import Row, Table
+from PLC.Roles import Role, Roles
+
+# xxx todo : deleting a tag type should delete the related nodegroup(s)
+
+class TagType (Row):
+
+    """
+    Representation of a row in the tag_types table.
+    """
+
+    table_name = 'tag_types'
+    primary_key = 'tag_type_id'
+    join_tables = ['node_tag', 'interface_tag', 'slice_tag', 'site_tag', 'person_tag' ]
+    fields = {
+        'tag_type_id': Parameter(int, "Node tag type identifier"),
+        'tagname': Parameter(str, "Node tag type name", max = 100),
+        'description': Parameter(str, "Node tag type description", max = 254),
+        'category' : Parameter (str, "Node tag category", max=64, optional=True),
+        'min_role_id': Parameter(int, "Minimum (least powerful) role that can set or change this attribute"),
+        }
+
+    def validate_name(self, name):
+        if not len(name):
+            raise PLCInvalidArgument, "node tag type name must be set"
+
+        conflicts = TagTypes(self.api, [name])
+        for tag_type in conflicts:
+            if 'tag_type_id' not in self or \
+                   self['tag_type_id'] != tag_type['tag_type_id']:
+                raise PLCInvalidArgument, "node tag type name already in use"
+
+        return name
+
+    def validate_min_role_id(self, role_id):
+        roles = [row['role_id'] for row in Roles(self.api)]
+        if role_id not in roles:
+            raise PLCInvalidArgument, "Invalid role"
+
+        return role_id
+
+class TagTypes(Table):
+    """
+    Representation of row(s) from the tag_types table
+    in the database.
+    """
+
+    def __init__(self, api, tag_type_filter = None, columns = None):
+        Table.__init__(self, api, TagType, columns)
+
+        sql = "SELECT %s FROM tag_types WHERE True" % \
+              ", ".join(self.columns)
+
+        if tag_type_filter is not None:
+            if isinstance(tag_type_filter, (list, tuple, set)):
+                # Separate the list into integers and strings
+                ints = filter(lambda x: isinstance(x, (int, long)), tag_type_filter)
+                strs = filter(lambda x: isinstance(x, StringTypes), tag_type_filter)
+                tag_type_filter = Filter(TagType.fields, {'tag_type_id': ints, 'tagname': strs})
+                sql += " AND (%s) %s" % tag_type_filter.sql(api, "OR")
+            elif isinstance(tag_type_filter, dict):
+                tag_type_filter = Filter(TagType.fields, tag_type_filter)
+                sql += " AND (%s) %s" % tag_type_filter.sql(api, "AND")
+            elif isinstance (tag_type_filter, StringTypes):
+                tag_type_filter = Filter(TagType.fields, {'tagname':[tag_type_filter]})
+                sql += " AND (%s) %s" % tag_type_filter.sql(api, "AND")
+            else:
+                raise PLCInvalidArgument, "Wrong node tag type filter %r"%tag_type_filter
+
+        self.selectall(sql)
 # $URL$
 #
 # Thierry Parmentelat - INRIA
index 1b1f9ad..a5ae66b 100644 (file)
@@ -19,7 +19,7 @@ from PLC.Parameter import Parameter, Mixed
 
 # a dummy class mostly used as a namespace
 class Timestamp:
-    
+
     debug=False
 #    debug=True
 
@@ -36,8 +36,8 @@ class Timestamp:
                       "%Y-%m-%d %H:%M UTC",
                       ]
 
-    # for timestamps we usually accept either an int, or an ISO string, 
-    # the datetime.datetime stuff can in general be used locally, 
+    # for timestamps we usually accept either an int, or an ISO string,
+    # the datetime.datetime stuff can in general be used locally,
     # but not sure it can be marshalled over xmlrpc though
 
     @staticmethod
@@ -49,17 +49,17 @@ class Timestamp:
     @staticmethod
     def sql_validate (input, timezone=False, check_future = False):
         """
-        Validates the specified GMT timestamp, returns a 
+        Validates the specified GMT timestamp, returns a
         standardized string suitable for SQL input.
 
         Input may be a number (seconds since UNIX epoch back in 1970,
-        or a string (in one of the supported input formats).  
+        or a string (in one of the supported input formats).
 
-        If timezone is True, the resulting string contains 
+        If timezone is True, the resulting string contains
         timezone information, which is hard-wired as 'UTC'
-        
+
         If check_future is True, raises an exception if timestamp is in
-        the past. 
+        the past.
 
         Returns a GMT timestamp string suitable to feed SQL.
         """
@@ -108,7 +108,7 @@ class Timestamp:
         Translates input timestamp as a unix timestamp.
 
         Input may be a number (seconds since UNIX epoch, i.e., 1970-01-01
-        00:00:00 GMT), a string (in one of the supported input formats above).  
+        00:00:00 GMT), a string (in one of the supported input formats above).
 
         """
         if Timestamp.debug: print 'cast_long, in:',input,