New per-service CLI access

This is intended to give greater access to the operator
to manipulate services.

Co-Authored-by: Angus Salkeld <asalkeld@mirantis.com>
Partially-Implements bp: per-service-cli
Change-Id: I449371e36c22826e3deea144cd35a4171fb24a06
This commit is contained in:
Angus Salkeld 2016-03-02 14:35:57 +10:00 committed by Andrey Pavlov
parent 6189be0c6d
commit 7903e0e499
12 changed files with 290 additions and 9 deletions

View File

45
kolla_mesos/cli/config.py Normal file
View File

@ -0,0 +1,45 @@
# 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 command
from cliff import lister
from cliff import show
from oslo_log import log
LOG = log.getLogger(__name__)
class ConfigList(lister.Lister):
"""List Zookeeper variables."""
def take_action(self, parsed_args):
LOG.info('sending greeting')
LOG.debug('debugging')
self.app.stdout.write('hi!\n')
class ConfigShow(show.ShowOne):
"""Show a Zookeeper variable value."""
def take_action(self, parsed_args):
LOG.info('sending greeting')
LOG.debug('debugging')
self.app.stdout.write('hi!\n')
class ConfigSet(command.Command):
"""Set a Zookeeper variable value."""
def take_action(self, parsed_args):
LOG.info('sending greeting')
LOG.debug('debugging')
self.app.stdout.write('hi!\n')

View File

@ -0,0 +1,63 @@
# 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 command
from cliff import lister
from cliff import show
from oslo_log import log
LOG = log.getLogger(__name__)
class Run(command.Command):
"""Run a service."""
def take_action(self, parsed_args):
LOG.info('sending greeting')
LOG.debug('debugging')
self.app.stdout.write('hi!\n')
class Kill(command.Command):
"""Kill a service."""
def take_action(self, parsed_args):
LOG.info('sending greeting')
LOG.debug('debugging')
LOG.stdout.write('hi!\n')
class Show(show.ShowOne):
"""Show the live status of the task or service."""
def take_action(self, parsed_args):
LOG.info('sending greeting')
LOG.debug('debugging')
self.app.stdout.write('hi!\n')
class List(lister.Lister):
"""List all deployed services for this deployment_id."""
def take_action(self, parsed_args):
LOG.info('sending greeting')
LOG.debug('debugging')
self.app.stdout.write('hi!\n')
class Log(command.Command):
"""Dump the logs for this task or service."""
def take_action(self, parsed_args):
LOG.info('sending greeting')
LOG.debug('debugging')
LOG.stdout.write('hi!\n')

View 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 command
from oslo_log import log
LOG = log.getLogger(__name__)
class Inspect(command.Command):
"""Show available parameters and info about a service definition."""
def take_action(self, parsed_args):
LOG.info('sending greeting')
LOG.debug('debugging')
self.app.stdout.write('hi!\n')
class Validate(command.Command):
"""Validate the service definition."""
def take_action(self, parsed_args):
LOG.info('sending greeting')
LOG.debug('debugging')
self.app.stdout.write('hi!\n')

96
kolla_mesos/cmd/shell.py Normal file
View File

@ -0,0 +1,96 @@
# 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 os.path
import sys
from cliff import app
from cliff import commandmanager
from oslo_config import cfg
from oslo_log import log
from kolla_mesos.common import file_utils
from kolla_mesos.common import utils
VERSION = '1.0'
CONF = cfg.CONF
CONF.import_group('kolla', 'kolla_mesos.config.kolla')
CONF.import_group('zookeeper', 'kolla_mesos.config.zookeeper')
CONF.import_group('marathon', 'kolla_mesos.config.marathon')
CONF.import_group('chronos', 'kolla_mesos.config.chronos')
cli_opts = [
cfg.StrOpt('service-dir',
default=utils.env(
'KM_SERVICE_DIR', default=os.path.join(
file_utils.find_base_dir(), 'services')),
help='Directory with services, (Env: KM_SERVICE_DIR)'),
]
CONF.register_cli_opts(cli_opts)
CMD_LIST = ('--version', '-v', '--verbose', '-q', '--quiet', '--debug')
# TODO(apavlov): implement custom --help
class KollaMesosShell(app.App):
def __init__(self):
super(KollaMesosShell, self).__init__(
description='Kolla-mesos command-line interface',
version=VERSION,
command_manager=commandmanager.CommandManager('kolla_mesos.cli'),
deferred_help=True,
)
def initialize_app(self, argv):
self.options.service_dir = CONF.service_dir
if self.options.verbose_level > 1:
CONF.log_opt_values(log.getLogger('kolla-mesos'),
log.DEBUG)
def _separate_args(argv):
config_args = []
command_args = argv[:]
while command_args:
if command_args[0].startswith('-'):
if (len(command_args) == 1 or command_args[1].startswith('-')
or command_args[0] in CMD_LIST):
config_args.append(command_args[0])
command_args.remove(command_args[0])
else:
config_args.extend(command_args[:2])
command_args = command_args[2:]
else:
break
return config_args, command_args
def main(argv=sys.argv[1:]):
config_args, command_args = _separate_args(argv)
need_help = ('help' in config_args or '-h' in config_args or
'--help' in config_args)
if need_help:
return KollaMesosShell().run(['help'])
for com in CMD_LIST:
if com in config_args:
config_args.remove(com)
command_args.insert(0, com)
CONF(config_args, project='kolla-mesos')
return KollaMesosShell().run(command_args)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))

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.
import os
def env(*args, **kwargs):
for arg in args:
value = os.environ.get(arg)
if value:
return value
return kwargs.get('default', '')

