Esempio n. 1
0
    def verify_users(self, slice_hrn, slice_record, users, sfa_peer, options=None):
        if options is None: options={}
        # get slice info
        slicename = hrn_to_nitos_slicename(slice_hrn)
        slices = self.driver.shell.getSlices({}, [])
        slice = self.driver.filter_nitos_results(slices, {'slice_name': slicename})[0]
        added_users = []
        #get users info
        users_info = []
        for user in users:
             user_urn = user['urn']
             user_hrn, type = urn_to_hrn(user_urn)
             username = str(user_hrn).split('.')[-1]
             email = user['email']
             # look for the user according to his username, email...
             nitos_users = self.driver.filter_nitos_results(self.driver.shell.getUsers(), {'username': username})
             if not nitos_users:
                 nitos_users = self.driver.filter_nitos_results(self.driver.shell.getUsers(), {'email': email})

             if not nitos_users:
                 # create the user
                 user_id = self.driver.shell.addUser({'username': email.split('@')[0], 'email': email})
                 added_users.append(user_id)
                 # add user keys
                 for key in user['keys']:
                      self.driver.shell.addUserKey({'user_id': user_id, 'key': key, 'slice_id': slice['slice_id']})
                 # add the user to the slice
                 self.driver.shell.addUserToSlice({'slice_id': slice['slice_id'], 'user_id': user_id})
             else:
                 # check if the users are in the slice
                 for user in nitos_users:
                      if not user['user_id'] in slice['user_ids']:
                          self.driver.shell.addUserToSlice({'slice_id': slice['slice_id'], 'user_id': user['user_id']})

        return added_users
Esempio n. 2
0
    def verify_users(self, slice_hrn, slice_record, users, sfa_peer, options={}):
        # get slice info
        slicename = hrn_to_nitos_slicename(slice_hrn)
        slices = self.driver.shell.getSlices({}, [])
        slice = self.driver.filter_nitos_results(slices, {"slice_name": slicename})[0]
        added_users = []
        # get users info
        users_info = []
        for user in users:
            user_urn = user["urn"]
            user_hrn, type = urn_to_hrn(user_urn)
            username = str(user_hrn).split(".")[-1]
            email = user["email"]
            # look for the user according to his username, email...
            nitos_users = self.driver.filter_nitos_results(self.driver.shell.getUsers(), {"username": username})
            if not nitos_users:
                nitos_users = self.driver.filter_nitos_results(self.driver.shell.getUsers(), {"email": email})

            if not nitos_users:
                # create the user
                user_id = self.driver.shell.addUser({"username": email.split("@")[0], "email": email})
                added_users.append(user_id)
                # add user keys
                for key in user["keys"]:
                    self.driver.shell.addUserKey({"user_id": user_id, "key": key, "slice_id": slice["slice_id"]})
                # add the user to the slice
                self.driver.shell.addUserToSlice({"slice_id": slice["slice_id"], "user_id": user_id})
            else:
                # check if the users are in the slice
                for user in nitos_users:
                    if not user["user_id"] in slice["user_ids"]:
                        self.driver.shell.addUserToSlice({"slice_id": slice["slice_id"], "user_id": user["user_id"]})

        return added_users
Esempio n. 3
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_nitos_slicename(slice_hrn)
        slices = self.driver.shell.getSlices({'slice_name': slice_name}, [])
        #filter results
        for slc in slices:
             if slc['slice_name'] == slice_name:
                 slice = slc
                 break

        if not slice:
            return (slice, slivers)
      
        reserved_nodes = self.driver.shell.getReservedNodes({'slice_id': slice['slice_id']}, [])
        reserved_node_ids = []
        # filter on the slice
        for node in reserved_nodes:
             if node['slice_id'] == slice['slice_id']:
                 reserved_node_ids.append(node['node_id'])
        #get all the nodes
        all_nodes = self.driver.shell.getNodes({}, [])
       
        for node in all_nodes:
             if node['node_id'] in reserved_node_ids:
                 slivers[node['node_id']] = node
        
        return (slice, slivers)
