Convert chronos-cli to kolla-mesos chronos
This is to place all commands in one place so it is obvious what the available commands are. partial blueprint per-service-cli Change-Id: Ib875d43b74f5a74fd7c2398e18f53edcb15c378a
This commit is contained in:
66
kolla_mesos/cli/chronos.py
Normal file
66
kolla_mesos/cli/chronos.py
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Command line interface for the Chronos API.
|
||||
"""
|
||||
|
||||
from cliff import lister
|
||||
from cliff import show
|
||||
from oslo_config import cfg
|
||||
|
||||
from kolla_mesos import chronos
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_group('chronos', 'kolla_mesos.config.chronos')
|
||||
|
||||
|
||||
class List(lister.Lister):
|
||||
"""List Chronos jobs."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(List, self).get_parser(prog_name)
|
||||
parser.add_argument('--path',
|
||||
default='/kolla/%s' % CONF.kolla.deployment_id)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = chronos.Client()
|
||||
jobs = client.get_jobs()
|
||||
return (('Name', 'Mem', 'CPUs', 'Last success', 'Last error',
|
||||
'Command', 'Schedule',),
|
||||
((job['name'], job['mem'], job['cpus'],
|
||||
job['lastSuccess'], job['lastError'], job['command'],
|
||||
job['schedule'],)
|
||||
for job in jobs))
|
||||
|
||||
|
||||
class Show(show.ShowOne):
|
||||
"""Show the chronos job."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(Show, self).get_parser(prog_name)
|
||||
parser.add_argument('job_name')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = chronos.Client()
|
||||
job = client.get_job(CONF.action.job_name)
|
||||
return (('Name', 'Mem', 'CPUs', 'Disk', 'Last success',
|
||||
'Last error', 'Command', 'Container', 'Environment',),
|
||||
(job['name'], job['mem'], job['cpus'], job['disk'],
|
||||
job['lastSuccess'], job['lastError'], job['command'],
|
||||
job['schedule'], job['container'],
|
||||
job['environmentVariables'],))
|
||||
@@ -1,70 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Command line interface for the Chronos API.
|
||||
"""
|
||||
|
||||
import functools
|
||||
import sys
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from kolla_mesos import chronos
|
||||
from kolla_mesos.common import cli_utils
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_group('chronos', 'kolla_mesos.config.chronos')
|
||||
CONF.import_opt('action', 'kolla_mesos.config.chronos_cli')
|
||||
|
||||
|
||||
def chronos_client(f):
|
||||
@functools.wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
client = chronos.Client()
|
||||
return f(client, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
|
||||
@chronos_client
|
||||
def do_list(client):
|
||||
jobs = client.get_jobs()
|
||||
cli_utils.lister(('Name', 'Mem', 'CPUs', 'Last success', 'Last error',
|
||||
'Command', 'Schedule',),
|
||||
((job['name'], job['mem'], job['cpus'],
|
||||
job['lastSuccess'], job['lastError'], job['command'],
|
||||
job['schedule'],)
|
||||
for job in jobs))
|
||||
|
||||
|
||||
@chronos_client
|
||||
def do_show(client):
|
||||
job = client.get_job(CONF.action.job_name)
|
||||
cli_utils.show(('Name', 'Mem', 'CPUs', 'Disk', 'Last success',
|
||||
'Last error', 'Command', 'Container', 'Environment',),
|
||||
(job['name'], job['mem'], job['cpus'], job['disk'],
|
||||
job['lastSuccess'], job['lastError'], job['command'],
|
||||
job['schedule'], job['container'],
|
||||
job['environmentVariables'],))
|
||||
|
||||
|
||||
def main():
|
||||
CONF(sys.argv[1:], project='kolla-mesos')
|
||||
function = globals()['do_{}'.format(CONF.action.name)]
|
||||
return function()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -34,7 +34,6 @@ console_scripts =
|
||||
kolla-mesos-deploy = kolla_mesos.cmd.deploy:main
|
||||
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 =
|
||||
@@ -43,6 +42,8 @@ kolla_mesos.cli =
|
||||
list = kolla_mesos.cli.service:List
|
||||
show = kolla_mesos.cli.service:Show
|
||||
log = kolla_mesos.cli.service:Log
|
||||
chronos list = kolla_mesos.cli.chronos:List
|
||||
chronos show = kolla_mesos.cli.chronos:Show
|
||||
config list = kolla_mesos.cli.config:ConfigList
|
||||
config show = kolla_mesos.cli.config:ConfigShow
|
||||
config set = kolla_mesos.cli.config:ConfigSet
|
||||
|
||||
Reference in New Issue
Block a user