From e7fb57fee676ab6616e6226087967b6f791f9212 Mon Sep 17 00:00:00 2001 From: Roopak Parikh Date: Fri, 8 Jul 2016 11:50:34 -0700 Subject: [PATCH] Preparing for OpenSource of Mors Added: - License.md with Apache 2 license - Added license header to all the python files - Added a better readme with an overview of functionality & installation --- LICENSE.md | 13 ++++++ README.md | 56 +++++++++++++++++++++++-- etc/pf9/pf9-mors.ini | 1 + mors/__init__.py | 15 +++++++ mors/context_util.py | 17 +++++++- mors/lease_manager.py | 16 ++++++- mors/leasehandler/__init__.py | 15 ++++++- mors/leasehandler/constants.py | 16 ++++++- mors/leasehandler/fake_lease_handler.py | 16 ++++++- mors/leasehandler/nova_lease_handler.py | 17 +++++++- mors/mors_wsgi.py | 16 ++++++- mors/persistence.py | 15 ++++++- mors_manage.py | 18 +++++++- mors_repo/__init__.py | 15 +++++++ mors_repo/manage.py | 15 +++++++ pf9_mors.py | 17 +++++++- setup.py | 18 +++++++- test/run_tests.py | 16 ++++++- test/test_api.py | 16 ++++++- test/test_persistence.py | 15 +++++++ 20 files changed, 319 insertions(+), 24 deletions(-) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..8909b43 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,13 @@ +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. \ No newline at end of file diff --git a/README.md b/README.md index 9df5164..0946275 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,55 @@ -# pf9-mors -Mors is the Roman God of death. Mors helps us implement leases. +# Mors - OpenStack Lease Manager -The functionality is described here in details: -https://platform9.atlassian.net/wiki/pages/viewpage.action?pageId=58490897 +![Mors](https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRIzc5fgaiZfJnbym_ZEx4CsZJ7qIiYjcrxth5hi80Q0IhfnxOg) +https://en.wikipedia.org/wiki/Mors_(mythology) +is a simple lease manager for OpenStack objects like Instances. + +Mors is a useful tool for OpenStack based cloud used for dev, test or lab setups. +Typical usage in these scenarios include automatically or manual creation of Instances for demo, test or experiments. +In most cases these Instances are forgotten and never deleted eating up valuable resources. + +Mors is a simple service that helps enforce a policy per Tenant or Instance and automatically delete Instances after +a specified duration. +## Details + +Mors works by specification of lease policy in a hierarchical fashion, first at a Tenant level and further at +individual Instance level. + +### Tenant Lease Policy + +Mors lease policy can be enabled or disabled at Tenant level. If Mors policy is disabled (default for each tenant) +no lease policies apply to the instances within that tenant. + +At Tenant level, policy is specified in terms of _duration_ . Once Mors policy is enabled, any Instance will be deleted +after `instance.created_time + tenant.lease duration = instance_expiration` + +#### Roles +Tenant leases can be viewed by user with 'member' role and modified by users with 'admin' role + +### Instance Lease Policy + +By default Instance leases are governed by the policies at Instance's Tenant level. As mentioned earlier: + `instance.created_time + tenant.lease duration = instance_expiration` + +A member of tenant can change the Instance expiry at any time, but it can never be later than now + tenant.lease duration + + `max instance lease <= now + tenant.lease duration` + +A user can always come back at a later point of time and renew the release again. + +#### Roles +Instance leases can be modified by both 'member' and 'admin' roles. + +## Build & Installation +Support subdirectory contains Makefile to build a RPM, apart from python 2.7, virtualenv it needs [fpm](https://github.com/jordansissel/fpm), _fpm_ +is a simple package build utility that can build both RPM and deb packages. RPM itself is a thin wrapper on top of the virtualenv. + +Configuration files are expected to be in /etc/pf9 directory. These are usual OpenStack style config files: +* pf9-mors.ini: configure the nova section with the user/password that can be used by mors to perform delete operations on nova instances. + The user needs to be an administrator. +* pf9-mors-api-paste.ini: configure the keystone middleware with keystone auth tokens. + +The packages comes with an init script that works on RHEL 7 compatible systems + diff --git a/etc/pf9/pf9-mors.ini b/etc/pf9/pf9-mors.ini index 18cf4b0..943a057 100644 --- a/etc/pf9/pf9-mors.ini +++ b/etc/pf9/pf9-mors.ini @@ -7,6 +7,7 @@ sleep_seconds=60 paste-ini=/etc/pf9/pf9-mors-api-paste.ini log_file=/var/log/pf9/pf9-mors.log repo=/opt/pf9/pf9-mors/lib/python2.7/site-packages/mors_repo + [nova] user_name= password= diff --git a/mors/__init__.py b/mors/__init__.py index e69de29..a343161 100644 --- a/mors/__init__.py +++ b/mors/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" \ No newline at end of file diff --git a/mors/context_util.py b/mors/context_util.py index 1a1e82f..6c3e8e3 100644 --- a/mors/context_util.py +++ b/mors/context_util.py @@ -1,5 +1,18 @@ -# Copyright (c) 2016 Platform9 Systems Inc. -# All Rights reserved +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" from flask import request, jsonify import functools, os diff --git a/mors/lease_manager.py b/mors/lease_manager.py index b52c60e..5153880 100644 --- a/mors/lease_manager.py +++ b/mors/lease_manager.py @@ -1,4 +1,18 @@ -# Copyright Platform9 Systems Inc. 2016 +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" from datetime import datetime, timedelta diff --git a/mors/leasehandler/__init__.py b/mors/leasehandler/__init__.py index e353ef6..2cb6657 100644 --- a/mors/leasehandler/__init__.py +++ b/mors/leasehandler/__init__.py @@ -1,5 +1,18 @@ -# Copyright 2016 Platform9 Systems Inc. +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) +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. +""" from nova_lease_handler import NovaLeaseHandler from fake_lease_handler import FakeLeaseHandler import constants diff --git a/mors/leasehandler/constants.py b/mors/leasehandler/constants.py index 85d0e24..7f1f943 100644 --- a/mors/leasehandler/constants.py +++ b/mors/leasehandler/constants.py @@ -1,4 +1,18 @@ -# Copyright Platform9 Systems Inc. 2016 +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" SUCCESS_OK = 0 ERR_NOT_FOUND = 1 diff --git a/mors/leasehandler/fake_lease_handler.py b/mors/leasehandler/fake_lease_handler.py index 2d69e12..4d04ccb 100644 --- a/mors/leasehandler/fake_lease_handler.py +++ b/mors/leasehandler/fake_lease_handler.py @@ -1,4 +1,18 @@ -# Copyright Platform9 Systems Inc. 2016 +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" import constants import logging from datetime import datetime diff --git a/mors/leasehandler/nova_lease_handler.py b/mors/leasehandler/nova_lease_handler.py index 90e8a92..04324a8 100644 --- a/mors/leasehandler/nova_lease_handler.py +++ b/mors/leasehandler/nova_lease_handler.py @@ -1,4 +1,19 @@ -# Copyright 2016 Platform9 Systems Inc. +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" + from novaclient import client import logging import novaclient diff --git a/mors/mors_wsgi.py b/mors/mors_wsgi.py index 9ffe460..75bcd20 100644 --- a/mors/mors_wsgi.py +++ b/mors/mors_wsgi.py @@ -1,6 +1,18 @@ -# Copyright (c) 2016 Platform9 Systems Inc. -# All Rights reserved +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) +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. +""" from flask import Flask, request, jsonify from lease_manager import LeaseManager from context_util import enforce, get_context, error_handler diff --git a/mors/persistence.py b/mors/persistence.py index c439508..7677049 100644 --- a/mors/persistence.py +++ b/mors/persistence.py @@ -1,5 +1,18 @@ -# Copyright Platform9 Systems Inc. 2016 +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) +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. +""" from sqlalchemy.pool import QueuePool from sqlalchemy import create_engine, text from sqlalchemy import Table, Column, Integer, String, MetaData, DateTime diff --git a/mors_manage.py b/mors_manage.py index a6042bd..d0bf6a9 100644 --- a/mors_manage.py +++ b/mors_manage.py @@ -1,6 +1,20 @@ #!/opt/pf9/pf9-mors/bin/python -# Copyright (c) 2016 Platform9 Systems Inc. -# All Rights reserved +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" + import argparse, logging import ConfigParser from migrate.versioning.api import upgrade, create, version_control diff --git a/mors_repo/__init__.py b/mors_repo/__init__.py index e69de29..a343161 100644 --- a/mors_repo/__init__.py +++ b/mors_repo/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" \ No newline at end of file diff --git a/mors_repo/manage.py b/mors_repo/manage.py index 39fa389..a07ad60 100644 --- a/mors_repo/manage.py +++ b/mors_repo/manage.py @@ -1,4 +1,19 @@ #!/usr/bin/env python +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" from migrate.versioning.shell import main if __name__ == '__main__': diff --git a/pf9_mors.py b/pf9_mors.py index 86331cd..eb5b9a4 100644 --- a/pf9_mors.py +++ b/pf9_mors.py @@ -1,6 +1,19 @@ #!/opt/pf9/pf9-mors/bin/python -# Copyright (c) 2016 Platform9 Systems Inc. -# All Rights reserved +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" from paste.deploy import loadapp from eventlet import wsgi diff --git a/setup.py b/setup.py index f2b2c55..afcd524 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,26 @@ #!/usr/bin/env python +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) +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. +""" from setuptools import setup setup(name='pf9-mors', version='0.1', description='Platform9 Mors (lease manager)', - author='Roopak Parikh', - author_email='rparikh@platform9.net', + author='Platform9', + author_email='opensource@platform9.com', url='https://github.com/platform9/pf9-mors', packages=['mors', 'mors/leasehandler', diff --git a/test/run_tests.py b/test/run_tests.py index eeed199..0ce0947 100644 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -1,6 +1,18 @@ -# Copyright (c) 2016 Platform9 Systems Inc. -# All Rights reserved +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) +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. +""" def run_tests(): from proboscis import TestProgram import test_api, test_persistence diff --git a/test/test_api.py b/test/test_api.py index 076707f..0b643fd 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -1,6 +1,18 @@ -# Copyright (c) 2016 Platform9 Systems Inc. -# All Rights reserved +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) +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. +""" from migrate.versioning.api import upgrade, create, version_control import ConfigParser, os import requests diff --git a/test/test_persistence.py b/test/test_persistence.py index e1de110..af584ff 100644 --- a/test/test_persistence.py +++ b/test/test_persistence.py @@ -1,3 +1,18 @@ +""" +Copyright 2016 Platform9 Systems Inc.(http://www.platform9.com) + +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. +""" from proboscis import test from mors.persistence import DbPersistence import uuid