Esempio n. 4
0
    def delete_sliver(self, slice_urn, slice_hrn, creds, options):
        slicename = hrn_to_nitos_slicename(slice_hrn)
        slices = self.filter_nitos_results(self.shell.getSlices({}, []),
                                           {'slice_name': slicename})
        if not slices:
            return 1
        slice = slices[0]

        slice_reserved_nodes = self.filter_nitos_results(
            self.shell.getReservedNodes({}, []),
            {'slice_id': slice['slice_id']})
        slice_reserved_channels = self.filter_nitos_results(
            self.shell.getReservedChannels(), {'slice_id': slice['slice_id']})

        slice_reserved_nodes_ids = [
            node['reservation_id'] for node in slice_reserved_nodes
        ]
        slice_reserved_channels_ids = [
            channel['reservation_id'] for channel in slice_reserved_channels
        ]

        # release all reserved nodes and channels for that slice
        try:
            released_nodes = self.shell.releaseNodes(
                {'reservation_ids': slice_reserved_nodes_ids})
            released_channels = self.shell.releaseChannels(
                {'reservation_ids': slice_reserved_channels_ids})
        except:
            pass
        return 1
Esempio n. 5
0
    def verify_users(self,
                     slice_hrn,
                     slice_record,
                     users,
                     sfa_peer,
                     options={}):
        # get slice info
        slicename = hrn_to_nitos_slicename(slice_hrn)
        slices = self.driver.shell.getSlices({}, [])
        slice = self.driver.filter_nitos_results(slices,
                                                 {'slice_name': slicename})[0]
        added_users = []
        #get users info
        users_info = []
        for user in users:
            user_urn = user['urn']
            user_hrn, type = urn_to_hrn(user_urn)
            username = str(user_hrn).split('.')[-1]
            email = user['email']
            # look for the user according to his username, email...
            nitos_users = self.driver.filter_nitos_results(
                self.driver.shell.getUsers(), {'username': username})
            if not nitos_users:
                nitos_users = self.driver.filter_nitos_results(
                    self.driver.shell.getUsers(), {'email': email})

            if not nitos_users:
                # create the user
                user_id = self.driver.shell.addUser({
                    'username':
                    email.split('@')[0],
                    'email':
                    email
                })
                added_users.append(user_id)
                # add user keys
                for key in user['keys']:
                    self.driver.shell.addUserKey({
                        'user_id': user_id,
                        'key': key,
                        'slice_id': slice['slice_id']
                    })
                # add the user to the slice
                self.driver.shell.addUserToSlice({
                    'slice_id': slice['slice_id'],
                    'user_id': user_id
                })
            else:
                # check if the users are in the slice
                for user in nitos_users:
                    if not user['user_id'] in slice['user_ids']:
                        self.driver.shell.addUserToSlice({
                            'slice_id':
                            slice['slice_id'],
                            'user_id':
                            user['user_id']
                        })

        return added_users
Esempio n. 6
0
    def verify_slice_leases_nodes(self, slice, rspec_requested_nodes):
        nodes = self.driver.shell.getNodes({}, [])
  
        requested_nodes = []
        for node in rspec_requested_nodes:
             requested_node = {}
             nitos_nodes = []
             nitos_nodes.extend(nodes)
             slice_name = hrn_to_nitos_slicename(node['slice_id'])
             if slice_name != slice['slice_name']:
                 continue
             hostname = xrn_to_hostname(node['component_id'])
             nitos_node = self.driver.filter_nitos_results(nitos_nodes, {'hostname': hostname})
             if not nitos_node:
                 continue
             nitos_node = nitos_node[0]
             # fill the requested node with nitos ids
             requested_node['slice_id'] = slice['slice_id']
             requested_node['node_id'] = nitos_node['node_id']
             requested_node['start_time'] = node['start_time']
             requested_node['end_time'] = str(int(node['duration']) * int(self.driver.testbedInfo['grain']) + int(node['start_time']))
             requested_nodes.append(requested_node)

        # get actual nodes reservation data for the slice
        reserved_nodes = self.driver.filter_nitos_results(self.driver.shell.getReservedNodes({}, []), {'slice_id': slice['slice_id']})
         
        reserved_nodes_by_id = {}
        for node in reserved_nodes:
             reserved_nodes_by_id[node['reservation_id']] = {'slice_id': node['slice_id'], \
                                      'node_id': node['node_id'], 'start_time': node['start_time'], \
                                      'end_time': node['end_time']}

        added_nodes = []
        kept_nodes_id = []
        deleted_nodes_id = []
        for reservation_id in reserved_nodes_by_id:
             if reserved_nodes_by_id[reservation_id] not in requested_nodes:
                 deleted_nodes_id.append(reservation_id)
             else:
                 kept_nodes_id.append(reservation_id)
                 requested_nodes.remove(reserved_nodes_by_id[reservation_id])
        added_nodes = requested_nodes


        try:
            deleted=self.driver.shell.releaseNodes({'reservation_ids': deleted_nodes_id})
            for node in added_nodes:
                added=self.driver.shell.reserveNodes({'slice_id': slice['slice_id'], 'start_time': node['start_time'], 'end_time': node['end_time'], 'nodes': [node['node_id']]})

        except:
            logger.log_exc('Failed to add/remove slice leases nodes')

        return added_nodes
Esempio n. 7
0
    def sfa_fields_to_nitos_fields(self, type, hrn, sfa_record):

        nitos_record = {}
 
        if type == "slice":
            nitos_record["slice_name"] = hrn_to_nitos_slicename(hrn)
        elif type == "node":
            if "hostname" not in sfa_record:
                raise MissingSfaInfo("hostname")
            nitos_record["node_name"] = sfa_record["hostname"]

        return nitos_record
Esempio n. 8
0
    def sfa_fields_to_nitos_fields(self, type, hrn, sfa_record):

        nitos_record = {}

        if type == "slice":
            nitos_record["slice_name"] = hrn_to_nitos_slicename(hrn)
        elif type == "node":
            if "hostname" not in sfa_record:
                raise MissingSfaInfo("hostname")
            nitos_record["node_name"] = sfa_record["hostname"]

        return nitos_record
Esempio n. 9
0
    def renew_sliver (self, slice_urn, slice_hrn, creds, expiration_time, options):
        slicename = hrn_to_nitos_slicename(slice_hrn)
        slices = self.shell.GetSlices({'slicename': slicename}, ['slice_id'])
        if not slices:
            raise RecordNotFound(slice_hrn)
        slice = slices[0]
        requested_time = utcparse(expiration_time)
        record = {'expires': int(datetime_to_epoch(requested_time))}
        try:
            self.shell.UpdateSlice(slice['slice_id'], record)

            return True
        except:
            return False
