cannot use UpdateNode to force an update of the 'hrn' node tag for peer nodes becuase...
authorTony Mack <tmack@cs.princeton.edu>
Fri, 12 Mar 2010 23:31:56 +0000 (23:31 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Fri, 12 Mar 2010 23:31:56 +0000 (23:31 +0000)
PLC/Methods/UpdateNode.py
PLC/Nodes.py
PLC/Peers.py

index dbcc2b4..136983f 100644 (file)
@@ -89,14 +89,7 @@ class UpdateNode(Method):
         # if hostname was modifed make sure to update the hrn
         # tag
         if 'hostname' in native:
-            # root authority should be PLC_HRN_ROOT for local
-            # objects or peer['hrn_root'] for peer objects 
             root_auth = self.api.config.PLC_HRN_ROOT
-            if node['peer_id']:
-                peers = Peers(self.api, node['peer_id'], ['hrn_root'])
-                if peers:
-                    root_auth = peers[0]['hrn_root'] 
-                     
             # sub auth is the login base of this node's site
             sites = Sites(self.api, node['site_id'], ['login_base'])
             site = sites[0]
index 46fb99a..48f8eeb 100644 (file)
@@ -139,14 +139,30 @@ class Node(Row):
                        " where node_id = %d" % (self['node_id']) )
         self.sync(commit)
 
+    def update_tags(self, tags):
+        from PLC.Shell import Shell
+        from PLC.NodeTags import NodeTags
+        from PLC.Methods.AddNodeTag import AddNodeTag
+        from PLC.Methods.UpdateNodeTag import UpdateNodeTag
+        shell = Shell()
+        for (tagname,value) in tags.iteritems():
+            # the tagtype instance is assumed to exist, just check that
+            if not TagTypes(self.api,{'tagname':tagname}):
+                raise PLCInvalidArgument,"No such TagType %s"%tagname
+            node_tags=NodeTags(self.api,{'tagname':tagname,'node_id':node['node_id']})
+            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) 
+    
     def associate_interfaces(self, auth, field, value):
-       """
-       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) 
-       """
+        """
+        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) 
+        """
 
-       assert 'interface_ids' in self
+        assert 'interface_ids' in self
         assert 'node_id' in self
         assert isinstance(value, list)
 
index d6eef65..e2f91d5 100644 (file)
@@ -8,17 +8,18 @@ import re
 from types import StringTypes
 from urlparse import urlparse
 
+import PLC.Auth
 from PLC.Faults import *
+from PLC.Namespace import hostname_to_hrn
 from PLC.Parameter import Parameter, Mixed
 from PLC.Filter import Filter
 from PLC.Table import Row, Table
-import PLC.Auth
-
 from PLC.Sites import Site, Sites
 from PLC.Persons import Person, Persons
 from PLC.Keys import Key, Keys
 from PLC.Nodes import Node, Nodes
 from PLC.TagTypes import TagType, TagTypes
+from PLC.NodeTags import NodeTag, NodeTags
 from PLC.SliceTags import SliceTag, SliceTags
 from PLC.Slices import Slice, Slices
 
@@ -164,11 +165,14 @@ class Peer(Row):
              'peer_node_id': peer_node_id},
             commit = commit)
 
-        # calling UpdateNode with the node's hostname
-        # will force the 'hrn' tag to be updated with the
-        # correct root auth
-        from PLC.Methods.UpdateNode import UpdateNode
-        UpdateNode.__call__(UpdateNode(self.api), auth, node['node_id'], {'hostname': node['hostname']})  
+        # attempt to manually update the 'hrn' tag
+        root_auth = self['hrn_root']
+        sites = Sites(self.api, node['site_id'], ['login_base'])
+        site = sites[0]
+        login_base = site['login_base']
+        hrn = hostname_to_hrn(root_auth, login_base, node['hostname'])
+        tags = {'hrn': hrn}
+        Node(self.api, node).update_tags(tags)
 
     def remove_node(self, node, commit = True):
         """
@@ -177,12 +181,14 @@ class Peer(Row):
     
         remove = Row.remove_object(Node, 'peer_node')
         remove(self, node, commit)
-
-        # calling UpdateNode with the node's hostname
-        # will force the 'hrn' tag to be updated with the
-        # correct root auth
-        from PLC.Methods.UpdateNode import UpdateNode
-        UpdateNode.__call__(UpdateNode(self.api), auth, node['node_id'], {'hostname': node['hostname']})  
+        # attempt to manually update the 'hrn' tag
+        root_auth = self.api.config.PLC_HRN_ROOT
+        sites = Sites(self.api, node['site_id'], ['login_base'])
+        site = sites[0]
+        login_base = site['login_base']
+        hrn = hostname_to_hrn(root_auth, login_base, node['hostname'])
+        tags = {'hrn': hrn}
+        Node(self.api, node).update_tags(tags)
 
     def add_slice(self, slice, peer_slice_id, commit = True):
         """