Initial commit
This commit is contained in:
commit
1a69bfa39d
7
.coveragerc
Normal file
7
.coveragerc
Normal file
@ -0,0 +1,7 @@
|
||||
[run]
|
||||
branch = True
|
||||
source = oaktree
|
||||
omit = oaktree/openstack/*
|
||||
|
||||
[report]
|
||||
ignore_errors = True
|
57
.gitignore
vendored
Normal file
57
.gitignore
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
*.py[cod]
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist
|
||||
build
|
||||
.eggs
|
||||
eggs
|
||||
parts
|
||||
bin
|
||||
var
|
||||
sdist
|
||||
develop-eggs
|
||||
.installed.cfg
|
||||
lib
|
||||
lib64
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.coverage
|
||||
.tox
|
||||
nosetests.xml
|
||||
.testrepository
|
||||
.venv
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
||||
# Mr Developer
|
||||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
||||
|
||||
# Complexity
|
||||
output/*.html
|
||||
output/*/index.html
|
||||
|
||||
# Sphinx
|
||||
doc/build
|
||||
|
||||
# pbr generates these
|
||||
AUTHORS
|
||||
ChangeLog
|
||||
|
||||
# Editors
|
||||
*~
|
||||
.*.swp
|
||||
.*sw?
|
||||
|
||||
# Protobuf Generated Files
|
||||
oaktree/rpc/*_pb2.py
|
4
.gitreview
Normal file
4
.gitreview
Normal file
@ -0,0 +1,4 @@
|
||||
[gerrit]
|
||||
host=review.openstack.org
|
||||
port=29418
|
||||
project=openstack/oaktree.git
|
3
.mailmap
Normal file
3
.mailmap
Normal file
@ -0,0 +1,3 @@
|
||||
# Format is:
|
||||
# <preferred e-mail> <other e-mail 1>
|
||||
# <preferred e-mail> <other e-mail 2>
|
7
.testr.conf
Normal file
7
.testr.conf
Normal file
@ -0,0 +1,7 @@
|
||||
[DEFAULT]
|
||||
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
|
||||
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
|
||||
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
|
||||
${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
|
||||
test_id_option=--load-list $IDFILE
|
||||
test_list_option=--list
|
17
CONTRIBUTING.rst
Normal file
17
CONTRIBUTING.rst
Normal file
@ -0,0 +1,17 @@
|
||||
If you would like to contribute to the development of OpenStack, you must
|
||||
follow the steps in this page:
|
||||
|
||||
http://docs.openstack.org/infra/manual/developers.html
|
||||
|
||||
If you already have a good understanding of how the system works and your
|
||||
OpenStack accounts are set up, you can skip to the development workflow
|
||||
section of this documentation to learn how changes to OpenStack should be
|
||||
submitted for review via the Gerrit tool:
|
||||
|
||||
http://docs.openstack.org/infra/manual/developers.html#development-workflow
|
||||
|
||||
Pull requests submitted through GitHub will be ignored.
|
||||
|
||||
Bugs should be filed on Launchpad, not GitHub:
|
||||
|
||||
https://bugs.launchpad.net/oaktree
|
4
HACKING.rst
Normal file
4
HACKING.rst
Normal file
@ -0,0 +1,4 @@
|
||||
oaktree Style Commandments
|
||||
===============================================
|
||||
|
||||
Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/
|
176
LICENSE
Normal file
176
LICENSE
Normal file
@ -0,0 +1,176 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
6
MANIFEST.in
Normal file
6
MANIFEST.in
Normal file
@ -0,0 +1,6 @@
|
||||
include AUTHORS
|
||||
include ChangeLog
|
||||
exclude .gitignore
|
||||
exclude .gitreview
|
||||
|
||||
global-exclude *.pyc
|
64
README.rst
Normal file
64
README.rst
Normal file
@ -0,0 +1,64 @@
|
||||
=======
|
||||
oaktree
|
||||
=======
|
||||
|
||||
Make your cloud throw some shade
|
||||
|
||||
oaktree is a gRPC interface for interacting with OpenStack clouds that is
|
||||
inherently interoperable and multi-cloud aware. It is based on the python
|
||||
shade library, which grew all of the logic needed to interact with OpenStack
|
||||
clouds and to work around differences in vendor deployment choices. Rather
|
||||
than keep all of that love in Python Library form, oaktree allows othre
|
||||
languages to reap the benefits as well.
|
||||
|
||||
oaktree is not a replacement for all of the individual project REST APIs.
|
||||
Those are all essential for cross-project communication and are well suited
|
||||
for operators who can be expected to know things about how they have
|
||||
deployed their clouds - and who in fact WANT to be able to make changes in
|
||||
the cloud knowing deployment specifics. oaktree will never be for them.
|
||||
|
||||
oaktree is for end-users who do not and should not know what hypervisor, what
|
||||
storage driver or what network stack the deployer has chosen. The two sets
|
||||
of people are different audiences, so oaktree is a project to support the
|
||||
end user.
|
||||
|
||||
Using
|
||||
-----
|
||||
|
||||
Install oaktreemodel by hand. Then:
|
||||
|
||||
In one window:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
python oaktree/server.py
|
||||
|
||||
oaktree/server.py assumes you have a clouds.yaml accessible.
|
||||
|
||||
In another window:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
python -i devstack/test.py
|
||||
|
||||
You'll have an images and a flavors object you can poke at.
|
||||
|
||||
If you want to operate against a different cloud than `devstack`, you can
|
||||
pass it to devstack/test.py as the first command line argument.
|
||||
|
||||
Shape of the Project
|
||||
--------------------
|
||||
|
||||
oaktree should be super simple to deploy, and completely safe for deployers
|
||||
to upgrade from master constantly. Once it's released as a 1.0, it should
|
||||
NEVER EVER EVER EVER EVER EVER EVER have a backwards incompatible change.
|
||||
There is no reason, no justification, no obessession important enough to
|
||||
inflict such pain on the user.
|
||||
|
||||
The shade library will grow the ability to detect if a cloud has an oaktree
|
||||
api available, and if it does, it will use it. Hopefully we'll quickly reach
|
||||
a point where all deployers are deploying oaktree.
|
||||
|
||||
* Documentation: http://docs.openstack.org/developer/oaktree
|
||||
* Source: http://git.openstack.org/cgit/openstack/oaktree
|
||||
* Bugs: http://bugs.launchpad.net/oaktree
|
120
devstack/plugin.sh
Normal file
120
devstack/plugin.sh
Normal file
@ -0,0 +1,120 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2016 Red Hat, 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.
|
||||
|
||||
# Install shade from git if requested. If not requested
|
||||
# oaktree install will pull it in.
|
||||
function install_shade {
|
||||
if use_library_from_git "shade"; then
|
||||
GITREPO["shade"]=$SHADE_REPO_URL
|
||||
GITDIR["shade"]=$DEST/shade
|
||||
GITBRANCH["shade"]=$SHADE_REPO_REF
|
||||
git_clone_by_name "shade"
|
||||
# Install shade globally, because the job config has LIBS_FROM_GIT
|
||||
# and if we don't install it globally, all hell breaks loose
|
||||
setup_dev_lib "shade"
|
||||
fi
|
||||
}
|
||||
|
||||
function install_oaktreemodel {
|
||||
if use_library_from_git "oaktreemodel"; then
|
||||
GITREPO["oaktreemodel"]=$OAKTREEMODEL_REPO_URL
|
||||
GITDIR["oaktreemodel"]=$DEST/oaktreemodel
|
||||
GITBRANCH["oaktreemodel"]=$OAKTREEMODEL_REPO_REF
|
||||
git_clone_by_name "oaktreemodel"
|
||||
pushd $DEST/oaktreemodel
|
||||
/usr/local/jenkins/slave_scripts/install-distro-packages.sh
|
||||
export GOPATH=$DEST/gopath
|
||||
mkdir $GOPATH
|
||||
export PATH=$GOPATH/bin:$PATH
|
||||
go get -u github.com/golang/protobuf/protoc-gen-go
|
||||
./bootstrap.sh
|
||||
./configure
|
||||
make
|
||||
sudo make install
|
||||
sudo pip install -e .
|
||||
popd
|
||||
fi
|
||||
}
|
||||
|
||||
# Install oaktree code
|
||||
function install_oaktree {
|
||||
if use_library_from_git "oaktree"; then
|
||||
GITREPO["oaktree"]=$OAKTREE_REPO_URL
|
||||
GITDIR["oaktree"]=$DEST/shade
|
||||
GITBRANCH["oaktree"]=$OAKTREE_REPO_REF
|
||||
git_clone_by_name "oaktree"
|
||||
setup_dev_lib "oaktree"
|
||||
fi
|
||||
}
|
||||
|
||||
function configure_oaktree {
|
||||
:
|
||||
}
|
||||
|
||||
function start_oaktree {
|
||||
|
||||
if is_service_enabled statsd; then
|
||||
# run a fake statsd so we test stats sending paths
|
||||
export STATSD_HOST=localhost
|
||||
export STATSD_PORT=8125
|
||||
run_process statsd "socat -u udp-recv:$STATSD_PORT -"
|
||||
fi
|
||||
|
||||
run_process oaktree "python -m oaktree.server"
|
||||
:
|
||||
}
|
||||
|
||||
function shutdown_oaktree {
|
||||
stop_process oaktree
|
||||
:
|
||||
}
|
||||
|
||||
function cleanup_oaktree {
|
||||
:
|
||||
}
|
||||
|
||||
# check for service enabled
|
||||
if is_service_enabled oaktree; then
|
||||
|
||||
if [[ "$1" == "stack" && "$2" == "install" ]]; then
|
||||
# Perform installation of service source
|
||||
echo_summary "Installing oaktree"
|
||||
install_oaktree
|
||||
|
||||
elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
|
||||
# Configure after the other layer 1 and 2 services have been configured
|
||||
echo_summary "Configuring oaktree"
|
||||
configure_oaktree
|
||||
|
||||
elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
|
||||
# Initialize and start the oaktree service
|
||||
echo_summary "Initializing oaktree"
|
||||
start_oaktree
|
||||
fi
|
||||
|
||||
if [[ "$1" == "unstack" ]]; then
|
||||
# Shut down oaktree services
|
||||
# no-op
|
||||
shutdown_oaktree
|
||||
fi
|
||||
|
||||
if [[ "$1" == "clean" ]]; then
|
||||
# Remove state and transient data
|
||||
# Remember clean.sh first calls unstack.sh
|
||||
# no-op
|
||||
cleanup_oaktree
|
||||
fi
|
||||
fi
|
11
devstack/settings
Normal file
11
devstack/settings
Normal file
@ -0,0 +1,11 @@
|
||||
SHADE_REPO_URL=${SHADE_REPO_URL:-https://git.openstack.org/openstack-infra/shade}
|
||||
SHADE_REPO_REF=${SHADE_REPO_REF:-master}
|
||||
|
||||
OAKTREE_REPO_URL=${OAKTREE_REPO_URL:-https://git.openstack.org/openstack/oaktree}
|
||||
OAKTREE_REPO_REF=${OAKTREE_REPO_REF:-master}
|
||||
|
||||
OAKTREEMODEL_REPO_URL=${OAKTREEMODEL_REPO_URL:-https://git.openstack.org/openstack/oaktreemodel}
|
||||
OAKTREEMODEL_REPO_REF=${OAKTREEMODEL_REPO_REF:-master}
|
||||
|
||||
enable_service statsd
|
||||
enable_service oaktree
|
21
devstack/test.py
Normal file
21
devstack/test.py
Normal file
@ -0,0 +1,21 @@
|
||||
# flake8: noqa
|
||||
import sys
|
||||
|
||||
import grpc
|
||||
|
||||
from oaktreemodel import model
|
||||
from oaktreemodel import oaktree_pb2
|
||||
|
||||
channel = grpc.insecure_channel('localhost:50051')
|
||||
stub = oaktree_pb2.OaktreeStub(channel)
|
||||
|
||||
cloud = model.Location()
|
||||
if len(sys.argv) > 1:
|
||||
cloud.cloud = sys.argv[1]
|
||||
else:
|
||||
cloud.cloud = 'devstack'
|
||||
|
||||
flavors = stub.SearchFlavors(model.Filter(location=cloud))
|
||||
print flavors
|
||||
images = stub.SearchImages(model.Filter(location=cloud))
|
||||
print images
|
75
doc/source/conf.py
Executable file
75
doc/source/conf.py
Executable file
@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# 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 os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.abspath('../..'))
|
||||
# -- General configuration ----------------------------------------------------
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
#'sphinx.ext.intersphinx',
|
||||
'oslosphinx'
|
||||
]
|
||||
|
||||
# autodoc generation is a bit aggressive and a nuisance when doing heavy
|
||||
# text edit cycles.
|
||||
# execute "export SPHINX_DEBUG=1" in your terminal to disable
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'oaktree'
|
||||
copyright = u'2013, OpenStack Foundation'
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
add_module_names = True
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# -- Options for HTML output --------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. Major themes that come with
|
||||
# Sphinx are currently 'default' and 'sphinxdoc'.
|
||||
# html_theme_path = ["."]
|
||||
# html_theme = '_theme'
|
||||
# html_static_path = ['static']
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = '%sdoc' % project
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass
|
||||
# [howto/manual]).
|
||||
latex_documents = [
|
||||
('index',
|
||||
'%s.tex' % project,
|
||||
u'%s Documentation' % project,
|
||||
u'OpenStack Foundation', 'manual'),
|
||||
]
|
||||
|
||||
# Example configuration for intersphinx: refer to the Python standard library.
|
||||
#intersphinx_mapping = {'http://docs.python.org/': None}
|
4
doc/source/contributing.rst
Normal file
4
doc/source/contributing.rst
Normal file
@ -0,0 +1,4 @@
|
||||
============
|
||||
Contributing
|
||||
============
|
||||
.. include:: ../../CONTRIBUTING.rst
|
25
doc/source/index.rst
Normal file
25
doc/source/index.rst
Normal file
@ -0,0 +1,25 @@
|
||||
.. oaktree documentation master file, created by
|
||||
sphinx-quickstart on Tue Jul 9 22:26:36 2013.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to oaktree's documentation!
|
||||
========================================================
|
||||
|
||||
Contents:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
readme
|
||||
installation
|
||||
usage
|
||||
contributing
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
12
doc/source/installation.rst
Normal file
12
doc/source/installation.rst
Normal file
@ -0,0 +1,12 @@
|
||||
============
|
||||
Installation
|
||||
============
|
||||
|
||||
At the command line::
|
||||
|
||||
$ pip install oaktree
|
||||
|
||||
Or, if you have virtualenvwrapper installed::
|
||||
|
||||
$ mkvirtualenv oaktree
|
||||
$ pip install oaktree
|
1
doc/source/readme.rst
Normal file
1
doc/source/readme.rst
Normal file
@ -0,0 +1 @@
|
||||
.. include:: ../../README.rst
|
7
doc/source/usage.rst
Normal file
7
doc/source/usage.rst
Normal file
@ -0,0 +1,7 @@
|
||||
========
|
||||
Usage
|
||||
========
|
||||
|
||||
To use oaktree in a project::
|
||||
|
||||
import oaktree
|
0
oaktree/__init__.py
Normal file
0
oaktree/__init__.py
Normal file
51
oaktree/_clouds.py
Normal file
51
oaktree/_clouds.py
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright (c) 2016 Red Hat, 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.
|
||||
|
||||
import shade
|
||||
|
||||
all_clouds = {}
|
||||
|
||||
|
||||
def _make_cloud_key(cloud, region, domain, project):
|
||||
return "{cloud}:{region}:{domain}:{project}".format(
|
||||
cloud=cloud, region=region, domain=domain, project=project)
|
||||
|
||||
|
||||
def _get_cloud(cloud, region, project=None):
|
||||
if project:
|
||||
domain_id = project.domain_id
|
||||
domain_name = project.domain_name
|
||||
project_id = project.id
|
||||
project_name = project.name
|
||||
kwargs = dict(
|
||||
project_domain_id=domain_id,
|
||||
project_domain_name=domain_name,
|
||||
project_id=project_id,
|
||||
project_name=project_name,
|
||||
)
|
||||
else:
|
||||
domain_id = domain_name = project_id = project_name = None
|
||||
kwargs = {}
|
||||
|
||||
key = _make_cloud_key(
|
||||
cloud, region,
|
||||
domain_id or domain_name,
|
||||
project_id or project_name
|
||||
)
|
||||
if key not in all_clouds:
|
||||
all_clouds[key] = shade.openstack_cloud(
|
||||
cloud=cloud, region_name=region,
|
||||
debug=True, strict=True, **kwargs)
|
||||
return all_clouds[key]
|
251
oaktree/server.py
Normal file
251
oaktree/server.py
Normal file
@ -0,0 +1,251 @@
|
||||
# Copyright (c) 2016 Red Hat, 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.
|
||||
|
||||
import shade
|
||||
|
||||
from concurrent import futures
|
||||
import logging
|
||||
import time
|
||||
|
||||
from google.protobuf.descriptor import FieldDescriptor
|
||||
import grpc
|
||||
|
||||
from oaktree import _clouds
|
||||
from oaktreemodel import model
|
||||
from oaktreemodel import oaktree_pb2
|
||||
|
||||
# Skipping bytes for now
|
||||
_BOOL_TYPES = (FieldDescriptor.TYPE_BOOL,)
|
||||
_ENUM_TYPES = (FieldDescriptor.TYPE_ENUM, )
|
||||
_STR_TYPES = (FieldDescriptor.TYPE_STRING, )
|
||||
_INT_TYPES = (
|
||||
FieldDescriptor.TYPE_FIXED32, FieldDescriptor.TYPE_FIXED64,
|
||||
FieldDescriptor.TYPE_SFIXED32, FieldDescriptor.TYPE_SFIXED64,
|
||||
FieldDescriptor.TYPE_INT32, FieldDescriptor.TYPE_INT64,
|
||||
FieldDescriptor.TYPE_SINT32, FieldDescriptor.TYPE_SINT64,
|
||||
FieldDescriptor.TYPE_UINT32, FieldDescriptor.TYPE_UINT64,
|
||||
)
|
||||
_FLOAT_TYPES = (
|
||||
FieldDescriptor.TYPE_DOUBLE, FieldDescriptor.TYPE_FLOAT,
|
||||
)
|
||||
_FIELDS_TO_STRIP = ('request_ids', 'HUMAN_ID', 'NAME_ATTR', 'human_id')
|
||||
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
|
||||
|
||||
|
||||
def _get_cloud(request):
|
||||
return _clouds._get_cloud(
|
||||
cloud=request.location.cloud,
|
||||
region=request.location.region,
|
||||
project=request.location.project)
|
||||
|
||||
|
||||
def convert_for_field(value, field):
|
||||
if value is None:
|
||||
return value
|
||||
if field.type in _BOOL_TYPES:
|
||||
return bool(value)
|
||||
elif field.type in _STR_TYPES:
|
||||
return str(value)
|
||||
elif field.type in _INT_TYPES:
|
||||
if value == '':
|
||||
return 0
|
||||
return int(value)
|
||||
elif field.type in _FLOAT_TYPES:
|
||||
return float(value)
|
||||
elif field.type in _ENUM_TYPES:
|
||||
return field.enum_type.values_by_name[value].number
|
||||
|
||||
|
||||
def convert_munch_to_pb(munch, pb):
|
||||
for key, value in munch.properties.items():
|
||||
pb.properties[key] = str(value)
|
||||
munch.pop('properties')
|
||||
for key, field in pb.DESCRIPTOR.fields_by_name.items():
|
||||
if field.label == field.LABEL_REPEATED:
|
||||
for value in munch.pop(key, []):
|
||||
converted = convert_for_field(value, field)
|
||||
pb.key.append(converted)
|
||||
else:
|
||||
value = convert_for_field(munch.pop(key, None), field)
|
||||
if value:
|
||||
setattr(pb, key, value)
|
||||
to_strip = set()
|
||||
for key, value in munch.items():
|
||||
if key in _FIELDS_TO_STRIP:
|
||||
to_strip.add(key)
|
||||
# TODO(mordred) this will not work for neutron, but it's fine til then
|
||||
if ':' in key:
|
||||
to_strip.add(key)
|
||||
for key in to_strip:
|
||||
munch.pop(key)
|
||||
|
||||
|
||||
def convert_flavor(flavor):
|
||||
flavor_pb = model.Flavor()
|
||||
convert_munch_to_pb(flavor, flavor_pb)
|
||||
for key, value in flavor.extra_specs.items():
|
||||
flavor_pb.properties.setdefault(key, str(value))
|
||||
return flavor_pb
|
||||
|
||||
|
||||
def convert_flavors(flavors):
|
||||
flavor_list = model.FlavorList()
|
||||
for flavor in flavors:
|
||||
# Why does this require a list extend? That seems silly enough that
|
||||
# I feel like I'm doing something wrong
|
||||
flavor_list.flavors.extend([convert_flavor(flavor)])
|
||||
return flavor_list
|
||||
|
||||
|
||||
def convert_image(image):
|
||||
image_pb = model.Image()
|
||||
tags = image.pop('tags', [])
|
||||
for tag in tags:
|
||||
image_pb.tags.append(str(tag))
|
||||
convert_munch_to_pb(image, image_pb)
|
||||
return image_pb
|
||||
|
||||
|
||||
def convert_images(images):
|
||||
image_list = model.ImageList()
|
||||
for image in images:
|
||||
# Why does this require a list extend? That seems silly enough that
|
||||
# I feel like I'm doing something wrong
|
||||
image_list.images.extend([convert_image(image)])
|
||||
return image_list
|
||||
|
||||
|
||||
def convert_security_groups(security_groups):
|
||||
security_group_list = model.SecurityGroupList()
|
||||
for security_group in security_groups:
|
||||
security_group_list.extend([convert_security_group(security_group)])
|
||||
return security_group_list
|
||||
|
||||
|
||||
def convert_security_group(security_group):
|
||||
secgroup_pb = model.SecurityGroup()
|
||||
rules = security_group.pop('security_group_rules', [])
|
||||
convert_munch_to_pb(security_group, secgroup_pb)
|
||||
for rule in rules:
|
||||
secgroup_pb.rules.append(convert_security_group_rule(rule))
|
||||
|
||||
|
||||
def convert_security_group_rules(security_group_rules):
|
||||
return _convert_dicts(
|
||||
security_group_rules,
|
||||
model.SecurityGroupRuleList,
|
||||
convert_security_group_rule,
|
||||
'rules')
|
||||
|
||||
|
||||
def _convert_dicts(dicts, list_class, convert_function, attrname):
|
||||
pb_list = list_class()
|
||||
items = []
|
||||
for item in dicts:
|
||||
items.append(convert_function(item))
|
||||
getattr(pb_list, attrname).extend(items)
|
||||
return pb_list
|
||||
|
||||
|
||||
def convert_security_group_rule(security_group_rule):
|
||||
secgroup_rule_pb = model.SecurityGroupRule()
|
||||
convert_munch_to_pb(security_group_rule, secgroup_rule_pb)
|
||||
return secgroup_rule_pb
|
||||
|
||||
|
||||
class OaktreeServicer(oaktree_pb2.OaktreeServicer):
|
||||
|
||||
def GetFlavor(self, request, context):
|
||||
logging.info('getting flavor')
|
||||
cloud = _get_cloud(request)
|
||||
return convert_flavor(
|
||||
cloud.get_flavor(
|
||||
name_or_id=request.name_or_id,
|
||||
filters=request.jmespath))
|
||||
|
||||
def SearchFlavors(self, request, context):
|
||||
logging.info('searching flavors')
|
||||
cloud = _get_cloud(request)
|
||||
return convert_flavors(
|
||||
cloud.search_flavors(
|
||||
name_or_id=request.name_or_id,
|
||||
filters=request.jmespath))
|
||||
|
||||
def GetImage(self, request, context):
|
||||
logging.info('getting image')
|
||||
cloud = _get_cloud(request)
|
||||
return convert_image(
|
||||
cloud.get_image(
|
||||
name_or_id=request.name_or_id,
|
||||
filters=request.jmespath))
|
||||
|
||||
def SearchImages(self, request, context):
|
||||
logging.info('searching images')
|
||||
cloud = _get_cloud(request)
|
||||
return convert_images(
|
||||
cloud.search_images(
|
||||
name_or_id=request.name_or_id,
|
||||
filters=request.jmespath))
|
||||
|
||||
def GetSecurityGroup(self, request, context):
|
||||
logging.info('getting security group')
|
||||
cloud = _get_cloud(request)
|
||||
return convert_security_group(
|
||||
cloud.get_security_group(
|
||||
name_or_id=request.name_or_id,
|
||||
filters=request.jmespath))
|
||||
|
||||
def SearchSecurityGroups(self, request, context):
|
||||
logging.info('searching security groups')
|
||||
cloud = _get_cloud(request)
|
||||
return convert_security_groups(
|
||||
cloud.search_security_groups(
|
||||
name_or_id=request.name_or_id,
|
||||
filters=request.jmespath))
|
||||
|
||||
def GetSecurityGroupRule(self, request, context):
|
||||
logging.info('getting security group rule')
|
||||
cloud = _get_cloud(request)
|
||||
return convert_security_group_rule(
|
||||
cloud.get_security_group_rule(
|
||||
name_or_id=request.name_or_id,
|
||||
filters=request.jmespath))
|
||||
|
||||
def SearchSecurityGroupRules(self, request, context):
|
||||
logging.info('searching security group rules')
|
||||
cloud = _get_cloud(request)
|
||||
return convert_security_group_rules(
|
||||
cloud.search_security_group_rules(
|
||||
name_or_id=request.name_or_id,
|
||||
filters=request.jmespath))
|
||||
|
||||
|
||||
def serve():
|
||||
shade.simple_logging(debug=True)
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
||||
oaktree_pb2.add_OaktreeServicer_to_server(OaktreeServicer(), server)
|
||||
server.add_insecure_port('[::]:50051')
|
||||
logging.info("Starting server")
|
||||
server.start()
|
||||
try:
|
||||
while True:
|
||||
time.sleep(_ONE_DAY_IN_SECONDS)
|
||||
except KeyboardInterrupt:
|
||||
server.stop(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
serve()
|
0
oaktree/tests/__init__.py
Normal file
0
oaktree/tests/__init__.py
Normal file
23
oaktree/tests/base.py
Normal file
23
oaktree/tests/base.py
Normal file
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2010-2011 OpenStack Foundation
|
||||
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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 oslotest import base
|
||||
|
||||
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
"""Test case base class for all unit tests."""
|
28
oaktree/tests/test_shadeapi.py
Normal file
28
oaktree/tests/test_shadeapi.py
Normal file
@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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.
|
||||
|
||||
"""
|
||||
test_oaktree
|
||||
----------------------------------
|
||||
|
||||
Tests for `oaktree` module.
|
||||
"""
|
||||
|
||||
from oaktree.tests import base
|
||||
|
||||
|
||||
class TestShadeapi(base.TestCase):
|
||||
|
||||
def test_something(self):
|
||||
pass
|
8
requirements.txt
Normal file
8
requirements.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# The order of packages is significant, because pip processes them in the order
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
pbr>=1.6
|
||||
oaktreemodel
|
||||
shade>=1.12.0
|
||||
grpc
|
32
setup.cfg
Normal file
32
setup.cfg
Normal file
@ -0,0 +1,32 @@
|
||||
[metadata]
|
||||
name = oaktree
|
||||
summary = Sane User-oriented API for OpenStack
|
||||
description-file =
|
||||
README.rst
|
||||
author = OpenStack
|
||||
author-email = openstack-dev@lists.openstack.org
|
||||
home-page = http://www.openstack.org/
|
||||
classifier =
|
||||
Environment :: OpenStack
|
||||
Intended Audience :: Information Technology
|
||||
Intended Audience :: System Administrators
|
||||
License :: OSI Approved :: Apache Software License
|
||||
Operating System :: POSIX :: Linux
|
||||
Programming Language :: Python
|
||||
Programming Language :: Python :: 2
|
||||
Programming Language :: Python :: 2.7
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3.3
|
||||
Programming Language :: Python :: 3.4
|
||||
|
||||
[files]
|
||||
packages =
|
||||
oaktree
|
||||
|
||||
[build_sphinx]
|
||||
source-dir = doc/source
|
||||
build-dir = doc/build
|
||||
all_files = 1
|
||||
|
||||
[upload_sphinx]
|
||||
upload-dir = doc/build/html
|
29
setup.py
Normal file
29
setup.py
Normal file
@ -0,0 +1,29 @@
|
||||
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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
|
||||
|
||||
# In python < 2.7.4, a lazy loading of package `pbr` will break
|
||||
# setuptools if some other modules registered functions in `atexit`.
|
||||
# solution from: http://bugs.python.org/issue15881#msg170215
|
||||
try:
|
||||
import multiprocessing # noqa
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['pbr'],
|
||||
pbr=True)
|
15
test-requirements.txt
Normal file
15
test-requirements.txt
Normal file
@ -0,0 +1,15 @@
|
||||
# The order of packages is significant, because pip processes them in the order
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
hacking<0.11,>=0.10.0
|
||||
|
||||
coverage>=3.6
|
||||
discover
|
||||
python-subunit>=0.0.18
|
||||
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
|
||||
oslosphinx>=2.5.0 # Apache-2.0
|
||||
oslotest>=1.10.0 # Apache-2.0
|
||||
testrepository>=0.0.18
|
||||
testscenarios>=0.4
|
||||
testtools>=1.4.0
|
35
tox.ini
Normal file
35
tox.ini
Normal file
@ -0,0 +1,35 @@
|
||||
[tox]
|
||||
minversion = 1.6
|
||||
envlist = py34,py27,pypy,pep8
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
usedevelop = True
|
||||
install_command = pip install -U {opts} {packages}
|
||||
setenv =
|
||||
VIRTUAL_ENV={envdir}
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
commands = python setup.py test --slowest --testr-args='{posargs}'
|
||||
|
||||
[testenv:pep8]
|
||||
commands = flake8
|
||||
|
||||
[testenv:venv]
|
||||
commands = {posargs}
|
||||
|
||||
[testenv:cover]
|
||||
commands = python setup.py test --coverage --testr-args='{posargs}'
|
||||
|
||||
[testenv:docs]
|
||||
commands = python setup.py build_sphinx
|
||||
|
||||
[testenv:debug]
|
||||
commands = oslo_debug_helper {posargs}
|
||||
|
||||
[flake8]
|
||||
# E123, E125 skipped as they are invalid PEP-8.
|
||||
|
||||
show-source = True
|
||||
ignore = E123,E125
|
||||
builtins = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,*_pb2.py
|
Loading…
Reference in New Issue
Block a user