Esempio n. 10
0
    def verify_slice_leases_channels(self, slice, rspec_requested_channels):
        channels = self.driver.shell.getChannels({}, [])

        requested_channels = []
        for channel in rspec_requested_channels:
             requested_channel = {}
             nitos_channels = []
             nitos_channels.extend(channels)
             slice_name = hrn_to_nitos_slicename(channel['slice_id'])
             if slice_name != slice['slice_name']:
                 continue
             channel_num = xrn_to_channel(channel['component_id'])
             nitos_channel = self.driver.filter_nitos_results(nitos_channels, {'channel': channel_num})[0]
             # fill the requested channel with nitos ids
             requested_channel['slice_id'] = slice['slice_id']
             requested_channel['channel_id'] = nitos_channel['channel_id']
             requested_channel['start_time'] = channel['start_time']
             requested_channel['end_time'] = str(int(channel['duration']) * int(self.driver.testbedInfo['grain']) + int(channel['start_time']))
             requested_channels.append(requested_channel)

        # get actual channel reservation data for the slice
        reserved_channels = self.driver.filter_nitos_results(self.driver.shell.getReservedChannels(), {'slice_id': slice['slice_id']})
        
        reserved_channels_by_id = {}
        for channel in reserved_channels:
             reserved_channels_by_id[channel['reservation_id']] = {'slice_id': channel['slice_id'], \
                                      'channel_id': channel['channel_id'], 'start_time': channel['start_time'], \
                                      'end_time': channel['end_time']}

        added_channels = []
        kept_channels_id = []
        deleted_channels_id = []
        for reservation_id in reserved_channels_by_id:
             if reserved_channels_by_id[reservation_id] not in requested_channels:
                 deleted_channels_id.append(reservation_id)
             else:
                 kept_channels_id.append(reservation_id)
                 requested_channels.remove(reserved_channels_by_id[reservation_id])
        added_channels = requested_channels

        
        try:
            deleted=self.driver.shell.releaseChannels({'reservation_ids': deleted_channels_id})
            for channel in added_channels:
                added=self.driver.shell.reserveChannels({'slice_id': slice['slice_id'], 'start_time': channel['start_time'], 'end_time': channel['end_time'], 'channels': [channel['channel_id']]})

        except:
            logger.log_exc('Failed to add/remove slice leases channels')
         
        return added_channels
