add vitrage client to osc
Change-Id: I73d64237f32ab7fff11cb7c2b7bf847f3bb0342f
This commit is contained in:
parent
603e2569b8
commit
020c1b3a7f
@ -5,5 +5,6 @@
|
||||
pbr>=1.8 # Apache-2.0
|
||||
Babel>=2.3.4 # BSD
|
||||
cliff>=2.3.0 # Apache-2.0
|
||||
osc-lib>=1.2.0 # Apache-2.0
|
||||
oslo.utils>=3.18.0 # Apache-2.0
|
||||
keystoneauth1>=2.14.0 # Apache-2.0
|
||||
|
13
setup.cfg
13
setup.cfg
@ -33,6 +33,19 @@ setup-hooks =
|
||||
console_scripts =
|
||||
vitrage = vitrageclient.shell:main
|
||||
|
||||
openstack.cli.extension =
|
||||
rca = vitrageclient.osc
|
||||
|
||||
openstack.rca.v1 =
|
||||
rca_show = vitrageclient.v1.cli.rca:RcaShow
|
||||
rca_topology_show = vitrageclient.v1.cli.topology:TopologyShow
|
||||
rca_alarm_list = vitrageclient.v1.cli.alarm:AlarmList
|
||||
rca_resource_list = vitrageclient.v1.cli.resource:ResourceList
|
||||
rca_resource_show = vitrageclient.v1.cli.resource:ResourceShow
|
||||
rca_template_list = vitrageclient.v1.cli.template:TemplateList
|
||||
rca_template_show = vitrageclient.v1.cli.template:TemplateShow
|
||||
rca_template_validate = vitrageclient.v1.cli.template:TemplateValidate
|
||||
|
||||
|
||||
[build_sphinx]
|
||||
source-dir = doc/source
|
||||
|
@ -30,3 +30,10 @@ def args_to_dict(args, attrs):
|
||||
def list2cols(cols, objs):
|
||||
return cols, [tuple([o[k] for k in cols])
|
||||
for o in objs]
|
||||
|
||||
|
||||
def get_client(obj):
|
||||
if hasattr(obj.app, 'client_manager'):
|
||||
return obj.app.client_manager.metric
|
||||
else:
|
||||
return obj.app.client
|
||||
|
55
vitrageclient/osc.py
Normal file
55
vitrageclient/osc.py
Normal file
@ -0,0 +1,55 @@
|
||||
# Copyright 2014 OpenStack Foundation
|
||||
#
|
||||
# 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 osc_lib import utils
|
||||
|
||||
|
||||
DEFAULT_RCA_API_VERSION = '1'
|
||||
API_VERSION_OPTION = 'os_rca_api_version'
|
||||
API_NAME = "rca"
|
||||
API_VERSIONS = {
|
||||
"1": "vitrageclient.v1.client.Client",
|
||||
}
|
||||
|
||||
|
||||
def make_client(instance):
|
||||
"""Returns a vitrage service client."""
|
||||
version = instance._api_version[API_NAME]
|
||||
try:
|
||||
version = int(version)
|
||||
except ValueError:
|
||||
version = float(version)
|
||||
|
||||
vitrage_client = utils.get_client_class(
|
||||
API_NAME,
|
||||
version,
|
||||
API_VERSIONS)
|
||||
instance.setup_auth()
|
||||
return vitrage_client(session=instance.session,
|
||||
interface=instance.interface,
|
||||
region_name=instance.region_name)
|
||||
|
||||
|
||||
def build_option_parser(parser):
|
||||
"""Hook to add global options."""
|
||||
parser.add_argument(
|
||||
'--os-rca-api-version',
|
||||
metavar='<rca-api-version>',
|
||||
default=utils.env(
|
||||
'OS_RCA_API_VERSION',
|
||||
default=DEFAULT_RCA_API_VERSION),
|
||||
help=('Rca API version, default=' +
|
||||
DEFAULT_RCA_API_VERSION +
|
||||
' (Env: OS_RCS_API_VERSION)'))
|
||||
return parser
|
@ -42,8 +42,8 @@ class AlarmList(lister.Lister):
|
||||
vitrage_id = parsed_args.vitrage_id
|
||||
all_tenants = parsed_args.all_tenants
|
||||
|
||||
alarms = self.app.client.alarm.list(vitrage_id=vitrage_id,
|
||||
all_tenants=all_tenants)
|
||||
alarms = utils.get_client(self).alarm.list(vitrage_id=vitrage_id,
|
||||
all_tenants=all_tenants)
|
||||
return utils.list2cols(('vitrage_id',
|
||||
'type',
|
||||
'name',
|
||||
|
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
from cliff import show
|
||||
from vitrageclient.common import utils
|
||||
|
||||
|
||||
# noinspection PyAbstractClass
|
||||
@ -40,7 +41,7 @@ class RcaShow(show.ShowOne):
|
||||
alarm_id = parsed_args.alarm_id
|
||||
all_tenants = parsed_args.all_tenants
|
||||
|
||||
alarm = self.app.client.rca.get(alarm_id=alarm_id,
|
||||
all_tenants=all_tenants)
|
||||
alarm = utils.get_client(self).rca.get(alarm_id=alarm_id,
|
||||
all_tenants=all_tenants)
|
||||
|
||||
return self.dict2columns(alarm)
|
||||
|
@ -13,6 +13,8 @@
|
||||
from cliff import lister
|
||||
from cliff import show
|
||||
|
||||
from vitrageclient.common import utils
|
||||
|
||||
|
||||
# noinspection PyAbstractClass
|
||||
class ResourceShow(show.ShowOne):
|
||||
@ -25,7 +27,7 @@ class ResourceShow(show.ShowOne):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
resource_id = parsed_args.resource_id
|
||||
resource = self.app.client.resource.get(resource_id=resource_id)
|
||||
resource = utils.get_client(self).resource.get(resource_id=resource_id)
|
||||
return self.dict2columns(resource)
|
||||
|
||||
|
||||
@ -42,5 +44,6 @@ class ResourceList(lister.Lister):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
resource_type = parsed_args.resource_type
|
||||
resources = self.app.client.resource.list(resource_type=resource_type)
|
||||
resources = utils.get_client(self).resource.list(
|
||||
resource_type=resource_type)
|
||||
return [], resources
|
||||
|
@ -36,8 +36,8 @@ class TemplateValidate(show.ShowOne):
|
||||
if not parsed_args.path:
|
||||
raise exc.CommandException(message='No path requested, add --path')
|
||||
|
||||
if parsed_args.path:
|
||||
result = self.app.client.template.validate(path=parsed_args.path)
|
||||
result = utils.get_client(self).template.validate(
|
||||
path=parsed_args.path)
|
||||
|
||||
return self.dict2columns(result)
|
||||
|
||||
@ -50,7 +50,7 @@ class TemplateList(lister.Lister):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
templates = self.app.client.template.list()
|
||||
templates = utils.get_client(self).template.list()
|
||||
return utils.list2cols(('uuid',
|
||||
'name',
|
||||
'status',
|
||||
@ -71,5 +71,5 @@ class TemplateShow(show.ShowOne):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
uuid = parsed_args.uuid
|
||||
template = self.app.client.template.show(uuid=uuid)
|
||||
template = utils.get_client(self).template.show(uuid=uuid)
|
||||
return self.dict2columns(template)
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
from cliff import show
|
||||
from vitrageclient.common import exc
|
||||
from vitrageclient.common import utils
|
||||
|
||||
|
||||
# noinspection PyAbstractClass
|
||||
@ -65,9 +66,9 @@ class TopologyShow(show.ShowOne):
|
||||
raise exc.CommandException(
|
||||
message="Graph-type 'graph' requires a 'root' with 'limit'.")
|
||||
|
||||
topology = self.app.client.topology.get(limit=limit,
|
||||
graph_type=graph_type,
|
||||
query=query,
|
||||
root=root,
|
||||
all_tenants=all_tenants)
|
||||
topology = utils.get_client(self).topology.get(limit=limit,
|
||||
graph_type=graph_type,
|
||||
query=query,
|
||||
root=root,
|
||||
all_tenants=all_tenants)
|
||||
return self.dict2columns(topology)
|
||||
|
Loading…
Reference in New Issue
Block a user