Пример #1
0
    def __init__(self):
        super(KollaCli, self).__init__(
            description='Command-Line Client for OpenStack Kolla',
            version='0.1',
            command_manager=CommandManager('kolla.cli'),
        )

        # check that current user is in the kolla group
        inventory_path = os.path.join(get_kollacli_etc(), INVENTORY_PATH)
        errString = 'Required file %s does not exist.\n' + \
                    'Please re-install the kollacli to recreate the file.'
        if os.path.isfile(inventory_path) is False:
            raise CommandError(errString % inventory_path)

        inventory_file = None
        try:
            inventory_file = open(inventory_path, 'r+')
        except Exception:
            raise CommandError('Permission denied to run the kollacli.' +
                               '\nPlease add user to the kolla group and ' +
                               'then log out and back in.')
        finally:
            if inventory_file and inventory_file.close is False:
                inventory_file.close()

        self.rotating_log_dir = get_kolla_log_dir()
        self.max_bytes = get_kolla_log_file_size()
        self.backup_count = 4

        self.dump_stack_trace = False

        self.add_rotational_log()
Пример #2
0
    def __init__(self):
        super(KollaCli, self).__init__(
            description='Command-Line Client for OpenStack Kolla',
            version='0.1',
            command_manager=CommandManager('kolla.cli'),
            )

        # check that current user is in the kolla group
        inventory_path = os.path.join(get_kollacli_etc(),
                                      INVENTORY_PATH)
        errString = 'Required file %s does not exist.\n' + \
                    'Please re-install the kollacli to recreate the file.'
        if os.path.isfile(inventory_path) is False:
            raise CommandError(errString % inventory_path)

        inventory_file = None
        try:
            inventory_file = open(inventory_path, 'r+')
        except Exception:
            raise CommandError('Permission denied to run the kollacli.' +
                               '\nPlease add user to the kolla group and ' +
                               'then log out and back in.')
        finally:
            if inventory_file and inventory_file.close is False:
                inventory_file.close()

        self.rotating_log_dir = get_kolla_log_dir()
        self.max_bytes = get_kolla_log_file_size()
        self.backup_count = 4

        self.dump_stack_trace = False

        self.add_rotational_log()
Пример #3
0
    def take_action(self, parsed_args):
        try:
            kolla_home = get_kolla_home()
            kolla_logs = get_kolla_log_dir()
            kolla_ansible = os.path.join(kolla_home, 'ansible')
            kolla_docs = os.path.join(kolla_home, 'docs')
            kolla_etc = get_kolla_etc()
            kolla_config = os.path.join(kolla_etc, 'config')
            kolla_globals = os.path.join(kolla_etc, 'globals.yml')
            kollacli_etc = get_kollacli_etc().rstrip('/')
            ketc = 'kolla/etc/'
            kshare = 'kolla/share/'
            fd, dump_path = tempfile.mkstemp(prefix='kollacli_dump_',
                                             suffix='.tgz')
            os.close(fd)  # avoid fd leak
            with tarfile.open(dump_path, 'w:gz') as tar:
                # Can't blanket add kolla_home because the .ssh dir is
                # accessible by the kolla user only (not kolla group)
                tar.add(kolla_ansible,
                        arcname=kshare + os.path.basename(kolla_ansible))
                tar.add(kolla_docs,
                        arcname=kshare + os.path.basename(kolla_docs))

                # Can't blanket add kolla_etc because the passwords.yml
                # file is accessible by the kolla user only (not kolla group)
                tar.add(kolla_config,
                        arcname=ketc + os.path.basename(kolla_config))
                tar.add(kolla_globals,
                        arcname=ketc + os.path.basename(kolla_globals))
                tar.add(kollacli_etc,
                        arcname=ketc + os.path.basename(kollacli_etc))

                # add kolla log files
                if os.path.isdir(kolla_logs):
                    tar.add(kolla_logs)

                # add output of various commands
                self._add_cmd_info(tar)

            self.log.info('dump successful to %s' % dump_path)
        except Exception:
            raise Exception(traceback.format_exc())