diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..585b0a2740 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +*.py[cod] +*.sqlite +*.swp + +# C extensions +*.so + +# Packages +*.egg +*.egg-info +dist +build +.venv +eggs +parts +#bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 +virtualenv + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox +nosetests.xml + +# Mr Developer +.idea +.DS_Store diff --git a/common/__init__.py b/common/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/common/stackstorm/__init__.py b/common/stackstorm/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/common/stackstorm/db/__init__.py b/common/stackstorm/db/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/common/stackstorm/db/models/__init__.py b/common/stackstorm/db/models/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/common/stackstorm/db/models/reactor.py b/common/stackstorm/db/models/reactor.py new file mode 100644 index 0000000000..167207363d --- /dev/null +++ b/common/stackstorm/db/models/reactor.py @@ -0,0 +1,85 @@ +import mongoengine as me + + +class Base(me.Document): + """Minimal representation a model entity. + Attribute: + name : name of the entity. + description : description of the entity. + id : unique identifier for the entity. If none is provided it + will be auto generate by the system. + """ + name = me.StringField() + description = me.StringField() + id = me.ObjectIdField() + + +class TriggerSource(Base): + """Source of a trigger. Typically an external system or service that + generates events which must be adapted to a trigger using the provided + adapter. + Attribute: + url: url of the source + auth_token: token used by an adapter to authenticate with the + adapter_file_uri: uri of the adapter which will translate an event + specific to the source to a corresponding trigger. + """ + url = me.URLField() + auth_token = me.StringField() + adapter_file_uri = me.StringField() + + +class Trigger(Base): + """Description of a specific kind/type of a trigger. The name is expected + uniquely identify a trigger in the namespace of all triggers provided + by a specific trigger_source. + Attribute: + trigger_source: Source that owns this trigger type. + payload_info: Meta information of the expected payload. + """ + trigger_source = me.ReferenceField() + payload_info = me.ListField() + + +class TriggerInstance(Base): + """An instance or occurrence of a type of Trigger. + Attribute: + trigger: Reference to the trigger type. + payload (dict): payload specific to the occurrence. + occurrence_time (datetime): time of occurrence of the trigger. + """ + trigger = me.ReferenceField() + payload = me.DictField() + occurrence_time = me.DateTimeField() + + +class Rule(Base): + """Specifies the action to invoke on the occurrence of a Trigger. It + also includes the transformation to perform to match the impedance + between the payload of a TriggerInstance and input of a staction. + Attribute: + trigger: Trigger that trips this rule. + staction: Staction to execute when the rule is tripped. + data_mapping: Data mappings that describe the input of a + staction. + status: enabled or disabled. If disabled occurence of the trigger + does not lead to execution of a staction and vice-versa. + """ + trigger = me.ReferenceField() + staction = me.ReferenceField() + data_mapping = me.DictField() + status = me.StringField() + + +class RuleEnforcement(Base): + """A record of when an enabled rule was enforced. + Attribute: + rule (Reference): Rule that was enforced. + trigger_instance (Reference): TriggerInstance leading to tripping of + the rule. + staction_execution (Reference): The StactionExecution that was + created to record execution of a staction as part of this enforcement. + """ + rule = me.ReferenceField() + trigger_instance = me.ReferenceField() + staction_execution = me.ReferenceField() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000..7c808bb9f0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pbr>=0.5.21,<1.0 +pymongo +mongoengine \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000..3b17cf65f5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,21 @@ +[metadata] +name = kandra +version = 0.01 +summary = stackstorm automation platform product +description-file = + README.md +license = Apache License, Version 2.0 +home-page = https://stackstorm.com +classifiers = + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Intended Audience :: Information Technology + Intended Audience :: System Administrators + Operating System :: POSIX :: Linux +author = StackStorm dev team +author-email = info@stackstorm.com + +[files] +packages = + common diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000..7b38d8a8d8 --- /dev/null +++ b/setup.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import setuptools + +setuptools.setup( + setup_requires=['pbr'], + pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..49a7ffe2a9 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +ipython diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000000..784413afbd --- /dev/null +++ b/tox.ini @@ -0,0 +1,30 @@ +[tox] +envlist = py27 +minversion = 1.6 +skipsdist = True + +[testenv] +usedevelop = True +install_command = pip install -U {opts} {packages} +setenv = + VIRTUAL_ENV={envdir} + NOSE_XUNIT=1 +deps = + -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +#commands = nosetests + +[testenv:pep8] +commands = flake8 {posargs} + +[testenv:venv] +commands = {posargs} + +[testenv:pylint] +setenv = VIRTUAL_ENV={envdir} +commands = bash tools/lintstack.sh + +[flake8] +show-source = true +builtins = _ +exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools