Merge branch 'master' into senslab2
authorSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 15 Dec 2011 15:30:45 +0000 (16:30 +0100)
committerSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 15 Dec 2011 15:30:45 +0000 (16:30 +0100)
Conflicts:
sfa/client/sfi.py
sfa/methods/CreateSliver.py
sfa/plc/plslices.py

1  2 
setup.py
sfa/client/sfi.py
sfa/managers/driver.py
sfa/methods/CreateSliver.py
sfa/methods/ListResources.py
sfa/plc/plslices.py

diff --cc setup.py
Simple merge
index b0fa53c,c5eadc5..8971435
mode 100755,100644..100644
@@@ -1033,117 -904,109 +904,110 @@@ or with an slice hrn, shows currently p
                  rspec = RSpec(rspec)
                  rspec.filter({'component_manager_id': server_version['urn']})
                  rspec = RSpecConverter.to_pg_rspec(rspec.toxml(), content_type='request')
-                 creds = [slice_cred]
              else:
 +                print >>sys.stderr, "\r\n \r\n \r\n WOOOOOO"
                  users = sfa_users_arg(user_records, slice_record)
-                 creds = [slice_cred]
-                 if delegated_cred:
-                     creds.append(delegated_cred)
-         call_args = [slice_urn, creds, rspec, users]
-         if self.server_supports_options_arg(server):
-             options = {'call_id': unique_call_id()}
-             call_args.append(options) 
-         print>>sys.stderr, " \r\n SFI.PY create  user" ,users
-         result = server.CreateSliver(*call_args)
+         
+         # do not append users, keys, or slice tags. Anything 
+         # not contained in this request will be removed from the slice
+         # CreateSliver has supported the options argument for a while now so it should
+         # be safe to assume this server support it
+         api_options = {}
+         api_options ['append'] = False
+         api_options ['call_id'] = unique_call_id()
+         result = server.CreateSliver(slice_urn, creds, rspec, users, *self.ois(server, api_options))
          value = ReturnValue.get_value(result)
-         if opts.file is None:
+         if options.file is None:
              print value
          else:
-             save_rspec_to_file (value, opts.file)
+             save_rspec_to_file (value, options.file)
          return value
  
-     # get a ticket for the specified slice
-     def get_ticket(self, opts, args):
-         slice_hrn, rspec_path = args[0], args[1]
-         slice_urn = hrn_to_urn(slice_hrn, 'slice')
-         user_cred = self.get_user_cred()
-         slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
+     def delete(self, options, args):
+         """
+         delete named slice (DeleteSliver)
+         """
+         server = self.sliceapi()
+         # slice urn
+         slice_hrn = args[0]
+         slice_urn = hrn_to_urn(slice_hrn, 'slice') 
+         # creds
+         slice_cred = self.slice_credential_string(slice_hrn)
          creds = [slice_cred]
-         if opts.delegate:
+         if options.delegate:
              delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
              creds.append(delegated_cred)
-         rspec_file = self.get_rspec_file(rspec_path) 
-         rspec = open(rspec_file).read()
-         server = self.server_proxy_from_opts(opts)
-         ticket_string = server.GetTicket(slice_urn, creds, rspec, [])
-         file = os.path.join(self.options.sfi_dir, get_leaf(slice_hrn) + ".ticket")
-         self.logger.info("writing ticket to %s"%file)
-         ticket = SfaTicket(string=ticket_string)
-         ticket.save_to_file(filename=file, save_parents=True)
-     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.gidObject.get_hrn()
-         slice_urn = hrn_to_urn(slice_hrn, 'slice') 
-         #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 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
-         connections = {}
-         for hostname in hostnames:
-             try:
-                 self.logger.info("Calling redeem_ticket at %(hostname)s " % locals())
-                 server = self.server_proxy(hostname, CM_PORT, self.key_file, \
-                                          self.cert_file, self.options.debug)
-                 server.RedeemTicket(ticket.save_to_string(save_parents=True), slice_cred)
-                 self.logger.info("Success")
-             except socket.gaierror:
-                 self.logger.error("redeem_ticket failed: Component Manager not accepting requests")
-             except Exception, e:
-                 self.logger.log_exc(e.message)
-         return
-  
-     # delete named slice
-     def delete(self, opts, args):
+         # options and call_id when supported
+         api_options = {}
+         api_options ['call_id'] = unique_call_id()
+         result = server.DeleteSliver(slice_urn, creds, *self.ois(server, api_options ) )
+         # xxx no ReturnValue ??
+         return result
+   
+     def status(self, options, args):
+         """
+         retrieve slice status (SliverStatus)
+         """
+         server = self.sliceapi()
+         # slice urn
          slice_hrn = args[0]
          slice_urn = hrn_to_urn(slice_hrn, 'slice') 
-         slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
+         # creds 
+         slice_cred = self.slice_credential_string(slice_hrn)
          creds = [slice_cred]
-         if opts.delegate:
+         if options.delegate:
              delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
              creds.append(delegated_cred)
-         server = self.server_proxy_from_opts(opts)
-         call_args = [slice_urn, creds]
-         if self.server_supports_options_arg(server):
-             options = {'call_id': unique_call_id()}
-             call_args.append(options)
-         return server.DeleteSliver(*call_args) 
-   
-     # start named slice
-     def start(self, opts, args):
+         # options and call_id when supported
+         api_options = {}
+       api_options['call_id']=unique_call_id()
+         result = server.SliverStatus(slice_urn, creds, *self.ois(server,api_options))
+         value = ReturnValue.get_value(result)
+         print value
+         if options.file:
+             save_variable_to_file(value, options.file, options.fileformat)
+     def start(self, options, args):
+         """
+         start named slice (Start)
+         """
+         server = self.sliceapi()
+         # the slice urn
          slice_hrn = args[0]
          slice_urn = hrn_to_urn(slice_hrn, 'slice') 
