creating tag sfa-0.9-11
[sfa.git] / sfa / client / sfi.py
index 8bade43..9e18bd7 100755 (executable)
@@ -8,6 +8,8 @@ import os, os.path
 import tempfile
 import traceback
 import socket
 import tempfile
 import traceback
 import socket
+from lxml import etree
+from StringIO import StringIO
 from types import StringTypes, ListType
 from optparse import OptionParser
 from sfa.trust.certificate import Keypair, Certificate
 from types import StringTypes, ListType
 from optparse import OptionParser
 from sfa.trust.certificate import Keypair, Certificate
@@ -15,35 +17,24 @@ from sfa.trust.credential import Credential
 from sfa.util.sfaticket import SfaTicket
 from sfa.util.record import *
 from sfa.util.namespace import *
 from sfa.util.sfaticket import SfaTicket
 from sfa.util.record import *
 from sfa.util.namespace import *
-from sfa.util.rspec import RSpec
 from sfa.util.xmlrpcprotocol import ServerException
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
 from sfa.util.config import Config
 
 from sfa.util.xmlrpcprotocol import ServerException
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
 from sfa.util.config import Config
 
+
 # utility methods here
 # display methods
 def display_rspec(rspec, format = 'rspec'):
     if format in ['dns']:
 # utility methods here
 # display methods
 def display_rspec(rspec, format = 'rspec'):
     if format in ['dns']:
-        spec = RSpec()
-        spec.parseString(rspec)
-        hostnames = []
-        nodespecs = spec.getDictsByTagName('NodeSpec')
-        for nodespec in nodespecs:
-            if nodespec.has_key('name') and nodespec['name']:
-                if isinstance(nodespec['name'], ListType):
-                    hostnames.extend(nodespec['name'])
-                elif isinstance(nodespec['name'], StringTypes):
-                     hostnames.append(nodespec['name'])
-        result = hostnames
+        tree = etree.parse(StringIO(rspec))
+        root = tree.getroot()
+        result = root.xpath("./network/site/node/hostname/text()")
     elif format in ['ip']:
     elif format in ['ip']:
-        spec = RSpec()
-        spec.parseString(rspec)
-        ips = []
-        ifspecs = spec.getDictsByTagName('IfSpec')
-        for ifspec in ifspecs:
-            if ifspec.has_key('addr') and ifspec['addr']:
-                ips.append(ifspec['addr'])
-        result = ips
+        # The IP address is not yet part of the new RSpec
+        # so this doesn't do anything yet.
+        tree = etree.parse(StringIO(rspec))
+        root = tree.getroot()
+        result = root.xpath("./network/site/node/ipv4/text()")
     else:
         result = rspec
 
     else:
         result = rspec
 
@@ -224,6 +215,9 @@ class Sfi:
         parser.add_option("-v", "--verbose",
                          action="store_true", dest="verbose", default=False,
                          help="verbose mode")
         parser.add_option("-v", "--verbose",
                          action="store_true", dest="verbose", default=False,
                          help="verbose mode")
+        parser.add_option("-D", "--debug",
+                          action="store_true", dest="debug", default=False,
+                          help="Debug (xml-rpc) protocol messages")
         parser.add_option("-p", "--protocol",
                          dest="protocol", default="xmlrpc",
                          help="RPC protocol (xmlrpc or soap)")
         parser.add_option("-p", "--protocol",
                          dest="protocol", default="xmlrpc",
                          help="RPC protocol (xmlrpc or soap)")
@@ -303,8 +297,8 @@ class Sfi:
        self.cert_file = cert_file
        self.cert = Certificate(filename=cert_file) 
        # Establish connection to server(s)
        self.cert_file = cert_file
        self.cert = Certificate(filename=cert_file) 
        # Establish connection to server(s)
-       self.registry = xmlrpcprotocol.get_server(reg_url, key_file, cert_file)  
-       self.slicemgr = xmlrpcprotocol.get_server(sm_url, key_file, cert_file)  
+       self.registry = xmlrpcprotocol.get_server(reg_url, key_file, cert_file, self.options.debug)  
+       self.slicemgr = xmlrpcprotocol.get_server(sm_url, key_file, cert_file, self.options.debug)  
        return
     
     #
        return
     
     #
@@ -516,7 +510,7 @@ class Sfi:
         record = records[0]
         cm_port = "12346"
         url = "https://%s:%s" % (record['hostname'], cm_port)
         record = records[0]
         cm_port = "12346"
         url = "https://%s:%s" % (record['hostname'], cm_port)
