several fixes
authorMohamed Larabi <mohamed.larabi@inria.fr>
Wed, 3 Apr 2013 07:49:00 +0000 (09:49 +0200)
committerMohamed Larabi <mohamed.larabi@inria.fr>
Wed, 3 Apr 2013 07:49:00 +0000 (09:49 +0200)
sfa/client/sfaadmin.py
sfa/client/sfi.py
sfa/importer/plimporter.py
sfa/managers/slice_manager.py
sfa/nitos/nitosaggregate.py
sfa/planetlab/plaggregate.py
sfa/planetlab/pldriver.py
sfa/planetlab/plslices.py
sfa/server/sfaapi.py

index bafc777..df4629f 100755 (executable)
@@ -354,79 +354,66 @@ class AggregateCommands(Commands):
         version = self.api.manager.GetVersion(self.api, {})
         pprinter.pprint(version)
 
+    def slices(self):
+        """List the running slices at this Aggregate"""
+        print self.api.manager.ListSlices(self.api, [], {})
 
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)') 
     def status(self, xrn):
         """Display the status of a slice or slivers"""
         urn = Xrn(xrn, 'slice').get_urn()
-        status = self.api.manager.SliverStatus(self.api, [urn], {}, {})
+        status = self.api.manager.SliverStatus(self.api, urn, [], {})
         pprinter.pprint(status)
  
-    @args('-r', '--rspec-version', dest='rspec_version', metavar='<rspec_version>', 
-          default='GENI', help='version/format of the resulting rspec response')  
-    def resources(self, rspec_version='GENI'):
-        """Display the available resources at an aggregate"""  
-        options = {'geni_rspec_version': rspec_version}
-        resources = self.api.manager.ListResources(self.api, {}, options)
-        print resources
-    
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn', default=None)
     @args('-r', '--rspec-version', dest='rspec_version', metavar='<rspec_version>', 
           default='GENI', help='version/format of the resulting rspec response')  
-    def describe(self, xrn, rspec_version='GENI'):
-        """Display the resources allocated by a slice or slivers"""
-        urn = Xrn(xrn, 'slice').get_urn()
+    def resources(self, xrn=None, rspec_version='GENI'):
+        """Display the available resources at an aggregate 
+or the resources allocated by a slice"""  
         options = {'geni_rspec_version': rspec_version}
-        status = self.api.manager.Describe(self.api, {}, [urn], options)      
-        print status
-    
+        if xrn:
+            options['geni_slice_urn'] = Xrn(xrn, 'slice').get_urn()
+        print options
+        resources = self.api.manager.ListResources(self.api, [], options)
+        print resources
+        
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
     @args('-r', '--rspec', dest='rspec', metavar='<rspec>', help='rspec file (mandatory)')  
     @args('-u', '--user', dest='user', metavar='<user>', help='hrn/urn of slice user (mandatory)')  
     @args('-k', '--key', dest='key', metavar='<key>', help="path to user's public key file (mandatory)")  
-    def allocate(self, xrn, rspec, user, key):
+    def create(self, xrn, rspec, user, key):
         """Allocate slivers"""
         xrn = Xrn(xrn, 'slice')
-        urn=xrn.get_urn()
+        slice_urn=xrn.get_urn()
         rspec_string = open(rspec).read()
         user_xrn = Xrn(user, 'user')
         user_urn = user_xrn.get_urn()
         user_key_string = open(key).read()
         users = [{'urn': user_urn, 'keys': [user_key_string]}]
-        options={'geni_users': users}
-        status = self.api.manager.Allocate(self.api, urn, {}, rspec_string, options) 
-        print status
-
-    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
-    def provision(self, xrns):
-        status = self.api.manager.Provision(self.api, [xrns], {}, {})
-        print status         
+        options={}
+        self.api.manager.CreateSliver(self, slice_urn, [], rspec_string, users, options) 
 
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
     def delete(self, xrn):
         """Delete slivers""" 