-         slice_cred = self.get_slice_cred(args[0]).save_to_string(save_parents=True)
+         
+         # cred
+         slice_cred = self.slice_credential_string(args[0])
          creds = [slice_cred]
-         if opts.delegate:
+         if options.delegate:
              delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
              creds.append(delegated_cred)
-         server = self.server_proxy_from_opts(opts)
+         # xxx Thierry - does this not need an api_options as well ?
          return server.Start(slice_urn, creds)
      
-     # stop named slice
-     def stop(self, opts, args):
+     def stop(self, options, args):
+         """
+         stop named slice (Stop)
+         """
+         server = self.sliceapi()
+         # slice urn
          slice_hrn = args[0]
          slice_urn = hrn_to_urn(slice_hrn, 'slice') 
-         slice_cred = self.get_slice_cred(args[0]).save_to_string(save_parents=True)
+         # cred
+         slice_cred = self.slice_credential_string(args[0])
          creds = [slice_cred]
-         if opts.delegate:
+         if options.delegate:
              delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
              creds.append(delegated_cred)
-         server = self.server_proxy_from_opts(opts)
          return server.Stop(slice_urn, creds)
      
      # reset named slice
@@@ -2,10 -2,16 +2,16 @@@
  # an attempt to document what a driver class should provide, 
  # and implement reasonable defaults
  #
 -
 +import sys
  class Driver:
      
-     def __init__ (self): pass
+     def __init__ (self, config): 
+         # this is the hrn attached to the running server
+         self.hrn = config.SFA_INTERFACE_HRN
+     ########################################
+     ########## registry oriented
+     ########################################
  
      # redefine this if you want to check again records 
      # when running GetCredential
      #     after looking up the sfa db, we wish to be able to display
      #     testbed-specific info as well
      # this at minima should fill in the 'researcher' field for slice records
+     # as this information is then used to compute rights
+     # roadmap: there is an intention to redesign the SFA database so as to clear up 
+     # this constraint, based on the principle that SFA should not rely on the
+     # testbed database to perform such a core operation (i.e. getting rights right)
      def augment_records_with_testbed_info (self, sfa_records):
 +        print >>sys.stderr, "  \r\n \r\n DRIVER.PY augment_records_with_testbed_info sfa_records ",sfa_records
          return sfa_records
  
      # incoming record, as provided by the client to the Register API call
@@@ -2,11 -2,8 +2,9 @@@ from sfa.util.faults import SfaInvalidA
  from sfa.util.xrn import urn_to_hrn
  from sfa.util.method import Method
  from sfa.util.sfatablesRuntime import run_sfatables
 +import sys
  from sfa.trust.credential import Credential
  from sfa.storage.parameter import Parameter, Mixed
  from sfa.rspecs.rspec import RSpec
  
  class CreateSliver(Method):
Simple merge
@@@ -1,12 -1,15 +1,16 @@@
  from types import StringTypes
  from collections import defaultdict
- from sfa.util.xrn import get_leaf, get_authority, urn_to_hrn
- from sfa.util.plxrn import hrn_to_pl_slicename
- from sfa.util.policy import Policy
 +import sys
+ from sfa.util.sfalogging import logger
+ from sfa.util.xrn import Xrn, get_leaf, get_authority, urn_to_hrn
+ #from sfa.util.policy import Policy
+ from sfa.util.xrn import Xrn
  from sfa.rspecs.rspec import RSpec
  from sfa.plc.vlink import VLink
- from sfa.util.xrn import Xrn
+ from sfa.util.plxrn import hrn_to_pl_slicename
  
  MAXINT =  2L**31-1
  
@@@ -135,19 -131,19 +132,19 @@@ class PlSlices
          # slice belongs to out local plc or a myplc peer. We will assume it 
          # is a local site, unless we find out otherwise  
          peer = None
-         print>>sys.stderr, " \r\n \r\n \t slices.py get_peer slice_authority  "
 -
++        print>>sys.stderr, " \r\n \r\n \tplslices.py get_peer slice_authority  "
          # get this slice's authority (site)
          slice_authority = get_authority(hrn)
  
          # get this site's authority (sfa root authority or sub authority)
          site_authority = get_authority(slice_authority).lower()
-         print>>sys.stderr, " \r\n \r\n \t slices.py get_peer slice_authority  %s site_authority %s" %(slice_authority,site_authority) 
 -
++        print>>sys.stderr, " \r\n \r\n \tplslices.py get_peer slice_authority  %s site_authority %s" %(slice_authority,site_authority) 
          # check if we are already peered with this site_authority, if so
-         #peers = self.api.driver.GetPeers({}, ['peer_id', 'peername', 'shortname', 'hrn_root'])
-         #for peer_record in peers:
-             #names = [name.lower() for name in peer_record.values() if isinstance(name, StringTypes)]
-             #if site_authority in names:
-                 #peer = peer_record
+         peers = self.driver.GetPeers({}, ['peer_id', 'peername', 'shortname', 'hrn_root'])
+         for peer_record in peers:
+             names = [name.lower() for name in peer_record.values() if isinstance(name, StringTypes)]
+             if site_authority in names:
+                 peer = peer_record
  
          return peer