本文整理汇总了Python中steelscript.appfwk.apps.devices.devicemanager.DeviceManager.get_device方法的典型用法代码示例。如果您正苦于以下问题:Python DeviceManager.get_device方法的具体用法?Python DeviceManager.get_device怎么用?Python DeviceManager.get_device使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类steelscript.appfwk.apps.devices.devicemanager.DeviceManager
的用法示例。
在下文中一共展示了DeviceManager.get_device方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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))
示例2: test_get_devices_with_unknown_module
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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)
示例3: run
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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
示例4: analyze
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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)
示例5: run
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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
示例6: netshark_source_name_choices
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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
示例7: add_widgets_to_live_report
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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)
示例8: test_get_devices
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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'])
示例9: post
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
def post(self, request, data_type):
if data_type not in ['columns', 'sources']:
raise Http404
device = 'AppResponse'
if data_type == 'columns':
form = AppResponseColumnsInputForm(request.POST)
else:
form = AppResponseInputForm(request.POST)
results = None
if form.is_valid():
data = form.cleaned_data
ar = DeviceManager.get_device(data['device'])
if data_type == 'columns':
rawcols = ar.reports.sources[data['source']]['columns']
for col in rawcols.values():
if 'synthesized' in col:
synth = col['synthesized']
if isinstance(synth, dict):
col['synthesized'] = \
(', '.join(['{}: {}'.format(k, v)
for k, v in synth.iteritems()]))
colkeys = ['id', 'field', 'label', 'metric', 'type',
'unit', 'description', 'synthesized', 'grouped_by']
coldf = pandas.DataFrame(rawcols.values(), columns=colkeys)
coldf.fillna('---', inplace=True)
coldf['iskey'] = coldf['grouped_by'].apply(
lambda x: True if x is True else '---')
coldf.sort_values(by='id', inplace=True)
results = list(coldf.to_records(index=False))
else:
colkeys = ['name', 'filters_on_metrics', 'granularities',
'groups']
coldf = pandas.DataFrame(ar.reports.sources.values(),
columns=colkeys)
coldf['groups'] = coldf['name'].apply(
lambda x: ', '.join(report_source_to_groups[x]))
coldf.sort_values(by='name', inplace=True)
results = list(coldf.to_records(index=False))
serialized_sources = json.dumps(report_sources)
return render_to_response('help.html',
{'device': device,
'report_sources': serialized_sources,
'data_type': data_type,
'form': form,
'results': results},
context_instance=RequestContext(request))
示例10: run
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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)
示例11: netprofiler_live_templates
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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'
示例12: run
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
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))
示例13: netprofiler_hostgroup_types
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
def netprofiler_hostgroup_types(form, id, field_kwargs, params):
""" Query netprofiler for all hostgroup types. """
netprofiler_device = form.get_field_value('netprofiler_device', id)
if netprofiler_device == '':
choices = [('', '<No netprofiler device>')]
else:
netprofiler = DeviceManager.get_device(netprofiler_device)
choices = []
for hgt in netprofiler.api.host_group_types.get_all():
choices.append((hgt['name'], hgt['name']))
field_kwargs['label'] = 'HostGroupType'
field_kwargs['choices'] = choices
示例14: netprofiler_application_choices
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
def netprofiler_application_choices(form, id, field_kwargs, params):
# let's get all the applications and store them
netprofiler_device = form.get_field_value('netprofiler_device', id)
if netprofiler_device == '':
choices = [('', '<No netprofiler device>')]
else:
netprofiler = DeviceManager.get_device(netprofiler_device)
apps = get_netprofiler_apps(netprofiler)
# now we've got the apps return just name and id
choices = [(x['name'], x['name']) for x in apps]
field_kwargs['label'] = 'Application'
field_kwargs['choices'] = choices
示例15: run
# 需要导入模块: from steelscript.appfwk.apps.devices.devicemanager import DeviceManager [as 别名]
# 或者: from steelscript.appfwk.apps.devices.devicemanager.DeviceManager import get_device [as 别名]
def run(self):
""" Main execution method
"""
criteria = self.job.criteria
if criteria.solarwinds_device == '':
logger.debug('%s: No solarwinds device selected' % self.table)
self.job.mark_error("No Solarwinds Device Selected")
return False
sw = DeviceManager.get_device(criteria.solarwinds_device)
# TODO add queries
self.data = None
logger.info("SolarwindsTable job %s returning %s data" %
(self.job, len(self.data)))
return True