add initial files for shell

Implements: blueprint vitrage-cli
Change-Id: I555152c53f4b27d95a215cea0fedf782daa446cf
This commit is contained in:
Eyal 2015-11-16 15:30:09 +02:00
parent cb99346606
commit 287aa41c50
8 changed files with 118 additions and 4 deletions

View File

@ -4,3 +4,5 @@
pbr>=1.6
Babel>=1.3
cliff>=1.14.0
oslo.utils>=2.0.0

View File

@ -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

View File

@ -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)

View File

View File

@ -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)

View File

@ -19,3 +19,7 @@ class VitrageBaseException(Exception):
def __str__(self):
return self.message or self.__class__.__doc__
class VitrageClientException(VitrageBaseException):
pass

View File

@ -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()

View File

@ -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