added rights for component
[sfa.git] / sfa / client / sfi.py
index 9a426dd..9283500 100755 (executable)
@@ -6,9 +6,9 @@ import sys
 import os, os.path
 import tempfile
 import traceback
+import socket
 from types import StringTypes, ListType
 from optparse import OptionParser
-
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.credential import Credential
 from sfa.util.geniclient import GeniClient
@@ -142,7 +142,7 @@ class Sfi:
                   "resources": "[name]",
                   "create": "name rspec",
                   "get_ticket": "name rspec",
-                  "redeem_ticket": "ticket rspec"  
+                  "redeem_ticket": "ticket",  
                   "delete": "name",
                   "reset": "name",
                   "start": "name",
@@ -723,21 +723,6 @@ class Sfi:
         display_list(result)
         return
 
-    def components(self, opts, args):
-        """
-        return a list of details about known components
-        """ 
-        user_cred = self.get_user_cred().save_to_string(save_parents=True)
-        hrn = None
-        if args:
-            hrn = args[0]
-        request_hash=None
-        if self.hashrequest:
-            arg_list = [user_cred, hrn]
-            request_hash = self.key.compute_hash(arg_list)
-        result = self.sm.components(user_cred, hrn, request_hash)
-        display_list(result)
-        return
  
     #
     # Slice-related commands
@@ -837,9 +822,41 @@ class Sfi:
         print "writing ticket to ", file        
         ticket = SfaTicket(string=ticket_string)
         ticket.save_to_file(filename=file, save_parents=True)
-        print ticket_string  
 
     def redeem_ticket(self, opts, args):
+        ticket_file = args[0]
+        
+        # get slice hrn from the ticket
+        # use this to get the right slice credential 
+        ticket = SfaTicket(filename=ticket_file)
+        ticket.decode()
+        slice_hrn = ticket.attributes['slivers'][0]['hrn']
+        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]
+        
+        # create an xmlrpc connection to the component manager at each of these
+        # components and gall redeem_ticket
+        connections = {}
+        for hostname in hostnames:
+            try:
+                cm_port = "12346" 
+                url = "https://%(hostname)s:%(cm_port)s" % locals() 
+                print "Calling get_ticket at %(url)s " % locals(),  
+                cm = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file)
+                cm.redeem_ticket(slice_cred, ticket.save_to_string(save_parents=True))
+                print "Success"
+            except socket.gaierror:
+                print "Failed:",
+                print "Componet Manager not accepting requests" 
+            except Exception, e:
+                print "Failed:", e.message
+             
         return
  
     # delete named slice