Esempio n. 1
0
 def create(self, xrn, rspec, user, key):
     """Allocate slivers"""
     xrn = Xrn(xrn, 'slice')
     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={}
     self.api.manager.CreateSliver(self, slice_urn, [], rspec_string, users, options) 
Esempio n. 2
0
 def provision(self, xrn):
     """Provision slivers"""
     xrn = Xrn(xrn, 'slice')
     slice_urn=xrn.get_urn()
     options={}
     manifest = self.api.manager.provision(self.api, [slice_urn], [], options)
     print manifest
Esempio n. 3
0
    def allocate(self, urn, rspec_string, expiration, options={}):
        xrn = Xrn(urn)
        aggregate = DummyAggregate(self)
        slices = DummySlices(self)
        slice_record = None
        users = options.get('geni_users', [])
        if users:
            slice_record = users[0].get('slice_record', {})

        # parse rspec
        rspec = RSpec(rspec_string)
        requested_attributes = rspec.version.get_slice_attributes()

        # ensure slice record exists
        slice = slices.verify_slice(xrn.hrn,
                                    slice_record,
                                    expiration=expiration,
                                    options=options)
        # ensure person records exists
        #persons = slices.verify_persons(xrn.hrn, slice, users, peer, sfa_peer, options=options)

        # add/remove slice from nodes
        request_nodes = rspec.version.get_nodes_with_slivers()
        nodes = slices.verify_slice_nodes(urn, slice, request_nodes)

        return aggregate.describe([xrn.get_urn()], version=rspec.version)
Esempio n. 4
0
 def GetVersion(self, api, options):
     # peers explicitly in aggregates.xml
     peers =dict ([ (peername,interface.get_url()) for (peername,interface) in api.aggregates.iteritems()
                    if peername != api.hrn])
     version_manager = VersionManager()
     ad_rspec_versions = []
     request_rspec_versions = []
     cred_types = [{'geni_type': 'geni_sfa', 'geni_version': str(i)} for i in range(4)[-2:]]
     for rspec_version in version_manager.versions:
         if rspec_version.content_type in ['*', 'ad']:
             ad_rspec_versions.append(rspec_version.to_dict())
         if rspec_version.content_type in ['*', 'request']:
             request_rspec_versions.append(rspec_version.to_dict())
     xrn=Xrn(api.hrn, 'authority+sm')
     version_more = {
         'interface':'slicemgr',
         'sfa': 2,
         'geni_api': 3,
         'geni_api_versions': {'3': 'http://%s:%s' % (api.config.SFA_SM_HOST, api.config.SFA_SM_PORT)},
         'hrn' : xrn.get_hrn(),
         'urn' : xrn.get_urn(),
         'peers': peers,
         'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state.
         'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way.
         'geni_credential_types': cred_types,
         }
     sm_version=version_core(version_more)
     # local aggregate if present needs to have localhost resolved
     if api.hrn in api.aggregates:
         local_am_url=api.aggregates[api.hrn].get_url()
         sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
     return sm_version
Esempio n. 5
0
 def _record_dict(self, xrn=None, type=None, 
                  url=None, description=None, email='', 
                  key=None, 
                  slices=[], researchers=[], pis=[]):
     record_dict = {}
     if xrn:
         if type:
             xrn = Xrn(xrn, type)
         else:
             xrn = Xrn(xrn)
         record_dict['urn'] = xrn.get_urn()
         record_dict['hrn'] = xrn.get_hrn()
         record_dict['type'] = xrn.get_type()
     if url:
         record_dict['url'] = url
     if description:
         record_dict['description'] = description
     if key:
         try:
             pubkey = open(key, 'r').read()
         except IOError:
             pubkey = key
         record_dict['keys'] = [pubkey]
     if slices:
         record_dict['slices'] = slices
     if researchers:
         record_dict['researcher'] = researchers
     if email:
         record_dict['email'] = email
     if pis:
         record_dict['pi'] = pis
     return record_dict
