def pub_get_granted_flowspace(self, slice_id, **kwargs):
    '''
    Return FlowVisor Rules for the slice.
    '''
    slice_id   = slice_id.replace(":","_")
    slice_id   = slice_id.replace("name_","nam__")
    def parse_granted_flowspaces(gfs):
      gfs_list=[] 
      for fs in gfs:
        fs_dict = dict(
            flowspace=dict(),
            openflow=dict()
        )
        fs_dict['openflow']=[]
        fs_dict['flowspace']=dict(
                                 mac_src_s=int_to_mac(fs.mac_src_s),
                                 mac_src_e=int_to_mac(fs.mac_src_e),
                                 mac_dst_s=int_to_mac(fs.mac_dst_s),
                                 mac_dst_e=int_to_mac(fs.mac_dst_e),
                                 eth_type_s=fs.eth_type_s,
                                 eth_type_e=fs.eth_type_e,
                                 vlan_id_s=fs.vlan_id_s,
                                 vlan_id_e=fs.vlan_id_e,
                                 ip_src_s=int_to_dotted_ip(fs.ip_src_s),
                                 ip_dst_s=int_to_dotted_ip(fs.ip_dst_s),
                                 ip_src_e=int_to_dotted_ip(fs.ip_src_e),
                                 ip_dst_e=int_to_dotted_ip(fs.ip_dst_e),
                                 ip_proto_s=fs.ip_proto_s,
                                 ip_proto_e=fs.ip_proto_e,
                                 tp_src_s=fs.tp_src_s,
                                 tp_dst_s=fs.tp_dst_s,
                                 tp_src_e=fs.tp_src_e,
                                 tp_dst_e=fs.tp_dst_e,
                             )
        openflow_dict=dict(
                                dpid=fs.dpid, 
                                direction=fs.direction, 
                                port_number_s=fs.port_number_s, 
                                port_number_e=fs.port_number_e, 
                           )
        existing_fs = False
        for prev_dict_list in gfs_list:
          prev_dict = prev_dict_list[0]
          if fs_dict['flowspace'] == prev_dict['flowspace']:
            if openflow_dict not in prev_dict['openflow']:
              prev_dict['openflow'].append(openflow_dict)
            existing_fs = True
            break
        if not existing_fs:
          fs_dict['openflow'].append(openflow_dict) 
          fs_list = [fs_dict]
          gfs_list.append(fs_list)
      
      return gfs_list

    if slice_id in self.slice_info_dict:
        slice_urn = "urn:publicid:IDN+openflow:foam:"+ str(THIS_SITE_TAG) +"+slice+" + "id_" + str(slice_id) + "name_" + str(self.slice_info_dict[slice_id]['slice_name'])
    else:
        return [] 
    if GeniDB.sliceExists(slice_urn):
      sliv_urn = GeniDB.getSliverURN(slice_urn)
    else:
      return []
      #raise Exception(parseFVexception(e))
    sliver = GeniDB.getSliverObj(sliv_urn) 
    is_allocated_by_FV = GeniDB.getEnabled(sliv_urn)
    if is_allocated_by_FV == True:
      #that means that the flow space as requested was allocated
      #so retrieve the fs in the form Expedient understands
      #TODO: check that ecery time this corresponds to the actual flowspec that FOAM has
      #retrieve updated dict as a json file from foam db folder
      filedir = './opt/ofelia/ofam/local/db'
      filename = os.path.join(filedir, 'expedient_slices_info.json')
      if os.path.isfile(filename):
        f = open(filename, 'r')
        self.slice_info_dict = json.load(f)
        f.close()
      else:
        self._log.info("Slice is probably not started yet, doing nothing...")
        return []
      if slice_id not in self.slice_info_dict:
        raise Exception("Something went wrong with the fs recovery")
      all_efs = self.create_slice_fs(self.slice_info_dict[slice_id]['switch_slivers']) 
      gfs = []    
      try:    
        gfs = parse_granted_flowspaces(all_efs)
      except Exception,e:
        import traceback
        traceback.print_exc()
        self._log.exception("FlowSpace for the allocated slice is not returned")
        raise Exception(parseFVexception(e))
      #self._log.info("FlowSpace for the allocated slice is returned")
      #for fs_list in gfs:
      #  fs = fs_list[0]
      #  self._log.info(fs['flowspace'])
      #  self._log.info(fs['openflow'])
      if gfs == []:
        self._log.info("Empty FlowSpace for the allocated slice returned! Need to debug...")
      return gfs
    else:
      return [] 
     

  #modified, to be checked
  #@check_user
  #@check_fv_set
  #@rpcmethod()
dataset/ETHPy150Open fp7-ofelia/ocf/ofam/src/src/foam/api/legacyexpedientapi.py/AMLegExpAPI.pub_get_granted_flowspace/original