Verified Commit 03b26995 authored by Aleksey Shirokih's avatar Aleksey Shirokih
Browse files

Merge

parents 716aee0f 0d9c71ea
......@@ -52,7 +52,7 @@ services:
postgres:
condition: service_healthy
mongodb-repl-set-init:
condition: service_started
condition: service_healthy
clickhouse:
condition: service_started
command: >
......
......@@ -33,5 +33,24 @@ mongo --host "$mongo_config_host" \
});
rs.initiate(rsConfig);
EOJS
for t in $(seq 120);do
mongo --host "$mongo_config_host" \
--username "$MONGO_INITDB_ROOT_USERNAME" \
--password "$MONGO_INITDB_ROOT_PASSWORD" \
--authenticationDatabase admin \
admin \
--eval 'rs.status()' | grep '"stateStr" : "PRIMARY"'
retVal=$?
if [ $retVal -eq 0 ]; then
echo "mongo has primary"
break
else
echo "mongo still not active. waiting 0.7s"
fi
sleep 0.7
done
echo healthy > /tmp/job_is_done
sleep 60
......@@ -210,6 +210,9 @@ Build docs:
paths:
- build/docs/en
expire_in: 1 day
only:
changes:
- docs/**
Build release image:
stage: Build release container
......
......@@ -56,7 +56,7 @@ class Migration(BaseMigration):
self.db.create_table(
"auth_user_groups", (
("id", models.AutoField(verbose_name="ID", primary_key=True, auto_created=True)),
("user", models.ForeignKey(User, null=False)),
("group", models.ForeignKey(Group, null=False))
("user", models.ForeignKey(User, null=False, on_delete=models.CASCADE)),
("group", models.ForeignKey(Group, null=False, on_delete=models.CASCADE))
)
)
......@@ -37,8 +37,8 @@ class Migration(BaseMigration):
self.db.create_table(
"main_permission_groups", (
("id", models.AutoField(verbose_name="ID", primary_key=True, auto_created=True)),
("permission", models.ForeignKey(Permission, null=False)),
("group", models.ForeignKey(Group, null=False))
("permission", models.ForeignKey(Permission, null=False, on_delete=models.CASCADE)),
("group", models.ForeignKey(Group, null=False, on_delete=models.CASCADE))
)
)
......@@ -50,7 +50,7 @@ class Migration(BaseMigration):
self.db.create_table(
"main_permission_users", (
("id", models.AutoField(verbose_name="ID", primary_key=True, auto_created=True)),
("permission", models.ForeignKey(Permission, null=False)),
("user", models.ForeignKey(User, null=False))
("permission", models.ForeignKey(Permission, null=False, on_delete=models.CASCADE)),
("user", models.ForeignKey(User, null=False, on_delete=models.CASCADE))
)
)
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# Remove UserProfile
# ----------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Third-party modules
from django.db import models
# NOC modules
from noc.core.migration.base import BaseMigration
from noc.settings import LANGUAGE_CODE
class Migration(BaseMigration):
depends_on = [
("main", "0056_userprofile_heatmap")
]
def migrate(self):
# Add fields to user
self.db.add_column(
"auth_user",
"preferred_language",
models.CharField("Preferred Language", max_length=16, null=True, blank=True, default=LANGUAGE_CODE)
)
self.db.add_column("auth_user", "heatmap_lon", models.FloatField("Longitude", blank=True, null=True))
self.db.add_column("auth_user", "heatmap_lat", models.FloatField("Latitude", blank=True, null=True))
self.db.add_column("auth_user", "heatmap_zoom", models.IntegerField("Zoom", blank=True, null=True))
# UserContacts
User = self.db.mock_model(
model_name="User",
db_table="auth_user"
)
TimePattern = self.db.mock_model(
model_name="TimePattern",
db_table="main_timepattern"
)
self.db.create_table(
"aaa_usercontact", (
("id", models.AutoField(primary_key=True)),
("user", models.ForeignKey(User, verbose_name="User", on_delete=models.CASCADE)),
("notification_method", models.CharField("Method", max_length=16)),
("params", models.CharField("Params", max_length=256)),
("time_pattern", models.ForeignKey(TimePattern, verbose_name="Time Pattern", on_delete=models.CASCADE))
)
)
# Creating unique_together for [user_profile, time_pattern, notification_method, params] on UserProfileContact.
self.db.create_index(
"aaa_usercontact", ["user_id", "time_pattern_id", "notification_method", "params"],
unique=True
)
# Update users
p_map = {} # profile_id -> user_id
data = self.db.execute(
"SELECT id, user_id, preferred_language, heatmap_lon, heatmap_lat, heatmap_zoom "
"FROM main_userprofile"
)
for p_id, user_id, preferred_language, heatmap_lon, heatmap_lat, heatmap_zoom in data:
self.db.execute(
"UPDATE auth_user "
"SET preferred_language=%s, heatmap_lon=%s, heatmap_lat=%s, heatmap_zoom=%s "
"WHERE id = %s",
[preferred_language, heatmap_lon, heatmap_lat, heatmap_zoom, user_id]
)
p_map[p_id] = user_id
# Move contacts
data = self.db.execute(
"SELECT user_profile_id, notification_method, params, time_pattern_id "
"FROM main_userprofilecontact"
)
for p_id, notification_method, params, time_pattern_id in data:
self.db.execute(
"INSERT INTO aaa_usercontact(user_id, notification_method, params, time_pattern_id) "
"VALUES(%s, %s, %s, %s)",
[p_map[p_id], notification_method, params, time_pattern_id]
)
# Delete profiles and contacts
self.db.delete_table("main_userprofilecontact")
self.db.delete_table("main_userprofile")
......@@ -14,19 +14,22 @@ import cachetools
import six
from django.db import models
# NOC modules
from noc.core.model.hacks import tuck_up_pants
from noc.core.model.base import NOCModel
from noc.core.model.decorator import on_delete_check
id_lock = Lock()
@tuck_up_pants
@on_delete_check(check=[
("sa.GroupAccess", "group")
])
@six.python_2_unicode_compatible
class Group(models.Model):
class Group(NOCModel):
class Meta(object):
verbose_name = "Group"
verbose_name_plural = "Groups"
app_label = "aaa"
# Point to django's auth_user table
# Point to django"s auth_user table
db_table = "auth_group"
ordering = ["name"]
......
......@@ -15,17 +15,16 @@ import six
from django.db.models import Model, CharField, ManyToManyField
import cachetools
# NOC modules
from noc.core.model.base import NOCModel
from noc.aaa.models.user import User
from noc.aaa.models.group import Group
from noc.core.model.hacks import tuck_up_pants
perm_lock = Lock()
id_lock = Lock()
@tuck_up_pants
@six.python_2_unicode_compatible
class Permission(Model):
class Permission(NOCModel):
"""
Permissions.
......
......@@ -18,16 +18,30 @@ from django.db import models
from django.core import validators
from django.contrib.auth.hashers import check_password, make_password
# NOC modules
from noc.core.model.hacks import tuck_up_pants
from noc.core.model.base import NOCModel
from noc.core.model.decorator import on_delete_check
from noc.core.translation import ugettext as _
from noc.settings import LANGUAGE_CODE, LANGUAGES
from .group import Group
id_lock = Lock()
@tuck_up_pants
@on_delete_check(check=[
("kb.KBEntryPreviewLog", "user"),
("aaa.UserContact", "user"),
("sa.UserAccess", "user"),
("kb.KBUserBookmark", "user"),
("main.Checkpoint", "user"),
("main.NotificationGroupUser", "user"),
("main.ReportSubscription", "run_as"),
("ip.PrefixBookmark", "user"),
("kb.KBEntryHistory", "user"),
("ip.PrefixAccess", "user"),
("main.Favorites", "user")
])
@six.python_2_unicode_compatible
class User(models.Model):
class User(NOCModel):
class Meta(object):
verbose_name = "User"
verbose_name_plural = "Users"
......@@ -66,6 +80,17 @@ class User(models.Model):
"his/her group."),
related_name="user_set", related_query_name="user"
)
# Custom profile
preferred_language = models.CharField(
max_length=16,
null=True, blank=True,
default=LANGUAGE_CODE,
choices=LANGUAGES
)
# Heatmap position
heatmap_lon = models.FloatField("Longitude", blank=True, null=True)
heatmap_lat = models.FloatField("Latitude", blank=True, null=True)
heatmap_zoom = models.IntegerField("Zoom", blank=True, null=True)
_id_cache=cachetools.TTLCache(maxsize=100, ttl=60)
_name_cache = cachetools.TTLCache(maxsize=100, ttl=60)
......@@ -103,3 +128,24 @@ class User(models.Model):
self.save(update_fields=["password"])
return check_password(raw_password, self.password, setter)
@property
def contacts(self):
from .usercontact import UserContact
return [
(c.time_pattern, c.notification_method, c.params)
for c in UserContact.objects.filter(user=self)]
@property
def active_contacts(self):
"""
Get list of currently active contacts
:returns: List of (method, params)
"""
now = datetime.datetime.now()
return [
(c.notification_method, c.params)
for c in self.contacts if c.time_pattern.match(now)
]
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# UserProfileContact model
# UserContact model
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
......@@ -8,39 +8,34 @@
# Python modules
from __future__ import absolute_import
# Third-party modules modules
# Third-party modules
import six
from django.db import models
# NOC modules
from noc.core.model.hacks import tuck_up_pants
from .userprofile import UserProfile
from .timepattern import TimePattern
from .notificationgroup import USER_NOTIFICATION_METHOD_CHOICES
from noc.core.model.base import NOCModel
from noc.main.models.timepattern import TimePattern
from noc.main.models. notificationgroup import USER_NOTIFICATION_METHOD_CHOICES
from .user import User
@tuck_up_pants
@six.python_2_unicode_compatible
class UserProfileContact(models.Model):
class UserContact(NOCModel):
class Meta(object):
verbose_name = "User Profile Contact"
verbose_name_plural = "User Profile Contacts"
unique_together = [("user_profile", "time_pattern",
unique_together = [("user", "time_pattern",
"notification_method", "params")]
app_label = "main"
db_table = "main_userprofilecontact"
app_label = "aaa"
db_table = "aaa_usercontact"
user_profile = models.ForeignKey(
UserProfile, verbose_name="User Profile")
time_pattern = models.ForeignKey(
TimePattern, verbose_name="Time Pattern")
notification_method = models.CharField(
"Method", max_length=16,
choices=USER_NOTIFICATION_METHOD_CHOICES)
user = models.ForeignKey(User, verbose_name="User", on_delete=models.CASCADE)
time_pattern = models.ForeignKey(TimePattern, verbose_name="Time Pattern", on_delete=models.CASCADE)
notification_method = models.CharField("Method", max_length=16, choices=USER_NOTIFICATION_METHOD_CHOICES)
params = models.CharField("Params", max_length=256)
def __str__(self):
return "%s %s %s" % (
self.user_profile.user.username,
return u"%s %s %s" % (
self.user.username,
self.time_pattern.name,
self.notification_method
)
......@@ -53,8 +53,8 @@ class Migration(BaseMigration):
self.db.create_table(
'cm_object_categories', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('object', models.ForeignKey(Object, null=False)),
('objectcategory', models.ForeignKey(ObjectCategory, null=False))
('object', models.ForeignKey(Object, null=False, on_delete=models.CASCADE)),
('objectcategory', models.ForeignKey(ObjectCategory, null=False, on_delete=models.CASCADE))
)
)
self.db.create_index('cm_object', ['handler_class_name', 'repo_path'], unique=True)
......@@ -33,7 +33,7 @@ class Migration(BaseMigration):
("pull_every", models.PositiveIntegerField("Pull Every (secs)", default=86400, blank=True, null=True)),
("next_pull", models.DateTimeField("Next Pull", blank=True, null=True)),
("last_pull", models.DateTimeField("Last Pull", blank=True, null=True)),
("activator", models.ForeignKey(Activator, verbose_name="Activator")),
("activator", models.ForeignKey(Activator, verbose_name="Activator", on_delete=models.CASCADE)),
("profile_name", models.CharField("Profile", max_length=128)),
("scheme", models.IntegerField("Scheme", choices=SCHEME_CHOICES)),
("address", models.CharField("Address", max_length=64)),
......@@ -58,8 +58,8 @@ class Migration(BaseMigration):
self.db.create_table(
"cm_config_categories", (
("id", models.AutoField(verbose_name="ID", primary_key=True, auto_created=True)),
("config", models.ForeignKey(Config, null=False)),
("objectcategory", models.ForeignKey(ObjectCategory, null=False))
("config", models.ForeignKey(Config, null=False, on_delete=models.CASCADE)),
("objectcategory", models.ForeignKey(ObjectCategory, null=False, on_delete=models.CASCADE))
)
)
# Model "PrefixList"
......@@ -89,8 +89,8 @@ class Migration(BaseMigration):
self.db.create_table(
"cm_prefixlist_categories", (
("id", models.AutoField(verbose_name="ID", primary_key=True, auto_created=True)),
("prefixlist", models.ForeignKey(PrefixList, null=False)),
("objectcategory", models.ForeignKey(ObjectCategory, null=False))
("prefixlist", models.ForeignKey(PrefixList, null=False, on_delete=models.CASCADE)),
("objectcategory", models.ForeignKey(ObjectCategory, null=False, on_delete=models.CASCADE))
)
)
# Model "DNS"
......@@ -121,7 +121,7 @@ class Migration(BaseMigration):
self.db.create_table(
"cm_dns_categories", (
("id", models.AutoField(verbose_name="ID", primary_key=True, auto_created=True)),
("dns", models.ForeignKey(DNS, null=False)),
("objectcategory", models.ForeignKey(ObjectCategory, null=False))
("dns", models.ForeignKey(DNS, null=False, on_delete=models.CASCADE)),
("objectcategory", models.ForeignKey(ObjectCategory, null=False, on_delete=models.CASCADE))
)
)
......@@ -41,7 +41,7 @@ class Migration(BaseMigration):
self.db.create_table(
'cm_rpsl_categories', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('rpsl', models.ForeignKey(RPSL, null=False)),
('objectcategory', models.ForeignKey(ObjectCategory, null=False))
('rpsl', models.ForeignKey(RPSL, null=False, on_delete=models.CASCADE)),
('objectcategory', models.ForeignKey(ObjectCategory, null=False, on_delete=models.CASCADE))
)
)
......@@ -38,7 +38,10 @@ class Migration(BaseMigration):
loc_id = self.db.execute("SELECT id FROM cm_objectlocation WHERE name=%s", ["default"])[0][0]
for ot in OBJECT_TYPES:
self.db.add_column("cm_%s" % ot, "location", models.ForeignKey(ObjectLocation, null=True, blank=True))
self.db.add_column(
"cm_%s" % ot,
"location",
models.ForeignKey(ObjectLocation, null=True, blank=True, on_delete=models.CASCADE))
self.db.execute("UPDATE cm_%s SET location_id=%%s" % ot, [loc_id])
self.db.execute("ALTER TABLE cm_%s ALTER location_id SET NOT NULL" % ot)
......@@ -61,9 +64,9 @@ class Migration(BaseMigration):
'cm_objectaccess', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('type', models.CharField("Type", max_length=16, choices=OBJECT_TYPE_CHOICES)),
('category', models.ForeignKey(ObjectCategory, verbose_name="Category", blank=True, null=True)),
('location', models.ForeignKey(ObjectLocation, verbose_name="Location", blank=True, null=True)),
('user', models.ForeignKey(User, verbose_name=User))
('category', models.ForeignKey(ObjectCategory, verbose_name="Category", blank=True, null=True, on_delete=models.CASCADE)),
('location', models.ForeignKey(ObjectLocation, verbose_name="Location", blank=True, null=True, on_delete=models.CASCADE)),
('user', models.ForeignKey(User, verbose_name=User, on_delete=models.CASCADE))
)
)
......@@ -82,8 +85,8 @@ class Migration(BaseMigration):
'cm_objectnotify', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('type', models.CharField("Type", max_length=16, choices=OBJECT_TYPE_CHOICES)),
('category', models.ForeignKey(ObjectCategory, verbose_name="Category", blank=True, null=True)),
('location', models.ForeignKey(ObjectLocation, verbose_name="Location", blank=True, null=True)),
('category', models.ForeignKey(ObjectCategory, verbose_name="Category", blank=True, null=True, on_delete=models.CASCADE)),
('location', models.ForeignKey(ObjectLocation, verbose_name="Location", blank=True, null=True, on_delete=models.CASCADE)),
('emails', models.CharField("Emails", max_length=128)),
('notify_immediately', models.BooleanField("Notify Immediately")),
('notify_delayed', models.BooleanField("Notify Delayed")),
......
......@@ -14,7 +14,7 @@ from noc.core.migration.base import BaseMigration
class Migration(BaseMigration):
def migrate(self):
self.db.add_column("cm_config", "trap_source_ip", models.IPAddressField("Trap Source IP", blank=True, null=True))
self.db.add_column("cm_config", "trap_source_ip", models.GenericIPAddressField("Trap Source IP", blank=True, null=True, protocol="IPv4"))
self.db.add_column(
"cm_config", "trap_community", models.CharField("Trap Community", blank=True, null=True, max_length=64)
)
......@@ -14,8 +14,8 @@ class Migration(BaseMigration):
depends_on = [("sa", "0008_copy_objects")]
def migrate(self):
self.db.execute("DROP INDEX cm_config_managed_object_id")
self.db.execute("CREATE UNIQUE INDEX cm_config_managed_object_id ON cm_config(managed_object_id)")
# self.db.execute("DROP INDEX cm_config_managed_object_id")
# self.db.execute("CREATE UNIQUE INDEX cm_config_managed_object_id ON cm_config(managed_object_id)")
self.db.delete_column("cm_objectnotify", "category_id")
self.db.delete_column("cm_objectnotify", "location_id")
for column in ["activator_id", "profile_name", "scheme", "address", "port", "user", "password",
......
......@@ -22,5 +22,8 @@ class Migration(BaseMigration):
)
self.db.add_column(
"cm_objectnotify", "notification_group",
models.ForeignKey(NotificationGroup, verbose_name="Notification Group", null=True, blank=True)
models.ForeignKey(
NotificationGroup,
verbose_name="Notification Group",
null=True, blank=True, on_delete=models.CASCADE)
)
......@@ -10,7 +10,7 @@
import six
from django.db import models
# NOC modules
from noc.core.model.hacks import tuck_up_pants
from noc.core.model.base import NOCModel
from noc.main.models.notificationgroup import NotificationGroup
from noc.sa.models.administrativedomain import AdministrativeDomain
......@@ -18,9 +18,8 @@ OBJECT_TYPES = ["config", "dns", "prefix-list", "rpsl"]
OBJECT_TYPE_CHOICES = [(x, x) for x in OBJECT_TYPES if x != "config"]
@tuck_up_pants
@six.python_2_unicode_compatible
class ObjectNotify(models.Model):
class ObjectNotify(NOCModel):
class Meta(object):
app_label = "cm"
db_table = "cm_objectnotify"
......@@ -28,13 +27,17 @@ class ObjectNotify(models.Model):
verbose_name_plural = "Object Notifies"
type = models.CharField("Type", max_length=16, choices=OBJECT_TYPE_CHOICES)
administrative_domain = models.ForeignKey(AdministrativeDomain,
verbose_name="Administrative Domain",
blank=True, null=True)
administrative_domain = models.ForeignKey(
AdministrativeDomain,
verbose_name="Administrative Domain",
blank=True, null=True,
on_delete=models.CASCADE
)
notify_immediately = models.BooleanField("Notify Immediately", default=False)
notify_delayed = models.BooleanField("Notify Delayed", default=False)
notification_group = models.ForeignKey(NotificationGroup,
verbose_name="Notification Group")
notification_group = models.ForeignKey(
NotificationGroup, verbose_name="Notification Group", on_delete=models.CASCADE
)
def __str__(self):
return u"(%s, %s, %s)" % (self.type, self.administrative_domain,
......
......@@ -211,7 +211,7 @@ class Command(BaseCommand):
# Get effective list of managed objects
mos = set()
for ox in objects:
for mo in ManagedObjectSelector.resolve_expression(ox):
for mo in ManagedObjectSelector.get_objects_from_expression(ox):
mos.add(mo)
# Collect beefs
for mo in mos:
......
......@@ -20,7 +20,7 @@ class Command(BaseCommand):
def handle(self, *args, **options):
clean = set()
for expr in args:
for obj in ManagedObjectSelector.resolve_expression(expr):
for obj in ManagedObjectSelector.get_objects_from_expression(expr):
if obj.id in clean:
continue # Already cleaned
self.clean_managed_object(obj)
......
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