diff --git a/Pipfile b/Pipfile new file mode 100644 index 000000000..116b02ecb --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +tobiko = {editable = true, path = "."} + +[dev-packages] + +[requires] +python_version = "3.7" diff --git a/tobiko/cmd/base.py b/tobiko/cmd/base.py index 841c6d49a..fc4373b62 100644 --- a/tobiko/cmd/base.py +++ b/tobiko/cmd/base.py @@ -20,6 +20,7 @@ from oslo_log import log from tobiko.common import clients from tobiko.common.managers import stack +from tobiko.common.managers import ansible from tobiko import config @@ -34,5 +35,9 @@ class TobikoCMD(object): curr_dir = os.path.dirname(__file__) self.templates_dir = os.path.join(curr_dir, "../tests/scenario/templates") + self.playbooks_dir = os.path.join(curr_dir, + "../tests/scenario/playbooks") self.stackManager = stack.StackManager(self.clientManager, self.templates_dir) + self.ansibleManager = ansible.AnsibleManager(self.clientManager, + self.playbooks_dir) diff --git a/tobiko/cmd/list.py b/tobiko/cmd/list.py index 264520a5e..cf35b6289 100644 --- a/tobiko/cmd/list.py +++ b/tobiko/cmd/list.py @@ -39,6 +39,10 @@ class ListUtil(base.TobikoCMD): help="List templates provided by Tobiko", const='list_templates', action='store_const', dest='action') + parser.add_argument('--playbooks', '-p', + help="List playbooks provided by Tobiko", + const='list_playbooks', + action='store_const', dest='action') return parser def list_stacks(self): @@ -47,10 +51,15 @@ class ListUtil(base.TobikoCMD): sys.stdout.write(stack + '\n') def list_templates(self): - """Lists stacks created by Tobiko.""" + """Lists templates included in Tobiko.""" for template in self.stackManager.get_templates_names(): sys.stdout.write(template + '\n') + def list_playbooks(self): + """Lists playbooks included in Tobiko.""" + for playbook in self.ansibleManager.get_playbooks_names(): + sys.stdout.write(playbook + '\n') + def main(): """List CLI main entry.""" diff --git a/tobiko/common/managers/ansible.py b/tobiko/common/managers/ansible.py new file mode 100644 index 000000000..1abb5515f --- /dev/null +++ b/tobiko/common/managers/ansible.py @@ -0,0 +1,41 @@ +# Copyright 2018 Red Hat +# +# 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 absolute_import + +import os + +from oslo_log import log + +from tobiko.common import constants + + +LOG = log.getLogger(__name__) + + +class AnsibleManager(object): + """Manages Ansible entities.""" + + def __init__(self, client_manager, templates_dir): + self.client_manager = client_manager.heat_client + self.playbooks_dir = templates_dir + + def get_playbooks_names(self, strip_suffix=False): + """Returns a list of all the files in playbooks dir.""" + playbooks = [] + for (_, _, files) in os.walk(self.playbooks_dir): + playbooks.extend(files) + if strip_suffix: + playbooks = [ + f[:-len(constants.TEMPLATE_SUFFIX)] for f in playbooks] + return playbooks diff --git a/tobiko/tests/scenario/playbooks/test_floatingip.yml b/tobiko/tests/scenario/playbooks/test_floatingip.yaml similarity index 100% rename from tobiko/tests/scenario/playbooks/test_floatingip.yml rename to tobiko/tests/scenario/playbooks/test_floatingip.yaml