Verified Commit 463e39da authored by Aleksey Shirokih's avatar Aleksey Shirokih
Browse files

Merge branch 'master' of code.getnoc.com:noc/noc

parents 05710893 bf5a1dfd
......@@ -49,3 +49,4 @@ lib_pypy/
site-packages/
lib/tcl/
lib/tk/
docs/src/en/src/
......@@ -276,10 +276,13 @@ Build docs:
stage: Build docs
environment: docs
image: registry.getnoc.com/infrastructure/docs:master
before_script:
- NOC_SRC_PATH=${CI_PROJECT_DIR}
script:
- cd docs/
- sphinx-build -a -E -b html src/en ../build/docs/en
- python ./scripts/build-go.py ../build/docs/en/objects.inv
- set -x
- mkdir -p docs/src/en/src
- sphinx-build -a -E -j auto -b html docs/src/en build/docs/en
- python ./docs/scripts/build-go.py build/docs/en/objects.inv
tags:
- docker
artifacts:
......
......@@ -20,6 +20,7 @@ import ujson
import yaml
# NOC modules
from noc.core.mongo.connection import connect
from noc.core.management.base import BaseCommand
from noc.core.script.beef import Beef
from noc.sa.models.managedobjectselector import ManagedObjectSelector
......@@ -102,6 +103,7 @@ class Command(BaseCommand):
build_test_case_parser.add_argument("--test-path", type=unicode, help="Path name")
def handle(self, cmd, *args, **options):
connect()
return getattr(self, "handle_%s" % cmd.replace("-", "_"))(*args, **options)
def handle_collect(self, storage, path, spec, force, objects, *args, **options):
......
......@@ -14,6 +14,7 @@ import datetime
# NOC modules
from noc.config import config
from noc.core.mongo.connection import connect
from noc.core.management.base import BaseCommand
from noc.core.clickhouse.connect import connection
from noc.main.models.chpolicy import CHPolicy
......@@ -41,6 +42,7 @@ class Command(BaseCommand):
getattr(self, "handle_%s" % cmd)(*args, **options)
def handle_apply(self, host=None, port=None, dry_run=True, *args, **options):
connect()
read_only = dry_run
ch = connection(host, port, read_only=read_only)
today = datetime.date.today()
......
......@@ -14,6 +14,7 @@ import yaml
import ujson
# NOC modules
from noc.core.mongo.connection import connect
from noc.core.management.base import BaseCommand
from noc.main.models.remotesystem import RemoteSystem
......@@ -65,6 +66,7 @@ class Command(BaseCommand):
return yaml.safe_load(f)
def handle(self, cmd, *args, **options):
connect()
return getattr(self, "handle_%s" % cmd)(*args, **options)
def handle_load(self, *args, **options):
......
......@@ -21,6 +21,7 @@ import pytz
# NOC modules
from noc.core.management.base import BaseCommand, CommandError
from noc.core.mongo.connection import connect
from noc.sa.models.administrativedomain import AdministrativeDomain
from noc.main.models.pool import Pool
from noc.sa.models.managedobjectprofile import ManagedObjectProfile
......@@ -230,6 +231,7 @@ class Command(BaseCommand):
return r
def handle(self, *args, **options):
connect()
if options["verbosity"] >= 2:
self.logger.setLevel(logging.DEBUG)
else:
......
......@@ -11,6 +11,7 @@ import argparse
# NOC modules
from noc.core.management.base import BaseCommand
from noc.core.mongo.connection import connect
from noc.inv.models.interface import Interface
from noc.inv.models.interfaceprofile import InterfaceProfile
from noc.inv.models.interfaceclassificationrule import InterfaceClassificationRule
......@@ -35,6 +36,7 @@ class Command(BaseCommand):
apply_parser.add_argument("mos", nargs=argparse.REMAINDER, help="List of object to showing")
def handle(self, cmd, *args, **options):
connect()
if "mos" in options:
moo = options["mos"]
else:
......
......@@ -20,11 +20,11 @@ import sys
from pymongo import UpdateOne
# NOC modules
from noc.core.mongo.connection import connect
from noc.core.management.base import BaseCommand
from noc.core.scheduler.scheduler import Scheduler
from noc.main.models.pool import Pool
SHARDING_SCHEDULER = {"discovery", "correlator", "escalator"}
......@@ -47,6 +47,7 @@ class Command(BaseCommand):
@staticmethod
def scheduler(s):
connect()
scheduler, pool = "scheduler", "default"
if "." in s:
scheduler, pool = s.split(".")
......
......@@ -54,7 +54,7 @@ def _on_model_change(sender, instance, *args, **kwargs):
def _on_document_change(sender, document, *args, **kwargs):
_on_change(document, changed_fields=document._changed_fields)
_on_change(document, changed_fields=getattr(document, "_changed_fields", {}))
def _on_change(obj, changed_fields=None):
......
......@@ -26,46 +26,6 @@ def render_tc(value, base_type, format=None):
:param value: Binary string
:param base_type: Basic SNMP TC Type
:param format: Optional format string (DISPLAY-HINT)
Integer32 formatting
>>> render_tc(1234, "Integer32")
'1234'
>>> render_tc(1234, "Integer32", "x")
'4d2'
>>> render_tc(1234, "Integer32", "o")
'2322'
>>> render_tc(1234, "Integer32", "d")
'1234'
>>> render_tc(1234, "Integer32", "d-2")
'12.34'
>>> render_tc(1234, "Integer32", "d-4")
'0.1234'
>>> render_tc(1234, "Integer32", "d-6")
'0.001234'
OctetString formatting
>>> render_tc("\x80", "OctetString", "1x")
'80'
>>> render_tc("\x80\xff", "OctetString", "2x")
'80ff'
>>> render_tc("\x01\x02\x03\x04", "OctetString", "1d:1d:1d:1d")
'1:2:3:4'
>>> render_tc("\x80", "OctetString", "1d")
'128'
>>> render_tc("\x80\xff", "OctetString", "2d")
'33023'
>>> render_tc("\x80", "OctetString", "1o")
'200'
>>> render_tc("\x04\x74\x65\x73\x74", "OctetString", "*1a")
'test'
>>> render_tc("\x74\x65\x73\x74", "OctetString", "255a")
'test'
>>> render_tc("UTF8", "OctetString", "255t")
'UTF8'
>>> render_tc("abcdef", "OctetString", "1x:")
'61:62:63:64:65:66'
>>> render_tc("\x07\xde\x02\x02\x03*\x0b\x01+\x01\x01", "OctetString", "2d-1d-1d,1d:1d:1d.1d,1a1d:1d")
'2014-2-2,3:42:11.1,+1:1'
"""
if format is None:
# if base_type == "OctetString":
......
......@@ -3,30 +3,23 @@ services:
shell:
image: "registry.getnoc.com/infrastructure/docs:master"
restart: "no"
working_dir: /docs
volumes:
- .:/docs
- ../noc:/noc
apidoc:
image: "registry.getnoc.com/infrastructure/docs:master"
restart: "no"
working_dir: /docs
working_dir: /noc
environment:
NOC_SRC_PATH: /noc
volumes:
- .:/docs
- ../noc:/noc
command: sphinx-apidoc -o src/en/src /noc
- $PWD:/noc
html-en:
image: "registry.getnoc.com/infrastructure/docs:master"
restart: "no"
volumes:
- .:/docs
- ../noc:/noc
- $PWD:/noc
environment:
NOC_SRC_PATH: /noc
working_dir: /docs
command: sphinx-build -a -E -b html src/en build/en
working_dir: /noc
command: >
sh -c "mkdir -p docs/src/en/src build/docs/en
&& sphinx-build -a -E -j auto -b html docs/src/en build/docs/en"
html-en-inc:
image: "registry.getnoc.com/infrastructure/docs:master"
......
......@@ -20,6 +20,9 @@
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# Python modules
import datetime
import subprocess
import os
import sys
......@@ -28,13 +31,9 @@ NOC_SRC_PATH = os.getenv("NOC_SRC_PATH")
HAS_NOC_SRC = NOC_SRC_PATH and os.path.exists(NOC_SRC_PATH)
if HAS_NOC_SRC:
NOC_SRC_PATH = os.path.abspath(NOC_SRC_PATH)
sys.path.insert(0, os.path.dirname(NOC_SRC_PATH))
# Python modules
import datetime
import subprocess
import os
def get_branch():
try:
......@@ -66,9 +65,12 @@ extensions = [
"sphinxcontrib.mermaid",
"sphinxcontrib.httpdomain",
]
if HAS_NOC_SRC:
extensions += ["sphinx.ext.autodoc"]
# autoapi
extensions += ["autoapi.extension"]
autoapi_type = "python"
autoapi_dirs = [NOC_SRC_PATH]
autoapi_root = "src"
# Add any paths that contain templates here, relative to this directory.
templates_path = [".templates"]
......
......@@ -7,4 +7,4 @@ Source Code Reference
.. toctree::
:titlesonly:
/src/noc
/src/noc/index
......@@ -101,6 +101,10 @@ class SubInterface(Document):
def iter_changed_datastream(self, changed_fields=None):
if config.datastream.enable_managedobject:
yield "managedobject", self.managed_object.id
if config.datastream.enable_cfgsyslog and "ipv4_addresses" in changed_fields:
yield "cfgsyslog", self.managed_object.id
if config.datastream.enable_cfgtrap and "ipv4_addresses" in changed_fields:
yield "cfgtrap", self.managed_object.id
@property
def effective_vc_domain(self):
......
......@@ -541,7 +541,7 @@ class TableSection(ReportSection):
"<input type='hidden' name='content_type' value='text/csv; charset=utf8'>",
"<input type='hidden' name='filename' value='report.csv'>",
"<input type='hidden' name='data' id='csv_data'>",
"<input class='button' disabled type='submit' value='CSV' onclick='getData(\".report-table\", \",\");'>",
"<input class='button' disabled type='button' value='CSV' onclick='getData(\".report-table\", \",\");'>",
"<input class='button' disabled type='button' value='"
+ _("Print")
+ "'onclick='window.print()'>",
......@@ -552,8 +552,8 @@ class TableSection(ReportSection):
"function getData(t, delimiter) {",
" $('.button').attr('disabled','disabled');",
" setTimeout(function() {",
" var v = $(t).TableCSVExport({delivery: 'value', separator: ';'});",
" $('#csv_data').val($(t).TableCSVExport({delivery: 'value', separator: delimiter}));",
" var v = $(t).TableCSVExport({delivery: 'value', separator: delimiter});",
" $('#csv_data').val(v);",
" $('.button').prop('disabled', false);",
" $('#report').submit();",
" }, 0);",
......
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# Escape/unescape to various encodings
# ---------------------------------------------------------------------
# Copyright (C) 2007-2011 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -10,9 +10,6 @@
import binascii
#
# JSON
#
def json_escape(s):
"""
Escape JSON predefined sequences
......@@ -24,15 +21,9 @@ def json_escape(s):
return s.replace("\\", "\\\\").replace("\n", "\\n").replace('"', '\\"')
#
# Fault management
#
def fm_escape(s):
"""
Escape binary FM data to string
>>> fm_escape("ab\xffcd")
'ab=FFcd'
"""
return binascii.b2a_qp(str(s)).replace("=\n", "")
......@@ -40,8 +31,6 @@ def fm_escape(s):
def fm_unescape(s):
"""
Decode escaped FM data to a raw string
>>> fm_unescape("ab=FFcd")
'ab\\xffcd'
"""
return binascii.a2b_qp(str(s))
......@@ -16,9 +16,13 @@ from django.db import models
# NOC modules
from noc.core.model.base import NOCModel
from noc.lib.timepattern import TimePattern as TP
from noc.core.model.decorator import on_init
from noc.core.datastream.decorator import datastream
from .timepattern import TimePattern
@on_init
@datastream
@six.python_2_unicode_compatible
class TimePatternTerm(NOCModel):
"""
......@@ -53,3 +57,10 @@ class TimePatternTerm(NOCModel):
"""
TimePatternTerm.check_syntax(self.term)
super(TimePatternTerm, self).save(*args, **kwargs)
def iter_changed_datastream(self, changed_fields=None):
from noc.sa.models.managedobject import ManagedObject
for mo in ManagedObject.objects.filter(time_pattern=self.time_pattern):
for c in mo.iter_changed_datastream(changed_fields=changed_fields):
yield c
......@@ -25,11 +25,7 @@ from noc.core.interface.parameter import ORParameter # noqa
class NoneParameter(Parameter):
"""
>>> NoneParameter().clean(None)
>>> NoneParameter().clean("None") #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: NoneParameter: 'None'
Checks value is None
"""
def __init__(self, required=True):
......@@ -43,22 +39,7 @@ class NoneParameter(Parameter):
class StringParameter(Parameter):
"""
>>> StringParameter().clean("Test")
'Test'
>>> StringParameter().clean(10)
'10'
>>> StringParameter().clean(None)
'None'
>>> StringParameter(default="test").clean("no test")
'no test'
>>> StringParameter(default="test").clean(None)
'test'
>>> StringParameter(choices=["1","2"]).clean("1")
'1'
>>> StringParameter(choices=["1","2"]).clean("3") #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: StringParameter: '3'.
Check value is string
"""
def __init__(self, required=True, default=None, choices=None):
......@@ -79,6 +60,10 @@ class StringParameter(Parameter):
class UnicodeParameter(StringParameter):
"""
Check value is unicode
"""
def clean(self, value):
if value is None and self.default is not None:
return self.default
......@@ -93,20 +78,7 @@ class UnicodeParameter(StringParameter):
class REStringParameter(StringParameter):
"""
>>> REStringParameter("ex+p").clean("exp")
'exp'
>>> REStringParameter("ex+p").clean("exxp")
'exxp'
>>> REStringParameter("ex+p").clean("regexp 1")
'regexp 1'
>>> REStringParameter("ex+p").clean("ex") #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: REStringParameter: 'ex'
>>> REStringParameter("ex+p",default="exxp").clean("regexp 1")
'regexp 1'
>>> REStringParameter("ex+p",default="exxp").clean(None)
'exxp'
Check value is string matching regular expression
"""
def __init__(self, regexp, required=True, default=None):
......@@ -124,13 +96,7 @@ class REStringParameter(StringParameter):
class REParameter(StringParameter):
"""
Check Regular Expression
>>> REParameter().clean(".+?")
'.+?'
>>> REParameter().clean("+") #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: REParameter: '+'
Check value is valid regular expression
"""
def clean(self, value):
......@@ -143,13 +109,7 @@ class REParameter(StringParameter):
class PyExpParameter(StringParameter):
"""
Check python expression
>>> PyExpParameter().clean("(a + 3) * 7")
'(a + 3) * 7'
>>> PyExpParameter().clean("a =!= b") #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: REParameter: 'a =!= b'
Check value is valid python expression
"""
def clean(self, value):
......@@ -162,26 +122,7 @@ class PyExpParameter(StringParameter):
class BooleanParameter(Parameter):
"""
>>> BooleanParameter().clean(True)
True
>>> BooleanParameter().clean(False)
False
>>> BooleanParameter().clean("True")
True
>>> BooleanParameter().clean("yes")
True
>>> BooleanParameter().clean(1)
True
>>> BooleanParameter().clean(0)
False
>>> BooleanParameter().clean([]) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: BooleanParameter: [].
>>> BooleanParameter(default=False).clean(None)
False
>>> BooleanParameter(default=True).clean(None)
True
Check value is boolean
"""
def clean(self, value):
......@@ -201,35 +142,7 @@ class BooleanParameter(Parameter):
class IntParameter(Parameter):
"""
>>> IntParameter().clean(1)
1
>>> IntParameter().clean("1")
1
>>> IntParameter().clean("not a number") #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: IntParameter: 'not a number'
>>> IntParameter(min_value=10).clean(5) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: IntParameter: 5
>>> IntParameter(max_value=7).clean(10) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: IntParameter: 10
>>> IntParameter(max_value=10, default=7).clean(5)
5
>>> IntParameter(max_value=10, default=7).clean(None)
7
>>> IntParameter(max_value=10, default=15) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: IntParameter: 15
>>> IntParameter().clean(None) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: IntParameter: None
None
Check value is integer
"""
def __init__(self, required=True, default=None, min_value=None, max_value=None):
......@@ -253,30 +166,7 @@ class IntParameter(Parameter):
class FloatParameter(Parameter):
"""
>>> FloatParameter().clean(1.2)
1.2
>>> FloatParameter().clean("1.2")
1.2
>>> FloatParameter().clean("not a number") #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: FloatParameter: 'not a number'
>>> FloatParameter(min_value=10).clean(5) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: FloatParameter: 5
>>> FloatParameter(max_value=7).clean(10) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: FloatParameter: 10
>>> FloatParameter(max_value=10,default=7).clean(5)
5.0
>>> FloatParameter(max_value=10,default=7).clean(None)
7.0
>>> FloatParameter(max_value=10,default=15) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: FloatParameter: 15
Check value is float
"""
def __init__(self, required=True, default=None, min_value=None, max_value=None):
......@@ -300,6 +190,10 @@ class FloatParameter(Parameter):
class ListParameter(Parameter):
"""
Check value is list
"""
def clean(self, value):
if value is None and self.default is not None:
return self.default
......@@ -317,23 +211,7 @@ class ListParameter(Parameter):
class InstanceOfParameter(Parameter):
"""
>>> class C: pass
>>> class X: pass
>>> class CC(C): pass
>>> InstanceOfParameter(cls=C).clean(C()) and "Ok"
'Ok'
>>> InstanceOfParameter(cls=C).clean(CC()) and "Ok"
'Ok'
>>> InstanceOfParameter(cls=C).clean(1) and "Ok" #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: InstanceOfParameter: 1
>>> InstanceOfParameter(cls="C").clean(C()) and "Ok"
'Ok'
>>> InstanceOfParameter(cls="C").clean(1) and "Ok" #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: InstanceOfParameter: 1
Check value is an instance of class
"""
def __init__(self, cls, required=True, default=None):
......@@ -366,27 +244,7 @@ class InstanceOfParameter(Parameter):
class SubclassOfParameter(Parameter):
"""
>>> class C: pass
>>> class C1(C): pass
>>> class C2(C1): pass
>>> class C3(C1): pass
>>> SubclassOfParameter(cls=C).clean(C2) and "Ok"
'Ok'
>>> SubclassOfParameter(cls=C).clean(1) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: SubclassOfParameter: 1
>>> SubclassOfParameter(cls="C").clean(C2) and "Ok"
'Ok'
>>> SubclassOfParameter(cls=C).clean(1) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: SubclassOfParameter: 1
>>> SubclassOfParameter(cls=C2).clean(C3) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: SubclassOfParameter: <class base.C3>
>>> SubclassOfParameter(cls="C",required=False).clean(None)
Check value is subclass of given class
"""
def __init__(self, cls, required=True, default=None):
......@@ -430,26 +288,7 @@ class SubclassOfParameter(Parameter):
class ListOfParameter(ListParameter):
"""
>>> ListOfParameter(element=IntParameter()).clean([1,2,3])
[1, 2, 3]
>>> ListOfParameter(element=IntParameter()).clean([1,2,"3"])
[1, 2, 3]