Commit 1528c8ff authored by Aleksey Shirokih's avatar Aleksey Shirokih
Browse files

flake8 solutions dir

parent 012a409f
......@@ -10,5 +10,7 @@
# Copyright (C) 2007-2011 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
def drop_event(event):
event.drop()
......@@ -10,8 +10,10 @@
# Copyright (C) 2007-2010 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
def get_single_result(task):
mt=task.maptask_set.all()[0]
if mt.status!="C":
mt = task.maptask_set.all()[0]
if mt.status != "C":
return None
return mt.script_result
......@@ -11,40 +11,40 @@
# Copyright (C) 2007-2009 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
import types
def matrix_report(task):
data={}
cl={}
rl={}
data = {}
cl = {}
rl = {}
for mt in task.maptask_set.all():
r=mt.script_result
if type(r)!=types.DictType: # Only applicable to returned dicts
data["status",mt.managed_object.name]="Fail"
rl[mt.managed_object.name]=None
r = mt.script_result
if isinstance(r, dict): # Only applicable to returned dicts
data["status", mt.managed_object.name] = "Fail"
rl[mt.managed_object.name] = None
continue
for k,v in r.items():
data[k,mt.managed_object.name]=v
cl[k]=None
rl[mt.managed_object.name]=None
data["status",mt.managed_object.name]="Success"
rl[mt.managed_object.name]=None
cl=["status"]+sorted(cl.keys())
rl=sorted(rl.keys())
out=["<SCRIPT TYPE=\"text/javascript\" SRC=\"/static/js/jquery.svg.js\"></SCRIPT>"]
out+=["<SCRIPT TYPE=\"text/javascript\" SRC=\"/static/js/jquery.rotate_text.js\"></SCRIPT>"]
out+=["<script type=\"text/javascript\">$(document).ready(function() {$(\".vtext\").rotate_text();});</script>"]
out+=["<TABLE SUMMARY='' BORDER='1'>"]
out+=["<TR><TH></TH>%s</TR>"%"".join(["<TH><DIV CLASS='vtext'>%s</DIV</TH>"%c for c in cl])]
n=0
for k, v in r.items():
data[k, mt.managed_object.name] = v
cl[k] = None
rl[mt.managed_object.name] = None
data["status", mt.managed_object.name] = "Success"
rl[mt.managed_object.name] = None
cl = ["status"] + sorted(cl.keys())
rl = sorted(rl.keys())
out = ["<SCRIPT TYPE=\"text/javascript\" SRC=\"/static/js/jquery.svg.js\"></SCRIPT>"]
out += ["<SCRIPT TYPE=\"text/javascript\" SRC=\"/static/js/jquery.rotate_text.js\"></SCRIPT>"]
out += ["<script type=\"text/javascript\">$(document).ready(function() {$(\".vtext\").rotate_text();});</script>"]
out += ["<TABLE SUMMARY='' BORDER='1'>"]
out += ["<TR><TH></TH>%s</TR>" % "".join(["<TH><DIV CLASS='vtext'>%s</DIV</TH>" % c for c in cl])]
n = 0
for r in rl:
out+=["<TR CLASS='row%d'><TD><B>%s</B></TD>"%((n%2)+1,r)]
out += ["<TR CLASS='row%d'><TD><B>%s</B></TD>" % ((n % 2) + 1, r)]
for c in cl:
try:
out+=["<TD>%s</TD>"%data[c,r]]
out += ["<TD>%s</TD>" % data[c, r]]
except KeyError:
out+=["<TD>&nbsp;</TD>"]
out+=["</TR>"]
n+=1
out+=["</TABLE>"]
out += ["<TD>&nbsp;</TD>"]
out += ["</TR>"]
n += 1
out += ["</TABLE>"]
return "".join(out)
......@@ -11,6 +11,7 @@
# See LICENSE for details
# ---------------------------------------------------------------------
def mrt_result(task):
"""
Format MRT task result to return as JSON
......
......@@ -11,5 +11,6 @@
# See LICENSE for details
# ---------------------------------------------------------------------
def open_event(event):
event.open_event()
......@@ -13,31 +13,33 @@
# Python modules
import datetime
# NOC modules
from noc.peer.models.prefixlistcache import PrefixListCache
def prefix_list_provisioning(task,peering_point):
status={True:[],False:[]}
def prefix_list_provisioning(task, peering_point):
status = {True: [], False: []}
for mt in task.maptask_set.filter(status="C"):
r=mt.script_result
r = mt.script_result
if not r:
continue
for tr in r:
status[tr["status"]]+=[tr["name"]]
status[tr["status"]] += [tr["name"]]
if peering_point.prefix_list_notification_group:
r=["Provisioned prefix-lists at %s"%peering_point.hostname]
r = ["Provisioned prefix-lists at %s" % peering_point.hostname]
if status[True]:
r+=["Success: %s"%", ".join(status[True])]
r += ["Success: %s" % ", ".join(status[True])]
if status[False]:
r+=["Failed: %s"%", ".join(status[True])]
peering_point.prefix_list_notification_group.notify(subject="Prefix-List provisioning report for %s"%peering_point.hostname,body="\n".join(r))
r += ["Failed: %s" % ", ".join(status[True])]
peering_point.prefix_list_notification_group.notify(
subject="Prefix-List provisioning report for %s" % peering_point.hostname, body="\n".join(r))
# Update PrefixListCache
now=datetime.datetime.now()
now = datetime.datetime.now()
for name in status[True]:
try:
c=PrefixListCache.objects.get(peering_point=peering_point,name=name)
c.pushed=now
c = PrefixListCache.objects.get(peering_point=peering_point, name=name)
c.pushed = now
c.save()
except PrefixListCache.DoesNotExist:
continue
......@@ -19,6 +19,7 @@ DELAY = 600
discovery_scheduler = get_scheduler()
def refresh_config(event):
# Check managed object is managed
if not event.managed_object.is_managed:
......
......@@ -12,12 +12,17 @@
# ---------------------------------------------------------------------
import pprint
def result_report(task):
"""
Returns a table of: managed object, status, pretty-printed result
"""
out=["<table border='1'>","<thead>","<tr><th>Object</th><th>Status</th><th>Result</th></tr>","</thead>","<tbody>"]
out+=["<TR><TD>%s</TD><TD>%s</TD><TD><PRE>%s</PRE></TD></TR>"%(mt.managed_object.name,mt.status,pprint.pformat(mt.script_result))\
for mt in task.maptask_set.all()]
out+=["</tbody>","</table>"]
out = ["<table border='1'>", "<thead>", "<tr><th>Object</th><th>Status</th><th>Result</th></tr>", "</thead>",
"<tbody>"]
out += ["<TR><TD>%s</TD><TD>%s</TD><TD><PRE>%s</PRE></TD></TR>" % (
mt.managed_object.name,
mt.status,
pprint.pformat(mt.script_result)
) for mt in task.maptask_set.all()]
out += ["</tbody>", "</table>"]
return "\n".join(out)
......@@ -13,33 +13,33 @@
# ---------------------------------------------------------------------
def vc_provisioning(task,config):
created={}
removed={}
def vc_provisioning(task, config):
created = {}
removed = {}
for mt in task.maptask_set.filter(status="C"):
r=mt.script_result
r = mt.script_result
if not r:
continue
for vlan in r["created"]:
if vlan not in created:
created[vlan]=[mt.managed_object.name]
created[vlan] = [mt.managed_object.name]
else:
created[vlan]+=[mt.managed_object.name]
created[vlan] += [mt.managed_object.name]
for vlan in r["removed"]:
if vlan not in removed:
removed[vlan]=[mt.managed_object.name]
removed[vlan] = [mt.managed_object.name]
else:
removed[vlan]+=[mt.managed_object.name]
notification_group=config.notification_group
removed[vlan] += [mt.managed_object.name]
notification_group = config.notification_group
if notification_group and (created or removed):
r=[]
r = []
if created:
r+=["Created VLANs"]
r += ["Created VLANs"]
for vlan in sorted(created.keys()):
r+=[" %d: %s"%(vlan,", ".join([n for n in sorted(created[vlan])]))]
r += [" %d: %s" % (vlan, ", ".join([n for n in sorted(created[vlan])]))]
if removed:
r+=["Removed VLANs"]
r += ["Removed VLANs"]
for vlan in sorted(removed.keys()):
r+=[" %d: %s"%(vlan,", ".join([n for n in sorted(removed[vlan])]))]
notification_group.notify(subject="VLAN Provisioning Report for Domain '%s'"%config.vc_domain.name,
body="\n".join(r))
r += [" %d: %s" % (vlan, ", ".join([n for n in sorted(removed[vlan])]))]
notification_group.notify(subject="VLAN Provisioning Report for Domain '%s'" % config.vc_domain.name,
body="\n".join(r))
......@@ -20,8 +20,8 @@ def version_inventory(task):
changes = []
for mt in task.maptask_set.filter(status="C"):
mo = mt.managed_object
c = [] # name, old, new
for k,v in mt.script_result.items():
c = [] # name, old, new
for k, v in mt.script_result.items():
if k == "attributes":
for kk, vv in v.items():
ov = mo.get_attr(kk)
......@@ -34,7 +34,7 @@ def version_inventory(task):
mo.set_attr(k, v)
c += [(k, ov, v)]
if c:
changes += [mo.name+":"]
changes += [mo.name + ":"]
for name, old, new in c:
if old:
changes += [" %s: %s -> %s" % (name, old, new)]
......@@ -43,4 +43,4 @@ def version_inventory(task):
changes += []
if changes:
SystemNotification.notify(name="sa.version_inventory",
subject="Version inventory changes", body="\n".join(changes))
subject="Version inventory changes", body="\n".join(changes))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment