several fixes
[sfa.git] / sfa / server / sfa_component_setup.py
index db1c965..f75f1ca 100755 (executable)
@@ -3,15 +3,19 @@ import sys
 import os
 import tempfile
 from optparse import OptionParser
 import os
 import tempfile
 from optparse import OptionParser
+
+from sfa.util.faults import ConnectionKeyGIDMismatch
 from sfa.util.config import Config
 from sfa.util.config import Config
-import sfa.util.xmlrpcprotocol as xmlrpcprotocol
-from sfa.util.namespace import *
-from sfa.util.faults import *
+
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.credential import Credential
 from sfa.trust.gid import GID
 from sfa.trust.hierarchy import Hierarchy
 
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.credential import Credential
 from sfa.trust.gid import GID
 from sfa.trust.hierarchy import Hierarchy
 
+from sfa.client.sfaserverproxy import SfaServerProxy
+
+from sfa.planetlab.plxrn import hrn_to_pl_slicename, slicename_to_hrn
+
 KEYDIR = "/var/lib/sfa/"
 CONFDIR = "/etc/sfa/"
 
 KEYDIR = "/var/lib/sfa/"
 CONFDIR = "/etc/sfa/"
 
@@ -26,7 +30,7 @@ def handle_gid_mismatch_exception(f):
 
     return wrapper
 
 
     return wrapper
 
-def get_server(url=None, port=None, keyfile=None, certfile=None,verbose=False):
+def server_proxy(url=None, port=None, keyfile=None, certfile=None,verbose=False):
     """
     returns an xmlrpc connection to the service a the specified 
     address
     """
     returns an xmlrpc connection to the service a the specified 
     address
@@ -46,7 +50,7 @@ def get_server(url=None, port=None, keyfile=None, certfile=None,verbose=False):
     if verbose:
         print "Contacting registry at: %(url)s" % locals()
 
     if verbose:
         print "Contacting registry at: %(url)s" % locals()
 
-    server = xmlrpcprotocol.get_server(url, keyfile, certfile)
+    server = SfaServerProxy(url, keyfile, certfile)
     return server    
     
 
     return server    
     
 
@@ -76,9 +80,9 @@ def clean_key_cred():
             os.unlink(f)
    
     # install the new key pair
             os.unlink(f)
    
     # install the new key pair
-    # get_credential will take care of generating the new keypair
+    # GetCredential will take care of generating the new keypair
     # and credential 
     # and credential 
-    get_credential()
+    GetCredential()
     
              
 def get_node_key(registry=None, verbose=False):
     
              
 def get_node_key(registry=None, verbose=False):
@@ -95,8 +99,8 @@ def get_node_key(registry=None, verbose=False):
     cert.sign()
     cert.save_to_file(certfile)
     
     cert.sign()
     cert.save_to_file(certfile)
     
-    registry = get_server(url = registry, keyfile=keyfile, certfile=certfile)    
-    registry.get_key()
+    registry = server_proxy(url = registry, keyfile=keyfile, certfile=certfile)    
+    registry.get_key_from_incoming_ip()
 
 def create_server_keypair(keyfile=None, certfile=None, hrn="component", verbose=False):
     """
 
 def create_server_keypair(keyfile=None, certfile=None, hrn="component", verbose=False):
     """
@@ -111,7 +115,7 @@ def create_server_keypair(keyfile=None, certfile=None, hrn="component", verbose=
     cert.save_to_file(certfile, save_parents=True)       
 
 @handle_gid_mismatch_exception
     cert.save_to_file(certfile, save_parents=True)       
 
 @handle_gid_mismatch_exception
-def get_credential(registry=None, force=False, verbose=False):
+def GetCredential(registry=None, force=False, verbose=False):
     config = Config()
     hierarchy = Hierarchy()
     key_dir= hierarchy.basedir
     config = Config()
     hierarchy = Hierarchy()
     key_dir= hierarchy.basedir
@@ -143,7 +147,7 @@ def get_credential(registry=None, force=False, verbose=False):
         create_server_keypair(keyfile, certfile, hrn, verbose)
 
         # get credential from registry 
         create_server_keypair(keyfile, certfile, hrn, verbose)
 
         # get credential from registry 
-        registry = get_server(url=registry, keyfile=keyfile, certfile=certfile)
+        registry = server_proxy(url=registry, keyfile=keyfile, certfile=certfile)
         cert = Certificate(filename=certfile)
         cert_str = cert.save_to_string(save_parents=True)
         cred = registry.GetSelfCredential(cert_str, 'node', hrn)
         cert = Certificate(filename=certfile)
         cert_str = cert.save_to_string(save_parents=True)
         cred = registry.GetSelfCredential(cert_str, 'node', hrn)
@@ -167,10 +171,10 @@ def get_trusted_certs(registry=None, verbose=False):
     node_gid = GID(filename=node_gid_file)
     hrn = node_gid.get_hrn()
     # get credential
     node_gid = GID(filename=node_gid_file)
     hrn = node_gid.get_hrn()
     # get credential
-    cred = get_credential(registry=registry, verbose=verbose)
+    cred = GetCredential(registry=registry, verbose=verbose)
     # make sure server key cert pair exists
     create_server_keypair(keyfile=keyfile, certfile=certfile, hrn=hrn, verbose=verbose)
     # make sure server key cert pair exists
     create_server_keypair(keyfile=keyfile, certfile=certfile, hrn=hrn, verbose=verbose)
-    registry = get_server(url=registry, keyfile=keyfile, certfile=certfile)
+    registry = server_proxy(url=registry, keyfile=keyfile, certfile=certfile)
     # get the trusted certs and save them in the right place
     if verbose:
         print "Getting trusted certs from registry"
     # get the trusted certs and save them in the right place
     if verbose:
         print "Getting trusted certs from registry"
@@ -212,17 +216,18 @@ def get_gids(registry=None, verbose=False):
     hrn = node_gid.get_hrn()
     interface_hrn = config.SFA_INTERFACE_HRN
     # get credential
     hrn = node_gid.get_hrn()
     interface_hrn = config.SFA_INTERFACE_HRN
     # get credential
-    cred = get_credential(registry=registry, verbose=verbose)
+    cred = GetCredential(registry=registry, verbose=verbose)
     # make sure server key cert pair exists
     create_server_keypair(keyfile=keyfile, certfile=certfile, hrn=hrn, verbose=verbose)
     # make sure server key cert pair exists
     create_server_keypair(keyfile=keyfile, certfile=certfile, hrn=hrn, verbose=verbose)
-    registry = get_server(url=registry, keyfile=keyfile, certfile=certfile)
+    registry = server_proxy(url=registry, keyfile=keyfile, certfile=certfile)
             
     if verbose:
         print "Getting current slices on this node"
     # get a list of slices on this node
             
     if verbose:
         print "Getting current slices on this node"
     # get a list of slices on this node
-    from sfa.plc.api import ComponentAPI
-    api = ComponentAPI()
-    xids_tuple = api.nodemanager.GetXIDs()
+    from sfa.generic import Generic
+    generic=Generic.the_flavour()
+    api = generic.make_api(interface='component')
+    xids_tuple = api.driver.nodemanager.GetXIDs()
     slices = eval(xids_tuple[1])
     slicenames = slices.keys()
 
     slices = eval(xids_tuple[1])
     slicenames = slices.keys()