Esempio n. 6
0
def GetVersion(api):
    # peers explicitly in aggregates.xml
    peers =dict ([ (peername,get_serverproxy_url(v)) for (peername,v) in api.aggregates.iteritems()
                   if peername != api.hrn])
    version_manager = VersionManager()
    ad_rspec_versions = []
    request_rspec_versions = []
    for rspec_version in version_manager.versions:
        if rspec_version.content_type in ['*', 'ad']:
            ad_rspec_versions.append(rspec_version.to_dict())
        if rspec_version.content_type in ['*', 'request']:
            request_rspec_versions.append(rspec_version.to_dict())
    default_rspec_version = version_manager.get_version("sfa 1").to_dict()
    xrn=Xrn(api.hrn, 'authority+sa')
    version_more = {'interface':'slicemgr',
                    'hrn' : xrn.get_hrn(),
                    'urn' : xrn.get_urn(),
                    'peers': peers,
                    'request_rspec_versions': request_rspec_versions,
                    'ad_rspec_versions': ad_rspec_versions,
                    'default_ad_rspec': default_rspec_version
                    }
    sm_version=version_core(version_more)
    # local aggregate if present needs to have localhost resolved
    if api.hrn in api.aggregates:
        local_am_url=get_serverproxy_url(api.aggregates[api.hrn])
        sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
    return sm_version
Esempio n. 7
0
 def provision(self, xrn):
     """Provision slivers"""
     xrn = Xrn(xrn, 'slice')
     slice_urn=xrn.get_urn()
     options = {'geni_rspec_version': 'KOREN'}
     manifest = self.api.manager.Provision(self.api, [slice_urn], [], options)
     print manifest
Esempio n. 8
0
 def GetVersion(self, api, options):
     # peers explicitly in aggregates.xml
     peers =dict ([ (peername,interface.get_url()) for (peername,interface) in api.aggregates.iteritems()
                    if peername != api.hrn])
     version_manager = VersionManager()
     ad_rspec_versions = []
     request_rspec_versions = []
     for rspec_version in version_manager.versions:
         if rspec_version.content_type in ['*', 'ad']:
             ad_rspec_versions.append(rspec_version.to_dict())
         if rspec_version.content_type in ['*', 'request']:
             request_rspec_versions.append(rspec_version.to_dict())
     xrn=Xrn(api.hrn, 'authority+sa')
     version_more = {
         'interface':'slicemgr',
         'sfa': 2,
         'geni_api': 2,
         'geni_api_versions': {'2': 'http://%s:%s' % (api.config.SFA_SM_HOST, api.config.SFA_SM_PORT)},
         'hrn' : xrn.get_hrn(),
         'urn' : xrn.get_urn(),
         'peers': peers,
         'geni_request_rspec_versions': request_rspec_versions,
         'geni_ad_rspec_versions': ad_rspec_versions,
         }
     sm_version=version_core(version_more)
     # local aggregate if present needs to have localhost resolved
     if api.hrn in api.aggregates:
         local_am_url=api.aggregates[api.hrn].get_url()
         sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
     return sm_version
