Skip to content

Commit 395cbc6

Browse files
committed
Add initial cliff CLI
Adds a fake cmd to print out static capacity.
1 parent 5a94ccb commit 395cbc6

22 files changed

+397
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,7 @@ ENV/
9999

100100
# mypy
101101
.mypy_cache/
102+
103+
# vim
104+
*.swp
105+
*.swo

CONTRIBUTING.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
os-capacity does not currently follow the upstream OpenStack development
2+
process, but we will still be incredibly grateful for any contributions.
3+
4+
Please raise issues and submit pull requests via Github.
5+
6+
Thanks in advance!

README.md renamed to README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
# os-capacity-probe
1+
os-capacity
2+
===========
3+
24
Find out how much capacity you have in your OpenStack cloud.

doc/source/conf.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright (c) 2017 StackHPC Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
# -*- coding: utf-8 -*-
16+
# Licensed under the Apache License, Version 2.0 (the "License");
17+
# you may not use this file except in compliance with the License.
18+
# You may obtain a copy of the License at
19+
#
20+
# http://www.apache.org/licenses/LICENSE-2.0
21+
#
22+
# Unless required by applicable law or agreed to in writing, software
23+
# distributed under the License is distributed on an "AS IS" BASIS,
24+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
25+
# implied.
26+
# See the License for the specific language governing permissions and
27+
# limitations under the License.
28+
29+
import os
30+
import sys
31+
32+
sys.path.insert(0, os.path.abspath('../..'))
33+
# -- General configuration ----------------------------------------------------
34+
35+
# Add any Sphinx extension module names here, as strings. They can be
36+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
37+
extensions = [
38+
'sphinx.ext.autodoc',
39+
#'sphinx.ext.intersphinx',
40+
# Uncomment this to enable the OpenStack documentation style, adding
41+
# oslosphinx to test-requirements.txt.
42+
#'oslosphinx',
43+
]
44+
45+
# autodoc generation is a bit aggressive and a nuisance when doing heavy
46+
# text edit cycles.
47+
# execute "export SPHINX_DEBUG=1" in your terminal to disable
48+
49+
# The suffix of source filenames.
50+
source_suffix = '.rst'
51+
52+
# The master toctree document.
53+
master_doc = 'index'
54+
55+
# General information about the project.
56+
project = u'os-capacity'
57+
copyright = u'2017, StackHPC Ltd.'
58+
59+
# If true, '()' will be appended to :func: etc. cross-reference text.
60+
add_function_parentheses = True
61+
62+
# If true, the current module name will be prepended to all description
63+
# unit titles (such as .. function::).
64+
add_module_names = True
65+
66+
# The name of the Pygments (syntax highlighting) style to use.
67+
pygments_style = 'sphinx'
68+
69+
# -- Options for HTML output --------------------------------------------------
70+
71+
# The theme to use for HTML and HTML Help pages. Major themes that come with
72+
# Sphinx are currently 'default' and 'sphinxdoc'.
73+
# html_theme_path = ["."]
74+
# html_theme = '_theme'
75+
# html_static_path = ['static']
76+
77+
# Output file base name for HTML help builder.
78+
htmlhelp_basename = '%sdoc' % project
79+
80+
# Grouping the document tree into LaTeX files. List of tuples
81+
# (source start file, target name, title, author, documentclass
82+
# [howto/manual]).
83+
latex_documents = [
84+
('index',
85+
'%s.tex' % project,
86+
u'%s Documentation' % project,
87+
u'OpenStack Foundation', 'manual'),
88+
]
89+
90+
# Example configuration for intersphinx: refer to the Python standard library.
91+
#intersphinx_mapping = {'http://docs.python.org/': None}

doc/source/development.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TODO development
2+
================

doc/source/index.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Welcome to os-capacity's documentation!
2+
=======================================
3+
4+
.. include:: ../../README.rst
5+
6+
Documentation
7+
-------------
8+
9+
.. note::
10+
11+
nothing to see here yet :(
12+
13+
.. toctree::
14+
:maxdepth: 2
15+
16+
installation
17+
usage
18+
19+
Developer Documentation
20+
-----------------------
21+
22+
.. toctree::
23+
:maxdepth: 2
24+
25+
development

doc/source/installation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TODO: Install
2+
=============

doc/source/usage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TODO: usage docs
2+
================

os_capacity/__init__.py

Whitespace-only changes.

os_capacity/cli/__init__.py

Whitespace-only changes.

os_capacity/cli/commands.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) 2017 StackHPC Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
16+
import logging
17+
import os
18+
19+
from cliff.lister import Lister
20+
21+
from os_capacity import utils
22+
23+
24+
class CapacityGet(Lister):
25+
"""Show a list of files in the current directory.
26+
27+
The file name and size are printed by default.
28+
"""
29+
30+
log = logging.getLogger(__name__)
31+
32+
def take_action(self, parsed_args):
33+
capacity = utils.get_capacity()
34+
return (
35+
('Flavor', 'Count'),
36+
((entry["flavor"], entry["count"]) for entry in capacity)
37+
)

