当前位置: 首页>>代码示例>>Python>>正文


Python GeniDB.sliceExists方法代码示例

本文整理汇总了Python中foam.geni.db.GeniDB.sliceExists方法的典型用法代码示例。如果您正苦于以下问题:Python GeniDB.sliceExists方法的具体用法?Python GeniDB.sliceExists怎么用?Python GeniDB.sliceExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在foam.geni.db.GeniDB的用法示例。


在下文中一共展示了GeniDB.sliceExists方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createSliver

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import sliceExists [as 别名]
def createSliver (slice_urn, credentials, rspec, user_info):
  flog = logging.getLogger('foam')

  if GeniDB.sliceExists(slice_urn):
    raise DuplicateSliver(slice_urn)

  creds = CredVerifier.fromStrings(credentials, "createsliver", slice_urn)
  try:
    s = StringIO(rspec)
    rspec_dom = ET.parse(s)
  except Exception, exc:
    flog.exception("XML rspec parsing error")
    raise RspecParseError(slice_urn, str(exc))
开发者ID:HalasNet,项目名称:felix,代码行数:15,代码来源:lib.py

示例2: pub_change_slice_controller

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import sliceExists [as 别名]
 def pub_change_slice_controller(self, slice_id, controller_url, **kwargs):
   slice_id   = slice_id.replace(":","_")
   slice_id   = slice_id.replace("name_","nam__")
   '''
   Changes the slice controller url.
   '''
   if slice_id not in self.slice_info_dict:
     self._log.info("Slice is probably not started yet, doing nothing...")
     return ""
     #raise Exception("Something went wrong with the fs recovery")
   #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 ""
   slice_of_rspec = create_ofv3_rspec(slice_id, self.slice_info_dict[slice_id]['project_name'], 
                                      self.slice_info_dict[slice_id]['project_desc'],
                                      self.slice_info_dict[slice_id]['slice_name'],
                                      self.slice_info_dict[slice_id]['slice_desc'], controller_url,
                                      self.slice_info_dict[slice_id]['owner_email'],
                                      self.slice_info_dict[slice_id]['owner_password'],
                                      self.slice_info_dict[slice_id]['switch_slivers'],
                                      self.create_slice_fs(self.slice_info_dict[slice_id]['switch_slivers']))
   self.slice_info_dict[slice_id]['controller_url'] = controller_url
   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'])
   creds = [] #creds are not needed at least for now: to be fixed
   user_info = {}
   user_info["urn"] = "urn:publicid:IDN+openflow:foam"+ str(THIS_SITE_TAG) +"+ch+" + "user+" + str(self.slice_info_dict[slice_id]['owner_email']) #temp hack
   user_info["email"] = str(self.slice_info_dict[slice_id]['owner_email'])
   if GeniDB.sliceExists(slice_urn):
     sliv_urn = GeniDB.getSliverURN(slice_urn)
   else:
     raise Exception("Something went wrong with the fs recovery, slice does not exist!")
   sliver = GeniDB.getSliverObj(sliv_urn) 
   is_allocated_by_FV = GeniDB.getEnabled(sliv_urn)
   was_allocated_by_FV = is_allocated_by_FV
   try:
     #old_exp_shutdown_success = legexpgapi2_apih.pub_Shutdown(slice_urn, creds, [])
     old_exp_shutdown_success = self.priv_DeleteSliver(slice_urn, creds, [])
   except Exception, e:
     import traceback
     traceback.print_exc()
     raise Exception("Exception while trying to shutdown old slice!")
开发者ID:HalasNet,项目名称:felix,代码行数:50,代码来源:legacyexpedientapi.py

示例3: pub_get_granted_flowspace

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import sliceExists [as 别名]
  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
开发者ID:HalasNet,项目名称:felix,代码行数:101,代码来源:legacyexpedientapi.py

示例4: pub_create_slice

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import sliceExists [as 别名]