Esempio n. 9
0
    def call(self, xrn, creds, rspec, options):
        xrn = Xrn(xrn, type='slice')
        self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, xrn.get_hrn(), self.name))
        (speaking_for, _) = urn_to_hrn(options.get('geni_speaking_for'))

        # Find the valid credentials
        valid_creds = self.api.auth.checkCredentials(creds, 'createsliver', xrn.get_hrn(), speaking_for_hrn=speaking_for)
        # use the expiration from the first valid credential to determine when 
        # the slivers should expire.
        expiration = datetime_to_string(Credential(cred=valid_creds[0]).expiration)
        
        # make sure request is not empty
        slivers = RSpec(rspec).version.get_nodes_with_slivers()
        if not slivers:
            raise InvalidRSpec("Missing <sliver_type> or <sliver> element. Request rspec must explicitly allocate slivers")    

        # flter rspec through sfatables
        if self.api.interface in ['aggregate']:
            chain_name = 'INCOMING'
        elif self.api.interface in ['slicemgr']:
            chain_name = 'FORWARD-INCOMING'
        self.api.logger.debug("Allocate: sfatables on chain %s"%chain_name)
        origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn()
        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, xrn, self.name)) 
        rspec = run_sfatables(chain_name, xrn.get_hrn(), origin_hrn, rspec)
        slivers = RSpec(rspec).version.get_nodes_with_slivers()
        if not slivers:
            raise SfatablesRejected(slice_xrn)

        result = self.api.manager.Allocate(self.api, xrn.get_urn(), creds, rspec, expiration, options)
        return result
Esempio n. 10
0
    def describe(self, urns, version=None, options=None):
        if options is None: options={}
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # Update connection for the current user
        xrn = Xrn(urns[0], type='slice')
        user_name = xrn.get_authority_hrn() + '.' + xrn.leaf.split('-')[0]
        tenant_name = OSXrn(xrn=urns[0], type='slice').get_hrn()
        self.driver.shell.compute_manager.connect(username=user_name, tenant=tenant_name, password=user_name)

        # For delay to collect instance info 
        time.sleep(3)
        # Get instances from the Openstack
        instances = self.get_instances(xrn)

        # Add sliver(s) from instance(s)
        geni_slivers = []
        rspec.xml.set( 'expires',  datetime_to_string(utcparse(time.time())) )
        rspec_nodes = []
        for instance in instances:
            rspec_nodes.append(self.instance_to_rspec_node(instance))
            geni_sliver = self.instance_to_geni_sliver(instance)
            geni_slivers.append(geni_sliver)
        rspec.version.add_nodes(rspec_nodes)

        result = { 'geni_urn': xrn.get_urn(),
                   'geni_rspec': rspec.toxml(), 
                   'geni_slivers': geni_slivers }
        return result
Esempio n. 11
0
 def _record_dict(self, xrn, type, email, key, 
                  slices, researchers, pis, 
                  url, description, extras):
     record_dict = {}
     if xrn:
         if type:
             xrn = Xrn(xrn, type)
         else:
             xrn = Xrn(xrn)
         record_dict['urn'] = xrn.get_urn()
         record_dict['hrn'] = xrn.get_hrn()
         record_dict['type'] = xrn.get_type()
     if url:
         record_dict['url'] = url
     if description:
         record_dict['description'] = description
     if key:
         try:
             pubkey = open(key, 'r').read()
         except IOError:
             pubkey = key
         record_dict['reg-keys'] = [pubkey]
     if slices:
         record_dict['slices'] = slices
     if researchers:
         record_dict['reg-researchers'] = researchers
     if email:
         record_dict['email'] = email
     if pis:
         record_dict['reg-pis'] = pis
     if extras:
         record_dict.update(extras)
     return record_dict
Esempio n. 12
0
 def allocate(self, xrn, rspec):
     """Allocate slivers"""
     xrn = Xrn(xrn, 'slice')
     slice_urn=xrn.get_urn()
     rspec_string = open(rspec).read()
     options={}
     manifest = self.api.manager.Allocate(self.api, slice_urn, [], rspec_string, options)
     print manifest
Esempio n. 13
0
 def SliverStatus (self, api, xrn, creds, options):
     call_id = options.get('call_id')
     if Callids().already_handled(call_id): return {}
 
     xrn = Xrn(xrn,'slice')
     slice_urn=xrn.get_urn()
     slice_hrn=xrn.get_hrn()
     return self.driver.sliver_status (slice_urn, slice_hrn)
Esempio n. 14
0
    def DeleteSliver(self, api, xrn, creds, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return True

        xrn = Xrn(xrn, 'slice')
        slice_urn=xrn.get_urn()
        slice_hrn=xrn.get_hrn()
        return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options)
Esempio n. 15
0
 def RenewSliver(self, api, xrn, creds, expiration_time, options):
     call_id = options.get('call_id')
     if Callids().already_handled(call_id): return True
     
     xrn = Xrn(xrn, 'slice')
     slice_urn=xrn.get_urn()
     slice_hrn=xrn.get_hrn()
     return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
Esempio n. 16
0
def GetVersion(api):
    peers =dict ([ (peername,v._ServerProxy__host) for (peername,v) in api.registries.iteritems() 
                   if peername != api.hrn])
    xrn=Xrn(api.hrn)
    return version_core({'interface':'registry',
                         'hrn':xrn.get_hrn(),
                         'urn':xrn.get_urn(),
                         'peers':peers})
Esempio n. 17
0
 def provision(self, xrn):
     """Provision slivers"""
     xrn = Xrn(xrn, 'slice')
     slice_urn = xrn.get_urn()
     options = {}
     manifest = self.api.manager.provision(self.api, [slice_urn], [],
                                           options)
     print manifest
Esempio n. 18
0
 def allocate(self, xrn, rspec):
     """Allocate slivers"""
     xrn = Xrn(xrn, 'slice')
     slice_urn = xrn.get_urn()
     rspec_string = open(rspec).read()
     options = {}
     manifest = self.api.manager.Allocate(self.api, slice_urn, [],
                                          rspec_string, options)
     print manifest
Esempio n. 19
0
    def GetTicket(self, api, xrn, creds, rspec, users, options):
    
        xrn = Xrn(xrn)
        slice_urn=xrn.get_urn()
        slice_hrn=xrn.get_hrn()

        # xxx sounds like GetTicket is dead, but if that gets resurrected we might wish
        # to pass 'users' over to the driver as well
        return self.driver.get_ticket (slice_urn, slice_hrn, creds, rspec, options)
Esempio n. 20
0
 def GetVersion(self, api, options):
     peers = dict ( [ (hrn,interface.get_url()) for (hrn,interface) in api.registries.iteritems() 
                    if hrn != api.hrn])
     xrn=Xrn(api.hrn,type='authority')
     return version_core({'interface':'registry',
                          'sfa': 3,
                          'hrn':xrn.get_hrn(),
                          'urn':xrn.get_urn(),
                          'peers':peers})
Esempio n. 21
0
 def test_void(self):
     void = Xrn(xrn='', type=None)
     expected = 'urn:publicid:IDN++'
     self.assertEqual(void.get_hrn(), '')
     self.assertEqual(void.get_type(), None)
     self.assertEqual(void.get_urn(), expected)
     loop = Xrn(xrn=expected)
     self.assertEqual(loop.get_hrn(), '')
     # xxx - this is not quite right as the first object has type None
     self.assertEqual(loop.get_type(), '')
Esempio n. 22
0
 def test_void(self):
     void=Xrn(xrn='',type=None)
     expected='urn:publicid:IDN++'
     self.assertEqual(void.get_hrn(),'')
     self.assertEqual(void.get_type(),None)
     self.assertEqual(void.get_urn(),expected)
     loop=Xrn(xrn=expected)
     self.assertEqual(loop.get_hrn(),'')
     # xxx - this is not quite right as the first object has type None
     self.assertEqual(loop.get_type(),'')        
Esempio n. 23
0
 def GetVersion(self, api, options):
     peers = dict ( [ (hrn,interface.get_url()) for (hrn,interface) in api.registries.iteritems()
                    if hrn != api.hrn])
     xrn=Xrn(api.hrn)
     return version_core({'interface':'registry',
                          'sfa': 2,
                          'geni_api': 2,
                          'hrn':xrn.get_hrn(),
                          'urn':xrn.get_urn(),
                          'peers':peers})
Esempio n. 24
0
 def __hrn(self,h,t,exp_urn):
     if verbose: print 'testing (',h,t,') expecting',exp_urn
     xrn=Xrn(h,type=t)
     if verbose: print xrn.dump_string()
     urn=xrn.get_urn()
     (h1,t1) = Xrn(urn).get_hrn_type()
     if h1!=h or t1!=t or urn!=exp_urn:
         print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn)
     self.assertEqual(h1,h)
     self.assertEqual(t1,t)
     self.assertEqual(urn,exp_urn)
Esempio n. 25
0
 def __hrn(self, h, t, exp_urn):
     if verbose: print 'testing (', h, t, ') expecting', exp_urn
     xrn = Xrn(h, type=t)
     if verbose: print xrn.dump_string()
     urn = xrn.get_urn()
     (h1, t1) = Xrn(urn).get_hrn_type()
     if h1 != h or t1 != t or urn != exp_urn:
         print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s" % (
             h, t, h1, t1, urn)
     self.assertEqual(h1, h)
     self.assertEqual(t1, t)
     self.assertEqual(urn, exp_urn)
Esempio n. 26
0
    def allocate(self, urn, rspec_string, expiration, options=None):
        """
        Allocate method submit an experiment on Iot-LAB testbed with :
            * user : get the slice user which launch request (caller_hrn)
            * reservation : get the start time and duration in RSpec leases
            * nodes : get the nodes list in RSpec leases
        If we have a request success on Iot-LAB testbed we store in SFA
        database the assocation OAR scheduler job id and slice hrn

        :param urn : slice urn
        :param rspec_string : RSpec received
        :param options : options with slice users (geni_users)
        """
        # pylint:disable=R0914

        logger.warning("iotlabdriver allocate")
        xrn = Xrn(urn)
        aggregate = IotLABAggregate(self)
        # parse rspec
        rspec = RSpec(rspec_string)

        caller_hrn = options.get('actual_caller_hrn', [])
        geni_users = options.get('geni_users', [])
        caller_user = [user for user in geni_users if
                       urn_to_hrn(user['urn'])[0] == caller_hrn][0]
        logger.warning("iotlabdriver allocate caller : %s" %
                       caller_user['email'])

        login = self._get_user_login(caller_user)
        # only if we have a user
        if login:
            nodes_list, start_time, duration = \
                self._get_experiment(rspec)
            logger.warning("iotlabdriver allocate submit OAR job :"
                           " %s %s %s %s" %
                           (xrn.hrn, start_time, duration, nodes_list))
            # [0-9A-Za-z_] with onelab.inria.test_iotlab
            exp_name = '_'.join((xrn.hrn).split('.'))
            # submit OAR job
            ret = self.shell.reserve_nodes(login,
                                           exp_name,
                                           nodes_list,
                                           start_time,
                                           duration)

            # in case of job submission success save slice and lease job
            # id association in database
            if 'id' in ret:
                self._save_db_lease(int(ret['id']),
                                    xrn.hrn)

        return aggregate.describe([xrn.get_urn()], version=rspec.version)
Esempio n. 27
0
File: Remove.py Progetto: aquila/sfa
    def call(self, xrn, creds, type):
        xrn=Xrn(xrn,type=type)
        
        # validate the cred
        valid_creds = self.api.auth.checkCredentials(creds, "remove")
        self.api.auth.verify_object_permission(xrn.get_hrn())

        #log the call
        origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
        self.api.logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s"%(
                self.api.interface, self.name, origin_hrn, xrn.get_urn()))

        return self.api.manager.Remove(self.api, xrn) 
Esempio n. 28
0
    def CreateSliver(self, api, xrn, creds, rspec_string, users, options):
        """
        Create the sliver[s] (slice) at this aggregate.    
        Verify HRN and initialize the slice record in PLC if necessary.
        """
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""
    
        xrn = Xrn(xrn, 'slice')
        slice_urn=xrn.get_urn()
        slice_hrn=xrn.get_hrn()

        return self.driver.create_sliver (slice_urn, slice_hrn, creds, rspec_string, users, options)
Esempio n. 29
0
    def ListResources(self, api, creds, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        # get slice's hrn from options
        slice_xrn = options.get('geni_slice_urn', None)
        # pass None if no slice is specified
        if not slice_xrn:
            slice_hrn, slice_urn = None, None
        else:
            xrn = Xrn(slice_xrn)
            slice_urn=xrn.get_urn()
            slice_hrn=xrn.get_hrn()
        return self.driver.list_resources (slice_urn, slice_hrn, creds, options)
Esempio n. 30
0
    def call(self, xrn, creds, type):
        xrn = Xrn(xrn, type=type)

        # validate the cred
        valid_creds = self.api.auth.checkCredentials(creds, "remove")
        self.api.auth.verify_object_permission(xrn.get_hrn())

        #log the call
        origin_hrn = Credential(
            string=valid_creds[0]).get_gid_caller().get_hrn()
        self.api.logger.info(
            "interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s" %
            (self.api.interface, self.name, origin_hrn, xrn.get_urn()))

        return self.api.manager.Remove(self.api, xrn)
Esempio n. 31
0
 def GetVersion(self, api, options):
     xrn=Xrn(api.hrn)
     version = version_core()
     version_generic = {
         'interface':'aggregate',
         'sfa': 2,
         'geni_api': 2,
         'geni_api_versions': {'2': 'http://%s:%s' % (api.config.SFA_AGGREGATE_HOST, api.config.SFA_AGGREGATE_PORT)}, 
         'hrn':xrn.get_hrn(),
         'urn':xrn.get_urn(),
         }
     version.update(version_generic)
     testbed_version = self.driver.aggregate_version()
     version.update(testbed_version)
     return version
Esempio n. 32
0
    def call(self, xrn, creds, rspec, options):
        xrn = Xrn(xrn, type='slice')
        self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s" %
                             (self.api.interface, xrn.get_hrn(), self.name))
        (speaking_for, _) = urn_to_hrn(options.get('geni_speaking_for'))

        # Find the valid credentials
        valid_creds = self.api.auth.checkCredentials(
            creds,
            'createsliver',
            xrn.get_hrn(),
            speaking_for_hrn=speaking_for)
        # use the expiration from the first valid credential to determine when
        # the slivers should expire.
        expiration = datetime_to_string(
            Credential(cred=valid_creds[0]).expiration)

        # make sure request is not empty
        slivers = RSpec(rspec).version.get_nodes_with_slivers()
        if not slivers:
            raise InvalidRSpec(
                "Missing <sliver_type> or <sliver> element. Request rspec must explicitly allocate slivers"
            )

        # flter rspec through sfatables
        if self.api.interface in ['aggregate']:
            chain_name = 'INCOMING'
        elif self.api.interface in ['slicemgr']:
            chain_name = 'FORWARD-INCOMING'
        self.api.logger.debug("Allocate: sfatables on chain %s" % chain_name)
        origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn()
        self.api.logger.info(
            "interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
            (self.api.interface, origin_hrn, xrn, self.name))
        rspec = run_sfatables(chain_name, xrn.get_hrn(), origin_hrn, rspec)
        slivers = RSpec(rspec).version.get_nodes_with_slivers()
        if not slivers:
            raise SfatablesRejected(slice_xrn)

        result = self.api.manager.Allocate(self.api, xrn.get_urn(), creds,
                                           rspec, expiration, options)
        return result
