Пример #1
0
    def verify_slice(self,
                     slice_hrn,
                     slice_record,
                     sfa_peer,
                     expiration,
                     options={}):
        #top_auth_hrn = top_auth(slice_hrn)
        #site_hrn = '.'.join(slice_hrn.split('.')[:-1])
        #slice_part = slice_hrn.split('.')[-1]
        #if top_auth_hrn == self.driver.hrn:
        #    login_base = slice_hrn.split('.')[-2][:12]
        #else:
        #    login_base = hash_loginbase(site_hrn)
        #slice_name = '_'.join([login_base, slice_part])
        plxrn = PlXrn(xrn=slice_hrn)
        slice_hrn = plxrn.get_hrn()
        type = plxrn.get_type()
        site_hrn = plxrn.get_authority_hrn()
        authority_name = plxrn.pl_authname()
        slicename = plxrn.pl_slicename()
        login_base = plxrn.pl_login_base()

        slices = self.driver.shell.GetSlices({'peer_id': None},
                                             ['slice_id', 'name', 'hrn'])
        # Filter slices by HRN
        slice_exists = [slice for slice in slices if slice['hrn'] == slice_hrn]
        expires = int(datetime_to_epoch(utcparse(expiration)))
        if not slice_exists:
            if slice_record:
                url = slice_record.get('url', slice_hrn)
                description = slice_record.get('description', slice_hrn)
            else:
                url = slice_hrn
                description = slice_hrn
            slice = {
                'name': slice_name,
                'url': url,
                'description': description
            }
            # add the slice
            slice['slice_id'] = self.driver.shell.AddSlice(slice)
            # set the slice HRN
            self.driver.shell.SetSliceHrn(int(slice['slice_id']), slice_hrn)
            # Tag this as created through SFA
            self.driver.shell.SetSliceSfaCreated(int(slice['slice_id']),
                                                 'True')
            # set the expiration
            self.driver.shell.UpdateSlice(int(slice['slice_id']),
                                          {'expires': expires})

        else:
            slice = slice_exists[0]
            #Update expiration if necessary
            if slice.get('expires', None) != expires:
                self.driver.shell.UpdateSlice(int(slice['slice_id']),
                                              {'expires': expires})

        return self.driver.shell.GetSlices(int(slice['slice_id']))[0]
Пример #2
0
    def verify_site(self,
                    slice_xrn,
                    slice_record={},
                    sfa_peer=None,
                    options={}):
        #(slice_hrn, type) = urn_to_hrn(slice_xrn)
        #top_auth_hrn = top_auth(slice_hrn)
        #site_hrn = '.'.join(slice_hrn.split('.')[:-1])
        #if top_auth_hrn == self.driver.hrn:
        #    login_base = slice_hrn.split('.')[-2][:12]
        #else:
        #    login_base = hash_loginbase(site_hrn)
        plxrn = PlXrn(xrn=slice_xrn)
        slice_hrn = plxrn.get_hrn()
        type = plxrn.get_type()
        site_hrn = plxrn.get_authority_hrn()
        authority_name = plxrn.pl_authname()
        slicename = plxrn.pl_slicename()
        login_base = plxrn.pl_login_base()

        sites = self.driver.shell.GetSites(
            {'peer_id': None},
            ['site_id', 'name', 'abbreviated_name', 'login_base', 'hrn'])

        # filter sites by hrn
        site_exists = [site for site in sites if site['hrn'] == site_hrn]

        if not site_exists:
            # create new site record
            site = {
                'name': 'sfa:%s' % site_hrn,
                'abbreviated_name': site_hrn,
                'login_base': login_base,
                'max_slices': 100,
                'max_slivers': 1000,
                'enabled': True,
                'peer_site_id': None
            }

            site['site_id'] = self.driver.shell.AddSite(site)
            # Set site HRN
            self.driver.shell.SetSiteHrn(int(site['site_id']), site_hrn)
            # Tag this as created through SFA
            self.driver.shell.SetSiteSfaCreated(int(site['site_id']), 'True')
            # exempt federated sites from monitor policies
            self.driver.shell.AddSiteTag(int(site['site_id']),
                                         'exempt_site_until', "20200101")

        else:
            site = site_exists[0]

        return site
Пример #3
0
 def test_login_base_001(self):
     xrn = PlXrn(xrn='ple.inria.omftest', type='slice')
     self.assertEqual(xrn.pl_login_base(), 'inria')