Commit daa1121e authored by Dmitry Volodin's avatar Dmitry Volodin
Browse files

Reworked Technology model

parent aab2eebb
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# Create initial technologies for migration purposes
# ----------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
from uuid import UUID
# Third-party modules
import bson
from pymongo import UpdateOne
# NOC modules
from noc.lib.nosql import get_db
class Migrate(object):
def forwards(self):
bulk = [
UpdateOne({
"_id": bson.ObjectId("5b6d6819d706360001a0b716"),
}, {
"name": "Group",
"uuid": UUID("8874518c-effd-41fe-81bf-d67f1519ccf2"),
"description": "Grouping element",
"single_service": False,
"single_client": False,
"allow_children": True
}, upsert=True),
UpdateOne({
"_id": bson.ObjectId("5b6d6c9fd706360001f5c053"),
}, {
"name": "Network | Controller",
"uuid": UUID("bcf7ad57-81a4-4da0-8e6d-e429c9e21532"),
"description": "Controller - CPE relation",
"service_model": "sa.ManagedObject",
"client_model": "sa.ManagedObject",
"single_service": False,
"single_client": True,
"allow_children": False
}, upsert=True),
UpdateOne({
"_id": bson.ObjectId("5b6dbbefd70636000170b980")
}, {
"name": "Object Group",
"uuid": UUID("f4c6d51d-d597-4183-918e-23efd748fd12"),
"description": "Arbitrary group of Managed Objects",
"service_model": "sa.ManagedObject",
"single_service": False,
"single_client": False,
"allow_children": False
}, upsert=True),
UpdateOne({
"_id": bson.ObjectId("5b6d6be1d706360001f5c04e")
}, {
"name": "Network | IPoE Termination",
"uuid": UUID("ef42d9fe-d217-4754-b628-a1f71f6159da"),
"description": "IPoE Temination (access equipment -> BRAS)",
"service_model": "sa.ManagedObject",
"client_model": "sa.ManagedObject",
"single_service": False,
"single_client": False,
"allow_children": False
}, upsert=True),
UpdateOne({
"_id": bson.ObjectId("5b6d6beed706360001f5c04f")
}, {
"name": "Network | PPPoE Termination",
"uuid": UUID("a8ddcd67-d8c4-471d-9a9b-9f4749e09011"),
"description": "PPPoE Temination (access equipment -> BRAS)",
"service_model": "sa.ManagedObject",
"client_model": "sa.ManagedObject",
"single_service": False,
"single_client": False,
"allow_children": False
}, upsert=True),
UpdateOne({
"_id": bson.ObjectId("5b6d6c56d706360001f5c052")
}, {
"name": "Network | PPTP Termination",
"uuid": UUID("8ce08fc8-a5b1-448d-9c2c-ac1419ad9816"),
"description": "PPTP Temination (access equipment -> BRAS)",
"service_model": "sa.ManagedObject",
"client_model": "sa.ManagedObject",
"single_service": False,
"single_client": False,
"allow_children": False
}, upsert=True),
UpdateOne({
"_id": bson.ObjectId("5b6e785ed70636000170b9a6")
}, {
"name": "Voice | SIP Termination",
"uuid": UUID("3e15a3ea-f4c1-49a1-a183-d61dd79531c2"),
"description": "SIP Temination (media gateway -> softswitch)",
"service_model": "sa.ManagedObject",
"client_model": "sa.ManagedObject",
"single_service": False,
"single_client": False,
"allow_children": False
}, upsert=True)
]
get_db().technologies.bulk_write(bulk)
def backwards(self):
pass
......@@ -2,26 +2,39 @@
# ---------------------------------------------------------------------
# Technology
# ---------------------------------------------------------------------
# Copyright (C) 2007-2014 The NOC Project
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import os
import operator
import threading
# Third-party modules
from mongoengine.document import Document
from mongoengine.fields import StringField, UUIDField
from mongoengine.fields import StringField, UUIDField, BooleanField, LongField
import cachetools
# NOC modules
from noc.core.model.decorator import on_delete_check
from noc.core.bi.decorator import bi_sync
from noc.lib.prettyjson import to_json
from noc.lib.text import quote_safe_path
id_lock = threading.Lock()
@bi_sync
@on_delete_check(check=[
("inv.ResourceGroup", "technology")
])
class Technology(Document):
"""
Equipment vendor
Technology
Abstraction to restrict ResourceGroup links
"""
meta = {
"collection": "noc.technologies",
"collection": "technologies",
"strict": False,
"auto_create_index": False,
"json_collection": "inv.technologies"
......@@ -31,10 +44,36 @@ class Technology(Document):
name = StringField(unique=True)
uuid = UUIDField(binary=True)
description = StringField()
service_model = StringField()
client_model = StringField()
single_service = BooleanField(default=False)
single_client = BooleanField(default=False)
allow_children = BooleanField(default=False)
# Object id in BI
bi_id = LongField(unique=True)
_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
_name_cache = cachetools.TTLCache(maxsize=100, ttl=60)
_bi_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
def __unicode__(self):
return self.name
@classmethod
@cachetools.cachedmethod(operator.attrgetter("_id_cache"), lock=lambda _: id_lock)
def get_by_id(cls, id):
return Technology.objects.filter(id=id).first()
@classmethod
@cachetools.cachedmethod(operator.attrgetter("_bi_id_cache"), lock=lambda _: id_lock)
def get_by_bi_id(cls, id):
return Technology.objects.filter(bi_id=id).first()
@classmethod
@cachetools.cachedmethod(operator.attrgetter("_name_cache"), lock=lambda _: id_lock)
def get_by_name(cls, name):
return Technology.objects.filter(name=name).first()
def get_json_path(self):
p = [quote_safe_path(n.strip()) for n in self.name.split("|")]
return os.path.join(*p) + ".json"
......@@ -42,10 +81,19 @@ class Technology(Document):
def to_json(self):
r = {
"name": self.name,
"$collection": self._meta["$collection"],
"uuid": self.uuid
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"single_service": self.single_service,
"single_client": self.single_client,
"allow_children": self.allow_children
}
if self.description:
r["description"] = self.description
return to_json(r, order=["name", "$collection",
"uuid", "description"])
if self.service_model:
r["service_model"] = self.service_model
if self.client_model:
r["client_model"] = self.client_model
return to_json(r, order=[
"name", "$collection", "uuid", "description", "service_model", "client_model",
"single_service", "single_client", "allow_children"
])
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# inv.technology application
# ---------------------------------------------------------------------
# Copyright (C) 2007-2014 The NOC Project
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -20,3 +20,9 @@ class TechnologyApplication(ExtDocApplication):
menu = [_("Setup"), _("Technologies")]
model = Technology
search = ["name"]
def field_service_model__label(self, o):
return o.service_model
def field_client_model__label(self, o):
return o.client_model
//---------------------------------------------------------------------
// inv.technology application
//---------------------------------------------------------------------
// Copyright (C) 2007-2014 The NOC Project
// Copyright (C) 2007-2018 The NOC Project
// See LICENSE for details
//---------------------------------------------------------------------
console.debug("Defining NOC.inv.technology.Application");
......@@ -9,7 +9,8 @@ console.debug("Defining NOC.inv.technology.Application");
Ext.define("NOC.inv.technology.Application", {
extend: "NOC.core.ModelApplication",
requires: [
"NOC.inv.technology.Model"
"NOC.inv.technology.Model",
"NOC.main.ref.modelid.LookupField"
],
model: "NOC.inv.technology.Model",
search: true,
......@@ -32,9 +33,32 @@ Ext.define("NOC.inv.technology.Application", {
width: 150
},
{
text: __("Description"),
dataIndex: "description",
flex: 1
text: __("Service Model"),
dataIndex: "service_model",
width: 150
},
{
text: __("Client Model"),
dataIndex: "client_model",
width: 150
},
{
text: __("Single Service"),
dataIndex: "single_service",
width: 50,
renderer: NOC.render.Bool
},
{
text: __("Single Client"),
dataIndex: "single_client",
width: 50,
renderer: NOC.render.Bool
},
{
text: __("Allow Children"),
dataIndex: "allow_children",
width: 50,
renderer: NOC.render.Bool
}
],
fields: [
......@@ -42,7 +66,8 @@ Ext.define("NOC.inv.technology.Application", {
name: "name",
xtype: "textfield",
fieldLabel: __("Name"),
allowBlank: false
allowBlank: false,
uiStyle: "medium"
},
{
name: "uuid",
......@@ -55,6 +80,33 @@ Ext.define("NOC.inv.technology.Application", {
xtype: "textarea",
fieldLabel: __("Description"),
allowBlank: true
},
{
name: "service_model",
xtype: "main.ref.modelid.LookupField",
fieldLabel: __("Service Model"),
allowBlank: true
},
{
name: "client_model",
xtype: "main.ref.modelid.LookupField",
fieldLabel: __("Client Model"),
allowBlank: true
},
{
name: "single_service",
xtype: "checkbox",
boxLabel: __("Single Service")
},
{
name: "single_client",
xtype: "checkbox",
boxLabel: __("Single Client")
},
{
name: "allow_children",
xtype: "checkbox",
boxLabel: __("Allow Children")
}
],
formToolbar: [
......
......@@ -26,6 +26,36 @@ Ext.define("NOC.inv.technology.Model", {
{
name: "name",
type: "string"
},
{
name: "service_model",
type: "string"
},
{
name: "client_model",
type: "string"
},
{
name: "single_service",
type: "boolean"
},
{
name: "single_client",
type: "boolean"
},
{
name: "allow_children",
type: "boolean"
},
{
name: "service_model__label",
type: "string",
persist: false
},
{
name: "client_model__label",
type: "string",
persist: false
}
]
});
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