Esempio n. 33
0
 def _record_dict(self,
                  xrn=None,
                  type=None,
                  url=None,
                  description=None,
                  email='',
                  key=None,
                  slices=[],
                  researchers=[],
                  pis=[],
                  extras={}):
     record_dict = {}
     if xrn:
         if type:
             xrn = Xrn(xrn, type)
         else:
             xrn = Xrn(xrn)
         record_dict['urn'] = xrn.get_urn()
         record_dict['hrn'] = xrn.get_hrn()
         record_dict['type'] = xrn.get_type()
     if url:
         record_dict['url'] = url
     if description:
         record_dict['description'] = description
     if key:
         try:
             pubkey = open(key, 'r').read()
         except IOError:
             pubkey = key
         record_dict['keys'] = [pubkey]
     if slices:
         record_dict['slices'] = slices
     if researchers:
         record_dict['researcher'] = researchers
     if email:
         record_dict['email'] = email
     if pis:
         record_dict['pi'] = pis
     if extras:
         record_dict.update(extras)
     return record_dict
Esempio n. 34
0
    def allocate (self, urn, rspec_string, expiration, options={}):
        xrn = Xrn(urn)
        aggregate = unigetestbedAggregate(self)
        slices = unigetestbedSlices(self)
        slice_record=None
        users = options.get('geni_users', [])
        if users:
            slice_record = users[0].get('slice_record', {})

        # parse rspec
        rspec = RSpec(rspec_string)
        requested_attributes = rspec.version.get_slice_attributes()

        # ensure slice record exists
        slice = slices.verify_slice(xrn.hrn, slice_record, expiration=expiration, options=options)
        # ensure person records exists
        #persons = slices.verify_persons(xrn.hrn, slice, users, peer, sfa_peer, options=options)

        # add/remove slice from nodes
        request_nodes = rspec.version.get_nodes_with_slivers()
        nodes = slices.verify_slice_nodes(urn, slice, request_nodes)

        return aggregate.describe([xrn.get_urn()], version=rspec.version)
Esempio n. 35
0
    def call(self, xrn, creds, rspec, options):
        xrn = Xrn(xrn, type='slice')

        # Find the valid credentials
        valid_creds = self.api.auth.checkCredentialsSpeaksFor(creds, 'createsliver', xrn.get_hrn(), options=options)
        the_credential = Credential(cred=valid_creds[0])

        # use the expiration from the first valid credential to determine when 
        # the slivers should expire.
        expiration = datetime_to_string(the_credential.expiration)
        
        self.api.logger.debug("Allocate, received expiration from credential: %s"%expiration)

# turned off, as passing an empty rspec is indeed useful for cleaning up the slice
#        # make sure request is not empty
#        slivers = RSpec(rspec).version.get_nodes_with_slivers()
#        if not slivers:
#            raise InvalidRSpec("Missing <sliver_type> or <sliver> element. Request rspec must explicitly allocate slivers")    

        # flter rspec through sfatables
        if self.api.interface in ['aggregate']:
            chain_name = 'INCOMING'
        elif self.api.interface in ['slicemgr']:
            chain_name = 'FORWARD-INCOMING'
        self.api.logger.debug("Allocate: sfatables on chain %s"%chain_name)
        actual_caller_hrn = the_credential.actual_caller_hrn()
        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, actual_caller_hrn, xrn.get_hrn(), self.name)) 
        rspec = run_sfatables(chain_name, xrn.get_hrn(), actual_caller_hrn, rspec)
# turned off, as passing an empty rspec is indeed useful for cleaning up the slice
#        slivers = RSpec(rspec).version.get_nodes_with_slivers()
#        if not slivers:
#            raise SfatablesRejected(slice_xrn)

        # pass this to the driver code in case they need it
        options['actual_caller_hrn'] = actual_caller_hrn
        result = self.api.manager.Allocate(self.api, xrn.get_urn(), creds, rspec, expiration, options)
        return result
