Commit 84693592 authored by Daniel Seybold's avatar Daniel Seybold
Browse files

initial commit with first version of maki manager

parents
.travis.yaml
.swagger-codegen-ignore
README.md
tox.ini
git_push.sh
test-requirements.txt
setup.py
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.python-version
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
#Ipython Notebook
.ipynb_checkpoints
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.python-version
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
#Ipython Notebook
.ipynb_checkpoints
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
# keep default controller for business logic
mowgli_maki_manager/controllers/default_controller.py
\ No newline at end of file
2.3.0
\ No newline at end of file
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "3.2"
- "3.3"
- "3.4"
- "3.5"
#- "3.5-dev" # 3.5 development branch
#- "nightly" # points to the latest development branch e.g. 3.6-dev
# command to install dependencies
install: "pip install -r requirements.txt"
# command to run tests
script: nosetests
FROM python:3-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . /usr/src/app
EXPOSE 9003
ENTRYPOINT ["python3"]
CMD ["-m", "mowgli_maki_manager"]
\ No newline at end of file
# Swagger generated server
## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
is an example of building a swagger-enabled Flask server.
This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.
## Requirements
Python 3.5.2+
## Usage
To run the server, please execute the following from the root directory:
```
pip3 install -r requirements.txt
python3 -m mowgli_maki_manager
```
and open your browser to here:
```
http://localhost:9003/v1/ui/
```
Your Swagger definition lives here:
```
http://localhost:9003/v1/swagger.json
```
To launch the integration tests, use tox:
```
sudo pip install tox
tox
```
## Running with Docker
To run the server on a Docker container, please execute the following from the root directory:
```bash
# building the image
docker build -t mowgli_maki_manager .
# starting up a container
docker run -p 9003:9003 mowgli_maki_manager
```
\ No newline at end of file
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
git_user_id=$1
git_repo_id=$2
release_note=$3
if [ "$git_user_id" = "" ]; then
git_user_id="GIT_USER_ID"
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
fi
if [ "$git_repo_id" = "" ]; then
git_repo_id="GIT_REPO_ID"
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
fi
if [ "$release_note" = "" ]; then
release_note="Minor update"
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
fi
# Initialize the local directory as a Git repository
git init
# Adds the files in the local repository and stages them for commit.
git add .
# Commits the tracked changes and prepares them to be pushed to a remote repository.
git commit -m "$release_note"
# Sets the new remote
git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined
if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
fi
fi
git pull origin master
# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'
#!/usr/bin/env python3
import connexion
from mowgli_maki_manager import encoder
def main():
app = connexion.App(__name__, specification_dir='./swagger/')
app.app.json_encoder = encoder.JSONEncoder
app.add_api('swagger.yaml', arguments={'title': 'Maki Manager API'})
app.run(port=9003)
if __name__ == '__main__':
main()
import connexion
import six
from mowgli_maki_manager.models.error import Error # noqa: E501
from mowgli_maki_manager.models.maki_command import MakiCommand # noqa: E501
from mowgli_maki_manager import util
from subprocess import Popen,PIPE,STDOUT
def management_command_post(makiCommand): # noqa: E501
"""execute DBMS specific management command
# noqa: E501
:param makiCommand: the Maki command object
:type makiCommand: dict | bytes
:rtype: None
"""
if connexion.request.is_json:
makiCommand = MakiCommand.from_dict(connexion.request.get_json()) # noqa: E501
if makiCommand.blocking:
print("Executing a blocking maki command:")
print(" ".join(makiCommand.command))
process = Popen(makiCommand.command, stderr=STDOUT,stdout=PIPE)
std_output, std_error = process.communicate()
print("Process finished with exit code: " + str(process.returncode))
print("Process STD output: " + str(std_output))
print("Process STD error: " + str(std_error))
else:
print("Executing a non-blocking maki command...")
print(" ".join(makiCommand.command))
process = Popen(makiCommand.command, stderr=STDOUT,stdout=PIPE)
print("Non-blocking process started, returning!")
return 'Successfully executed Maki management command!'
from connexion.apps.flask_app import FlaskJSONEncoder
import six
from mowgli_maki_manager.models.base_model_ import Model
class JSONEncoder(FlaskJSONEncoder):
include_nulls = False
def default(self, o):
if isinstance(o, Model):
dikt = {}
for attr, _ in six.iteritems(o.swagger_types):
value = getattr(o, attr)
if value is None and not self.include_nulls:
continue
attr = o.attribute_map[attr]
dikt[attr] = value
return dikt
return FlaskJSONEncoder.default(self, o)
# coding: utf-8
# flake8: noqa
from __future__ import absolute_import
# import models into model package
from mowgli_maki_manager.models.error import Error
from mowgli_maki_manager.models.maki_command import MakiCommand
import pprint
import six
import typing
from mowgli_maki_manager import util
T = typing.TypeVar('T')
class Model(object):
# swaggerTypes: The key is attribute name and the
# value is attribute type.
swagger_types = {}
# attributeMap: The key is attribute name and the
# value is json key in definition.
attribute_map = {}
@classmethod
def from_dict(cls: typing.Type[T], dikt) -> T:
"""Returns the dict as a model"""
return util.deserialize_model(dikt, cls)
def to_dict(self):
"""Returns the model properties as a dict
:rtype: dict
"""
result = {}
for attr, _ in six.iteritems(self.swagger_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
return result
def to_str(self):
"""Returns the string representation of the model
:rtype: str
"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from mowgli_maki_manager.models.base_model_ import Model
from mowgli_maki_manager.models.database_config_property import DatabaseConfigProperty # noqa: F401,E501
from mowgli_maki_manager import util
class DatabaseConfig(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, database_binding: str=None, endpoint_parameter_name: str=None, table_parameter_name: str=None, table_name: str=None, config_porperties: List[DatabaseConfigProperty]=None): # noqa: E501
"""DatabaseConfig - a model defined in Swagger
:param database_binding: The database_binding of this DatabaseConfig. # noqa: E501
:type database_binding: str
:param endpoint_parameter_name: The endpoint_parameter_name of this DatabaseConfig. # noqa: E501
:type endpoint_parameter_name: str
:param table_parameter_name: The table_parameter_name of this DatabaseConfig. # noqa: E501
:type table_parameter_name: str
:param table_name: The table_name of this DatabaseConfig. # noqa: E501
:type table_name: str
:param config_porperties: The config_porperties of this DatabaseConfig. # noqa: E501
:type config_porperties: List[DatabaseConfigProperty]
"""
self.swagger_types = {
'database_binding': str,
'endpoint_parameter_name': str,
'table_parameter_name': str,
'table_name': str,
'config_porperties': List[DatabaseConfigProperty]
}
self.attribute_map = {
'database_binding': 'databaseBinding',
'endpoint_parameter_name': 'endpointParameterName',
'table_parameter_name': 'tableParameterName',
'table_name': 'tableName',
'config_porperties': 'configPorperties'
}
self._database_binding = database_binding
self._endpoint_parameter_name = endpoint_parameter_name
self._table_parameter_name = table_parameter_name
self._table_name = table_name
self._config_porperties = config_porperties
@classmethod
def from_dict(cls, dikt) -> 'DatabaseConfig':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The DatabaseConfig of this DatabaseConfig. # noqa: E501
:rtype: DatabaseConfig
"""
return util.deserialize_model(dikt, cls)
@property
def database_binding(self) -> str:
"""Gets the database_binding of this DatabaseConfig.
:return: The database_binding of this DatabaseConfig.
:rtype: str
"""
return self._database_binding
@database_binding.setter
def database_binding(self, database_binding: str):
"""Sets the database_binding of this DatabaseConfig.
:param database_binding: The database_binding of this DatabaseConfig.
:type database_binding: str
"""
allowed_values = ["COUCHBASE", "COUCHBASE2", "RIAK", "CASSANDRA2", "COCKROACHDB", "VOLTDB"] # noqa: E501
if database_binding not in allowed_values:
raise ValueError(
"Invalid value for `database_binding` ({0}), must be one of {1}"
.format(database_binding, allowed_values)
)
self._database_binding = database_binding
@property
def endpoint_parameter_name(self) -> str:
"""Gets the endpoint_parameter_name of this DatabaseConfig.
the name of the endpoint parameter of the selected driver, e.g. couchbase.host # noqa: E501
:return: The endpoint_parameter_name of this DatabaseConfig.
:rtype: str
"""
return self._endpoint_parameter_name
@endpoint_parameter_name.setter
def endpoint_parameter_name(self, endpoint_parameter_name: str):
"""Sets the endpoint_parameter_name of this DatabaseConfig.
the name of the endpoint parameter of the selected driver, e.g. couchbase.host # noqa: E501
:param endpoint_parameter_name: The endpoint_parameter_name of this DatabaseConfig.
:type endpoint_parameter_name: str
"""
self._endpoint_parameter_name = endpoint_parameter_name
@property
def table_parameter_name(self) -> str:
"""Gets the table_parameter_name of this DatabaseConfig.
the name of the parameter to specify the table to use with YCSB, e.g. couchbase.bucket # noqa: E501
:return: The table_parameter_name of this DatabaseConfig.
:rtype: str
"""
return self._table_parameter_name
@table_parameter_name.setter
def table_parameter_name(self, table_parameter_name: str):
"""Sets the table_parameter_name of this DatabaseConfig.
the name of the parameter to specify the table to use with YCSB, e.g. couchbase.bucket # noqa: E501
:param table_parameter_name: The table_parameter_name of this DatabaseConfig.
:type table_parameter_name: str
"""
self._table_parameter_name = table_parameter_name
@property
def table_name(self) -> str:
"""Gets the table_name of this DatabaseConfig.
the table name to use with YCSB, e.g. ycsb # noqa: E501
:return: The table_name of this DatabaseConfig.
:rtype: str