Add Ansible manager

Ansible manager will be used for creating resources based
on playbooks written with Ansible.

Right now, modified tobiko-list to list playbooks
included in Tobiko.

Also added a pipfile for quick development setup.

Change-Id: Ief626dd26b173e2de1941f173d301405ff0c9f14
This commit is contained in:
abregman 2018-12-10 16:31:55 +02:00
parent d48271f1f4
commit 2ca7e378ce
5 changed files with 68 additions and 1 deletions

12
Pipfile Normal file
View File

@ -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"

View File

@ -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)

View File

@ -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."""

View File

@ -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