define systemd.log_target=console when used with systemd-debug
[plcapi.git] / PLC / Methods / UpdateInterface.py
index b7d7f30..034780e 100644 (file)
@@ -1,4 +1,3 @@
-# $Id$
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
@@ -12,7 +11,7 @@ from PLC.Interfaces import Interface, Interfaces
 from PLC.Methods.AddInterfaceTag import AddInterfaceTag
 from PLC.Methods.UpdateInterfaceTag import UpdateInterfaceTag
 
-can_update = ['interface_id','node_id']
+cannot_update = ['interface_id','node_id']
 
 class UpdateInterface(Method):
     """
@@ -22,21 +21,22 @@ 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.
     """
 
     roles = ['admin', 'pi', 'tech']
 
-    accepted_fields = Row.accepted_fields(can_update, [Interface.fields,Interface.tags])
+    accepted_fields = Row.accepted_fields(cannot_update, Interface.fields,exclude=True)
+    accepted_fields.update(Interface.tags)
 
     accepts = [
         Auth(),
-       Interface.fields['interface_id'],
-       accepted_fields
+        Interface.fields['interface_id'],
+        accepted_fields
         ]
 
     returns = Parameter(int, '1 if successful')
@@ -45,20 +45,22 @@ class UpdateInterface(Method):
 
         [native,tags,rejected] = Row.split_fields(interface_fields,[Interface.fields,Interface.tags])
 
+        # type checking
+        native= Row.check_fields (native, self.accepted_fields)
         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']])
@@ -68,9 +70,10 @@ 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.update_last_updated(commit=False)
         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}):
@@ -81,8 +84,11 @@ class UpdateInterface(Method):
             else:
                 UpdateInterfaceTag(self.api).__call__(auth,interface_tags[0]['interface_tag_id'],value)
 
-       self.event_objects = {'Interface': [interface['interface_id']]}
-       self.message = "Interface %d updated: %s " % \
-           (interface['interface_id'], ", ".join(interface_fields.keys()))
+        self.event_objects = {'Interface': [interface['interface_id']]}
+        if 'ip' in interface:
+            self.message = "Interface %s updated"%interface['ip']
+        else:
+            self.message = "Interface %d updated"%interface['interface_id']
+        self.message += "[%s]." % ", ".join(interface_fields.keys())
 
         return 1