-        result = self.api.manager.DeleteSliver(self.api, [xrn], {}, {})
-        print result
-
+        self.api.manager.DeleteSliver(self.api, xrn, [], {})
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
-    @args('-e', '--expiration', dest='expiration', metavar='<expiration>', help='Expiration date (mandatory)')
-    def renew(self, xrn, expiration):
+    def start(self, xrn):
         """Start slivers"""
-        result = self.api.manager.start_slice(self.api, xrn, {}, expiration, {})
-        print result
+        self.api.manager.start_slice(self.api, xrn, [])
 
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
-    def shutdown(self, xrn):
+    def stop(self, xrn):
         """Stop slivers"""
-        result = self.api.manager.Shutdown(self.api, xrn, {}, {})      
-        print result
+        self.api.manager.stop_slice(self.api, xrn, [])      
 
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
-    @args('-a', '--action', dest='action', metavar='<action>', help='Action name (mandatory)')
-    def operation(self, xrn, action):
+    def reset(self, xrn):
         """Reset sliver"""
-        result = self.api.manager.PerformOperationalAction(self.api, [xrn], {}, action, {})
-        print result
+        self.api.manager.reset_slice(self.api, xrn)
+
 
 #    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn', default=None)
 #    @args('-r', '--rspec', dest='rspec', metavar='<rspec>', help='request rspec', default=None)
index 53d655b..d2eecac 100644 (file)
@@ -264,7 +264,6 @@ class Sfi:
         ("remove", "name"),
         ("resources", ""),
         ("describe", "slice_hrn"),
-        ("create", "slice_hrn rspec"),
         ("allocate", "slice_hrn rspec"),
         ("provision", "slice_hrn"),
         ("action", "slice_hrn action"), 
@@ -333,7 +332,7 @@ class Sfi:
                                help="set extra/testbed-dependent flags, e.g. --extra enabled=true")
 
         # user specifies remote aggregate/sm/component                          
-        if command in ("resources", "describe", "allocate", "provision", "create", "delete", "allocate", "provision", 
+        if command in ("resources", "describe", "allocate", "provision", "delete", "allocate", "provision", 
                        "action", "shutdown",  "get_ticket", "renew", "status"):
             parser.add_option("-d", "--delegate", dest="delegate", default=None, 
                              action="store_true",
@@ -341,7 +340,7 @@ class Sfi:
                                   "authority in set of credentials for this call")
 
         # show_credential option
-        if command in ("list","resources", "describe", "provision", "allocate", "create","add","update","remove","slices","delete","status","renew"):
+        if command in ("list","resources", "describe", "provision", "allocate", "add","update","remove","slices","delete","status","renew"):
             parser.add_option("-C","--credential",dest='show_credential',action='store_true',default=False,
                               help="show credential(s) used in human-readable form")
         # registy filter option
@@ -374,8 +373,7 @@ class Sfi:
                                 choices=("all", "resources", "leases"), default="resources")
 
 
-        # 'create' does return the new rspec, makes sense to save that too
-        if command in ("resources", "describe", "allocate", "provision", "show", "list", "gid", 'create'):
+        if command in ("resources", "describe", "allocate", "provision", "show", "list", "gid"):
            parser.add_option("-o", "--output", dest="file",
                             help="output XML to file", metavar="FILE", default=None)
 
@@ -1091,81 +1089,6 @@ or with an slice hrn, shows currently provisioned resources
 
         return 
 
