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


Python GeniDB.getSliverObj方法代码示例

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


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

示例1: renewSliver

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getSliverObj [as 别名]
def renewSliver (slice_urn, creds, exptime):
  from foam.geni.db import GeniDB

  sliver_urn = GeniDB.getSliverURN(slice_urn)

  reqexp = dateutil.parser.parse(str(exptime))
  reqexp = _asUTC(reqexp)

  max_expiration = _asUTC(datetime.datetime.utcnow()) + ConfigDB.getConfigItemByKey("geni.max-lease").getValue()

  if reqexp > max_expiration:
    raise BadSliverExpiration(
      "The requested expiration date (%s) is past the allowed maximum expiration (%s)." %
        (reqexp, max_expiration))

  for cred in creds:
    credexp = _asUTC(cred.expiration)
    if reqexp > credexp:
      continue
    else:
      GeniDB.updateSliverExpiration(sliver_urn, reqexp)
      sobj = GeniDB.getSliverObj(sliver_urn)
      sobj.resetExpireEmail()
      sobj.store()
      return sliver_urn

  raise BadSliverExpiration(
      "No credential found whose expiration is greater than or equal to the requested sliver expiration (%s)" %
        (reqexp))
开发者ID:HalasNet,项目名称:felix,代码行数:31,代码来源:lib.py

示例2: approveSliver

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getSliverObj [as 别名]
def approveSliver (request, logger):
  try:
    jsonValidate(request.json, [("sliver_urn", (unicode,str)), ("priority", int)], logger)

    if (not request.json.has_key("sliver_urn")) or (not request.json.has_key("priority")):
      return jsonify({"exception" : "You must specify a sliver_urn and priority"})
    slice_name = GeniDB.getFlowvisorSliceName(sliver_urn=request.json["sliver_urn"])
    if FV.sliceExists(slice_name):
      return jsonify({"Fault" : "Flowvisor slice '%s' already exists" % (slice_name)})

    sobj = GeniDB.getSliverObj(request.json["sliver_urn"])
    GeniDB.setSliverStatus(request.json["sliver_urn"], True)
    GeniDB.setSliverPriority(request.json["sliver_urn"], request.json["priority"])

    GeniDB.commit()

    foam.geni.approval.AppData.addSliver(sobj)

    sobj.createSlice()
    sobj.insertFlowspace(request.json["priority"])
    sobj.insertVirtualLink()

    data = GeniDB.getSliverData(sobj.getURN(), True)
    foam.task.emailApproveSliver(data)

    return jsonify(None)
  except JSONValidationError, e:
    jd = e.__json__()
    return jsonify(jd, code = 1, msg = jd["exception"])
开发者ID:HalasNet,项目名称:felix,代码行数:31,代码来源:lib.py

示例3: showSliver

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getSliverObj [as 别名]
  def showSliver (self):
#    from foam.core.tracer import Tracer
#    Tracer.enable()

    if not request.json:
      return

    try:
      return_obj = {}

      self.validate(request.json, [("sliver_urn", (unicode,str))])

      sobj = GeniDB.getSliverObj(request.json["sliver_urn"])
      return_obj["sliver"] = sobj

      if request.json.has_key("flowspace") and request.json["flowspace"]:
        return_obj["flowspace"] = sobj.generateFlowEntries()

      if request.json.has_key("flowspec") and request.json["flowspec"]:
        return_obj["flowspec"] = sobj.json_flowspec()

      if request.json.has_key("rspec") and request.json["rspec"]:
        return_obj["rspec"] = GeniDB.getRspec(request.json["sliver_urn"])

#      path = Tracer.disable()
#      self._log.debug("Tracer path: %s" % (path))

      return jsonify(return_obj)
    except JSONValidationError, e:
      jd = e.__json__()
      return jsonify(jd, code = 1, msg = jd["exception"])
开发者ID:HalasNet,项目名称:felix,代码行数:33,代码来源:admin.py

示例4: getSliverFlowspace

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getSliverObj [as 别名]
 def getSliverFlowspace (self):
   if not request.json:
     return
   try:
     self.validate(request.json, [("sliver_urn", (unicode,str))])
     sobj = GeniDB.getSliverObj(request.json["sliver_urn"])
     return jsonify({"flowspace" : sobj.generateFlowEntries()})
   except JSONValidationError, e:
     return jsonify(e.__json__())
开发者ID:HalasNet,项目名称:felix,代码行数:11,代码来源:admin.py

示例5: pub_change_slice_controller

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getSliverObj [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

示例6: emailPendingQueue

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getSliverObj [as 别名]
 def emailPendingQueue (self):
   try:
     lines = []
     pending_list = GeniDB.getSliverList(False, None)
     for sliver in pending_list:
       sobj = GeniDB.getSliverObj(sliver["sliver_urn"])
       lines.append("Sliver URN: %s" % sobj.getURN())
       lines.append("     User: %s [%s]" % (sobj.getEmail(), sobj.getUserURN()))
       lines.append("")
     if lines:
       self._log.info("[Daily Queue] Sending email for %d sliver(s)" % (len(lines)/3))
       queue = "\n".join(lines)
       foam.task.emailPendingQueue({"pending-queue" : queue})
       return jsonify(None)
     self._log.info("[Daily Queue] No pending slivers to email")
     return jsonify(None)
   except Exception, e:
     self._log.exception("Exception")
     return jsonify(None, code = 2, msg  = traceback.format_exc())
开发者ID:dana-i2cat,项目名称:felix,代码行数:21,代码来源:auto.py

示例7: rejectSliver

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getSliverObj [as 别名]
  def rejectSliver (self):
    if not request.json:
      return
    try:
      self.validate(request.json, [("sliver_urn", (unicode,str))])
      slice_name = GeniDB.getFlowvisorSliceName(sliver_urn=request.json["sliver_urn"])
      sobj = GeniDB.getSliverObj(request.json["sliver_urn"])

      data = GeniDB.getSliverData(sobj.getURN(), True)

      GeniDB.setSliverStatus(request.json["sliver_urn"], False)
      if FV.sliceExists(slice_name):
        FV.deleteSlice(slice_name)

      foam.task.emailRejectSliver(data)

      return jsonify(None)
    except JSONValidationError, e:
      jd = e.__json__()
      return jsonify(jd, code = 1, msg = jd["exception"])
开发者ID:HalasNet,项目名称:felix,代码行数:22,代码来源:admin.py

示例8: processExpirationEmails

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getSliverObj [as 别名]
 def processExpirationEmails (self):
   now = _asUTC(datetime.datetime.utcnow())
   self._log.debug("Expiration check: %s" % (str(now)))
   day_alert = []
   week_alert = []
   try:
     slivers = GeniDB.getSliverList(False)
     for sliver in slivers:
       sobj = GeniDB.getSliverObj(sliver["sliver_urn"])
       (urn, action) = sobj.emailCheck(now)
       if action == 1:
         day_alert.append(urn)
         self._log.info("[%s] Sent email for expiry within 30 hours" % (urn))
       elif action == 2:
         week_alert.append(urn)
         self._log.info("[%s] Sent email for expiry within 7 days" % (urn))
       else:
         self._log.debug("[%s] Expiration check: No email required for sliver expiration (%s)" % (urn, sobj.getExpiration()))
     return jsonify({"status" : "success", "day_alerts" : day_alert, "week_alerts" : week_alert})
   except Exception, e:
     self._log.exception("Exception")
     return jsonify(None, code = 2, msg  = traceback.format_exc())
开发者ID:dana-i2cat,项目名称:felix,代码行数:24,代码来源:auto.py

示例9: pub_get_granted_flowspace

# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getSliverObj [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


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