Merge "Renamed/Moved files, Split some files, Renamed few classes"
This commit is contained in:
commit
69f033591d
|
@ -29,14 +29,14 @@ logging.getLogger("requests").setLevel(logging.INFO)
|
||||||
logging.getLogger("stevedore.extension").setLevel(logging.INFO)
|
logging.getLogger("stevedore.extension").setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
class KollaKubernetesShell(app.App):
|
class KollaKubernetesApp(app.App):
|
||||||
_singleton = None
|
_singleton = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def Get():
|
def Get():
|
||||||
if KollaKubernetesShell._singleton is None:
|
if KollaKubernetesApp._singleton is None:
|
||||||
KollaKubernetesShell._singleton = KollaKubernetesShell()
|
KollaKubernetesApp._singleton = KollaKubernetesApp()
|
||||||
return KollaKubernetesShell._singleton
|
return KollaKubernetesApp._singleton
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(self.__class__, self).__init__(
|
super(self.__class__, self).__init__(
|
||||||
|
@ -80,10 +80,10 @@ class KollaKubernetesShell(app.App):
|
||||||
command.Command.get_parser(). That argparse namepace is then
|
command.Command.get_parser(). That argparse namepace is then
|
||||||
handed directly to the command.Command.take_action() method of
|
handed directly to the command.Command.take_action() method of
|
||||||
each subcommand. Subcommands may access global options by
|
each subcommand. Subcommands may access global options by
|
||||||
calling KollaKubernetesShell.Get().get_parsed_options().
|
calling KollaKubernetesApp.Get().get_parsed_options().
|
||||||
|
|
||||||
"""
|
"""
|
||||||
parser = super(KollaKubernetesShell, self).build_option_parser(
|
parser = super(KollaKubernetesApp, self).build_option_parser(
|
||||||
description,
|
description,
|
||||||
version)
|
version)
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ class KollaKubernetesShell(app.App):
|
||||||
|
|
||||||
|
|
||||||
def main(argv=sys.argv[1:]):
|
def main(argv=sys.argv[1:]):
|
||||||
kks = KollaKubernetesShell().Get()
|
kks = KollaKubernetesApp().Get()
|
||||||
return kks.run(argv)
|
return kks.run(argv)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
|
@ -10,10 +10,13 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
from cliff import command
|
||||||
|
|
||||||
def str_to_bool(text):
|
from kolla_kubernetes.app import KollaKubernetesApp
|
||||||
if not text:
|
|
||||||
return False
|
|
||||||
if text.lower() in ['true', 'yes']:
|
class KollaKubernetesBaseCommand(command.Command):
|
||||||
return True
|
|
||||||
return False
|
def get_global_args(self):
|
||||||
|
"""Provides a method to access global parsed options"""
|
||||||
|
return KollaKubernetesApp.Get().get_parsed_options()
|
|
@ -13,70 +13,21 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from cliff import command
|
|
||||||
from oslo_config import cfg
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from kolla_kubernetes.cmd.shell import KollaKubernetesShell
|
from kolla_kubernetes.commands.base_command import KollaKubernetesBaseCommand
|
||||||
from kolla_kubernetes.common.utils import FileUtils
|
|
||||||
from kolla_kubernetes.common.utils import JinjaUtils
|
|
||||||
from kolla_kubernetes.common.utils import YamlUtils
|
|
||||||
from kolla_kubernetes.service_resources import KollaKubernetesResources
|
from kolla_kubernetes.service_resources import KollaKubernetesResources
|
||||||
from kolla_kubernetes.service_resources import Service
|
from kolla_kubernetes.service_resources import Service
|
||||||
|
from kolla_kubernetes.utils import FileUtils
|
||||||
|
from kolla_kubernetes.utils import JinjaUtils
|
||||||
|
from kolla_kubernetes.utils import YamlUtils
|
||||||
|
|
||||||
CONF = cfg.CONF
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
KKR = KollaKubernetesResources.Get()
|
KKR = KollaKubernetesResources.Get()
|
||||||
|
|
||||||
|
|
||||||
class _BaseCommand(command.Command):
|
class Resource(KollaKubernetesBaseCommand):
|
||||||
|
|
||||||
def get_global_args(self):
|
|
||||||
"""Provides a method to access global parsed options"""
|
|
||||||
return KollaKubernetesShell.Get().get_parsed_options()
|
|
||||||
|
|
||||||
|
|
||||||
class _ServiceCommand(_BaseCommand):
|
|
||||||
|
|
||||||
_action = None # must be set in derived classes
|
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
|
||||||
parser = super(_ServiceCommand, self).get_parser(prog_name)
|
|
||||||
parser.add_argument('service')
|
|
||||||
return parser
|
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
|
||||||
assert self._action is not None, (
|
|
||||||
"code error: derived classes must set _action")
|
|
||||||
|
|
||||||
service = KKR.getServiceByName(parsed_args.service)
|
|
||||||
if (self._action == 'bootstrap'):
|
|
||||||
service.do_apply('create', Service.LEGACY_BOOTSTRAP_RESOURCES)
|
|
||||||
elif (self._action == 'run'):
|
|
||||||
service.do_apply('create', Service.LEGACY_RUN_RESOURCES)
|
|
||||||
elif (self._action == 'kill'):
|
|
||||||
service.do_apply('delete', Service.VALID_RESOURCE_TYPES)
|
|
||||||
else:
|
|
||||||
raise Exception("Code Error")
|
|
||||||
|
|
||||||
|
|
||||||
class Bootstrap(_ServiceCommand):
|
|
||||||
"""Roll out configurations and bootstrap a service."""
|
|
||||||
_action = 'bootstrap'
|
|
||||||
|
|
||||||
|
|
||||||
class Run(_ServiceCommand):
|
|
||||||
"""Run a service."""
|
|
||||||
_action = 'run'
|
|
||||||
|
|
||||||
|
|
||||||
class Kill(_ServiceCommand):
|
|
||||||
"""Kill a service."""
|
|
||||||
_action = 'kill'
|
|
||||||
|
|
||||||
|
|
||||||
class Resource(_BaseCommand):
|
|
||||||
"""Create or delete kolla-kubernetes resources"""
|
"""Create or delete kolla-kubernetes resources"""
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
|
@ -185,7 +136,7 @@ class ResourceTemplate(Resource):
|
||||||
FileUtils.read_string_from_file(args.template_file)))
|
FileUtils.read_string_from_file(args.template_file)))
|
||||||
|
|
||||||
|
|
||||||
class ResourceMap(_BaseCommand):
|
class ResourceMap(KollaKubernetesBaseCommand):
|
||||||
"""List available kolla-kubernetes resources to be created or deleted"""
|
"""List available kolla-kubernetes resources to be created or deleted"""
|
||||||
|
|
||||||
# If the operator has any question on what Services have what resources,
|
# If the operator has any question on what Services have what resources,
|
|
@ -0,0 +1,62 @@
|
||||||
|
# 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 __future__ import print_function
|
||||||
|
|
||||||
|
from oslo_log import log
|
||||||
|
|
||||||
|
from kolla_kubernetes.commands.base_command import KollaKubernetesBaseCommand
|
||||||
|
from kolla_kubernetes.service_resources import KollaKubernetesResources
|
||||||
|
from kolla_kubernetes.service_resources import Service
|
||||||
|
|
||||||
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
KKR = KollaKubernetesResources.Get()
|
||||||
|
|
||||||
|
|
||||||
|
class _ServiceCommand(KollaKubernetesBaseCommand):
|
||||||
|
|
||||||
|
_action = None # must be set in derived classes
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(_ServiceCommand, self).get_parser(prog_name)
|
||||||
|
parser.add_argument('service')
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
assert self._action is not None, (
|
||||||
|
"code error: derived classes must set _action")
|
||||||
|
|
||||||
|
service = KKR.getServiceByName(parsed_args.service)
|
||||||
|
if (self._action == 'bootstrap'):
|
||||||
|
service.do_apply('create', Service.LEGACY_BOOTSTRAP_RESOURCES)
|
||||||
|
elif (self._action == 'run'):
|
||||||
|
service.do_apply('create', Service.LEGACY_RUN_RESOURCES)
|
||||||
|
elif (self._action == 'kill'):
|
||||||
|
service.do_apply('delete', Service.VALID_RESOURCE_TYPES)
|
||||||
|
else:
|
||||||
|
raise Exception("Code Error")
|
||||||
|
|
||||||
|
|
||||||
|
class Bootstrap(_ServiceCommand):
|
||||||
|
"""Roll out configurations and bootstrap a service."""
|
||||||
|
_action = 'bootstrap'
|
||||||
|
|
||||||
|
|
||||||
|
class Run(_ServiceCommand):
|
||||||
|
"""Run a service."""
|
||||||
|
_action = 'run'
|
||||||
|
|
||||||
|
|
||||||
|
class Kill(_ServiceCommand):
|
||||||
|
"""Kill a service."""
|
||||||
|
_action = 'kill'
|
|
@ -38,8 +38,8 @@ class PathFinder(object):
|
||||||
# Editable installs (aka. Development: pip install --editable .)
|
# Editable installs (aka. Development: pip install --editable .)
|
||||||
# use this root path to locate ../kolla
|
# use this root path to locate ../kolla
|
||||||
# For editable, resolves to /path/to/git/repo/kolla-kubernetes
|
# For editable, resolves to /path/to/git/repo/kolla-kubernetes
|
||||||
return os.path.dirname(os.path.dirname(
|
return os.path.dirname(
|
||||||
os.path.dirname(os.path.abspath(__file__))))
|
os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_kolla_dir():
|
def find_kolla_dir():
|
|
@ -18,11 +18,11 @@ import time
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from kolla_kubernetes.common.pathfinder import PathFinder
|
from kolla_kubernetes.pathfinder import PathFinder
|
||||||
from kolla_kubernetes.common.utils import ExecUtils
|
from kolla_kubernetes.utils import ExecUtils
|
||||||
from kolla_kubernetes.common.utils import JinjaUtils
|
from kolla_kubernetes.utils import JinjaUtils
|
||||||
from kolla_kubernetes.common.utils import StringUtils
|
from kolla_kubernetes.utils import StringUtils
|
||||||
from kolla_kubernetes.common.utils import YamlUtils
|
from kolla_kubernetes.utils import YamlUtils
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger()
|
LOG = logging.getLogger()
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
# 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 kolla_kubernetes.common import type_utils
|
|
||||||
from kolla_kubernetes.tests import base
|
|
||||||
|
|
||||||
|
|
||||||
class StrToBoolTest(base.BaseTestCase):
|
|
||||||
|
|
||||||
scenarios = [
|
|
||||||
('none', dict(text=None, expect=False)),
|
|
||||||
('empty', dict(text='', expect=False)),
|
|
||||||
('junk', dict(text='unlikely', expect=False)),
|
|
||||||
('no', dict(text='no', expect=False)),
|
|
||||||
('yes', dict(text='yes', expect=True)),
|
|
||||||
('0', dict(text='0', expect=False)),
|
|
||||||
('1', dict(text='1', expect=False)),
|
|
||||||
('True', dict(text='True', expect=True)),
|
|
||||||
('False', dict(text='False', expect=False)),
|
|
||||||
('true', dict(text='true', expect=True)),
|
|
||||||
('false', dict(text='false', expect=False)),
|
|
||||||
('shouty', dict(text='TRUE', expect=True)),
|
|
||||||
]
|
|
||||||
|
|
||||||
def test_str_to_bool(self):
|
|
||||||
self.assertEqual(self.expect, type_utils.str_to_bool(self.text))
|
|
|
@ -10,7 +10,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from kolla_kubernetes.common.pathfinder import PathFinder
|
from kolla_kubernetes.pathfinder import PathFinder
|
||||||
from kolla_kubernetes.tests import base
|
from kolla_kubernetes.tests import base
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,12 @@ import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from kolla_kubernetes.common.utils import FileUtils
|
|
||||||
from kolla_kubernetes.common.utils import JinjaUtils
|
|
||||||
from kolla_kubernetes.common.utils import StringUtils
|
|
||||||
from kolla_kubernetes.common.utils import YamlUtils
|
|
||||||
from kolla_kubernetes.tests import base
|
from kolla_kubernetes.tests import base
|
||||||
|
from kolla_kubernetes.utils import FileUtils
|
||||||
|
from kolla_kubernetes.utils import JinjaUtils
|
||||||
|
from kolla_kubernetes.utils import StringUtils
|
||||||
|
from kolla_kubernetes.utils import TypeUtils
|
||||||
|
from kolla_kubernetes.utils import YamlUtils
|
||||||
|
|
||||||
|
|
||||||
test_yaml = '''
|
test_yaml = '''
|
||||||
|
@ -146,6 +147,27 @@ class TestStringUtils(UtilsTestCase):
|
||||||
self.assertEqual(StringUtils.pad_str("aa", 2, ""), "aaaa")
|
self.assertEqual(StringUtils.pad_str("aa", 2, ""), "aaaa")
|
||||||
|
|
||||||
|
|
||||||
|
class TestTypeUtils(base.BaseTestCase):
|
||||||
|
|
||||||
|
scenarios = [
|
||||||
|
('none', dict(text=None, expect=False)),
|
||||||
|
('empty', dict(text='', expect=False)),
|
||||||
|
('junk', dict(text='unlikely', expect=False)),
|
||||||
|
('no', dict(text='no', expect=False)),
|
||||||
|
('yes', dict(text='yes', expect=True)),
|
||||||
|
('0', dict(text='0', expect=False)),
|
||||||
|
('1', dict(text='1', expect=False)),
|
||||||
|
('True', dict(text='True', expect=True)),
|
||||||
|
('False', dict(text='False', expect=False)),
|
||||||
|
('true', dict(text='true', expect=True)),
|
||||||
|
('false', dict(text='false', expect=False)),
|
||||||
|
('shouty', dict(text='TRUE', expect=True)),
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_str_to_bool(self):
|
||||||
|
self.assertEqual(self.expect, TypeUtils.str_to_bool(self.text))
|
||||||
|
|
||||||
|
|
||||||
class TestYamlUtils(UtilsTestCase):
|
class TestYamlUtils(UtilsTestCase):
|
||||||
|
|
||||||
def test_write_and_read_string(self):
|
def test_write_and_read_string(self):
|
|
@ -21,8 +21,6 @@ import yaml
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from kolla_kubernetes.common import type_utils
|
|
||||||
|
|
||||||
LOG = logging.getLogger()
|
LOG = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,7 +121,7 @@ class JinjaUtils(object):
|
||||||
loader=jinja2.DictLoader({name: template_str}))
|
loader=jinja2.DictLoader({name: template_str}))
|
||||||
|
|
||||||
# Do not print type for bools "!!bool" on output
|
# Do not print type for bools "!!bool" on output
|
||||||
j2env.filters['bool'] = type_utils.str_to_bool
|
j2env.filters['bool'] = TypeUtils.str_to_bool
|
||||||
|
|
||||||
# Add a "raise" keyword for raising exceptions from within jinja
|
# Add a "raise" keyword for raising exceptions from within jinja
|
||||||
def jinja_raise(message):
|
def jinja_raise(message):
|
||||||
|
@ -163,6 +161,17 @@ class StringUtils(object):
|
||||||
return re.sub("^", (pad * num), s, 0, re.MULTILINE)
|
return re.sub("^", (pad * num), s, 0, re.MULTILINE)
|
||||||
|
|
||||||
|
|
||||||
|
class TypeUtils(object):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def str_to_bool(text):
|
||||||
|
if not text:
|
||||||
|
return False
|
||||||
|
if text.lower() in ['true', 'yes']:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class YamlUtils(object):
|
class YamlUtils(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
14
setup.cfg
14
setup.cfg
|
@ -28,15 +28,15 @@ data_files =
|
||||||
|
|
||||||
[entry_points]
|
[entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
kolla-kubernetes = kolla_kubernetes.cmd.shell:main
|
kolla-kubernetes = kolla_kubernetes.app:main
|
||||||
|
|
||||||
kolla_kubernetes.cli =
|
kolla_kubernetes.cli =
|
||||||
bootstrap = kolla_kubernetes.cli.service:Bootstrap
|
bootstrap = kolla_kubernetes.commands.cmd_service:Bootstrap
|
||||||
run = kolla_kubernetes.cli.service:Run
|
run = kolla_kubernetes.commands.cmd_service:Run
|
||||||
kill = kolla_kubernetes.cli.service:Kill
|
kill = kolla_kubernetes.commands.cmd_service:Kill
|
||||||
resource = kolla_kubernetes.cli.service:Resource
|
resource = kolla_kubernetes.commands.cmd_resource:Resource
|
||||||
resource-template = kolla_kubernetes.cli.service:ResourceTemplate
|
resource-template = kolla_kubernetes.commands.cmd_resource:ResourceTemplate
|
||||||
resource-map = kolla_kubernetes.cli.service:ResourceMap
|
resource-map = kolla_kubernetes.commands.cmd_resource:ResourceMap
|
||||||
|
|
||||||
[pbr]
|
[pbr]
|
||||||
warnerrors = true
|
warnerrors = true
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
../kolla_kubernetes/cmd/shell.py
|
../kolla_kubernetes/app.py
|
Loading…
Reference in New Issue