Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactor model and basic tox setup #1

Merged
merged 3 commits into from
Apr 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Empty file added common/__init__.py
Empty file.
Empty file added common/stackstorm/__init__.py
Empty file.
Empty file.
Empty file.
85 changes: 85 additions & 0 deletions common/stackstorm/db/models/reactor.py
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pbr>=0.5.21,<1.0
pymongo
mongoengine
21 changes: 21 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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 = [email protected]

[files]
packages =
common
23 changes: 23 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ipython
30 changes: 30 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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