Add command for healthcheck

Change-Id: I874809435b9afbb7282b7012a8b720c30b523a2a
This commit is contained in:
Yujun Zhang 2017-07-05 10:52:25 +08:00
parent 5d3a9a6125
commit c5804d89de
5 changed files with 65 additions and 1 deletions

View File

@ -5,12 +5,13 @@ _vitrage()
_get_comp_words_by_ref -n : cur prev words
# Command data:
cmds='alarm complete event help rca resource template topology'
cmds='alarm complete event healthcheck help rca resource template topology'
cmds_alarm='list'
cmds_alarm_list='-h --help -f --format -c --column --max-width --print-empty --noindent --quote --all-tenants'
cmds_complete='-h --help --name --shell'
cmds_event='post'
cmds_event_post='-h --help --type --time --details'
cmds_healthcheck='-h --help -f --format -c --column --max-width --print-empty --noindent --variable --prefix'
cmds_help='-h --help'
cmds_rca='show'
cmds_rca_show='-h --help -f --format -c --column --max-width --print-empty --noindent --variable --prefix --all-tenants'

View File

@ -34,6 +34,7 @@ from vitrageclient import client
from vitrageclient.v1.cli import alarm
from vitrageclient.v1.cli import event
from vitrageclient.v1.cli import healthcheck
from vitrageclient.v1.cli import rca
from vitrageclient.v1.cli import resource
from vitrageclient.v1.cli import template
@ -51,6 +52,7 @@ class VitrageCommandManager(commandmanager.CommandManager):
'template list': template.TemplateList,
'template show': template.TemplateShow,
'event post': event.EventPost,
'healthcheck': healthcheck.HealthCheck
}
def load_commands(self, namespace):

View File

@ -0,0 +1,23 @@
# Copyright 2017 - ZTE Corporation
#
# 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 show
# noinspection PyAbstractClass
class HealthCheck(show.ShowOne):
"""Check api health status"""
def take_action(self, parsed_args):
return self.dict2columns(self.app.client.healthcheck.get())

View File

@ -14,6 +14,7 @@ from vitrageclient import client
from vitrageclient.v1 import alarm
from vitrageclient.v1 import event
from vitrageclient.v1 import healthcheck
from vitrageclient.v1 import rca
from vitrageclient.v1 import resource
from vitrageclient.v1 import template
@ -31,3 +32,4 @@ class Client(object):
self.rca = rca.Rca(self._api)
self.template = template.Template(self._api)
self.event = event.Event(self._api)
self.healthcheck = healthcheck.HealthCheck(self._api)

View File

@ -0,0 +1,36 @@
# Copyright 2017 - ZTE Corporation
#
# 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 vitrageclient.exc import ClientException
class HealthCheck(object):
URL = 'healthcheck/'
STATUS_CODE_OK = 200
def __init__(self, api):
self.api = api
def get(self):
"""Get healthcheck result"""
try:
resp = self.api.get(self.URL)
except ClientException as e:
return {"passed": False,
"message": e.message,
"url": e.url,
"status_code": e.code}
return {"passed": resp.status_code == self.STATUS_CODE_OK,
"status_code": resp.status_code}