add more api
added topology show and topology list Implements: blueprint vitrage-cli Change-Id: Id630e19c240fef95692260235e67e36b970120c6
This commit is contained in:
parent
3a20796127
commit
ae3935d7a5
@ -10,11 +10,27 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import exc
|
||||||
|
|
||||||
|
from keystoneauth1 import adapter
|
||||||
from vitrageclient.common import utils
|
from vitrageclient.common import utils
|
||||||
|
|
||||||
|
|
||||||
def get_client(version, *args, **kwargs):
|
# noinspection PyPep8Naming
|
||||||
|
def Client(version, *args, **kwargs):
|
||||||
module = utils.import_versioned_module(version, 'client')
|
module = utils.import_versioned_module(version, 'client')
|
||||||
client_class = getattr(module, 'Client')
|
client_class = getattr(module, 'Client')
|
||||||
return client_class(*args, **kwargs)
|
return client_class(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class VitrageClient(adapter.Adapter):
|
||||||
|
def request(self, url, method, **kwargs):
|
||||||
|
raise_exc = kwargs.pop('raise_exc', True)
|
||||||
|
resp = super(VitrageClient, self).request(url,
|
||||||
|
method,
|
||||||
|
raise_exc=False,
|
||||||
|
**kwargs)
|
||||||
|
|
||||||
|
if raise_exc and resp.status_code >= 400:
|
||||||
|
raise exc.from_response(resp, url, method)
|
||||||
|
return resp
|
||||||
|
@ -30,3 +30,7 @@ class ClientException(Exception):
|
|||||||
formatted_string += " (Request-ID: %s)" % self.request_id
|
formatted_string += " (Request-ID: %s)" % self.request_id
|
||||||
|
|
||||||
return formatted_string
|
return formatted_string
|
||||||
|
|
||||||
|
|
||||||
|
def from_response(resp, url, method):
|
||||||
|
return None
|
||||||
|
@ -16,9 +16,8 @@ Vitrage command line interface
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import client
|
|
||||||
import logging
|
import logging
|
||||||
import noauth
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
@ -27,7 +26,10 @@ from cliff import app
|
|||||||
from cliff import commandmanager
|
from cliff import commandmanager
|
||||||
from keystoneauth1 import exceptions
|
from keystoneauth1 import exceptions
|
||||||
from keystoneauth1 import loading
|
from keystoneauth1 import loading
|
||||||
from v1 import topology
|
|
||||||
|
import client
|
||||||
|
import noauth
|
||||||
|
from v1.cli import topology
|
||||||
from vitrageclient import __version__
|
from vitrageclient import __version__
|
||||||
|
|
||||||
|
|
||||||
@ -115,7 +117,7 @@ class VitrageShell(app.App):
|
|||||||
self.options, auth=auth_plugin)
|
self.options, auth=auth_plugin)
|
||||||
|
|
||||||
# noinspection PyAttributeOutsideInit
|
# noinspection PyAttributeOutsideInit
|
||||||
self._client = client.get_client(
|
self._client = client.Client(
|
||||||
self.options.vitrage_api_version,
|
self.options.vitrage_api_version,
|
||||||
session=session,
|
session=session,
|
||||||
interface=self.options.interface,
|
interface=self.options.interface,
|
||||||
@ -135,7 +137,6 @@ class VitrageShell(app.App):
|
|||||||
|
|
||||||
def configure_logging(self):
|
def configure_logging(self):
|
||||||
if self.options.debug:
|
if self.options.debug:
|
||||||
# Set this here so cliff.app.configure_logging() can work
|
|
||||||
self._set_debug_logging_messages()
|
self._set_debug_logging_messages()
|
||||||
|
|
||||||
super(VitrageShell, self).configure_logging()
|
super(VitrageShell, self).configure_logging()
|
||||||
|
0
vitrageclient/v1/cli/__init__.py
Normal file
0
vitrageclient/v1/cli/__init__.py
Normal file
34
vitrageclient/v1/cli/topology.py
Normal file
34
vitrageclient/v1/cli/topology.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# 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):
|
||||||
|
|
||||||
|
COLS = ('id', 'name', 'description')
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
topologies = self.app.client.topology.list()
|
||||||
|
return self.COLS, [tuple([topologies[col] for col in self.COLS])]
|
||||||
|
|
||||||
|
|
||||||
|
class TopologyShow(show.ShowOne):
|
||||||
|
def get_parser(self, uuid):
|
||||||
|
parser = super(TopologyShow, self).get_parser(uuid)
|
||||||
|
parser.add_argument("id", help="Id of the topology")
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
topology = self.app.client.topology.get(id=parsed_args.id)
|
||||||
|
return self.dict2columns(topology)
|
@ -10,6 +10,25 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from v1 import topology
|
||||||
|
from vitrageclient import client
|
||||||
|
|
||||||
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
pass
|
DEFAULT_HEADERS = {
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, session=None, service_type='rca', **kwargs):
|
||||||
|
self._set_default_headers(kwargs)
|
||||||
|
self._api = client.VitrageClient(session, service_type=service_type,
|
||||||
|
**kwargs)
|
||||||
|
self.topology = topology.Topology(self._api)
|
||||||
|
|
||||||
|
def _set_default_headers(self, kwargs):
|
||||||
|
headers = kwargs.get('headers', {})
|
||||||
|
for k, v in self.DEFAULT_HEADERS.items():
|
||||||
|
if k not in headers:
|
||||||
|
headers[k] = v
|
||||||
|
kwargs['headers'] = headers
|
||||||
|
return kwargs
|
||||||
|
@ -10,15 +10,23 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from cliff import lister
|
|
||||||
from cliff import show
|
|
||||||
|
|
||||||
|
class Topology(object):
|
||||||
|
URL = "v1/topologies/"
|
||||||
|
|
||||||
class TopologyList(lister.Lister):
|
def __init__(self, api):
|
||||||
def take_action(self, parsed_args):
|
self.api = api
|
||||||
pass
|
|
||||||
|
|
||||||
|
def list(self):
|
||||||
|
"""List topologies"""
|
||||||
|
|
||||||
class TopologyShow(show.ShowOne):
|
return self.api.get(self.URL).json()
|
||||||
def take_action(self, parsed_args):
|
|
||||||
pass
|
def get(self, uuid):
|
||||||
|
"""Get a topology
|
||||||
|
|
||||||
|
:param uuid: Id of topology
|
||||||
|
:type uuid: str
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self.api.get(self.URL + uuid).json()
|
||||||
|
Loading…
Reference in New Issue
Block a user