Merge branch 'master' of ssh://git.planet-lab.org/git/sfa
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Tue, 25 Oct 2011 15:41:02 +0000 (11:41 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Tue, 25 Oct 2011 15:41:02 +0000 (11:41 -0400)
15 files changed:
Makefile
sfa/client/sfi.py
sfa/managers/aggregate_manager.py
sfa/managers/aggregate_manager_vini.py
sfa/managers/component_manager_pl.py
sfa/managers/slice_manager.py
sfa/plc/api.py
sfa/trust/auth.py
sfa/trust/hierarchy.py
sfa/trust/sfaticket.py [moved from sfa/util/sfaticket.py with 100% similarity]
tests/testInterfaces.py
tools/Makefile [new file with mode: 0644]
tools/depgraph2dot.py [new file with mode: 0755]
tools/py2depgraph.py [new file with mode: 0755]
tools/readme [new file with mode: 0644]

index f162f5f..9466961 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -87,7 +87,7 @@ force:
 
 ##########
 tags:  
-       find . -type f | egrep -v '/\.git/|/\.svn/|TAGS|\.py[co]$$|\.doc$$|\.html$$|\.pdf$$|~$$|\.png$$|\.svg$$|\.out$$|\.bak$$|\.xml$$' | xargs etags
+       find . -type f | egrep -v '/\.git/|/\.svn/|TAGS|~$$|\.(py[co]|doc|html|pdf|png|svg|out|bak|xml|dg)$$' | xargs etags
 .PHONY: tags
 
 signatures:
index 83a66f9..0b44726 100755 (executable)
@@ -18,7 +18,7 @@ from sfa.util.sfalogging import sfi_logger
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.gid import GID
 from sfa.trust.credential import Credential
-from sfa.util.sfaticket import SfaTicket
+from sfa.trust.sfaticket import SfaTicket
 from sfa.util.record import SfaRecord, UserRecord, SliceRecord, NodeRecord, AuthorityRecord
 from sfa.rspecs.rspec import RSpec
 from sfa.rspecs.rspec_converter import RSpecConverter
index b4f109f..7646dd3 100644 (file)
@@ -11,7 +11,7 @@ from sfa.util.plxrn import slicename_to_hrn, hrn_to_pl_slicename, hostname_to_ur
 from sfa.util.record import SfaRecord
 from sfa.util.policy import Policy
 from sfa.util.record import *
-from sfa.util.sfaticket import SfaTicket
+from sfa.trust.sfaticket import SfaTicket
 from sfa.plc.slices import Slices
 from sfa.trust.credential import Credential
 import sfa.plc.peers as peers
index 3b92eeb..88c4438 100644 (file)
@@ -10,7 +10,7 @@ from sfa.util.faults import *
 from sfa.util.record import SfaRecord
 from sfa.util.policy import Policy
 from sfa.util.record import *
-from sfa.util.sfaticket import SfaTicket
+from sfa.trust.sfaticket import SfaTicket
 from sfa.server.registry import Registries
 from sfa.plc.slices import Slices
 import sfa.plc.peers as peers
index 6100e76..ec5e24c 100644 (file)
@@ -3,7 +3,7 @@ import xmlrpclib
 
 from sfa.util.faults import *
 from sfa.util.plxrn import PlXrn
-from sfa.util.sfaticket import SfaTicket
+from sfa.trust.sfaticket import SfaTicket
 from sfa.util.version import version_core
 
 def GetVersion(api):
index 3eda3db..d3ce06b 100644 (file)
@@ -19,7 +19,7 @@ from sfa.rspecs.version_manager import VersionManager
 from sfa.rspecs.rspec import RSpec 
 from sfa.util.policy import Policy
 from sfa.util.prefixTree import prefixTree
-from sfa.util.sfaticket import *
+from sfa.trust.sfaticket import SfaTicket
 from sfa.trust.credential import Credential
 from sfa.util.threadmanager import ThreadManager
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol     
index cad2267..8a03a87 100644 (file)
@@ -576,12 +576,22 @@ class SfaAPI(BaseAPI):
         self.fill_record_sfa_info(records)
 
     def update_membership_list(self, oldRecord, record, listName, addFunc, delFunc):
-        # get a list of the HRNs tht are members of the old and new records
+        # get a list of the HRNs that are members of the old and new records
         if oldRecord:
             oldList = oldRecord.get(listName, [])
         else:
             oldList = []     
         newList = record.get(listName, [])
+        # ugly hack to see what's next
+        def normalize (value):
+            from types import StringTypes
+            from sfa.util.sfalogging import logger
+            if isinstance(value,StringTypes): return value
+            elif isinstance(value,dict): 
+                newvalue=value['text']
+                logger.info("Normalizing %s=>%s"%(value,newvalue))
+                return newvalue
+        newList=[normalize(v) for v in newList]
 
         # if the lists are the same, then we don't have to update anything
         if (oldList == newList):
index 41c71cf..c3dbc46 100644 (file)
@@ -10,7 +10,7 @@ from sfa.util.faults import *
 from sfa.trust.hierarchy import Hierarchy
 from sfa.util.config import *
 from sfa.util.xrn import get_authority
-from sfa.util.sfaticket import *
+from sfa.trust.sfaticket import SfaTicket
 
 from sfa.util.sfalogging import logger
 
index 6323436..dc66ef8 100644 (file)
@@ -21,7 +21,7 @@ from sfa.trust.certificate import Keypair
 from sfa.trust.credential import Credential
 from sfa.trust.gid import GID, create_uuid
 from sfa.util.config import Config
-from sfa.util.sfaticket import SfaTicket
+from sfa.trust.sfaticket import SfaTicket
 
 ##
 # The AuthInfo class contains the information for an authority. This information
similarity index 100%
rename from sfa/util/sfaticket.py
rename to sfa/trust/sfaticket.py
index d25484c..9160637 100755 (executable)
@@ -12,7 +12,7 @@ from sfa.util.xrn import get_authority
 from sfa.util.config import *
 from sfa.trust.certificate import *
 from sfa.trust.credential import *
-from sfa.util.sfaticket import *
+from sfa.trust.sfaticket import SfaTicket
 from sfa.client import sfi
 
 def random_string(size):
diff --git a/tools/Makefile b/tools/Makefile
new file mode 100644 (file)
index 0000000..63bb765
--- /dev/null
@@ -0,0 +1,18 @@
+########## compute dependency graphs
+DEPTOOLS=py2depgraph.py depgraph2dot.py
+
+all:deps
+
+deps: server.png client.png
+
+server.dg: $(DEPTOOLS)
+       py2depgraph.py ../sfa/server/sfa-server.py > $@
+
+client.dg: $(DEPTOOLS)
+       py2depgraph.py ../sfa/client/sfi.py > $@
+
+%.png: %.dg
+       depgraph2dot.py < $*.dg | dot -T png -o $*.png
+
+clean: 
+       rm -f *png *dg
diff --git a/tools/depgraph2dot.py b/tools/depgraph2dot.py
new file mode 100755 (executable)
index 0000000..930e24f
--- /dev/null
@@ -0,0 +1,197 @@
+#!/usr/bin/python
+# Copyright 2004 Toby Dickenson
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject
+# to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+import sys, getopt, colorsys, imp, md5
+
+class pydepgraphdot:
+
+    def main(self,argv):    
+        opts,args = getopt.getopt(argv,'',['mono'])
+        self.colored = 1
+        for o,v in opts:
+            if o=='--mono':
+                self.colored = 0
+        self.render()
+
+    def fix(self,s):
+        # Convert a module name to a syntactically correct node name
+        return s.replace('.','_')
+    
+    def render(self):
+        p,t = self.get_data()
+
+        # normalise our input data
+        for k,d in p.items():
+            for v in d.keys():
+                if not p.has_key(v):
+                    p[v] = {}
+                    
+        f = self.get_output_file()                    
+                    
+        f.write('digraph G {\n')
+        #f.write('concentrate = true;\n')
+        #f.write('ordering = out;\n')
+        f.write('ranksep=1.0;\n')
+        f.write('node [style=filled,fontname=Helvetica,fontsize=10];\n')
+        allkd = p.items()
+        allkd.sort()
+        for k,d in allkd:
+            tk = t.get(k)
+            if self.use(k,tk):
+                allv = d.keys()
+                allv.sort()
+                for v in allv:
+                    tv = t.get(v)
+                    if self.use(v,tv) and not self.toocommon(v,tv):
+                        f.write('%s -> %s' % ( self.fix(k),self.fix(v) ) )
+                        self.write_attributes(f,self.edge_attributes(k,v))
+                        f.write(';\n')
+                f.write(self.fix(k))
+                self.write_attributes(f,self.node_attributes(k,tk))
+                f.write(';\n')
+        f.write('}\n')
+
+    def write_attributes(self,f,a):
+        if a:
+            f.write(' [')
+            f.write(','.join(a))
+            f.write(']')
+
+    def node_attributes(self,k,type):
+        a = []
+        a.append('label="%s"' % self.label(k))
+        if self.colored:
+            a.append('fillcolor="%s"' % self.color(k,type))
+        else:
+            a.append('fillcolor=white')
+        if self.toocommon(k,type):
+            a.append('peripheries=2')
+        return a
+                
+    def edge_attributes(self,k,v):
+        a = []
+        weight = self.weight(k,v)
+        if weight!=1:
+            a.append('weight=%d' % weight)
+        length = self.alien(k,v)
+        if length:
+            a.append('minlen=%d' % length)
+        return a
+            
+    def get_data(self):
+        t = eval(sys.stdin.read())
+        return t['depgraph'],t['types']
+    
+    def get_output_file(self):
+        return sys.stdout
+
+    def use(self,s,type):
+        # Return true if this module is interesting and should be drawn. Return false
+        # if it should be completely omitted. This is a default policy - please override.
+        if s in ('os','sys','qt','time','__future__','types','re','string'):
+            # nearly all modules use all of these... more or less. They add nothing to
+            # our diagram.
+            return 0
+        if s.startswith('encodings.'):
+            return 0
+        if s=='__main__':
+            return 1
+        if self.toocommon(s,type):
+            # A module where we dont want to draw references _to_. Dot doesnt handle these
+            # well, so it is probably best to not draw them at all.
+            return 0
+        return 1
+
+    def toocommon(self,s,type):
+        # Return true if references to this module are uninteresting. Such references
+        # do not get drawn. This is a default policy - please override.
+        #
+        if s=='__main__':
+            # references *to* __main__ are never interesting. omitting them means
+            # that main floats to the top of the page
+            return 1
+        if type==imp.PKG_DIRECTORY:
+            # dont draw references to packages.
+            return 1
+        return 0
+        
+    def weight(self,a,b):
+        # Return the weight of the dependency from a to b. Higher weights
+        # usually have shorter straighter edges. Return 1 if it has normal weight.
+        # A value of 4 is usually good for ensuring that a related pair of modules 
+        # are drawn next to each other. This is a default policy - please override.
+        #
+        if b.split('.')[-1].startswith('_'):
+            # A module that starts with an underscore. You need a special reason to
+            # import these (for example random imports _random), so draw them close
+            # together
+            return 4
+        return 1
+    
+    def alien(self,a,b):
+        # Return non-zero if references to this module are strange, and should be drawn
+        # extra-long. the value defines the length, in rank. This is also good for putting some
+        # vertical space between seperate subsystems. This is a default policy - please override.
+        #
+        return 0
+
+    def label(self,s):
+        # Convert a module name to a formatted node label. This is a default policy - please override.
+        #
+        return '\\.\\n'.join(s.split('.'))
+
+    def color(self,s,type):
+        # Return the node color for this module name. This is a default policy - please override.
+        #
+        # Calculate a color systematically based on the hash of the module name. Modules in the
+        # same package have the same color. Unpackaged modules are grey
+        t = self.normalise_module_name_for_hash_coloring(s,type)
+        return self.color_from_name(t)
+        
+    def normalise_module_name_for_hash_coloring(self,s,type):
+        if type==imp.PKG_DIRECTORY:
+            return s
+        else:
+            i = s.rfind('.')
+            if i<0:
+                return ''
+            else:
+                return s[:i]
+        
+    def color_from_name(self,name):
+        n = md5.md5(name).digest()
+        hf = float(ord(n[0])+ord(n[1])*0xff)/0xffff
+        sf = float(ord(n[2]))/0xff
+        vf = float(ord(n[3]))/0xff
+        r,g,b = colorsys.hsv_to_rgb(hf, 0.3+0.6*sf, 0.8+0.2*vf)
+        return '#%02x%02x%02x' % (r*256,g*256,b*256)
+
+
+def main():
+    pydepgraphdot().main(sys.argv[1:])
+
+if __name__=='__main__':
+    main()
+
+
+
diff --git a/tools/py2depgraph.py b/tools/py2depgraph.py
new file mode 100755 (executable)
index 0000000..15f60e8
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+# Copyright 2004,2009 Toby Dickenson
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject
+# to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+import sys, pprint
+import modulefinder
+
+class mymf(modulefinder.ModuleFinder):
+    def __init__(self,*args,**kwargs):
+        self._depgraph = {}
+        self._types = {}
+        self._last_caller = None
+        modulefinder.ModuleFinder.__init__(self,*args,**kwargs)
+        
+    def import_hook(self, name, caller=None, fromlist=None, level=None):
+        old_last_caller = self._last_caller
+        try:
+            self._last_caller = caller
+            return modulefinder.ModuleFinder.import_hook(self,name,caller,fromlist)
+        finally:
+            self._last_caller = old_last_caller
+            
+    def import_module(self,partnam,fqname,parent):
+        if not fqname.startswith('sfa'): 
+            print >>sys.stderr, "Trimmed fqname",fqname
+            return
+        r = modulefinder.ModuleFinder.import_module(self,partnam,fqname,parent)
+        if r is not None:
+            self._depgraph.setdefault(self._last_caller.__name__,{})[r.__name__] = 1
+        return r
+    
+    def load_module(self, fqname, fp, pathname, (suffix, mode, type)):
+        r = modulefinder.ModuleFinder.load_module(self, fqname, fp, pathname, (suffix, mode, type))
+        if r is not None:
+            self._types[r.__name__] = type
+        return r
+        
+        
+def main(argv):    
+    path = sys.path[:]
+    debug = 0
+    exclude = []
+    mf = mymf(path,debug,exclude)
+    mf.run_script(argv[0])
+    pprint.pprint({'depgraph':mf._depgraph,'types':mf._types})
+    
+if __name__=='__main__':
+    main(sys.argv[1:])
diff --git a/tools/readme b/tools/readme
new file mode 100644 (file)
index 0000000..bb82894
--- /dev/null
@@ -0,0 +1,5 @@
+initial version from
+ http://www.tarind.com/py2depgraph.py
+ http://www.tarind.com/depgraph2dot.py
+
+customized for trimming all non-project dependencies