Commit 52e4197a authored by Aleksey Shirokih's avatar Aleksey Shirokih
Browse files

changes from config2 branch. have to be tested

--HG--
branch : feature/microservices
parent eaf1c831
......@@ -16,76 +16,6 @@
- config
- noc_config
- name: Set up noc.conf 1/2
ini_file:
dest: "{{noc_etc}}/noc.conf"
section: "{{item.section}}"
option: "{{item.option}}"
value: "{{item.value}}"
create: yes
no_log: true
with_items:
- section: main
option: secret_key
value: "{{ django_key }}"
- section: main
option: language_code
value: "{{ web_ui_language }}"
- section: database
option: name
value: "{{ noc_pg_db }}"
- section: database
option: user
value: "{{ noc_pg_user }}"
- section: database
option: password
value: "{{ noc_pg_password }}"
- section: database
option: host
value: "{{postgres_master}}"
- section: nosql_database
option: name
value: "{{ noc_mongo_db }}"
- section: nosql_database
option: user
value: "{{ noc_mongo_user }}"
- section: nosql_database
option: password
value: "{{ noc_mongo_password }}"
- section: nosql_database
option: host
value: "{{ groups['svc-mongod'] | join(',') }}"
- section: nosql_database
option: replica_set
value: "{{ noc_mongo_replicaset }}"
- section: customization
option: installation_name
value: "{{ noc_installation_name }}"
tags:
- config
- noc_config
- name: Set up noc.conf for sentry 2/2
ini_file:
dest: "{{noc_etc}}/noc.conf"
section: "{{item.section}}"
option: "{{item.option}}"
value: "{{item.value}}"
create: yes
no_log: true
with_items:
- section: main
option: sentry_url
value: "{{sentry_url}}"
- section: main
option: sentry_js_token
value: "{{sentry_js_token}}"
when: "sentry_secret_key is defined and sentry_secret_key
and sentry_js_token is defined and sentry_js_token"
tags:
- config
- noc_config
- name: install services templates
template:
src: "etc/services/{{item}}"
......@@ -121,25 +51,6 @@
- config
- noc_config
- name: install various configs
copy:
src: "etc/{{item.file}}"
dest: "{{item.dest}}"
owner: "{{noc_user}}"
mode: "0644"
with_items:
- file: fias.defaults
dest: "{{noc_etc}}/address/fias.defaults"
- file: babel.cfg
dest: "{{noc_etc}}/babel.cfg"
- file: beef.defaults
dest: "{{noc_etc}}/beef.defaults"
- file: noc.defaults
dest: "{{noc_etc}}/noc.defaults"
tags:
- config
- noc_config
- name: Build supervisor config
command: "{{ noc_root }}/scripts/deploy/apply-config {{ ansible_nodename }}"
register: result
......
- name: Install noc.pth
template:
src: "lib/python/site-packages/noc.pth.j2"
dest: "{{noc_root}}/lib/python/site-packages/noc.pth"
- name: Check sitecustomize
stat: path="{{noc_root}}/lib/python/site-packages/sitecustomize.py"
......
......@@ -29,11 +29,12 @@
- name: Create dirs
include: "dirs.yml"
- name: Include post install
include: "post_install.yml"
- name: Generate configs
include: "config.yml"
- name: Include noc hacks
include: "hacks.yml"
\ No newline at end of file
include: "hacks.yml"
- name: Include post install
include: "post_install.yml"
......@@ -48,6 +48,12 @@
tags:
- requirements
- name: Install noc.pth
template:
src: "lib/python/site-packages/noc.pth.j2"
dest: "{{noc_root}}/lib/python/site-packages/noc.pth"
- name: Apply local patches
command: "{{ noc_root }}/scripts/deploy/apply-patches"
args:
......
This diff is collapsed.
......@@ -12,7 +12,7 @@ import os
import yaml
# NOC modules
from base import BaseProtocol
from noc.config import config
class LegacyProtocol(BaseProtocol):
"""
......@@ -21,7 +21,7 @@ class LegacyProtocol(BaseProtocol):
legacy:///
"""
PATH = "etc/noc.yml"
PATH = config.path.legacy_config
NOC_MAPPINGS = [
("noc.installation_name", "installation_name"),
("noc.language", "language"),
......@@ -127,6 +127,9 @@ class LegacyProtocol(BaseProtocol):
# SyslogCollector
("syslogcollector.listen_syslog", "syslogcollector.listen"),
("syslogcollector-%(pool)s-%(node)s.listen_syslog", "syslogcollector.listen"),
#TgSender
("tgsender.token", "tgsender.token"),
("tgsender-global-%(node)s.token", "tgsender.token"),
# TrapCollector
("trapcollector.listen_traps", "trapcollector.listen"),
("trapcollector-%(pool)s-%(node)s.listen_traps", "trapcollector.listen"),
......
......@@ -10,6 +10,7 @@
from __future__ import print_function
import itertools
import os
import six
# Third-party modules
import yaml
# NOC modules
......@@ -57,10 +58,12 @@ class YAMLProtocol(BaseProtocol):
for pp in prefix[len(current):]:
r += ["%s%s:" % (self.INDENT * len(current), pp)]
current += [pp]
if isinstance(v, six.string_types) and v.startswith("%"):
v = "\\" + v
r += ["%s%s: %s" % (self.INDENT * len(current), p[-1], v)]
r = "\n".join(r)
if self.path:
with open(self.path, "w") as f:
f.write(r)
else:
print(r)
print(yaml.dump(yaml.load(r), default_flow_style=False))
......@@ -53,9 +53,6 @@ class Service(object):
"""
# Service name
name = None
# Format string to set process name
# config variables can be expanded as %(name)s
process_name = "noc-%(name).10s"
# Leader lock name
# Only one active instace per leader lock can be active
# at given moment
......@@ -73,6 +70,13 @@ class Service(object):
# to allow only one instance of services per node or datacenter
pooled = False
# Format string to set process name
# config variables can be expanded as %(name)s
if pooled:
process_name = "noc-%(name).10s-%(pool).5s"
else:
process_name = "noc-%(name).10s"
# Run NSQ writer on service startup
require_nsq_writer = False
# List of API instances
......@@ -488,17 +492,20 @@ class Service(object):
def get_register_tags(self):
tags = []
if self.traefik_backend and self.traefik_frontend_rule:
tags += [
"traefik.backend=%s" % self.traefik_backend,
"traefik.frontend.rule=%s" % self.traefik_frontend_rule
]
weight = self.get_backend_weight()
if weight:
tags += ["traefik.backend.weight=%s" % weight]
limit = self.get_backend_limit()
if limit:
tags += ["traefik.backend.maxconn.amount=%s" % limit]
if config.features.traefik:
if self.traefik_backend and self.traefik_frontend_rule:
tags += [
"traefik.tags=backend",
"traefik.backend=%s" % self.traefik_backend,
"traefik.frontend.rule=%s" % self.traefik_frontend_rule,
"traefik.backend.load-balancing=wrr"
]
weight = self.get_backend_weight()
if weight:
tags += ["traefik.backend.weight=%s" % weight]
limit = self.get_backend_limit()
if limit:
tags += ["traefik.backend.maxconn.amount=%s" % limit]
return tags
@tornado.gen.coroutine
......
......@@ -16,10 +16,11 @@ import os
# Third party modules
import six
import yaml
from noc.config import config
SUPERVISORD_CFG = "etc/noc_services.conf"
NOC_CFG = "etc/noc.yml"
SUPERVISORD_CFG = config.path.supervisor_cfg
NOC_CFG = config.path.legacy_config
ENV_MAP = {
"loglevel": "NOC_LOGLEVEL"
......@@ -120,4 +121,8 @@ def build(node):
print "CHANGED"
if __name__ == "__main__":
build(sys.argv[1])
if len(sys.argv) > 1:
build(sys.argv[1])
else:
build(config.node)
......@@ -11,8 +11,9 @@
import yaml
# NOC modules
from noc.main.models.pool import Pool
from noc.config import config
CONFIG = "etc/noc.yml"
CONFIG = config.path.legacy_config
def update_if_changed(pool, values):
changed = False
......
......@@ -10,8 +10,9 @@
import os
import subprocess
import stat
from noc.config import config
CYTHONIZE = "./bin/cythonize"
CYTHONIZE = config.path.cythonize
def main():
......
......@@ -14,10 +14,11 @@ import tempfile
import urllib2
import json
import shutil
from noc.config import config
class NPkg(object):
VAR = "var/pkg"
VAR = config.path.npkg_root
def __init__(self, config):
self.config = config
......
......@@ -26,7 +26,8 @@ class ActivatorAPI(API):
"""
name = "activator"
HTTP_CLIENT_DEFAULTS = dict(connect_timeout=20, request_timeout=30)
HTTP_CLIENT_DEFAULTS = dict(connect_timeout=config.activator.http_connect_timeout,
request_timeout=config.activator.http_request_timeout)
@api
@executor("script")
......@@ -146,9 +147,9 @@ class ActivatorAPI(API):
self.logger.debug("HTTP GET %s", url)
code, header, body = yield fetch(
url,
request_timeout=20,
request_timeout=config.activator.http_request_timeout,
follow_redirects=True,
validate_cert=False
validate_cert=config.activator.http_validate_cert
)
if 200 <= code <= 299:
raise tornado.gen.Return(body)
......
......@@ -11,14 +11,12 @@
from noc.core.service.base import Service
from api.activator import ActivatorAPI
class ActivatorService(Service):
name = "activator"
pooled = True
api = [
ActivatorAPI
]
process_name = "noc-%(name).10s-%(instance).2s-%(pool).3s"
def __init__(self):
super(ActivatorService, self).__init__()
......
......@@ -11,18 +11,19 @@
from noc.core.service.ui import UIService
from api.bi import BIAPI
from noc.core.service.authapi import AuthAPIRequestHandler
from noc.config import config
class BIService(UIService):
name = "bi"
process_name = "noc-%(name).10s-%(instance).2s"
api = [
BIAPI
]
api_request_handler = AuthAPIRequestHandler
use_translation = True
traefik_backend = "bi"
traefik_frontend_rule = "PathPrefix:/api/bi"
if config.features.traefik:
traefik_backend = "bi"
traefik_frontend_rule = "PathPrefix:/api/bi"
def __init__(self):
......
......@@ -21,13 +21,14 @@ from noc.core.service.ui import UIHandler
from noc.services.card.cards.base import BaseCard
from noc.core.debug import error_report
from noc.main.models import User
from noc.config import config
user_lock = Lock()
class CardRequestHandler(UIHandler):
CARDS = None
CARD_TEMPLATE_PATH = "services/card/templates/card.html.j2"
CARD_TEMPLATE_PATH = config.path.card_template_path
CARD_TEMPLATE = None
_user_cache = cachetools.TTLCache(maxsize=1000, ttl=60)
......
......@@ -19,6 +19,7 @@ from noc.sa.models.servicesummary import ServiceSummary, SummaryItem
from noc.gis.models.layer import Layer
from noc.inv.models.objectconnection import ObjectConnection
from noc.maintainance.models.maintainance import Maintainance
from noc.config import config
class AlarmHeatCard(BaseCard):
......@@ -36,7 +37,7 @@ class AlarmHeatCard(BaseCard):
default_template_name = "alarmheat"
_layer_cache = {}
TOOLTIP_LIMIT = 5
TOOLTIP_LIMIT = config.card.alarmheat_tooltip_limit
def get_data(self):
p = self.current_user.get_profile()
......
......@@ -11,17 +11,16 @@
from noc.core.service.ui import UIService
from card import CardRequestHandler
from search import SearchRequestHandler
from noc.config import config
class CardService(UIService):
name = "card"
process_name = "noc-%(name).10s-%(instance).2s"
use_translation = True
use_jinja = True
traefik_backend = "card"
traefik_frontend_rule = "PathPrefix:/api/card"
if config.features.traefik:
traefik_backend = "card"
traefik_frontend_rule = "PathPrefix:/api/card"
def get_handlers(self):
CardRequestHandler.load_cards()
......
......@@ -23,10 +23,8 @@ from noc.config import config
class CHWriterService(Service):
name = "chwriter"
process_name = "noc-%(name).10s"
# @fixme took better one from config with shard settings
HOST = os.environ.get("NOC_CLICKHOUSE_HOST", "clickhouse")
PORT = os.environ.get("NOC_CLICKHOUSE_PORT", 8123)
address = config.clickhouse.addresses
DB = config.clickhouse.db
def __init__(self):
......@@ -124,8 +122,8 @@ class CHWriterService(Service):
written = False
try:
response = yield client.fetch(
"http://%s:%s/?database=%s&query=%s" % (
self.HOST, self.PORT, self.DB,
"http://%s/?database=%s&query=%s" % (
self.address, self.DB,
channel.get_encoded_insert_sql()),
method="POST",
body=data
......
......@@ -80,9 +80,7 @@ class ClassifierService(Service):
name = "classifier"
leader_group_name = "classifier-%(pool)s"
pooled = True
process_name = "noc-%(name).10s-%(pool).2s"
DEFAULT_RULE = "Unknown | Default"
DEFAULT_RULE = config.classifier.default_rule
# SNMP OID pattern
rx_oid = re.compile(r"^(\d+\.){6,}")
......
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