예제 #1
0
    def verify_slice(self, slice_hrn, slice_record, expiration, options={}):
        slicename = hrn_to_unigetestbed_slicename(slice_hrn)
        parts = slicename.split("_")
        login_base = parts[0]
        slices = self.driver.shell.GetSlices({'slice_name': slicename})
        if not slices:
            slice = {'slice_name': slicename}
            # add the slice
            slice['slice_id'] = self.driver.shell.AddSlice(slice)
            slice['node_ids'] = []
            slice['user_ids'] = []
        else:
            slice = slices[0]
            if slice_record and slice_record.get('expires'):
                requested_expires = int(
                    datetime_to_epoch(utcparse(slice_record['expires'])))
                if requested_expires and slice['expires'] != requested_expires:
                    self.driver.shell.UpdateSlice({
                        'slice_id': slice['slice_id'],
                        'fields': {
                            'expires': expiration
                        }
                    })

        return slice
예제 #2
0
    def verify_users(self, slice_hrn, slice_record, users, options={}):
        slice_name = hrn_to_unigetestbed_slicename(slice_hrn)
        users_by_email = {}
        for user in users:
            user['urn'] = user['urn'].lower()
            hrn, type = urn_to_hrn(user['urn'])
            username = get_leaf(hrn)
            user['username'] = username

            if 'email' in user:
                user['email'] = user['email'].lower()
                users_by_email[user['email']] = user

        # start building a list of existing users
        existing_users_by_email = {}
        existing_slice_users_by_email = {}
        existing_users = self.driver.shell.GetUsers()
        existing_slice_users_ids = self.driver.shell.GetSlices(
            {'slice_name': slice_name})[0]['user_ids']
        for user in existing_users:
            existing_users_by_email[user['email']] = user
            if user['user_id'] in existing_slice_users_ids:
                existing_slice_users_by_email[user['email']] = user

        add_users_by_email = set(users_by_email).difference(
            existing_slice_user_by_email)
        delete_users_by_email = set(existing_slice_user_by_email).difference(
            users_by_email)
        try:
            for user in add_users_by_email:
                self.driver.shell.AddUser()
        except:
            pass
예제 #3
0
    def verify_users(self, slice_hrn, slice_record, users, options={}):
        slice_name = hrn_to_unigetestbed_slicename(slice_hrn)
        users_by_email = {}
        for user in users:
            user['urn'] = user['urn'].lower()
            hrn, type = urn_to_hrn(user['urn'])
            username = get_leaf(hrn)
            user['username'] = username

            if 'email' in user:
                user['email'] = user['email'].lower() 
                users_by_email[user['email']] = user

        # start building a list of existing users
        existing_users_by_email = {}
        existing_slice_users_by_email = {}
        existing_users = self.driver.shell.GetUsers()
        existing_slice_users_ids = self.driver.shell.GetSlices({'slice_name': slice_name})[0]['user_ids']
        for user in existing_users:
            existing_users_by_email[user['email']] = user  
            if user['user_id'] in existing_slice_users_ids:
                existing_slice_users_by_email[user['email']] = user

        add_users_by_email = set(users_by_email).difference(existing_slice_user_by_email)
        delete_users_by_email = set(existing_slice_user_by_email).difference(users_by_email)
        try:
            for user in add_users_by_email: 
                self.driver.shell.AddUser()
        except: 
            pass
예제 #4
0
    def get_slice_and_slivers(self, slice_xrn):
        """
        Returns a dict of slivers keyed on the sliver's node_id
        """
        slivers = {}
        slice = None
        if not slice_xrn:
            return (slice, slivers)
        slice_urn = hrn_to_urn(slice_xrn, 'slice')
        slice_hrn, _ = urn_to_hrn(slice_xrn)
        slice_name = hrn_to_unigetestbed_slicename(slice_hrn)
        slices = self.driver.shell.GetSlices({'slice_name': slice_name})
        if not slices:
            return (slice, slivers)
        slice = slices[0]

        # sort slivers by node id
        slice_nodes = []
        if 'node_ids' in slice.keys():
            slice_nodes = self.driver.shell.GetNodes(
                {'node_ids': slice['node_ids']})
        for node in slice_nodes:
            slivers[node['node_id']] = node

        return (slice, slivers)
예제 #5
0
    def sfa_fields_to_unigetestbed_fields(self, type, hrn, sfa_record):

        unigetestbed_record = {}

        if type == "slice":
            unigetestbed_record["slice_name"] = hrn_to_unigetestbed_slicename(
                hrn)

        elif type == "node":
            if "hostname" not in sfa_record:
                raise MissingSfaInfo("hostname")
            unigetestbed_record["hostname"] = sfa_record["hostname"]
            if "type" in sfa_record:
                unigetestbed_record["type"] = sfa_record["type"]
            else:
                unigetestbed_record["type"] = "unigetestbed_type"

        elif type == "authority":
            unigetestbed_record["name"] = hrn

        elif type == "user":
            unigetestbed_record["user_name"] = sfa_record["email"].split(
                '@')[0]
            unigetestbed_record["email"] = sfa_record["email"]

        return unigetestbed_record
예제 #6
0
    def verify_slice(self, slice_hrn, slice_record, expiration, options={}):
        slicename = hrn_to_unigetestbed_slicename(slice_hrn)
        parts = slicename.split("_")
        login_base = parts[0]
        slices = self.driver.shell.GetSlices({'slice_name': slicename}) 
        if not slices:
            slice = {'slice_name': slicename}
            # add the slice                          
            slice['slice_id'] = self.driver.shell.AddSlice(slice)
            slice['node_ids'] = []
            slice['user_ids'] = []
        else:
            slice = slices[0]
            if slice_record and slice_record.get('expires'):
                requested_expires = int(datetime_to_epoch(utcparse(slice_record['expires'])))
                if requested_expires and slice['expires'] != requested_expires:
                    self.driver.shell.UpdateSlice( {'slice_id': slice['slice_id'], 'fields':{'expires' : expiration}})

        return slice
예제 #7
0
    def get_slivers(self, xrn, node=None):
        hrn, type = urn_to_hrn(xrn)

        slice_name = hrn_to_unigetestbed_slicename(hrn)

        slices = self.driver.shell.GetSlices({'slice_name': slice_name})
        slice = slices[0]
        # Build up list of users and slice attributes
        user_ids = slice['user_ids']
        # Get user information
        all_users_list = self.driver.shell.GetUsers({'user_id': user_ids})
        all_users = {}
        for user in all_users_list:
            all_users[user['user_id']] = user

        # Build up list of keys
        all_keys = set()
        for user in all_users_list:
            all_keys.extend(user['keys'])

        slivers = []
        for slice in slices:
            keys = all_keys
            # XXX Sanity check; though technically this should be a system invariant
            # checked with an assertion
            if slice['expires'] > MAXINT: slice['expires'] = MAXINT

            slivers.append({
                'hrn': hrn,
                'name': slice['name'],
                'slice_id': slice['slice_id'],
                'expires': slice['expires'],
                'keys': keys,
            })

        return slivers
예제 #8
0
    def get_slivers(self, xrn, node=None):
        hrn, type = urn_to_hrn(xrn)

        slice_name = hrn_to_unigetestbed_slicename(hrn)

        slices = self.driver.shell.GetSlices({'slice_name': slice_name})
        slice = slices[0]
        # Build up list of users and slice attributes
        user_ids = slice['user_ids']
        # Get user information
        all_users_list = self.driver.shell.GetUsers({'user_id':user_ids})
        all_users = {}
        for user in all_users_list:
            all_users[user['user_id']] = user        

        # Build up list of keys
        all_keys = set()
        for user in all_users_list:
            all_keys.extend(user['keys'])

        slivers = []
        for slice in slices:
            keys = all_keys
            # XXX Sanity check; though technically this should be a system invariant
            # checked with an assertion
            if slice['expires'] > MAXINT:  slice['expires']= MAXINT

            slivers.append({
                'hrn': hrn,
                'name': slice['name'],
                'slice_id': slice['slice_id'],
                'expires': slice['expires'],
                'keys': keys,
            })

        return slivers
예제 #9
0
    def get_slice_and_slivers(self, slice_xrn):
        """
        Returns a dict of slivers keyed on the sliver's node_id
        """
        slivers = {}
        slice = None
        if not slice_xrn:
            return (slice, slivers)
        slice_urn = hrn_to_urn(slice_xrn, 'slice')
        slice_hrn, _ = urn_to_hrn(slice_xrn)
        slice_name = hrn_to_unigetestbed_slicename(slice_hrn)
        slices = self.driver.shell.GetSlices({'slice_name': slice_name})
        if not slices:
            return (slice, slivers)
        slice = slices[0]
        
        # sort slivers by node id 
        slice_nodes = []
        if 'node_ids' in slice.keys():
            slice_nodes = self.driver.shell.GetNodes({'node_ids': slice['node_ids']}) 
        for node in slice_nodes:
            slivers[node['node_id']] = node  

        return (slice, slivers)
예제 #10
0
    def sfa_fields_to_unigetestbed_fields(self, type, hrn, sfa_record):

        unigetestbed_record = {}

        if type == "slice":
            unigetestbed_record["slice_name"] = hrn_to_unigetestbed_slicename(hrn)

        elif type == "node":
            if "hostname" not in sfa_record:
                raise MissingSfaInfo("hostname")
            unigetestbed_record["hostname"] = sfa_record["hostname"]
            if "type" in sfa_record:
                unigetestbed_record["type"] = sfa_record["type"]
            else:
                unigetestbed_record["type"] = "unigetestbed_type"

        elif type == "authority":
            unigetestbed_record["name"] = hrn

        elif type == "user":
            unigetestbed_record["user_name"] = sfa_record["email"].split('@')[0]
            unigetestbed_record["email"] = sfa_record["email"]

        return unigetestbed_record