View File

@ -13,6 +13,7 @@
from oslo_config import cfg
from kolla_mesos.common import network_utils
from kolla_mesos.common import utils
CHRONOS_URL = 'http://{}:4400'.format(network_utils.get_ip_address())
@ -20,8 +21,9 @@ CHRONOS_URL = 'http://{}:4400'.format(network_utils.get_ip_address())
CONF = cfg.CONF
chronos_opts = [
cfg.StrOpt('host',
default=CHRONOS_URL,
help='Chronos connection URL (http://host:port)'),
default=utils.env('KM_CHRONOS_HOST', default=CHRONOS_URL),
help='Chronos connection URL (http://host:port), '
'(Env: KM_CHRONOS_HOST)'),
cfg.IntOpt('timeout',
default=30,
help='Timeout for the request to the Chronos API')

View File

@ -13,15 +13,16 @@
from oslo_config import cfg
from kolla_mesos.common import network_utils
from kolla_mesos.common import utils
MARATHON_URL = 'http://{}:8080'.format(network_utils.get_ip_address())
CONF = cfg.CONF
marathon_opts = [
cfg.StrOpt('host',
default=MARATHON_URL,
help='Marathon connection URL (http://host:port)'),
default=utils.env('KM_MARATHON_HOST', default=MARATHON_URL),
help='Marathon connection URL (http://host:port), '
'(Env: KM_MARATHON_HOST)'),
cfg.IntOpt('timeout',
default=5,
help='Timeout for the request to the Marathon API')

View File

@ -13,14 +13,16 @@
from oslo_config import cfg
from kolla_mesos.common import network_utils
from kolla_mesos.common import utils
MESOS_URL = 'http://{}:5050'.format(network_utils.get_ip_address())
CONF = cfg.CONF
mesos_opts = [
cfg.StrOpt('host',
default=MESOS_URL,
help='Mesos connection URL (http://host:port)'),
default=utils.env('KM_MESOS_HOST', default=MESOS_URL),
help='Mesos connection URL (http://host:port), '
'(Env: KM_MESOS_HOST)'),
cfg.IntOpt('timeout',
default=5,
help='Timeout for the request to the Marathon API')

View File

@ -13,6 +13,7 @@
from oslo_config import cfg
from kolla_mesos.common import network_utils
from kolla_mesos.common import utils
ZOOKEEPER_URL = '{}:2181'.format(network_utils.get_ip_address())
@ -20,8 +21,9 @@ ZOOKEEPER_URL = '{}:2181'.format(network_utils.get_ip_address())
CONF = cfg.CONF
zookeeper_opts = [
cfg.StrOpt('host',
default=ZOOKEEPER_URL,
help='ZooKeeper connection URL (host:port)')
default=utils.env('KM_ZOOKEEPER_HOST', default=ZOOKEEPER_URL),
help='ZooKeeper connection URL (host:port), '
'(Env: KM_ZOOKEEPER_HOST)')
]
zookeeper_opt_group = cfg.OptGroup(name='zookeeper',
title='Options for ZooKeeper')

View File

@ -4,6 +4,7 @@
pbr>=1.6 # Apache-2.0
Babel>=1.3 # BSD
cliff!=1.16.0,!=1.17.0,>=1.15.0 # Apache-2.0
dcos>=0.1.3 # Apache-2.0
docker-py>=1.6.0 # Apache-2.0
Jinja2>=2.8 # BSD License (3 clause)

View File

@ -36,6 +36,20 @@ console_scripts =
kolla-mesos-cleanup = kolla_mesos.cmd.cleanup:main
kolla-mesos-update = kolla_mesos.cmd.update:main
chronos-cli = kolla_mesos.cmd.chronos:main
kolla-mesos = kolla_mesos.cmd.shell:main
kolla_mesos.cli =
run = kolla_mesos.cli.service:Run
kill = kolla_mesos.cli.service:Kill
list = kolla_mesos.cli.service:List
show = kolla_mesos.cli.service:Show
log = kolla_mesos.cli.service:Log
config list = kolla_mesos.cli.config:ConfigList
config show = kolla_mesos.cli.config:ConfigShow
config set = kolla_mesos.cli.config:ConfigSet
definition validate = kolla_mesos.cli.service_definition:Validate
definition inspect = kolla_mesos.cli.service_definition:Inspect
oslo.config.opts =
kolla_mesos = kolla_mesos.opts:list_opts