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

Generate and process $collection attribute in JSON files

--HG--
branch : develop
parent cd247543
......@@ -37,11 +37,13 @@ class ErrorType(Document):
def to_json(self):
r = {
"name": self.name,
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"subject_template": self.subject_template,
"body_template": self.body_template
}
if self.description:
r["description"] = self.description
return to_json(r, order=["name", "uuid", "description",
return to_json(r, order=["name", "$collection",
"uuid", "description",
"subject_template", "body_template"])
......@@ -115,6 +115,7 @@ class AlarmClass(nosql.Document):
c = self
r = ["{"]
r += [" \"name\": \"%s\"," % q(c.name)]
r += [" \"$collection\": \"%s\"," % self._meta["json_collection"]]
r += [" \"uuid\": \"%s\"," % c.uuid]
if c.description:
r += [" \"desciption\": \"%s\"," % q(c.description)]
......
......@@ -51,8 +51,10 @@ class AlarmSeverity(Document):
def to_json(self):
return to_json({
"name": self.name,
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"description": self.description,
"severity": self.severity,
"style__name": self.style.name
}, order=["name", "uuid", "description", "severity", "style"])
}, order=["name", "$collection", "uuid",
"description", "severity", "style"])
......@@ -40,6 +40,7 @@ class CloneClassificationRule(Document):
def to_json(self):
return to_json({
"name": self.name,
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"re": self.re,
"key_re": self.key_re,
......
......@@ -34,6 +34,7 @@ class Enumeration(Document):
def to_json(self):
return to_json({
"name": self.name,
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"values": self.values
}, order=["name", "uuid"])
}, order=["name", "$collection", "uuid"])
......@@ -268,6 +268,7 @@ class EventClass(Document):
c = self
r = ["{"]
r += [" \"name\": \"%s\"," % q(c.name)]
r += [" \"$collection\": \"%s\"," % self._meta["json_collection"]]
r += [" \"uuid\": \"%s\"," % c.uuid]
if c.description:
r += [" \"description\": \"%s\"," % q(c.description)]
......
......@@ -111,6 +111,7 @@ class EventClassificationRule(Document):
def to_json(self):
r = ["{"]
r += [" \"name\": \"%s\"," % jq(self.name)]
r += [" \"$collection\": \"%s\"," % jq(self._meta["json_collection"])]
r += [" \"uuid\": \"%s\"," % self.uuid]
if self.description:
r += [" \"description\": \"%s\"," % jq(self.description)]
......
......@@ -20,7 +20,8 @@ class MIBAlias(Document):
"""
meta = {
"collection": "noc.mibaliases",
"allow_inheritance": False
"allow_inheritance": False,
"json_collection": "fm.mibaliases"
}
rewrite_mib = StringField(unique=True)
to_mib = StringField()
......@@ -52,7 +53,8 @@ class MIBAlias(Document):
def to_json(self):
return to_json({
"$collection": self._meta["json_collection"],
"rewrite_mib": self.rewrite_mib,
"to_mib": self.to_mib,
"uuid": self.uuid
}, order=["rewrite_mib", "to_mib", "uuid"])
}, order=["$collection", "rewrite_mib", "to_mib", "uuid"])
......@@ -32,6 +32,7 @@ class MIBPreference(Document):
def to_json(self):
return to_json({
"mib": self.mib,
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"preference": self.preference
}, order=["mib", "uuid", "preference"])
}, order=["mib", "$collection", "uuid", "preference"])
......@@ -16,7 +16,8 @@ from noc.lib.prettyjson import to_json
class OIDAlias(Document):
meta = {
"collection": "noc.oidaliases",
"allow_inheritance": False
"allow_inheritance": False,
"json_collection": "fm.oidaliases"
}
rewrite_oid = StringField(unique=True)
......@@ -60,8 +61,10 @@ class OIDAlias(Document):
r = {
"rewrite_oid": self.rewrite_oid,
"to_oid": self.to_oid,
"uuid": self.uuid
"uuid": self.uuid,
"$collection": self._meta["json_collection"]
}
if self.description:
r["description"] = self.description
return to_json(r, order=["rewrite_oid", "to_oid", "uuid"])
return to_json(r, order=["$collection",
"rewrite_oid", "to_oid", "uuid"])
......@@ -16,7 +16,8 @@ from noc.lib.prettyjson import to_json
class SyntaxAlias(Document):
meta = {
"collection": "noc.syntaxaliases",
"allow_inheritance": False
"allow_inheritance": False,
"json_collection": "fm.syntaxaliases"
}
name = StringField(unique=True, required=True)
syntax = DictField(required=False)
......@@ -40,6 +41,7 @@ class SyntaxAlias(Document):
def to_json(self):
return to_json({
"name": self.name,
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"syntax": self.syntax
}, order=["name", "uuid", "syntax"])
}, order=["name", "$collection", "uuid", "syntax"])
......@@ -59,6 +59,7 @@ class Layer(Document):
def json_data(self):
r = {
"name": self.name,
"$collection": self._meta["$collection"],
"code": self.code,
"uuid": str(self.uuid),
"min_zoom": self.min_zoom,
......@@ -78,7 +79,8 @@ class Layer(Document):
return r
def to_json(self):
return to_json(self.json_data, order=["name", "uuid", "description"])
return to_json(self.json_data, order=["name", "$collection",
"uuid", "description"])
def get_json_path(self):
p = [quote_safe_path(n.strip()) for n in self.name.split("|")]
......
......@@ -35,6 +35,7 @@ class Capability(Document):
def json_data(self):
r = {
"name": self.name,
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"description": self.description,
"type": self.type
......@@ -43,7 +44,8 @@ class Capability(Document):
def to_json(self):
return to_json(self.json_data,
order=["name", "uuid", "description", "type"])
order=["name", "$collection",
"uuid", "description", "type"])
def get_json_path(self):
p = [quote_safe_path(n.strip()) for n in self.name.split("|")]
......
......@@ -108,6 +108,7 @@ class ConnectionRule(Document):
def json_data(self):
return {
"name": self.name,
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"description": self.description,
"context": [c.json_data for c in self.context],
......@@ -116,7 +117,9 @@ class ConnectionRule(Document):
def to_json(self):
return to_json(self.json_data,
order=["name", "uuid", "description"])
order=["name", "$collection",
"uuid", "description",
"context", "rules"])
def get_json_path(self):
p = [quote_safe_path(n.strip()) for n in self.name.split("|")]
......
......@@ -68,6 +68,7 @@ class ConnectionType(Document):
def json_data(self):
r = {
"name": self.name,
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"description": self.description,
"genders": self.genders,
......@@ -79,7 +80,8 @@ class ConnectionType(Document):
def to_json(self):
return to_json(self.json_data,
order=["name", "uuid", "description"])
order=["name", "$collection",
"uuid", "description"])
def get_json_path(self):
p = [quote_safe_path(n.strip()) for n in self.name.split("|")]
......
......@@ -117,6 +117,7 @@ class ModelInterface(Document):
r = [
"{",
" \"name\": \"%s\"," % q(self.name),
" \"$collection\": \"%s\"," % self._meta["json_collection"],
" \"uuid\": \"%s\"," % str(self.uuid),
" \"description\": \"%s\"," % q(self.description),
" \"attrs\": [",
......
......@@ -173,6 +173,7 @@ class ObjectModel(Document):
def json_data(self):
r = {
"name": self.name,
"$collection": self._meta["json_collection"],
"uuid": self.uuid,
"description": self.description,
"vendor__code": self.vendor.code,
......@@ -189,7 +190,8 @@ class ObjectModel(Document):
def to_json(self):
return to_json(self.json_data,
order=["name", "uuid", "vendor__code",
order=["name", "$collection",
"uuid", "vendor__code",
"description",
"connection_rule__name",
"cr_context",
......
......@@ -41,8 +41,10 @@ class Technology(Document):
def to_json(self):
r = {
"name": self.name,
"$collection": self._meta["$collection"],
"uuid": self.uuid
}
if self.description:
r["description"] = self.description
return to_json(r, order=["name", "uuid", "description"])
return to_json(r, order=["name", "$collection",
"uuid", "description"])
......@@ -21,6 +21,7 @@ class Vendor(Document):
meta = {
"collection": "noc.vendors",
"allow_inheritance": False,
"json_collection": "noc.vendors"
}
name = StringField(unique=True)
......@@ -34,6 +35,7 @@ class Vendor(Document):
def to_json(self):
return to_json({
"name": self.name,
"$collection": self._meta["json_collection"],
"code": self.code,
"site": self.site,
"uuid": self.uuid
......
......@@ -266,6 +266,8 @@ class Collection(object):
partial = False
for k in d:
v = d[k]
if k.startswith("$"):
continue # Ignore $name
if k == "uuid":
r["uuid"] = UUID(v)
continue
......@@ -391,6 +393,9 @@ class Collection(object):
pass
def install_item(self, data, load=False):
if "$collection" in data and data["$collection"] != self.name:
self.die("Installing to invalid collection: %s instead of %s",
data["$collection"], self.name)
o = self.doc(**self.dereference(self.doc, data))
self.logger.info("Installing %s", unicode(o))
if not o.uuid:
......
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