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


Python API类代码示例

本文整理汇总了Python中API的典型用法代码示例。如果您正苦于以下问题:Python API类的具体用法?Python API怎么用?Python API使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: index

    def index(self, length, span, type, site, **rest ):

        _span=3600 
        if span == 'days': _span=24*3600

        query_time = int(length)*_span
        end_time = time.time() - time.altzone
        start_time = end_time - query_time
 
        status_site_dict = {} 
        import Sites
        if site == 'all' :
            for st1,st2 in Sites.SiteMap().items():
                query =  API.getKeyNum( 'status_scheduler', st2, query_time ) 
                for a,b in query:
                    status_site_dict[b] = {str(st1).split('_')[2]:a}         
        else:
            site_to_query = Sites.SiteMap()[site]
            query = API.getKeyNum('status_scheduler', site_to_query, query_time ) 
            for a,b in query:
                status_site_dict[b] = {site:a}         
         
        if type == 'plot':
            html = self.TypePlot(span, length, site, status_site_dict)
        else:
            html = """<html><body><h2>NOT YET IMPLEMENTED """
         #   html += "Last %s %s</h2>\n " % ( length, span )
         #   html += self.TypeList(sites)
 
        return html
开发者ID:bbockelm,项目名称:CRAB,代码行数:30,代码来源:JobMon.py

示例2: Host_getVMList_Call

def Host_getVMList_Call(api, args):
    """
    This call is only interested in returning the VM UUIDs so pass False for
    the first argument in order to suppress verbose results.
    """
    API.updateTimestamp()  # required for editNetwork flow
    vmList = args.get('vmList', [])
    return API.Global().getVMList(False, vmList)
开发者ID:aiminickwong,项目名称:vdsm,代码行数:8,代码来源:Bridge.py

示例3: checkWorkerHeartbeat

def checkWorkerHeartbeat(events):
    for worker in API.getWorkers():
        if (datetime.now() - worker.heartbeat) > WORKER_HEARTBEAT_TIMEOUT:
            for schedule in API.getSchedules(worker):
                schedule.worker = API.getNextWorker()

            API.destroyWorker(worker)

    events.enter(WORKER_HEARTBEAT_TIMEOUT.total_seconds(), 1, checkWorkerHeartbeat, (events,))
开发者ID:nin-ten,项目名称:MegaCron,代码行数:9,代码来源:scheduler.py

示例4: test

    def test(self):
        API.updatecsv()
        a=sqldb.getDBbalance(MSISDN)
	print a
        makecall.Call(dur)
        b=sqldb.getDBbalance(MSISDN)
	print b
        c=format(a-b, '.2f')
        m1=mbilling.billingcalc(dur,rate)
        m2=format(m1, '.2f')
        self.assertEqual(float(c),float(m2))
开发者ID:jeevan449,项目名称:MyPracticeCode,代码行数:11,代码来源:testrun2.py

示例5: runSchedules

def runSchedules(events):
    global schedules

    if len(schedules) > 0:
        schedule = schedules[-1]
        secondsToNextRun = (schedule.timeToRun - datetime.now()).total_seconds()
        if secondsToNextRun <= 0:
            subprocess.call(schedule.job.command, shell=True)
            API.removeSchedule(schedule)
            schedules.pop()

        events.enter(secondsToNextRun, 1, runSchedules, (events,))
开发者ID:nin-ten,项目名称:MegaCron,代码行数:12,代码来源:worker.py

示例6: index

    def index(self, length , span, type, **rest):

        _span=3600
        if span == 'days': _span=24*3600

        query_time = int(length)*_span
        end_time = time.time() - time.altzone
        start_time = end_time - query_time

        dataset = API.getKeyNum_task('dataset',from_time=query_time)

        if not len(dataset): 
           html = """<html><body><h2> No dataset accessed  </h2>\n """
           html += """</body></html>"""
           return html

        data={}
        for num,dat in dataset:
            data[dat]= num

        if type == 'plot':
            html = self.DatasetGraph(span, length, data)
        else:
            html = self.DatasetList(data,query_time)

        return html
开发者ID:bbockelm,项目名称:CRAB,代码行数:26,代码来源:TaskMon.py

示例7: sync_predictions

def sync_predictions(routes, session):
    
    Logger.log.info("Syncing predictions...")
    Logger.log.info("Input routes: %s" % routes)

    if 'Red-Ashmont' in routes or 'Red-Braintree' in routes:
        routes.remove('Red-Ashmont')
        routes.remove('Red-Braintree')
        routes.append('Red')

    Logger.log.info("Using routes: %s" % routes)
    
    to_save = []

    route_string = ",".join(routes)
    data = API.get("predictionsbyroutes", {'routes': route_string})
    mode = data['mode']
    for route in mode:
        route_sub = route['route']
        for route_sub_sub in route_sub:
            route_name = route_sub_sub['route_id']
            Logger.log.info("Processing route %s" % route_name)
            for direction in route_sub_sub['direction']:
                for trip in direction['trip']:
                    api_trip_id = trip['trip_id']
                    trip_ref = session.query(db.Trip).filter(db.Trip.api_id == api_trip_id).first()
                    if trip_ref is None:
                        Logger.log.info('No trip record for this prediction. trip_api_id: %s' % api_trip_id)
                        continue
                    for stop in trip['stop']:
                        stop_name = stop['stop_name'].split(' -')[0]
                        
                        if 'JFK/UMASS' in stop_name:
                            stop_name = stop_name.split(' ')[0]
                        
                        try:
                            station_id = session.query(db.Station).filter(db.Station.route_id == trip_ref.route_id)\
                                .filter(db.Station.name_human_readable.like('%' + stop_name + '%')).first().id
                        
                        except AttributeError as e:
                            station_id = station_with_most_similar_name(session, trip_ref.route_id, stop_name)
                            
                        try:
                            seconds = stop['pre_away']
                            new_prediction_record = db.PredictionRecord(trip_id=trip_ref.id,
                                                                        stamp=datetime.datetime.utcnow(),
                                                                        station_id=station_id,
                                                                        seconds_away_from_stop=seconds)

                            to_save.append(new_prediction_record)
                        except KeyError as e:
                            continue
                            Logger.log.info('trip %s has terminated' % api_trip_id)

    for object in to_save:
        session.merge(object)

    session.commit()

    return to_save
开发者ID:nettube,项目名称:mbtapuller,代码行数:60,代码来源:APIFunctions.py

示例8: test_getDatasetDownload14

 def test_getDatasetDownload14(self):
     a = API.getDatasetDownload([1, 2, 3, 4])
     i = 0
     while i < len(a.items):
         b = a.items[i]
         self.assertIsInstance(b, classes.DatasetDownload)  ##make sure all items in list are download
         i += 1
开发者ID:scottsfarley93,项目名称:python-neotoma,代码行数:7,代码来源:tests.py

示例9: put

    def put(self, request):
        """
        Create a new VNF template. The 'vnf_id' assigned by the datastore is contained in the response.
        """
        if request.META['CONTENT_TYPE'] != 'application/json':
            return HttpResponse(status=415)

        if 'image-upload-status' not in request.data.keys():
            try:
                if 'functional-capability' not in request.data.keys():
                    return HttpResponse("Missing functional-capability field", status=400)
                capability = request.data['functional-capability']
                ValidateTemplate().validate(request.data)
                template = json.dumps(request.data)
                image_upload_status = VNF.REMOTE
            except:
                return HttpResponse(status=400)
        elif all(request.data['image-upload-status'] not in state for state in VNF.IMAGE_UPLOAD_STATUS):
            return HttpResponse("Wrong value of image-upload-status field", status=400)
        elif 'template' not in request.data.keys():
            return HttpResponse("Missing template field", status=400)
        else:
            try:
                if 'functional-capability' not in request.data['template'].keys():
                    return HttpResponse("Missing functional-capability field", status=400)
                capability = request.data['template']['functional-capability']
                ValidateTemplate().validate(request.data['template'])
                template = json.dumps(request.data['template'])
                image_upload_status = request.data['image-upload-status']
            except:
                return HttpResponse(status=400)

        vnf_id = API.addVNFTemplateV2(template, capability, image_upload_status)
        return HttpResponse(vnf_id, status=200)
开发者ID:netgroup-polito,项目名称:VNF-repository,代码行数:34,代码来源:views.py

示例10: delete

 def delete(self, request, yang_id):
     '''
     Delete a YANG model given the yang id
     '''
     if API.deleteYANG_model(yang_id):
         return HttpResponse(status=200)
     return HttpResponse(status=404)
开发者ID:netgroup-polito,项目名称:VNF-repository,代码行数:7,代码来源:views.py

示例11: search

def search(query):
  data = {
    'resources': 'volume',
    'field_list': ','.join(Series.fields)
  }
  search = API.search(query, data)
  return [Series(result) for result in search['results']]
开发者ID:sgtFloyd,项目名称:Vinery,代码行数:7,代码来源:Series.py

示例12: DatasetList

    def DatasetList(self, data,query_time):


          #                                           <td align="left"><a href=\"%s?dataset+%s\">%s</a></td>\
          #                                           self.baseDDUrl,'job::%s'%dataset,jobs,\
        
        html = "<html><body><h2>List of Dataset</h2>\n "
        html += '<table cellspacing="10" cellpadding=5>\n'
    
        st = ['Dataset name','Numeber of users','Number of tasks','Total Number of jobs','Efficiency']
        html += '<tr>'  
        for s in st:        
            html += '<th align="left"> %s</th>\n'%s
        html += '</tr>'  
        for dataset in data.keys():
            if dataset:
                html += '<tr>'  
                users  = API.countUsers(dataset,query_time)
                tasks  = API.countTasks(dataset,query_time)
                jobs  = API.countJobs(dataset,query_time)
                exitcodes=API.getJobExit(dataset,query_time) 
                if not len(exitcodes):
                    TotEff = 'Not yet available' 
                    eff = 'eff::%s::%s'%('None',dataset)
                else:  
                    tot = len(exitcodes) 
                    countSucc = 0
                    for appl, wrapp in exitcodes:
                        if wrapp == 0: countSucc += 1
                    TotEff = countSucc*1./tot
                    eff = 'eff::%s::%s'%(query_time,dataset)
                
                user = 'user::%s::%s'%(query_time,dataset)
                task = 'task::%s::%s'%(query_time,dataset)
                if dataset == 'None': dataset='User Private MC Production'
                html += '<td align="left">%s</td><td align="left"><a href=\"%s?user=%s\">%s</a></td>\
                                                     <td align="left"><a href=\"%s?task=%s\">%s</a></td>\
                                                     <td align="left">%s</td>\
                                                     <td align="left"><a href=\"%s?eff=%s\">%s</a></td>\n'\
                                                    %(str(dataset),self.baseDDUrl,user,users,\
                                                     self.baseDDUrl,task,tasks,\
                                                     jobs,\
                                                     self.baseDDUrl,eff,TotEff)
                html += '</tr>'  
        html += "</table>\n"
        html += """</body></html>"""
        return  html
开发者ID:bbockelm,项目名称:CRAB,代码行数:47,代码来源:TaskMon.py

示例13: get

 def get(self, request, yang_id):
     '''
     Retrieve a YANG model given the yang id
     '''
     yang = API.getYANG_model(yang_id)
     if yang is None:
         return HttpResponse(status=404)
     return Response(data=yang)
开发者ID:netgroup-polito,项目名称:VNF-repository,代码行数:8,代码来源:views.py

示例14: updateSchedules

def updateSchedules(events):
    global worker
    global schedules

    schedules = API.getSchedules(worker)
    runSchedules(events)

    events.enter(SCHEDULES_UPDATE_INTERVAL.total_seconds(), 1, updateSchedules, (events,))
开发者ID:nin-ten,项目名称:MegaCron,代码行数:8,代码来源:worker.py

示例15: post

 def post(self, request, yang_id):
     '''
     Insert a new YANG model into the repository.
     Before saving the yang model into the DB, it is checked that the it is sintactically correct
     '''
     yang_model = request.data
     res = API.addYANG_model(yang_id, yang_model)
     return HttpResponse(status=200)
开发者ID:netgroup-polito,项目名称:VNF-repository,代码行数:8,代码来源:views.py


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