#.........这里部分代码省略.........
        FlowVisor Web interface. Will need to be changed on initial login.
    @type owner_password: string
    
    @param switch_slivers: description of the topology and flowspace for slice
    @type switch_slivers: list of dicts
    
    @param kwargs: will contain additional useful information about the request.
        Of most use are the items in the C{kwargs['request'].META} dict. These
        include 'REMOTE_USER' which is the username of the user connecting or
        if using x509 certs then the domain name. Additionally, kwargs has the
        user using the 'user' key.
    
    @return: switches and links that have caused errors
    @rtype: dict
    '''
    slice_id   = slice_id.replace(":","_")
    slice_id   = slice_id.replace("name_","nam__")
    slice_name = slice_name.replace(":","_") 
    
#    self._actionLog.info("Legacy Expedient API: create_slice got the following:")
#    self._actionLog.info("    slice_id: %s" % slice_id)
#    self._actionLog.info("    project_name: %s" % project_name)
#    self._actionLog.info("    project_desc: %s" % project_description)
#    self._actionLog.info("    slice_name: %s" % slice_name)
#    self._actionLog.info("    slice_desc: %s" % slice_description)
#    self._actionLog.info("    controller: %s" % controller_url)
#    self._actionLog.info("    owner_email: %s" % owner_email)
#    self._actionLog.info("    owner_pass: %s" % owner_password)
    #self._actionLog.info("    switch_slivers"
    #pprint(switch_slivers, indent=8)
    
    #legacy experiment creation (old database access)
    '''    
    e = Experiment.objects.filter(slice_id=slice_id)
    if (e.count()>0):
      old_e = e[0]
      old_fv_name = old_e.get_fv_slice_name()
      update_exp = True
      old_exp_fs = ExperimentFLowSpace.objects.filtswier(exp=old_e)
    else:
      update_exp = False  
    '''  
  
#    e = Experiment()
#    e.slice_id = slice_id
#    e.project_name = project_name
#    e.project_desc = project_description
#    e.slice_name = slice_name
#    e.slice_desc = slice_description
#    e.controller_url = controller_url
#    e.owner_email = owner_email
#    e.owner_password = owner_password
#    e.save()
    #update dict info
    purged_switch_slivers = self.purge_switch_slivers_from_null_fs(switch_slivers)
    self.slice_info_dict[slice_id] = {}
    self.slice_info_dict[slice_id]['project_name'] = project_name
    self.slice_info_dict[slice_id]['project_desc'] = project_description
    self.slice_info_dict[slice_id]['slice_name'] = slice_name
    self.slice_info_dict[slice_id]['slice_desc'] = slice_description
    self.slice_info_dict[slice_id]['controller_url'] = controller_url
    self.slice_info_dict[slice_id]['owner_email'] = owner_email
    self.slice_info_dict[slice_id]['owner_password'] = owner_password
    self.slice_info_dict[slice_id]['switch_slivers'] = purged_switch_slivers
   
    all_efs = self.create_slice_fs(purged_switch_slivers)
    
    #set the necessary parameters so that we can use FOAM internal functions for sliver creation
    #Vasileios: now that the requested flowspaces are identified, create the rspec (to be used in FOAM)
    slice_of_rspec = create_ofv3_rspec(slice_id, project_name, project_description, \
                                      slice_name, slice_description, controller_url, \
                                      owner_email, owner_password, \
                                      purged_switch_slivers, all_efs)
    self._log.info(slice_of_rspec) #print the rspec in the log for debugging

    #form the slice URN according to http://groups.geni.net/geni/wiki/GeniApiIdentifiers
    slice_urn = "urn:publicid:IDN+openflow:foam:"+ str(THIS_SITE_TAG) +"+slice+" + "id_" + str(slice_id) + "name_" + str(slice_name) 
    creds = [] #creds are not needed at least for now: to be fixed
    user_info = {}
    user_info["urn"] = "urn:publicid:IDN+openflow:foam"+ str(THIS_SITE_TAG) +"+ch+" + "user+" + str(owner_email) #temp hack
    user_info["email"] = str(owner_email)
    
    #now we have: slice_urn, creds, rspec and user_info : great!
    update_exp = True    
    #if GeniDB.getSliverURN(slice_urn) is None:
    if not GeniDB.sliceExists(slice_urn):
      update_exp = False    

    #moving on (now use gapi2 calls)
    if (update_exp):
      try:
        #old_exp_fs.delete()
        #old_e.delete()
        old_exp_shutdown_success = self.priv_DeleteSliver(slice_urn, creds, [])
      except Exception, e:
        import traceback
        traceback.print_exc()
        raise Exception("Exception while trying to shutdown old slice!")
      if old_exp_shutdown_success == False:
        raise Exception("Old slice could not be shutdown")
开发者ID:HalasNet,项目名称:felix,代码行数:104,代码来源:legacyexpedientapi.py


注:本文中的foam.geni.db.GeniDB.sliceExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。