Esempio n. 36
0
    def allocate (self, urn, rspec_string, expiration, options=None):
        if options is None: options={}
        xrn = Xrn(urn)
        aggregate = PlAggregate(self)
        slices = PlSlices(self)
        sfa_peer = slices.get_sfa_peer(xrn.get_hrn())
        slice_record=None    
        users = options.get('geni_users', [])

        if users:
            slice_record = users[0].get('slice_record', {})
    
        # parse rspec
        rspec = RSpec(rspec_string)
        requested_attributes = rspec.version.get_slice_attributes()
        
        # ensure site record exists
        site = slices.verify_site(xrn.hrn, slice_record, sfa_peer, options=options)
        # ensure slice record exists
        slice = slices.verify_slice(xrn.hrn, slice_record, sfa_peer, expiration=expiration, options=options)
        # ensure person records exists
        persons = slices.verify_persons(xrn.hrn, slice, users, sfa_peer, options=options)
        # ensure slice attributes exists
        slices.verify_slice_attributes(slice, requested_attributes, options=options)
       
        # add/remove slice from nodes
        request_nodes = rspec.version.get_nodes_with_slivers()
        nodes = slices.verify_slice_nodes(urn, slice, request_nodes)
         
        # add/remove links links 
        slices.verify_slice_links(slice, rspec.version.get_link_requests(), nodes)

        # add/remove leases
        rspec_requested_leases = rspec.version.get_leases()
        leases = slices.verify_slice_leases(slice, rspec_requested_leases)

        return aggregate.describe([xrn.get_urn()], version=rspec.version)
Esempio n. 37
0
 def GetVersion(self, api, options):
     xrn=Xrn(api.hrn, type='authority+am')
     version = version_core()
     cred_types = [{'geni_type': 'geni_sfa', 'geni_version': str(i)} for i in range(4)[-2:]]
     geni_api_versions = ApiVersions().get_versions()
     geni_api_versions['3'] = 'http://%s:%s' % (api.config.sfa_aggregate_host, api.config.sfa_aggregate_port)
     version_generic = {
         'testbed': api.driver.testbed_name(),
         'interface':'aggregate',
         'sfa': 3,
         'hrn':xrn.get_hrn(),
         'urn':xrn.get_urn(),
         'geni_api': 3,
         'geni_api_versions': geni_api_versions,
         'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state.
         'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way.
         'geni_credential_types': cred_types,
         'geni_handles_speaksfor': True,     # supports 'speaks for' credentials
     }
     version.update(version_generic)
     version.update(self.rspec_versions())
     testbed_version = api.driver.aggregate_version()
     version.update(testbed_version)
     return version
Esempio n. 38
0
 def GetVersion(self, api, options):
     xrn=Xrn(api.hrn, type='authority+am')
     version = version_core()
     cred_types = [{'geni_type': 'geni_sfa', 'geni_version': str(i)} for i in range(4)[-2:]]
     geni_api_versions = ApiVersions().get_versions()
     geni_api_versions['3'] = 'http://%s:%s' % (api.config.sfa_aggregate_host, api.config.sfa_aggregate_port)
     version_generic = {
         'testbed': api.driver.testbed_name(),
         'interface':'aggregate',
         'sfa': 3,
         'hrn':xrn.get_hrn(),
         'urn':xrn.get_urn(),
         'geni_api': 3,
         'geni_api_versions': geni_api_versions,
         'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state.
         'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way.
         'geni_credential_types': cred_types,
         'geni_handles_speaksfor': True,     # supports 'speaks for' credentials
     }
     version.update(version_generic)
     version.update(self.rspec_versions())
     testbed_version = api.driver.aggregate_version()
     version.update(testbed_version)
     return version
Esempio n. 39
0
 def reset_slice(self, api, xrn):
     xrn = Xrn(xrn)
     slice_urn=xrn.get_urn()
     slice_hrn=xrn.get_hrn()
     return self.driver.reset_slice (slice_urn, slice_hrn)
Esempio n. 40
0
 def stop_slice(self, api, xrn, creds):
     xrn = Xrn(xrn)
     slice_urn=xrn.get_urn()
     slice_hrn=xrn.get_hrn()
     return self.driver.stop_slice (slice_urn, slice_hrn, creds)