Esempio n. 11
0
    def verify_slice(self, slice_hrn, slice_record, sfa_peer, options={}):
        slicename = hrn_to_nitos_slicename(slice_hrn)
        slices = self.driver.shell.getSlices({}, [])
        slices = self.driver.filter_nitos_results(slices, {"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]

        return slice
Esempio n. 12
0
 def verify_slice(self, slice_hrn, slice_record, sfa_peer, options=None):
     if options is None: options={}
     slicename = hrn_to_nitos_slicename(slice_hrn)
     slices = self.driver.shell.getSlices({}, []) 
     slices = self.driver.filter_nitos_results(slices, {'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]
    
     return slice
Esempio n. 13
0
    def verify_slice(self, slice_hrn, slice_record, sfa_peer, options={}):
        slicename = hrn_to_nitos_slicename(slice_hrn)
        slices = self.driver.shell.getSlices({}, [])
        slices = self.driver.filter_nitos_results(slices,
                                                  {'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]

        return slice
Esempio n. 14
0
    def renew_sliver(self, slice_urn, slice_hrn, creds, expiration_time,
                     options):
        slicename = hrn_to_nitos_slicename(slice_hrn)
        slices = self.shell.GetSlices({'slicename': slicename}, ['slice_id'])
        if not slices:
            raise RecordNotFound(slice_hrn)
        slice = slices[0]
        requested_time = utcparse(expiration_time)
        record = {'expires': int(datetime_to_epoch(requested_time))}
        try:
            self.shell.UpdateSlice(slice['slice_id'], record)

            return True
        except:
            return False
Esempio n. 15
0
    def delete_sliver (self, slice_urn, slice_hrn, creds, options):
        slicename = hrn_to_nitos_slicename(slice_hrn)
        slices = self.filter_nitos_results(self.shell.getSlices({}, []), {'slice_name': slicename})
        if not slices:
            return 1
        slice = slices[0]

        slice_reserved_nodes = self.filter_nitos_results(self.shell.getReservedNodes({}, []), {'slice_id': slice['slice_id'] })
        slice_reserved_channels = self.filter_nitos_results(self.shell.getReservedChannels(), {'slice_id': slice['slice_id'] })

        slice_reserved_nodes_ids = [node['reservation_id'] for node in slice_reserved_nodes]
        slice_reserved_channels_ids = [channel['reservation_id'] for channel in slice_reserved_channels]

        # release all reserved nodes and channels for that slice
        try:
            released_nodes = self.shell.releaseNodes({'reservation_ids': slice_reserved_nodes_ids})
            released_channels = self.shell.releaseChannels({'reservation_ids': slice_reserved_channels_ids})
        except:
            pass
        return 1
Esempio n. 16
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_nitos_slicename(slice_hrn)
        slices = self.driver.shell.getSlices({'slice_name': slice_name}, [])
        #filter results
        for slc in slices:
            if slc['slice_name'] == slice_name:
                slice = slc
                break

        if not slice:
            return (slice, slivers)

        reserved_nodes = self.driver.shell.getReservedNodes(
            {'slice_id': slice['slice_id']}, [])
        reserved_node_ids = []
        # filter on the slice
        for node in reserved_nodes:
            if node['slice_id'] == slice['slice_id']:
                reserved_node_ids.append(node['node_id'])
        #get all the nodes
        all_nodes = self.driver.shell.getNodes({}, [])

        for node in all_nodes:
            if node['node_id'] in reserved_node_ids:
                slivers[node['node_id']] = node

        return (slice, slivers)
Esempio n. 17
0
    def verify_slice_leases_channels(self, slice, rspec_requested_channels):
        channels = self.driver.shell.getChannels({}, [])

        requested_channels = []
        for channel in rspec_requested_channels:
            requested_channel = {}
            nitos_channels = []
            nitos_channels.extend(channels)
            slice_name = hrn_to_nitos_slicename(channel['slice_id'])
            if slice_name != slice['slice_name']:
                continue
            channel_num = xrn_to_channel(channel['component_id'])
            nitos_channel = self.driver.filter_nitos_results(
                nitos_channels, {'channel': channel_num})[0]
            # fill the requested channel with nitos ids
            requested_channel['slice_id'] = slice['slice_id']
            requested_channel['channel_id'] = nitos_channel['channel_id']
            requested_channel['start_time'] = channel['start_time']
            requested_channel['end_time'] = str(
                int(channel['duration']) *
                int(self.driver.testbedInfo['grain']) +
                int(channel['start_time']))
            requested_channels.append(requested_channel)

        # get actual channel reservation data for the slice
        reserved_channels = self.driver.filter_nitos_results(
            self.driver.shell.getReservedChannels(),
            {'slice_id': slice['slice_id']})

        reserved_channels_by_id = {}
        for channel in reserved_channels:
            reserved_channels_by_id[channel['reservation_id']] = {'slice_id': channel['slice_id'], \
                                     'channel_id': channel['channel_id'], 'start_time': channel['start_time'], \
                                     'end_time': channel['end_time']}

        added_channels = []
        kept_channels_id = []
        deleted_channels_id = []
        for reservation_id in reserved_channels_by_id:
            if reserved_channels_by_id[
                    reservation_id] not in requested_channels:
                deleted_channels_id.append(reservation_id)
            else:
                kept_channels_id.append(reservation_id)
                requested_channels.remove(
                    reserved_channels_by_id[reservation_id])
        added_channels = requested_channels

        try:
            deleted = self.driver.shell.releaseChannels(
                {'reservation_ids': deleted_channels_id})
            for channel in added_channels:
                added = self.driver.shell.reserveChannels({
                    'slice_id':
                    slice['slice_id'],
                    'start_time':
                    channel['start_time'],
                    'end_time':
                    channel['end_time'],
                    'channels': [channel['channel_id']]
                })

        except:
            logger.log_exc('Failed to add/remove slice leases channels')

        return added_channels
Esempio n. 18
0
    def verify_slice_leases_nodes(self, slice, rspec_requested_nodes):
        nodes = self.driver.shell.getNodes({}, [])

        requested_nodes = []
        for node in rspec_requested_nodes:
            requested_node = {}
            nitos_nodes = []
            nitos_nodes.extend(nodes)
            slice_name = hrn_to_nitos_slicename(node["slice_id"])
            if slice_name != slice["slice_name"]:
                continue
            hostname = xrn_to_hostname(node["component_id"])
            nitos_node = self.driver.filter_nitos_results(nitos_nodes, {"hostname": hostname})
            if not nitos_node:
                continue
            nitos_node = nitos_node[0]
            # fill the requested node with nitos ids
            requested_node["slice_id"] = slice["slice_id"]
            requested_node["node_id"] = nitos_node["node_id"]
            requested_node["start_time"] = node["start_time"]
            requested_node["end_time"] = str(
                int(node["duration"]) * int(self.driver.testbedInfo["grain"]) + int(node["start_time"])
            )
            requested_nodes.append(requested_node)

        # get actual nodes reservation data for the slice
        reserved_nodes = self.driver.filter_nitos_results(
            self.driver.shell.getReservedNodes({}, []), {"slice_id": slice["slice_id"]}
        )

        reserved_nodes_by_id = {}
        for node in reserved_nodes:
            reserved_nodes_by_id[node["reservation_id"]] = {
                "slice_id": node["slice_id"],
                "node_id": node["node_id"],
                "start_time": node["start_time"],
                "end_time": node["end_time"],
            }

        added_nodes = []
        kept_nodes_id = []
        deleted_nodes_id = []
        for reservation_id in reserved_nodes_by_id:
            if reserved_nodes_by_id[reservation_id] not in requested_nodes:
                deleted_nodes_id.append(reservation_id)
            else:
                kept_nodes_id.append(reservation_id)
                requested_nodes.remove(reserved_nodes_by_id[reservation_id])
        added_nodes = requested_nodes

        try:
            deleted = self.driver.shell.releaseNodes({"reservation_ids": deleted_nodes_id})
            for node in added_nodes:
                added = self.driver.shell.reserveNodes(
                    {
                        "slice_id": slice["slice_id"],
                        "start_time": node["start_time"],
                        "end_time": node["end_time"],
                        "nodes": [node["node_id"]],
                    }
                )

        except:
            logger.log_exc("Failed to add/remove slice leases nodes")

        return added_nodes
Esempio n. 19
0
    def verify_slice_leases_channels(self, slice, rspec_requested_channels):
        channels = self.driver.shell.getChannels({}, [])

        requested_channels = []
        for channel in rspec_requested_channels:
            requested_channel = {}
            nitos_channels = []
            nitos_channels.extend(channels)
            slice_name = hrn_to_nitos_slicename(channel["slice_id"])
            if slice_name != slice["slice_name"]:
                continue
            channel_num = channel["channel_num"]
            nitos_channel = self.driver.filter_nitos_results(nitos_channels, {"channel": channel_num})[0]
            # fill the requested channel with nitos ids
            requested_channel["slice_id"] = slice["slice_id"]
            requested_channel["channel_id"] = nitos_channel["channel_id"]
            requested_channel["start_time"] = channel["start_time"]
            requested_channel["end_time"] = str(
                int(channel["duration"]) * int(self.driver.testbedInfo["grain"]) + int(channel["start_time"])
            )
            requested_channels.append(requested_channel)

        # get actual channel reservation data for the slice
        reserved_channels = self.driver.filter_nitos_results(
            self.driver.shell.getReservedChannels(), {"slice_id": slice["slice_id"]}
        )

        reserved_channels_by_id = {}
        for channel in reserved_channels:
            reserved_channels_by_id[channel["reservation_id"]] = {
                "slice_id": channel["slice_id"],
                "channel_id": channel["channel_id"],
                "start_time": channel["start_time"],
                "end_time": channel["end_time"],
            }

        added_channels = []
        kept_channels_id = []
        deleted_channels_id = []
        for reservation_id in reserved_channels_by_id:
            if reserved_channels_by_id[reservation_id] not in requested_channels:
                deleted_channels_id.append(reservation_id)
            else:
                kept_channels_id.append(reservation_id)
                requested_channels.remove(reserved_channels_by_id[reservation_id])
        added_channels = requested_channels

        try:
            deleted = self.driver.shell.releaseChannels({"reservation_ids": deleted_channels_id})
            for channel in added_channels:
                added = self.driver.shell.reserveChannels(
                    {
                        "slice_id": slice["slice_id"],
                        "start_time": channel["start_time"],
                        "end_time": channel["end_time"],
                        "channels": [channel["channel_id"]],
                    }
                )

        except:
            logger.log_exc("Failed to add/remove slice leases channels")

        return added_channels
Esempio n. 20
0
    def sliver_status(self, slice_urn, slice_hrn):
        # find out where this slice is currently running
        slicename = hrn_to_nitos_slicename(slice_hrn)

        slices = self.shell.getSlices({}, [])
        # filter slicename
        if len(slices) == 0:
            raise SliverDoesNotExist("%s (used %s as slicename internally)" %
                                     (slice_hrn, slicename))

        for slice in slices:
            if slice['slice_name'] == slicename:
                user_slice = slice
                break

        if not user_slice:
            raise SliverDoesNotExist("%s (used %s as slicename internally)" %
                                     (slice_hrn, slicename))

        # report about the reserved nodes only
        reserved_nodes = self.shell.getReservedNodes({}, [])
        nodes = self.shell.getNodes({}, [])

        slice_reserved_nodes = []
        for r_node in reserved_nodes:
            if r_node['slice_id'] == slice['slice_id']:
                for node in nodes:
                    if node['node_id'] == r_node['node_id']:
                        slice_reserved_nodes.append(node)

        if len(slice_reserved_nodes) == 0:
            raise SliverDoesNotExist("You have not allocated any slivers here")

##### continue from here
# get login info
        user = {}
        keys = []
        if slice['user_ids']:
            users = self.shell.getUsers()
            # filter users on slice['user_ids']
            for usr in users:
                if usr['user_id'] in slice['user_ids']:
                    keys.extend(usr['keys'])

            user.update({
                'urn': slice_urn,
                'login': slice['slice_name'],
                'protocol': ['ssh'],
                'port': ['22'],
                'keys': keys
            })

        result = {}
        top_level_status = 'unknown'
        if slice_reserved_nodes:
            top_level_status = 'ready'
        result['geni_urn'] = slice_urn
        result['nitos_gateway_login'] = slice['slice_name']
        #result['pl_expires'] = datetime_to_string(utcparse(slice['expires']))
        #result['geni_expires'] = datetime_to_string(utcparse(slice['expires']))

        resources = []
        for node in slice_reserved_nodes:
            res = {}
            res['nitos_hostname'] = node['hostname']
            sliver_id = Xrn(slice_urn, type='slice', id=node['node_id']).urn
            res['geni_urn'] = sliver_id
            res['geni_status'] = 'ready'
            res['geni_error'] = ''
            res['users'] = [user]

            resources.append(res)

        result['geni_status'] = top_level_status
        result['geni_resources'] = resources

        return result
Esempio n. 21
0
    def sliver_status (self, slice_urn, slice_hrn):
        # find out where this slice is currently running
        slicename = hrn_to_nitos_slicename(slice_hrn)
        
        slices = self.shell.getSlices({}, [])
        # filter slicename
        if len(slices) == 0:        
            raise SliverDoesNotExist("%s (used %s as slicename internally)" % (slice_hrn, slicename))
        
        for slice in slices:
             if slice['slice_name'] == slicename: 
                 user_slice = slice
                 break

        if not user_slice:
            raise SliverDoesNotExist("%s (used %s as slicename internally)" % (slice_hrn, slicename))

        # report about the reserved nodes only
        reserved_nodes = self.shell.getReservedNodes({}, [])
        nodes = self.shell.getNodes({}, [])

        slice_reserved_nodes = []
        for r_node in reserved_nodes:
             if r_node['slice_id'] == slice['slice_id']:
                 for node in nodes:
                     if node['node_id'] == r_node['node_id']:
                         slice_reserved_nodes.append(node)
        
        


        if len(slice_reserved_nodes) == 0:
            raise SliverDoesNotExist("You have not allocated any slivers here") 

##### continue from here
        # get login info
        user = {}
        keys = []
        if slice['user_ids']:
            users = self.shell.getUsers()
            # filter users on slice['user_ids']
            for usr in users:
                 if usr['user_id'] in slice['user_ids']:
                     keys.extend(usr['keys'])
                     

            user.update({'urn': slice_urn,
                         'login': slice['slice_name'],
                         'protocol': ['ssh'],
                         'port': ['22'],
                         'keys': keys})

    
        result = {}
        top_level_status = 'unknown'
        if slice_reserved_nodes:
            top_level_status = 'ready'
        result['geni_urn'] = slice_urn
        result['nitos_gateway_login'] = slice['slice_name']
        #result['pl_expires'] = datetime_to_string(utcparse(slice['expires']))
        #result['geni_expires'] = datetime_to_string(utcparse(slice['expires']))
        
        resources = []
        for node in slice_reserved_nodes:
            res = {}
            res['nitos_hostname'] = node['hostname']
            sliver_id = Xrn(slice_urn, type='slice', id=node['node_id']).urn
            res['geni_urn'] = sliver_id
            res['geni_status'] = 'ready'
            res['geni_error'] = ''
            res['users'] = [user]  
    
            resources.append(res)
            
        result['geni_status'] = top_level_status
        result['geni_resources'] = resources
        
        return result
Esempio n. 22
0
    def verify_slice_leases_nodes(self, slice, rspec_requested_nodes):
        nodes = self.driver.shell.getNodes({}, [])

        requested_nodes = []
        for node in rspec_requested_nodes:
            requested_node = {}
            nitos_nodes = []
            nitos_nodes.extend(nodes)
            slice_name = hrn_to_nitos_slicename(node['slice_id'])
            if slice_name != slice['slice_name']:
                continue
            hostname = xrn_to_hostname(node['component_id'])
            nitos_node = self.driver.filter_nitos_results(
                nitos_nodes, {'hostname': hostname})
            if not nitos_node:
                continue
            nitos_node = nitos_node[0]
            # fill the requested node with nitos ids
            requested_node['slice_id'] = slice['slice_id']
            requested_node['node_id'] = nitos_node['node_id']
            requested_node['start_time'] = node['start_time']
            requested_node['end_time'] = str(
                int(node['duration']) * int(self.driver.testbedInfo['grain']) +
                int(node['start_time']))
            requested_nodes.append(requested_node)

        # get actual nodes reservation data for the slice
        reserved_nodes = self.driver.filter_nitos_results(
            self.driver.shell.getReservedNodes({}, []),
            {'slice_id': slice['slice_id']})

        reserved_nodes_by_id = {}
        for node in reserved_nodes:
            reserved_nodes_by_id[node['reservation_id']] = {'slice_id': node['slice_id'], \
                                     'node_id': node['node_id'], 'start_time': node['start_time'], \
                                     'end_time': node['end_time']}

        added_nodes = []
        kept_nodes_id = []
        deleted_nodes_id = []
        for reservation_id in reserved_nodes_by_id:
            if reserved_nodes_by_id[reservation_id] not in requested_nodes:
                deleted_nodes_id.append(reservation_id)
            else:
                kept_nodes_id.append(reservation_id)
                requested_nodes.remove(reserved_nodes_by_id[reservation_id])
        added_nodes = requested_nodes

        try:
            deleted = self.driver.shell.releaseNodes(
                {'reservation_ids': deleted_nodes_id})
            for node in added_nodes:
                added = self.driver.shell.reserveNodes({
                    'slice_id':
                    slice['slice_id'],
                    'start_time':
                    node['start_time'],
                    'end_time':
                    node['end_time'],
                    'nodes': [node['node_id']]
                })

        except:
            logger.log_exc('Failed to add/remove slice leases nodes')

        return added_nodes