Sharing an early development version

Signed-off-by: Petr Šabata <contyk@redhat.com>
This commit is contained in:
Petr Šabata
2016-06-24 10:28:04 +02:00
parent 0d47dce6c0
commit 400e8bfde8
6 changed files with 181 additions and 26 deletions

30
rida.py
View File

@@ -35,3 +35,33 @@ This is the implementation of the orchestrator's public RESTful API.
# TODO: Emit messages about module submission.
# TODO: Set the build state to init once the module NVR is known.
# TODO: Set the build state to wait once we're done.
from flask import Flask
from rida import config
app = Flask(__name__)
app.config.from_envvar("RIDA_SETTINGS", silent=True)
conf = config.from_file()
@app.teardown_appcontext
def close_db(error):
"""Closes the database connection at the end of the request."""
@app.route("/rida/module-builds/", methods=["POST"])
def submit_build():
"""Handles new module build submissions."""
return "submit_build()", 501
@app.route("/rida/module-builds/", methods=["GET"])
def query_builds():
"""Lists all tracked module builds."""
return "query_builds()", 501
@app.route("/rida/module-builds/<int:id>")
def query_build(id):
"""Lists details for the specified module builds."""
return "query_build(id)", 501
if __name__ == "__main__":
app.run()

View File

@@ -1,26 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2016 Red Hat, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Written by Petr Šabata <contyk@redhat.com>
"""Configuration handler functions."""

95
rida/config.py Normal file
View File

@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2016 Red Hat, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Written by Petr Šabata <contyk@redhat.com>
"""Configuration handler functions."""
# TODO: Pick the configuration format
# TODO: Add properties for all the required options.
def from_file(filename=None):
"""Create the configuration instance from a file.
The file name is optional and defaults to /etc/rida/rida.conf.
:param str filename: The configuration file to load, optional.
"""
if filename is None:
filename = "/etc/rida/rida.conf"
if not isinstance(filename, str):
raise TypeError("The configuration filename must be a string.")
conf = Config()
# TODO: Parse the file and set the properties
return conf
class Config(object):
"""Class representing the orchestrator configuration."""
def __init__(self):
"""Initialize the Config object."""
# Buildsystem to use; koji, copr, mock
self._system = ""
# SQLAlchemy RDB URL
self._db = ""
# PDC URL
self._pdc = ""
# Koji URL
self._koji = ""
@property
def system():
"""Buildsystem to use by the orchestrator."""
return self._system
@system.setter
def system(s):
# XXX: Check if it's one of the supported values
self._system = str(s)
@property
def db():
"""RDB URL for the orchestrator."""
return self._db
@db.setter
def db(s):
self._db = str(s)
@property
def pdc():
"""PDC URL for the orchestrator."""
return self._pdc
@pdc.setter
def pdc(s):
self._pdc = str(s)
@property
def koji():
"""Koji URL for the orchestrator."""
return self._koji
@koji.setter
def koji(s):
self._koji = str(s)

View File

@@ -24,3 +24,59 @@
# Written by Petr Šabata <contyk@redhat.com>
"""Database handler functions."""
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Database(object):
"""Class for handling database connections."""
def __init__(self, conf):
"""..."""
if not isinstance(conf, rida.config.Config):
raise TypeError("Database requires a configuration object.")
self._conf = conf
def connect_db():
# TODO: implement this
def disconnect_db():
# TODO: implement this
def get_db():
# TODO: Implement this
@property
def conf():
"""Database configuration."""
return self._conf
@conf.setter
def conf(o):
if not isinstance(conf, rida.config.Config):
raise TypeError("Invalid data passed for conf")
self._conf = o
class Module(Base):
__tablename__ = "modules"
id = Column(Integer, primary_key=True)
name = Column(String)
version = Column(String)
release = Column(String)
# XXX: Consider making this a proper ENUM
state = Column(String)
modulemd = Column(String)
class Build(Base):
__tablename__ = "builds"
id = Column(Integer, primary_key=True)
# XXX: Consider making this a proper foreign key
module_id = Column(Integer)
package = Column(String)
# XXX: Consider making this a proper ENUM
format = Column(String)
task = Column(Integer)
# XXX: Consider making this a proper ENUM
state = Column(String)