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


Python devicemanager.DeviceManager类代码示例

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


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

示例1: put

    def put(self, request, *args, **kwargs):
        """ Function to save changes to multiple devices once.

        This function is called only when the "Save Changes" button is
        clicked on /devices/ page. However, it only supports enable/disable
        device(s). The url sent out will only include 'enable' field.
        """
        DeviceFormSet = modelformset_factory(Device,
                                             form=DeviceListForm,
                                             extra=0)
        formset = DeviceFormSet(request.DATA)

        if formset.is_valid():
            formset.save()
            DeviceManager.clear()
            messages.success(request._request,
                             'Changes successfully saved')
            if '/devices' not in request.META['HTTP_REFERER']:
                return HttpResponseRedirect(request.META['HTTP_REFERER'])
            else:
                return HttpResponseRedirect(reverse('device-list'))

        else:
            data = {'formset': formset, 'auth': Auth}
            return Response(data, template_name='device_list.html')
开发者ID:riverbed,项目名称:steelscript-appfwk,代码行数:25,代码来源:views.py

示例2: post

    def post(self, request):

        form = DeviceBatchForm(data=request.POST,
                               files=request.FILES)

        if not form.is_valid():
            return Response({'form': form},
                            template_name='device_batch.html')

        data = form.cleaned_data

        try:
            msg = StringIO()
            management.call_command('device', batch_file=data['batch_file'],
                                    stdout=msg)
            messages.add_message(request._request, messages.INFO,
                                 msg.getvalue())
        except CommandError as e:
            form._errors['batch_file'] = form.error_class([e])

            return Response({'form': form},
                            template_name='device_batch.html')

        DeviceManager.clear()

        return HttpResponseRedirect(reverse('device-list'))
开发者ID:riverbed,项目名称:steelscript-appfwk,代码行数:26,代码来源:views.py

示例3: post

    def post(self, request, device_type):
        if device_type == 'netprofiler':
            device = 'NetProfiler'
            form = NetProfilerInputForm(request.POST)
        elif device_type == 'netshark':
            device = 'NetShark'
            form = NetSharkInputForm(request.POST)
        else:
            raise Http404

        results = None
        if form.is_valid():
            data = form.cleaned_data
            if device_type == 'netprofiler':
                profiler = DeviceManager.get_device(data['device'])

                results = profiler.search_columns(realms=[data['realm']],
                                                  centricities=[data['centricity']],
                                                  groupbys=[data['groupby']])
                results.sort(key=operator.attrgetter('key'))
                results.sort(key=operator.attrgetter('iskey'), reverse=True)
                results = [(c.iskey, c.key, c.label, c.id) for c in results]
            elif device_type == 'netshark':
                shark = DeviceManager.get_device(data['device'])

                results = [(f.id, f.description, f.type) for f in shark.get_extractor_fields()]
                results.sort(key=operator.itemgetter(0))

        return render_to_response('help.html',
                                  {'device': device,
                                   'form': form,
                                   'results': results},
                                  context_instance=RequestContext(request))
开发者ID:carriercomm,项目名称:steelscript-appfwk,代码行数:33,代码来源:views.py

示例4: test_get_devices_with_unknown_module

 def test_get_devices_with_unknown_module(self):
     dev = copy.copy(self.dev)
     dev['id'] = 2
     dev['module'] = 'unknown_module'
     dev_obj = Device(**dev)
     dev_obj.save()
     with self.assertRaises(DeviceModuleNotFound):
         DeviceManager.get_device(2)
开发者ID:riverbed,项目名称:steelscript-appfwk,代码行数:8,代码来源:test_internal.py

示例5: analyze

    def analyze(self, jobs):
        criteria = self.job.criteria

        sharks_query_table = Table.from_ref(
            self.table.options.related_tables['basetable'])

        depjobs = {}

        # For every (shark, job), we spin off a new job to grab the data, then
        # merge everything into one dataframe at the end.
        for s in Device.objects.filter(module='netshark', enabled=True):
            shark = DeviceManager.get_device(s.id)

            for capjob in shark.get_capture_jobs():
                # Start with criteria from the primary table -- this gives us
                # endtime, duration and netshark_filterexpr.
                bytes_criteria = copy.copy(criteria)
                bytes_criteria.netshark_device = s.id
                bytes_criteria.netshark_source_name = 'jobs/' + capjob.name
                bytes_criteria.resolution = datetime.timedelta(0, 1)
                bytes_criteria.aggregated = True

                job = Job.create(table=sharks_query_table,
                                 criteria=bytes_criteria)

                depjobs[job.id] = job

        return QueryContinue(self.collect, depjobs)
开发者ID:riverbed,项目名称:steelscript-netshark,代码行数:28,代码来源:netshark_scanner_source.py

示例6: run

    def run(self):
        """ Main execution method
        """

        criteria = self.job.criteria

        if criteria.sharepoint_device == '':
            logger.debug('%s: No sharepoint device selected' % self.table)
            self.job.mark_error("No Sharepoint Device Selected")
            return False

        sp = DeviceManager.get_device(criteria.sharepoint_device)

        site = sp.get_site_object(self.table.options.site_url)

        site_instance = site.lists[self.table.options.list_name]
        fields = [tc.name for tc in self.table.get_columns(synthetic=False)]

        self.data = []
        for row in site_instance.rows:
            d = [getattr(row, f) for f in fields]
            self.data.append(d)

        logger.info("SharepointTable job %s returning %s data" %
                    (self.job, len(self.data)))

        return True
开发者ID:carriercomm,项目名称:steelscript-appfwk,代码行数:27,代码来源:sharepoint.py

示例7: __init__

    def __init__(self, *args, **kwargs):
        super(DeviceDetailForm, self).__init__(*args, **kwargs)

        modules = DeviceManager.get_modules()
        choices = zip(modules, modules)

        self.fields['module'] = forms.ChoiceField(choices=choices)
开发者ID:carriercomm,项目名称:steelscript-appfwk,代码行数:7,代码来源:forms.py

示例8: add_widgets_to_live_report

def add_widgets_to_live_report(report, template_id, widget_query_ids,
                               netprofiler_name=None):

    if netprofiler_name:
        netprofiler_id = Device.objects.filter(name=netprofiler_name)[0].id
    else:
        netprofiler_id = Device.objects.\
            filter(enabled=True, module='netprofiler')[0].id

    profiler = DeviceManager.get_device(netprofiler_id)

    lr = LiveReport(profiler, template_id)

    for wid, qid in widget_query_ids.items():
        q = [q for q in lr.queries if q.id.endswith(qid)][0]
        t = NetProfilerLiveTable.create(
            'live-{0}-{1}'.format(template_id, wid),
            netprofiler_id=netprofiler_id,
            template_id=template_id,
            query_id=q.id,
            widget_id=wid,
            cacheable=False)

        if q.is_time_series:
            widget_cls = yui3.TimeSeriesWidget
            t.add_column('time', 'Time', datatype='time', iskey=True)
        else:
            widget_cls = yui3.TableWidget

        widget_title = 'Template %s Widget %s' % (template_id, wid)
        report.add_widget(widget_cls, t, widget_title, width=12)
开发者ID:riverbed,项目名称:steelscript-netprofiler,代码行数:31,代码来源:netprofiler_live.py

示例9: run

    def run(self):
        """ Main execution method
        """

        criteria = self.job.criteria

        if criteria.netprofiler_device == '':
            logger.debug('%s: No netprofiler device selected' % (self.table))
            self.job.mark_error("No NetProfiler Device Selected")
            return False

        profiler = DeviceManager.get_device(criteria.netprofiler_device)

        columns = [col.name for col in self.table.get_columns(synthetic=False)]

        # This returns an array of rows, one row per device
        # Each row is a dict containing elements such as:
        #      id, ipaddr, name, type, type_id, and version
        with lock:
            devicedata = profiler.api.devices.get_all()

        # Convert to a DataFrame to make it easier to work with
        df = pandas.DataFrame(devicedata)

        for col in columns:
            if col not in df:
                raise KeyError("Devices table has no column '%s'" % col.name)

        df = df.ix[:,columns]

        self.data = df

        logger.info("DeviceTable job %s returning %d devices" % (self.job, len(self.data)))
        return True
开发者ID:riverbed,项目名称:steelscript-netprofiler,代码行数:34,代码来源:netprofiler_devices.py

示例10: netshark_source_name_choices

def netshark_source_name_choices(form, id, field_kwargs, params):
    """ Query netshark for available capture jobs / trace clips. """
    netshark_device = form.get_field_value('netshark_device', id)
    if netshark_device == '':
        label = 'Source'
        choices = [('', '<No netshark device>')]
    else:
        netshark = DeviceManager.get_device(netshark_device)
        #source_type = form.get_field_value('shark_source_type', id)
        source_type = 'job'

        choices = []
        if source_type == 'job':
            for job in netshark.get_capture_jobs():
                choices.append(('jobs/' + job.name, job.name))
            label = 'Capture Job'
        elif source_type == 'clip':
            # Not tested
            label = 'Trace Clip'
            for clip in netshark.get_clips():
                choices.append((clip, clip))
        else:
            raise KeyError('Unknown source type: %s' % source_type)

    field_kwargs['label'] = label
    field_kwargs['choices'] = choices
开发者ID:jr69ss,项目名称:steelscript-netshark,代码行数:26,代码来源:netshark.py

示例11: test_get_devices

    def test_get_devices(self):
        with patch("dev_pkg.new_device_instance", MockDevice):
            device = DeviceManager.get_device(1)

        self.assertEqual(device.host, self.dev['host'])
        self.assertEqual(device.port, self.dev['port'])
        self.assertEqual(device.auth.username, self.dev['username'])
        self.assertEqual(device.auth.password, self.dev['password'])
开发者ID:riverbed,项目名称:steelscript-appfwk,代码行数:8,代码来源:test_internal.py

示例12: __init__

    def __init__(self, *args, **kwargs):
        super(DeviceDetailForm, self).__init__(*args, **kwargs)

        modules = DeviceManager.get_modules()
        choices = zip(modules, modules)

        self.fields['module'] = forms.ChoiceField(
            choices=choices,
            widget=forms.Select(attrs={"onChange": 'changeMod()'}))
开发者ID:riverbed,项目名称:steelscript-appfwk,代码行数:9,代码来源:forms.py

示例13: run

    def run(self):

        criteria = self.job.criteria

        if criteria.scc_device == '':
            logger.debug('%s: No scc device selected' % (self.table))
            self.job.mark_error("No SCC Device Selected")
            return False

        columns = [col.name for col in self.table.get_columns(synthetic=False)]

        scc = DeviceManager.get_device(criteria.scc_device)

        # obtain the report class definition
        report_cls = get_scc_report_class(self.service, self.resource)

        # instatiate a report object
        report_obj = report_cls(scc)

        # Build criteria kwargs
        kwargs = {}
        for name in set(report_obj.required_fields +
                        report_obj.non_required_fields):
            # criteria has attrs as starttime, endtime
            # which maps to start_time and end_time
            # referenced in a SCC service
            if name in ['start_time', 'end_time']:
                name_in_criteria = name.replace('_', '')
            else:
                name_in_criteria = name

            if hasattr(criteria, name_in_criteria):
                kwargs[name] = getattr(criteria, name_in_criteria)
        report_obj.run(**kwargs)

        df = self.extract_dataframe(report_obj.data)

        if df is not None:
            for col in columns:
                if col not in df:
                    raise KeyError("Table %s has no column '%s'" %
                                   (self.job.table.name, col))

            df = df.ix[:, columns]

            self.data = df

            logger.info("SCC job %s returning %d rows of data" %
                        (self.job, len(self.data)))
        else:
            self.data = None
        return QueryComplete(self.data)
开发者ID:carriercomm,项目名称:steelscript-scc,代码行数:52,代码来源:scc.py

示例14: netprofiler_live_templates

def netprofiler_live_templates(form, id, field_kwargs):
    """Query netprofiler for available live templates. """
    netprofiler_device = form.get_field_value('netprofiler_device', id)
    if netprofiler_device == '':
        choices = [('', '<No netprofiler device>')]
    else:
        netprofiler = DeviceManager.get_device(netprofiler_device)

        choices = [(t['id'], t['name'])
                   for t in netprofiler.api.templates.get_live_templates()]

    field_kwargs['choices'] = choices
    field_kwargs['label'] = 'Live Template'
开发者ID:riverbed,项目名称:steelscript-netprofiler,代码行数:13,代码来源:netprofiler_live.py

示例15: run

    def run(self):

        criteria = self.job.criteria
        profiler = DeviceManager.get_device(criteria.netprofiler_device)
        widget_config = profiler.api.templates.get_config(criteria.template_id)
        recs = []
        for w in widget_config:
            dict0 = {'template_id': str(criteria.template_id)}
            dict1 = dict((k, w[k]) for k in ['widget_id', 'title'])
            dict2 = dict((k, w['config'][k]) for k in
                         ['widget_type', 'visualization', 'datasource'])
            recs.append(dict((k, v) for d in [dict0, dict1, dict2]
                             for k, v in d.items()))

        return QueryComplete(pd.DataFrame(recs))
开发者ID:riverbed,项目名称:steelscript-netprofiler,代码行数:15,代码来源:netprofiler_live.py


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