-        return xmlrpcprotocol.get_server(url, self.key_file, self.cert_file)
+        return xmlrpcprotocol.get_server(url, self.key_file, self.cert_file, self.options.debug)
     
     #
     # Following functions implement the commands
     
     #
     # Following functions implement the commands
@@ -749,7 +743,7 @@ class Sfi:
                 raise Exception, "No such aggregate %s" % agg_hrn
             aggregate = aggregates[0]
             url = "http://%s:%s" % (aggregate['addr'], aggregate['port'])     
                 raise Exception, "No such aggregate %s" % agg_hrn
             aggregate = aggregates[0]
             url = "http://%s:%s" % (aggregate['addr'], aggregate['port'])     
-            server = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file)
+            server = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file, self.options.debug)
         if args:
             cred = self.get_slice_cred(args[0]).save_to_string(save_parents=True)
             hrn = args[0]
         if args:
             cred = self.get_slice_cred(args[0]).save_to_string(save_parents=True)
             hrn = args[0]
@@ -782,7 +776,7 @@ class Sfi:
                 raise Exception, "No such aggregate %s" % opts.aggregate
             aggregate = aggregates[0]
             url = "http://%s:%s" % (aggregate['addr'], aggregate['port'])
                 raise Exception, "No such aggregate %s" % opts.aggregate
             aggregate = aggregates[0]
             url = "http://%s:%s" % (aggregate['addr'], aggregate['port'])
-            server = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file, self.options.protocol)
+            server = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file, self.options.debug)
         return server.create_slice(slice_cred, slice_hrn, rspec)
 
     # get a ticket for the specified slice
         return server.create_slice(slice_cred, slice_hrn, rspec)
 
     # get a ticket for the specified slice
@@ -799,7 +793,7 @@ class Sfi:
                 raise Exception, "No such aggregate %s" % opts.aggregate
             aggregate = aggregates[0]
             url = "http://%s:%s" % (aggregate['addr'], aggregate['port'])
                 raise Exception, "No such aggregate %s" % opts.aggregate
             aggregate = aggregates[0]
             url = "http://%s:%s" % (aggregate['addr'], aggregate['port'])
-            server = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file, self.options.protocol)
+            server = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file, self.options.debug)
         ticket_string = server.get_ticket(slice_cred, slice_hrn, rspec)
         file = os.path.join(self.options.sfi_dir, get_leaf(slice_hrn) + ".ticket")
         print "writing ticket to ", file        
         ticket_string = server.get_ticket(slice_cred, slice_hrn, rspec)
         file = os.path.join(self.options.sfi_dir, get_leaf(slice_hrn) + ".ticket")
         print "writing ticket to ", file        
@@ -818,11 +812,10 @@ class Sfi:
         user_cred = self.get_user_cred()
         slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
         
         user_cred = self.get_user_cred()
         slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
         
-        # get a list node hostnames from the nodespecs in the rspec 
-        rspec = RSpec()
-        rspec.parseString(ticket.rspec)
-        nodespecs = rspec.getDictsByTagName('NodeSpec')
-        hostnames = [nodespec['name'] for nodespec in nodespecs]
+        # get a list of node hostnames from the RSpec 
+        tree = etree.parse(StringIO(ticket.rspec))
+        root = tree.getroot()
+        hostnames = root.xpath("./network/site/node/hostname/text()")
         
         # create an xmlrpc connection to the component manager at each of these
         # components and gall redeem_ticket
         
         # create an xmlrpc connection to the component manager at each of these
         # components and gall redeem_ticket
@@ -832,7 +825,7 @@ class Sfi:
                 cm_port = "12346" 
                 url = "https://%(hostname)s:%(cm_port)s" % locals() 
                 print "Calling redeem_ticket at %(url)s " % locals(),  
                 cm_port = "12346" 
                 url = "https://%(hostname)s:%(cm_port)s" % locals() 
                 print "Calling redeem_ticket at %(url)s " % locals(),  
-                cm = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file)
+                cm = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file, self.options.debug)
                 cm.redeem_ticket(slice_cred, ticket.save_to_string(save_parents=True))
                 print "Success"
             except socket.gaierror:
                 cm.redeem_ticket(slice_cred, ticket.save_to_string(save_parents=True))
                 print "Success"
             except socket.gaierror: