![Paul Belanger](/assets/img/avatar_default.png)
This is for the same reasoning as oslo_log. We don't want to depending on OpenStack libraries. Change-Id: I34e66af578d3f4b5ac5e710554aad91524285816 Signed-off-by: Paul Belanger <pabelanger@redhat.com>
102 lines
3.2 KiB
Python
102 lines
3.2 KiB
Python
# Copyright 2015 Red Hat, Inc.
|
|
#
|
|
# 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.
|
|
|
|
import argparse
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
from six.moves import configparser as ConfigParser
|
|
|
|
from grafana_dashboards.builder import Builder
|
|
from grafana_dashboards import version
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class Client(object):
|
|
|
|
def main(self):
|
|
self.parse_arguments()
|
|
self.read_config()
|
|
self.setup_logging()
|
|
|
|
self.args.func()
|
|
|
|
def parse_arguments(self):
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument(
|
|
'--config-file', dest='config', help='Path to a config file to '
|
|
'use. The default file used is: /etc/grafyaml/grafyaml.conf')
|
|
parser.add_argument(
|
|
'--debug', dest='debug', action='store_true',
|
|
help='Print debugging output (set logging level to DEBUG instead '
|
|
' of default INFO level)')
|
|
parser.add_argument(
|
|
'--version', dest='version', action='version',
|
|
version=version.version_info.release_string(), help="show "
|
|
"program's version number and exit")
|
|
|
|
subparsers = parser.add_subparsers(
|
|
title='commands')
|
|
|
|
parser_update = subparsers.add_parser('update')
|
|
parser_update.add_argument(
|
|
'path', help='colon-separated list of paths to YAML files or'
|
|
' directories')
|
|
parser_update.set_defaults(func=self.update)
|
|
|
|
parser_validate = subparsers.add_parser('validate')
|
|
parser_validate.add_argument(
|
|
'path', help='colon-separated list of paths to YAML files or'
|
|
' directories')
|
|
parser_validate.set_defaults(func=self.validate)
|
|
|
|
self.args = parser.parse_args()
|
|
|
|
def read_config(self):
|
|
self.config = ConfigParser.ConfigParser()
|
|
if self.args.config:
|
|
fp = self.args.config
|
|
else:
|
|
fp = '/etc/grafyaml/grafyaml.conf'
|
|
self.config.read(os.path.expanduser(fp))
|
|
|
|
def setup_logging(self):
|
|
if self.args.debug:
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
else:
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
def update(self):
|
|
LOG.info('Updating dashboards in %s', self.args.path)
|
|
builder = Builder(self.config)
|
|
builder.update_dashboard(self.args.path)
|
|
|
|
def validate(self):
|
|
LOG.info('Validating dashboards in %s', self.args.path)
|
|
builder = Builder(self.config)
|
|
try:
|
|
builder.load_files(self.args.path)
|
|
print('SUCCESS!')
|
|
except Exception as e:
|
|
print('%s: ERROR: %s' % (self.args.path, e))
|
|
sys.exit(1)
|
|
|
|
|
|
def main():
|
|
client = Client()
|
|
client.main()
|
|
sys.exit(0)
|