diff --git a/requirements.txt b/requirements.txt index 08b0f01..95d7e07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,5 @@ pbr>=1.6 Babel>=1.3 +cliff>=1.14.0 +oslo.utils>=2.0.0 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index a52b3c6..dc343c2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,6 +20,14 @@ classifier = packages = vitrageclient +[global] +setup-hooks = + pbr.hooks.setup_hook + +[entry_points] +console_scripts = + vitrage = vitrageclient.shell:main + [build_sphinx] source-dir = doc/source build-dir = doc/build diff --git a/vitrageclient/client.py b/vitrageclient/client.py index d5bcf39..a233d60 100644 --- a/vitrageclient/client.py +++ b/vitrageclient/client.py @@ -11,5 +11,10 @@ # under the License. -class Client(object): - pass +from vitrageclient.common import utils + + +def get_client_class(version, *args, **kwargs): + module = utils.import_versioned_module(version, 'client') + client_class = getattr(module, 'Client') + return client_class(*args, **kwargs) diff --git a/vitrageclient/common/__init__.py b/vitrageclient/common/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/vitrageclient/common/utils.py b/vitrageclient/common/utils.py new file mode 100644 index 0000000..964a79c --- /dev/null +++ b/vitrageclient/common/utils.py @@ -0,0 +1,21 @@ +# +# 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 oslo_utils import importutils + + +def import_versioned_module(version, submodule=None): + module = 'vitrageclient.v%s' % version + if submodule: + module = '.'.join((module, submodule)) + return importutils.import_module(module) diff --git a/vitrageclient/exc.py b/vitrageclient/exc.py index 7125090..ccc6f16 100644 --- a/vitrageclient/exc.py +++ b/vitrageclient/exc.py @@ -19,3 +19,7 @@ class VitrageBaseException(Exception): def __str__(self): return self.message or self.__class__.__doc__ + + +class VitrageClientException(VitrageBaseException): + pass diff --git a/vitrageclient/shell.py b/vitrageclient/shell.py index 12055bf..ede4a52 100644 --- a/vitrageclient/shell.py +++ b/vitrageclient/shell.py @@ -11,5 +11,55 @@ # under the License. -class VitrageShell(object): - pass +""" +Vitrage command line interface +""" + +from __future__ import print_function + +from cliff import app +from cliff import commandmanager + +import sys +from v1 import topology +from vitrageclient import __version__ + + +class VitrageCommandManager(commandmanager.CommandManager): + COMMANDS = { + "topology list": topology.TopologyList, + "topology show": topology.TopologyShow, + } + + def load_commands(self, namespace): + for k, v in self.COMMANDS.items(): + self.add_command(k, v) + + +class VitrageShell(app.App): + def __init__(self): + super(VitrageShell, self).__init__( + description=__doc__, + version=__version__, + command_manager=VitrageCommandManager(None), + deferred_help=True, + ) + + def run(self, args): + pass + + +def main(args=None): + try: + if args is None: + args = sys.argv[1:] + return VitrageShell().run(args) + except KeyboardInterrupt: + print("... terminating vitrage client", file=sys.stderr) + sys.exit(1) + except Exception as e: + print(e) + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/vitrageclient/v1/topology.py b/vitrageclient/v1/topology.py new file mode 100644 index 0000000..c7ae7aa --- /dev/null +++ b/vitrageclient/v1/topology.py @@ -0,0 +1,24 @@ +# 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 cliff import lister +from cliff import show + + +class TopologyList(lister.Lister): + def take_action(self, parsed_args): + pass + + +class TopologyShow(show.ShowOne): + def take_action(self, parsed_args): + pass