os_capacity/cmd/__init__.py

Whitespace-only changes.

os_capacity/cmd/os_capacity.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) 2017 StackHPC Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
import sys
16+
17+
from cliff.app import App
18+
from cliff.commandmanager import CommandManager
19+
20+
21+
class CapacityApp(App):
22+
23+
def __init__(self):
24+
super(CapacityApp, self).__init__(
25+
description='OS-Capacity (StackHPC) Command Line Interface (CLI)',
26+
version='0.1',
27+
command_manager=CommandManager('os_capacity.cli'),
28+
deferred_help=True,
29+
)
30+
31+
def initialize_app(self, argv):
32+
self.LOG.debug('initialize_app')
33+
34+
def prepare_to_run_command(self, cmd):
35+
self.LOG.debug('prepare_to_run_command %s', cmd.__class__.__name__)
36+
37+
def clean_up(self, cmd, result, err):
38+
self.LOG.debug('clean_up %s', cmd.__class__.__name__)
39+
if err:
40+
self.LOG.debug('got an error: %s', err)
41+
42+
43+
def main(argv=sys.argv[1:]):
44+
myapp = CapacityApp()
45+
return myapp.run(argv)
46+
47+
48+
if __name__ == '__main__':
49+
sys.exit(main(sys.argv[1:]))

os_capacity/tests/__init__.py

Whitespace-only changes.

os_capacity/tests/unit/__init__.py

Whitespace-only changes.

os_capacity/tests/unit/test_utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2017 StackHPC Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
import unittest
16+
17+
from os_capacity import utils
18+
19+
20+
class TestUtils(unittest.TestCase):
21+
22+
def test_get_capacity(self):
23+
result = utils.get_capacity()
24+
self.assertEqual(1, len(result))
25+
self.assertEqual(2, len(result[0]))
26+
self.assertEqual("foo", result[0]["flavor"])
27+
self.assertEqual(1, result[0]["count"])

os_capacity/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2017 StackHPC Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
16+
def get_capacity():
17+
return [{"flavor": "foo", "count": 1}]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cliff>=2.5.0 # Apache

setup.cfg

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[metadata]
2+
name = kayobe
3+
summary = Deployment of Scientific OpenStack using OpenStack Kolla
4+
description-file =
5+
README.rst
6+
author = Mark Goddard
7+
author-email = [email protected]
8+
home-page = https://stackhpc.com
9+
classifier =
10+
Environment :: OpenStack
11+
Intended Audience :: Information Technology
12+
Intended Audience :: System Administrators
13+
Operating System :: POSIX :: Linux
14+
Programming Language :: Python
15+
Programming Language :: Python :: 2
16+
Programming Language :: Python :: 2.7
17+
18+
[files]
19+
packages =
20+
kayobe
21+
22+
[build_sphinx]
23+
all-files = 1
24+
source-dir = doc/source
25+
build-dir = doc/build
26+
27+
[upload_sphinx]
28+
upload-dir = doc/build/html

setup.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) 2017 StackHPC Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
#!/usr/bin/env python
16+
17+
from setuptools import setup, find_packages
18+
19+
20+
PROJECT = 'os_capacity'
21+
VERSION = '0.1'
22+
23+
try:
24+
long_description = open('README.md', 'rt').read()
25+
except IOError:
26+
long_description = ''
27+
28+
setup(
29+
name=PROJECT,
30+
version=VERSION,
31+
32+
description='OpenStack capacity tooling',
33+
long_description=long_description,
34+
35+
author='StackHPC',
36+
author_email='[email protected]',
37+
38+
url='https://github.com/stackhpc/os-capacity',
39+
download_url='https://github.com/stackhpc/os-capacity/tarball/master',
40+
41+
provides=[],
42+
install_requires=open('requirements.txt', 'rt').read().splitlines(),
43+
44+
namespace_packages=[],
45+
packages=find_packages(),
46+
include_package_data=True,
47+
48+
entry_points={
49+
'console_scripts': [
50+
'os-capacity = os_capacity.cmd.os_capacity:main',
51+
],
52+
'os_capacity.cli': [
53+
'capacity_get = os_capacity.cli.commands:CapacityGet',
54+
],
55+
},
56+
)

test-requirements.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# The order of packages is significant, because pip processes them in the order
2+
# of appearance. Changing the order has an impact on the overall integration
3+
# process, which may cause wedges in the gate later.
4+
5+
hacking>=0.12.0,<0.13 # Apache-2.0
6+
7+
coverage>=4.0 # Apache-2.0
8+
doc8 # Apache-2.0
9+
sphinx>=1.5.1 # BSD
10+
oslotest>=1.10.0 # Apache-2.0

0 commit comments

Comments
 (0)