-    def create(self, options, args):
-        """
-        create or update named slice with given rspec
-        """
-        server = self.sliceapi()
-
-        # xxx do we need to check usage (len(args)) ?
-        # slice urn
-        slice_hrn = args[0]
-        slice_urn = hrn_to_urn(slice_hrn, 'slice')
-
-        # credentials
-        creds = [self.slice_credential_string(slice_hrn)]
-
-        delegated_cred = None
-        server_version = self.get_cached_server_version(server)
-        if server_version.get('interface') == 'slicemgr':
-            # delegate our cred to the slice manager
-            # do not delegate cred to slicemgr...not working at the moment
-            pass
-            #if server_version.get('hrn'):
-            #    delegated_cred = self.delegate_cred(slice_cred, server_version['hrn'])
-            #elif server_version.get('urn'):
-            #    delegated_cred = self.delegate_cred(slice_cred, urn_to_hrn(server_version['urn']))
-
-        if options.show_credential:
-            show_credentials(creds)
-
-        # rspec
-        rspec_file = self.get_rspec_file(args[1])
-        rspec = open(rspec_file).read()
-
-        # users
-        # need to pass along user keys to the aggregate.
-        # users = [
-        #  { urn: urn:publicid:IDN+emulab.net+user+alice
-        #    keys: [<ssh key A>, <ssh key B>]
-        #  }]
-        users = []
-        # xxx Thierry 2012 sept. 21
-        # contrary to what I was first thinking, calling Resolve with details=False does not yet work properly here
-        # I am turning details=True on again on a - hopefully - temporary basis, just to get this whole thing to work again
-        slice_records = self.registry().Resolve(slice_urn, [self.my_credential_string])
-        # slice_records = self.registry().Resolve(slice_urn, [self.my_credential_string], {'details':True})
-        if slice_records and 'reg-researchers' in slice_records[0] and slice_records[0]['reg-researchers']:
-            slice_record = slice_records[0]
-            user_hrns = slice_record['reg-researchers']
-            user_urns = [hrn_to_urn(hrn, 'user') for hrn in user_hrns]
-            user_records = self.registry().Resolve(user_urns, [self.my_credential_string])
-
-            if 'sfa' not in server_version:
-                users = pg_users_arg(user_records)
-                rspec = RSpec(rspec)
-                rspec.filter({'component_manager_id': server_version['urn']})
-                rspec = RSpecConverter.to_pg_rspec(rspec.toxml(), content_type='request')
-            else:
-                users = sfa_users_arg(user_records, slice_record)
-
-        # do not append users, keys, or slice tags. Anything
-        # not contained in this request will be removed from the slice
-
-        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 self.options.raw:
-            save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
-        if options.file is not None:
-            save_rspec_to_file (value, options.file)
-        if (self.options.raw is None) and (options.file is None):
-            print value
-
-        return value
-
     def delete(self, options, args):
         """
         delete named slice (DeleteSliver)
index 8d197b6..ff3afc4 100644 (file)
@@ -367,8 +367,13 @@ class PlImporter:
                     self.logger.log_exc("PlImporter: failed to import person %d %s"%(person['person_id'],person['email']))
     
             # maintain the list of PIs for a given site
+            # for the record, Jordan had proposed the following addition as a welcome hotfix to a previous version:
+            # site_pis = list(set(site_pis)) 
+            # this was likely due to a bug in the above logic, that had to do with disabled persons
+            # being improperly handled, and where the whole loop on persons
+            # could be performed twice with the same person...
+            # so hopefully we do not need to eliminate duplicates explicitly here anymore
             site_record.reg_pis = list(site_pis)
-            site_record.reg_pis = site_pis
             dbsession.commit()
 
             # import slices
@@ -399,9 +404,11 @@ class PlImporter:
                     if slice_id != slice_record.pointer:
                         self.logger.info("updating record (slice) pointer")
                         slice_record.pointer = slice_id
-                        dbsession.commit()             
+                        dbsession.commit() 
                     # xxx update the record ...
-                    #self.logger.warning ("Slice update not yet implemented")
+                    # given that we record the current set of users anyways, there does not seem to be much left to do here
+                    # self.logger.warning ("Slice update not yet implemented on slice %s (%s)"%(slice_hrn,slice['name']))
+                    #pass
                 # record current users affiliated with the slice
                 slice_record.reg_researchers = \
                     [ self.locate_by_type_pointer ('user',user_id) for user_id in slice['person_ids'] ]
index 1c1c062..928be37 100644 (file)
@@ -337,7 +337,7 @@ class SliceManager:
                 result['aggregate'] = aggregate
                 return result
             except:
-                logger.log_exc('Something wrong in _RenewSliver with URL %s'%server.url)
+                logger.log_exc('Something wrong in _Renew with URL %s'%server.url)
                 return {'aggregate': aggregate, 'exc_info': traceback.format_exc(),
                         'code': {'geni_code': -1},
                         'value': False, 'output': ""}
@@ -381,7 +381,7 @@ class SliceManager:
         def _Delete(server, xrn, creds, options):
             return server.Delete(xrn, creds, options)
 
-        (hrn, type) = urn_to_hrn(xrn)
+        (hrn, type) = urn_to_hrn(xrn[0])
         # get the callers hrn
         valid_cred = api.auth.checkCredentials(creds, 'deletesliver', hrn)[0]
         caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
@@ -398,7 +398,7 @@ class SliceManager:
                 continue
             interface = api.aggregates[aggregate]
             server = api.server_proxy(interface, cred)
-            threads.run(_DeleteSliver, server, xrn, [cred], options)
+            threads.run(_Delete, server, xrn, [cred], options)
         threads.get_results()
         return 1
     
@@ -442,7 +442,7 @@ class SliceManager:
         }
 
    
-    def Describe(self, api, xrns, creds, options):
+    def Describe(self, api, creds, xrns, options):
         def _Describe(server, xrn, creds, options):
             return server.Describe(xrn, creds, options)
 
@@ -456,7 +456,7 @@ class SliceManager:
         for aggregate in api.aggregates:
             interface = api.aggregates[aggregate]
             server = api.server_proxy(interface, cred)
-            threads.run (_Describe, server, slice_xrn, [cred], options)
+            threads.run (_Describe, server, xrns, [cred], options)
         results = [ReturnValue.get_value(result) for result in threads.get_results()]
 
         # get rid of any void result - e.g. when call_id was hit, where by convention we return {}
@@ -466,6 +466,7 @@ class SliceManager:
         if not results : return {}
 
         # otherwise let's merge stuff
+        version_manager = VersionManager()
         manifest_version = version_manager._get_version('GENI', '3', 'manifest')
         result_rspec = RSpec(version=manifest_version)
         geni_slivers = []
@@ -473,8 +474,8 @@ class SliceManager:
         for result in results:
             try:
                 geni_urn = result['geni_urn']
-                result_rspec.version.merge(ReturnValue.get_value(result['result']['geni_rspec']))
-                geni_slivers.extend(result['result']['geni_slivers'])
+                result_rspec.version.merge(ReturnValue.get_value(result['geni_rspec']))
+                geni_slivers.extend(result['geni_slivers'])
             except:
                 api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec")
         return {
index 2a36fbf..742d45b 100644 (file)
@@ -5,14 +5,13 @@ from sfa.util.sfalogging import logger
 
 from sfa.rspecs.rspec import RSpec
 from sfa.rspecs.elements.hardware_type import HardwareType
-from sfa.rspecs.elements.node import Node
+from sfa.rspecs.elements.node import NodeElement
 from sfa.rspecs.elements.link import Link
 from sfa.rspecs.elements.sliver import Sliver
 from sfa.rspecs.elements.login import Login
 from sfa.rspecs.elements.location import Location
 from sfa.rspecs.elements.position_3d import Position3D
 from sfa.rspecs.elements.interface import Interface
-from sfa.rspecs.elements.services import Services
 from sfa.rspecs.elements.pltag import PLTag
 from sfa.rspecs.elements.lease import Lease
 from sfa.rspecs.elements.granularity import Granularity
index 01a06ec..b5e8073 100644 (file)
@@ -248,9 +248,10 @@ class PlAggregate:
                          'type': 'plab-vserver',
                          'tags': []})
         rspec_node['sliver_id'] = rspec_sliver['sliver_id']
-        rspec_node['client_id'] = sliver_allocations[sliver['urn']].client_id
-        if sliver_allocations[sliver['urn']].component_id:
-            rspec_node['component_id'] = sliver_allocations[sliver['urn']].component_id
+        if sliver['urn'] in sliver_allocations:
+            rspec_node['client_id'] = sliver_allocations[sliver['urn']].client_id
+            if sliver_allocations[sliver['urn']].component_id:
+                rspec_node['component_id'] = sliver_allocations[sliver['urn']].component_id
         rspec_node['slivers'] = [rspec_sliver]
 
         # slivers always provide the ssh service
@@ -319,7 +320,7 @@ class PlAggregate:
                        }
         return geni_sliver        
 
-    def get_leases(self, slice_xrn=None, slice=None, options={}):
+    def get_leases(self, slice=None, options={}):
         
         if slice_xrn and not slice:
             return []
@@ -350,12 +351,8 @@ class PlAggregate:
             site=sites_dict[site_id]
 
             rspec_lease['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], lease['hostname'])
-            if slice_xrn:
-                slice_urn = slice_xrn
-                slice_hrn = urn_to_hrn(slice_urn)
-            else:
-                slice_hrn = slicename_to_hrn(self.driver.hrn, lease['name'])
-                slice_urn = hrn_to_urn(slice_hrn, 'slice')
+            slice_hrn = slicename_to_hrn(self.driver.hrn, lease['name'])
+            slice_urn = hrn_to_urn(slice_hrn, 'slice')
             rspec_lease['slice_id'] = slice_urn
             rspec_lease['start_time'] = lease['t_from']
             rspec_lease['duration'] = (lease['t_until'] - lease['t_from']) / grain
index 4bcb793..1d0fedf 100644 (file)
@@ -621,7 +621,7 @@ class PlDriver (Driver):
     
     def status (self, urns, options={}):
         aggregate = PlAggregate(self)
-        desc =  aggregate.describe(urns)
+        desc =  aggregate.describe(urns, version='GENI 3')
         status = {'geni_urn': desc['geni_urn'],
                   'geni_slivers': desc['geni_slivers']}
         return status
@@ -737,7 +737,7 @@ class PlDriver (Driver):
         requested_time = utcparse(expiration_time)
         record = {'expires': int(datetime_to_epoch(requested_time))}
         self.shell.UpdateSlice(slice['slice_id'], record)
-        description = self.describe(urns, None, options)
+        description = self.describe(urns, 'GENI 3', options)
         return description['geni_slivers']
             
 
index 351335e..4c28040 100644 (file)
@@ -232,22 +232,6 @@ class PlSlices:
         nodes = self.driver.shell.GetNodes(slice['node_ids'], ['node_id', 'hostname', 'interface_ids'])
         current_slivers = [node['hostname'] for node in nodes]
 
-        requested_slivers = []
-        tags = []
-        for node in slivers:
-            hostname = None
-            if node.get('component_name'):
-                hostname = node.get('component_name').strip()
-            elif node.get('component_id'):
-                hostname = xrn_to_hostname(node.get('component_id').strip())
-            if node.get('client_id'):
-                tags.append({'slicename': slice['name'], 
-                             'tagname': 'client_id',
-                             'value': node['client_id'],
-                             'node': hostname})
-            if hostname:
-                requested_slivers.append(hostname)
-        
         # remove nodes not in rspec
         deleted_nodes = list(set(current_slivers).difference(slivers.keys()))
 
index 898fb66..a0fc7f4 100644 (file)
@@ -211,6 +211,7 @@ class SfaApi (XmlrpcApi):
         code = {
             'geni_code': GENICODE.SUCCESS, 
             'am_type': 'sfa',
+            'am_code': None,
         }
         if isinstance(result, SfaFault):
             code['geni_code'] = result.faultCode