Skip to content

Commit

Permalink
Add initial cliff CLI
Browse files Browse the repository at this point in the history
Adds a fake cmd to print out static capacity.
  • Loading branch information
JohnGarbutt committed Aug 21, 2017
1 parent 5a94ccb commit 395cbc6
Show file tree
Hide file tree
Showing 22 changed files with 397 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ ENV/

# mypy
.mypy_cache/

# vim
*.swp
*.swo
6 changes: 6 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
os-capacity does not currently follow the upstream OpenStack development
process, but we will still be incredibly grateful for any contributions.

Please raise issues and submit pull requests via Github.

Thanks in advance!
4 changes: 3 additions & 1 deletion README.md → README.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# os-capacity-probe
os-capacity
===========

Find out how much capacity you have in your OpenStack cloud.
91 changes: 91 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright (c) 2017 StackHPC Ltd.
#
# 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.

# -*- 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',
# Uncomment this to enable the OpenStack documentation style, adding
# oslosphinx to test-requirements.txt.
#'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'os-capacity'
copyright = u'2017, StackHPC Ltd.'

# 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}
2 changes: 2 additions & 0 deletions doc/source/development.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TODO development
================
25 changes: 25 additions & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Welcome to os-capacity's documentation!
=======================================

.. include:: ../../README.rst

Documentation
-------------

.. note::

nothing to see here yet :(

.. toctree::
:maxdepth: 2

installation
usage

Developer Documentation
-----------------------

.. toctree::
:maxdepth: 2

development
2 changes: 2 additions & 0 deletions doc/source/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TODO: Install
=============
2 changes: 2 additions & 0 deletions doc/source/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TODO: usage docs
================
Empty file added os_capacity/__init__.py
Empty file.
Empty file added os_capacity/cli/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions os_capacity/cli/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2017 StackHPC Ltd.
#
# 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 logging
import os

from cliff.lister import Lister

from os_capacity import utils


class CapacityGet(Lister):
"""Show a list of files in the current directory.
The file name and size are printed by default.
"""

log = logging.getLogger(__name__)

def take_action(self, parsed_args):
capacity = utils.get_capacity()
return (
('Flavor', 'Count'),
((entry["flavor"], entry["count"]) for entry in capacity)
)
Empty file added os_capacity/cmd/__init__.py
Empty file.
49 changes: 49 additions & 0 deletions os_capacity/cmd/os_capacity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) 2017 StackHPC Ltd.
#
# 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 sys

from cliff.app import App
from cliff.commandmanager import CommandManager


class CapacityApp(App):

def __init__(self):
super(CapacityApp, self).__init__(
description='OS-Capacity (StackHPC) Command Line Interface (CLI)',
version='0.1',
command_manager=CommandManager('os_capacity.cli'),
deferred_help=True,
)

def initialize_app(self, argv):
self.LOG.debug('initialize_app')

def prepare_to_run_command(self, cmd):
self.LOG.debug('prepare_to_run_command %s', cmd.__class__.__name__)

def clean_up(self, cmd, result, err):
self.LOG.debug('clean_up %s', cmd.__class__.__name__)
if err:
self.LOG.debug('got an error: %s', err)


def main(argv=sys.argv[1:]):
myapp = CapacityApp()
return myapp.run(argv)


if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
Empty file added os_capacity/tests/__init__.py
Empty file.
Empty file.
27 changes: 27 additions & 0 deletions os_capacity/tests/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2017 StackHPC Ltd.
#
# 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 unittest

from os_capacity import utils


class TestUtils(unittest.TestCase):

def test_get_capacity(self):
result = utils.get_capacity()
self.assertEqual(1, len(result))
self.assertEqual(2, len(result[0]))
self.assertEqual("foo", result[0]["flavor"])
self.assertEqual(1, result[0]["count"])
17 changes: 17 additions & 0 deletions os_capacity/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2017 StackHPC Ltd.
#
# 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 get_capacity():
return [{"flavor": "foo", "count": 1}]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cliff>=2.5.0 # Apache
28 changes: 28 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[metadata]
name = kayobe
summary = Deployment of Scientific OpenStack using OpenStack Kolla
description-file =
README.rst
author = Mark Goddard
author-email = [email protected]
home-page = https://stackhpc.com
classifier =
Environment :: OpenStack
Intended Audience :: Information Technology
Intended Audience :: System Administrators
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7

[files]
packages =
kayobe

[build_sphinx]
all-files = 1
source-dir = doc/source
build-dir = doc/build

[upload_sphinx]
upload-dir = doc/build/html
56 changes: 56 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2017 StackHPC Ltd.
#
# 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.

#!/usr/bin/env python

from setuptools import setup, find_packages


PROJECT = 'os_capacity'
VERSION = '0.1'

try:
long_description = open('README.md', 'rt').read()
except IOError:
long_description = ''

setup(
name=PROJECT,
version=VERSION,

description='OpenStack capacity tooling',
long_description=long_description,

author='StackHPC',
author_email='[email protected]',

url='https://github.com/stackhpc/os-capacity',
download_url='https://github.com/stackhpc/os-capacity/tarball/master',

provides=[],
install_requires=open('requirements.txt', 'rt').read().splitlines(),

namespace_packages=[],
packages=find_packages(),
include_package_data=True,

entry_points={
'console_scripts': [
'os-capacity = os_capacity.cmd.os_capacity:main',
],
'os_capacity.cli': [
'capacity_get = os_capacity.cli.commands:CapacityGet',
],
},
)
10 changes: 10 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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.12.0,<0.13 # Apache-2.0

coverage>=4.0 # Apache-2.0
doc8 # Apache-2.0
sphinx>=1.5.1 # BSD
oslotest>=1.10.0 # Apache-2.0
Loading

0 comments on commit 395cbc6

Please sign in to comment.