Merge "Create 'certificate init' command."
This commit is contained in:
commit
502bb06d2f
|
@ -0,0 +1,37 @@
|
|||
# Copyright(c) 2018, Oracle and/or its affiliates. All Rights Reserved.
|
||||
#
|
||||
# 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 kolla_cli.i18n as u
|
||||
|
||||
from kolla_cli.api.job import Job
|
||||
from kolla_cli.common.ansible import actions
|
||||
from kolla_cli.common.utils import check_arg
|
||||
|
||||
|
||||
class CertificateApi(object):
|
||||
|
||||
@staticmethod
|
||||
def certificate_init(verbose_level=1):
|
||||
"""Certificate Init.
|
||||
|
||||
Creates a self-signed certificate for secure TLS communication.
|
||||
|
||||
:param verbose_level: the higher the number, the more verbose
|
||||
:type verbose_level: integer
|
||||
:return: Job object
|
||||
:rtype: Job
|
||||
"""
|
||||
check_arg(verbose_level, u._('Verbose level'), int)
|
||||
|
||||
ansible_job = actions.certificate_init(verbose_level)
|
||||
return Job(ansible_job)
|
|
@ -15,6 +15,7 @@
|
|||
import logging
|
||||
import sys
|
||||
|
||||
from kolla_cli.api.certificate import CertificateApi
|
||||
from kolla_cli.api.control_plane import ControlPlaneApi
|
||||
from kolla_cli.api.group import GroupApi
|
||||
from kolla_cli.api.host import HostApi
|
||||
|
@ -30,6 +31,7 @@ VERSION = '0.1'
|
|||
|
||||
|
||||
class ClientApi(
|
||||
CertificateApi,
|
||||
ControlPlaneApi,
|
||||
GroupApi,
|
||||
HostApi,
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
# Copyright(c) 2018, Oracle and/or its affiliates. All Rights Reserved.
|
||||
#
|
||||
# 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 logging
|
||||
import traceback
|
||||
|
||||
from cliff.command import Command
|
||||
|
||||
from kolla_cli.api.client import ClientApi
|
||||
import kolla_cli.i18n as u
|
||||
|
||||
from kolla_cli.commands.exceptions import CommandError
|
||||
|
||||
CLIENT = ClientApi()
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CertificateInit(Command):
|
||||
"""Generates self-signed certificate"""
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
verbose_level = self.app.options.verbose_level
|
||||
|
||||
try:
|
||||
job = CLIENT.certificate_init(verbose_level)
|
||||
|
||||
# wait for job to complete
|
||||
status = job.wait()
|
||||
if verbose_level > 2:
|
||||
LOG.info('\n\n' + 80 * '=')
|
||||
LOG.info(u._('DEBUG command output:\n{out}')
|
||||
.format(out=job.get_console_output()))
|
||||
if status == 0:
|
||||
LOG.info(u._('Success'))
|
||||
else:
|
||||
raise CommandError(u._('Job failed:\n{msg}')
|
||||
.format(msg=job.get_error_message()))
|
||||
|
||||
except Exception:
|
||||
raise Exception(traceback.format_exc())
|
|
@ -30,6 +30,21 @@ from kolla_cli.common.utils import is_string_true
|
|||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def certificate_init(verbose_level=1):
|
||||
'''Creates a self-signed certificate'''
|
||||
playbook = AnsiblePlaybook()
|
||||
playbook_name = 'certificates.yml'
|
||||
|
||||
kolla_home = get_kolla_ansible_home()
|
||||
playbook.playbook_path = os.path.join(kolla_home,
|
||||
'ansible/' + playbook_name)
|
||||
playbook.verbose_level = verbose_level
|
||||
playbook.local_only = True
|
||||
|
||||
job = playbook.run()
|
||||
return job
|
||||
|
||||
|
||||
def destroy_hosts(hostnames, destroy_type,
|
||||
verbose_level=1, include_data=False,
|
||||
remove_images=False):
|
||||
|
|
|
@ -42,10 +42,17 @@ class AnsiblePlaybook(object):
|
|||
serial = False
|
||||
deploy_id = None # type: str
|
||||
inventory = None # type: Inventory
|
||||
local_only = False
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
self.inventory = Inventory.load()
|
||||
if self.local_only:
|
||||
# Create a temporary local inventory with only localhost
|
||||
self.inventory = Inventory()
|
||||
self.inventory.set_deploy_mode(False)
|
||||
self.inventory.add_host('localhost')
|
||||
else:
|
||||
self.inventory = Inventory.load()
|
||||
inventory_path = self._make_temp_inventory()
|
||||
cmd = self._get_playbook_cmd(inventory_path)
|
||||
self._log_ansible_cmd(cmd, inventory_path)
|
||||
|
|
Loading…
Reference in New Issue