harden fragile code
Thierry Parmentelat [Wed, 7 Dec 2011 14:16:10 +0000 (15:16 +0100)]
sfa/managers/registry_manager.py
sfa/managers/slice_manager.py
sfa/plc/plshell.py

index 8c0e586..c056035 100644 (file)
@@ -27,7 +27,7 @@ class RegistryManager:
 
     # The GENI GetVersion call
     def GetVersion(self, api, options={}):
-        peers = dict ( [ (hrn,interface._ServerProxy__host) for (hrn,interface) in api.registries.iteritems() 
+        peers = dict ( [ (hrn,interface.get_url()) for (hrn,interface) in api.registries.iteritems() 
                        if hrn != api.hrn])
         xrn=Xrn(api.hrn)
         return version_core({'interface':'registry',
index 76ea6d2..b5c5fdc 100644 (file)
@@ -42,18 +42,9 @@ class SliceManager:
                     return True
         return False
     
-    # we have specialized xmlrpclib.ServerProxy to remember the input url
-    # OTOH it's not clear if we're only dealing with XMLRPCServerProxy instances
-    def get_serverproxy_url (self, server):
-        try:
-            return server.get_url()
-        except:
-            logger.warning("GetVersion, falling back to xmlrpclib.ServerProxy internals")
-            return server._ServerProxy__host + server._ServerProxy__handler
-    
     def GetVersion(self, api, options={}):
         # peers explicitly in aggregates.xml
-        peers =dict ([ (peername,self.get_serverproxy_url(v)) for (peername,v) in api.aggregates.iteritems()
+        peers =dict ([ (peername,interface.get_url()) for (peername,interface) in api.aggregates.iteritems()
                        if peername != api.hrn])
         version_manager = VersionManager()
         ad_rspec_versions = []
@@ -76,7 +67,7 @@ class SliceManager:
         sm_version=version_core(version_more)
         # local aggregate if present needs to have localhost resolved
         if api.hrn in api.aggregates:
-            local_am_url=self.get_serverproxy_url(api.aggregates[api.hrn])
+            local_am_url=api.aggregates[api.hrn].get_url()
             sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
         return sm_version
     
index eaa772a..ffe138d 100644 (file)
@@ -37,10 +37,14 @@ class PlShell:
         hostname=urlparse(url).hostname
         is_local=False
         if hostname == 'localhost': is_local=True
-        # otherwise compare IP addresses
-        url_ip=socket.gethostbyname(hostname)
-        local_ip=socket.gethostbyname(socket.gethostname())
-        if url_ip==local_ip: is_local=True
+        # otherwise compare IP addresses; 
+        # this might fail for any number of reasons, so let's harden that
+        try:
+            url_ip=socket.gethostbyname(hostname)
+            local_ip=socket.gethostbyname(socket.gethostname())
+            if url_ip==local_ip: is_local=True
+        except:
+            pass
 
         if is_local:
             try: