Exemplo n.º 1
0
    def _list_plugins(self, print_available=False):
        """Print a list of installed & available plugins"""
        table_rows = []
        table_headers = ["Type", "Name"]
        installed_mark = ' ' * (len('Installed') / 2) + '*'

        all_plugins_dict = self.plugin_manager.get_all_plugins()

        for plugins_type, plugins in all_plugins_dict.iteritems():
            all_plugins_list = []
            installed_plugins_list = []
            plugins_names = plugins.keys()
            plugins_names.sort()
            for plugin_name in plugins_names:
                all_plugins_list.append(plugin_name)
                if plugins[plugin_name]:
                    installed_plugins_list.append(plugin_name)

            if print_available:
                installed_plugins_mark_list = \
                    [installed_mark if plugin_name in installed_plugins_list
                     else '' for plugin_name in all_plugins_list]
                table_rows.append([
                    plugins_type,
                    '\n'.join(all_plugins_list),
                    '\n'.join(installed_plugins_mark_list)])
            else:
                table_rows.append([
                    plugins_type,
                    '\n'.join(installed_plugins_list)])

        if print_available:
            table_headers.append("Installed")

        print fancy_table(table_headers, *table_rows)
Exemplo n.º 2
0
    def _list_plugins(self, print_available=False):
        """Print a list of installed & available plugins"""
        table_rows = []
        table_headers = ["Type", "Name"]
        installed_mark = ' ' * (len('Installed') / 2) + '*'

        all_plugins_dict = self.plugin_manager.get_all_plugins()

        for plugins_type, plugins in all_plugins_dict.iteritems():
            all_plugins_list = []
            installed_plugins_list = []
            plugins_names = plugins.keys()
            plugins_names.sort()
            for plugin_name in plugins_names:
                all_plugins_list.append(plugin_name)
                if plugins[plugin_name]:
                    installed_plugins_list.append(plugin_name)

            if print_available:
                installed_plugins_mark_list = \
                    [installed_mark if plugin_name in installed_plugins_list
                     else '' for plugin_name in all_plugins_list]
                table_rows.append([
                    plugins_type, '\n'.join(all_plugins_list),
                    '\n'.join(installed_plugins_mark_list)
                ])
            else:
                table_rows.append(
                    [plugins_type, '\n'.join(installed_plugins_list)])

        if print_available:
            table_headers.append("Installed")

        print fancy_table(table_headers, *table_rows)
Exemplo n.º 3
0
    def spec_handler(self, parser, args):
        """
        Handles all the plugin manager commands
        :param parser: the infrared parser object.
        :param args: the list of arguments received from cli.
        """
        pargs = parser.parse_args(args)
        subcommand = pargs.command0

        if subcommand == 'create':
            self._create_workspace(pargs.name)
        elif subcommand == 'checkout':
            self._checkout_workspace(pargs.name, pargs.checkout_create)
        elif subcommand == 'inventory':
            self._fetch_inventory(pargs.name)
        elif subcommand == 'list':
            if pargs.print_active:
                print(self.workspace_manager.get_active_workspace().name)
            else:
                workspaces = self.workspace_manager.list()
                headers = ("Name", "Active")
                workspaces = sorted([workspace.name for workspace in
                                     self.workspace_manager.list()])
                print(fancy_table(
                    headers,
                    *[(workspace, ' ' * (len(headers[-1]) // 2) + "*" if
                        self.workspace_manager.is_active(workspace) else "")
                      for workspace in workspaces]))
        elif subcommand == 'delete':
            for workspace_name in pargs.name:
                self.workspace_manager.delete(workspace_name)
                print("Workspace '{}' deleted".format(workspace_name))
        elif subcommand == 'cleanup':
            self.workspace_manager.cleanup(pargs.name)
        elif subcommand == 'export':
            self.workspace_manager.export_workspace(
                pargs.workspacename, pargs.filename, pargs.copykeys)
        elif subcommand == 'import':
            self.workspace_manager.import_workspace(
                pargs.filename, pargs.workspacename)
        elif subcommand == 'node-list':
            nodes = self.workspace_manager.node_list(pargs.name, pargs.group)
            if pargs.format == 'json':
                nodes_dict = [
                    {'name': name, 'address': address, 'groups': groups}
                    for name, address, groups in nodes]
                print(json.dumps({'nodes': nodes_dict}))
            else:
                print(fancy_table(
                    ("Name", "Address", "Groups"),
                    *[node_name for node_name in nodes]))
        elif subcommand == "group-list":
            groups = self.workspace_manager.group_list(pargs.name)
            print(fancy_table(
                ("Name", "Nodes"), *[group_name for group_name in groups]))
Exemplo n.º 4
0
    def _search_plugins(self):
        """
        Search git organizations and print a list of available plugins
        """
        table_rows = []
        table_headers = ["Type", "Name", "Description", "Source"]

        plugins_dict = \
            self.plugin_manager.get_all_git_plugins()

        for plugins_type, plugins in plugins_dict.items():
            # prepare empty lists
            all_plugins_list = []
            plugins_descs = []
            plugins_sources = []

            for plugin_name in sorted(plugins.iterkeys()):
                # get all plugin names
                all_plugins_list.append(plugin_name)
                # get all plugin descriptions
                plugins_descs.append(plugins[plugin_name]["desc"])
                # get all plugins sources
                plugins_sources.append(plugins[plugin_name]["src"])

            table_rows.append([
                plugins_type, '\n'.join(all_plugins_list),
                '\n'.join(plugins_descs), '\n'.join(plugins_sources)
            ])

        print(fancy_table(table_headers, *table_rows))
Exemplo n.º 5
0
    def _search_plugins(self):
        """
        Search git organizations and print a list of available plugins
        """
        table_rows = []
        table_headers = ["Type", "Name", "Description", "Source"]

        plugins_dict = \
            self.plugin_manager.get_all_git_plugins()

        for plugins_type, plugins in plugins_dict.iteritems():
            # prepare empty lists
            all_plugins_list = []
            plugins_descs = []
            plugins_sources = []

            for plugin_name in sorted(plugins.iterkeys()):
                # get all plugin names
                all_plugins_list.append(plugin_name)
                # get all plugin descriptions
                plugins_descs.append(plugins[plugin_name]["desc"])
                # get all plugins sources
                plugins_sources.append(plugins[plugin_name]["src"])

            table_rows.append([
                plugins_type,
                '\n'.join(all_plugins_list),
                '\n'.join(plugins_descs),
                '\n'.join(plugins_sources)])

        print(fancy_table(table_headers, *table_rows))
Exemplo n.º 6
0
    def _list_plugins(self, print_available=False):
        """Print a list of installed & available plugins"""
        table_rows = []
        table_headers = ["Type", "Name"]
        installed_mark = ' ' * (len('Installed') / 2) + '*'

        plugins_dict = \
            self.plugin_manager.get_all_plugins() \
            if print_available \
            else self.plugin_manager.get_installed_plugins()

        for plugins_type, plugins in plugins_dict.iteritems():
            installed_plugins_list = \
                self.plugin_manager.get_installed_plugins(plugins_type).keys()
            plugins_names = plugins.keys()
            plugins_names.sort()

            if print_available:
                all_plugins_list = []
                for plugin_name in plugins_names:
                    all_plugins_list.append(plugin_name)
                installed_plugins_mark_list = \
                    [installed_mark if plugin_name in installed_plugins_list
                     else '' for plugin_name in all_plugins_list]

                plugins_descs = \
                    [PLUGINS_REGISTRY.get(plugin, {}).get('desc', '')
                     for plugin in all_plugins_list]

                table_rows.append([
                    plugins_type,
                    '\n'.join(all_plugins_list),
                    '\n'.join(installed_plugins_mark_list),
                    '\n'.join(plugins_descs)])
            else:
                table_rows.append([
                    plugins_type,
                    '\n'.join(installed_plugins_list)])

        if print_available:
            table_headers.append("Installed")
            table_headers.append("Description")

        print fancy_table(table_headers, *table_rows)
Exemplo n.º 7
0
    def _list_plugins(self, print_available=False):
        """Print a list of installed & available plugins"""
        table_rows = []
        table_headers = ["Type", "Name"]
        installed_mark = ' ' * (len('Installed') / 2) + '*'

        plugins_dict = \
            self.plugin_manager.get_all_plugins() \
            if print_available \
            else self.plugin_manager.get_installed_plugins()

        for plugins_type, plugins in plugins_dict.iteritems():
            installed_plugins_list = \
                self.plugin_manager.get_installed_plugins(plugins_type).keys()
            plugins_names = plugins.keys()
            plugins_names.sort()

            if print_available:
                all_plugins_list = []
                for plugin_name in plugins_names:
                    all_plugins_list.append(plugin_name)
                installed_plugins_mark_list = \
                    [installed_mark if plugin_name in installed_plugins_list
                     else '' for plugin_name in all_plugins_list]

                plugins_descs = \
                    [PLUGINS_REGISTRY.get(plugin, {}).get('desc', '')
                     for plugin in all_plugins_list]

                table_rows.append([
                    plugins_type,
                    '\n'.join(all_plugins_list),
                    '\n'.join(installed_plugins_mark_list),
                    '\n'.join(plugins_descs)])
            else:
                table_rows.append([
                    plugins_type,
                    '\n'.join(installed_plugins_list)])

        if print_available:
            table_headers.append("Installed")
            table_headers.append("Description")

        print fancy_table(table_headers, *table_rows)
Exemplo n.º 8
0
    def spec_handler(self, parser, args):
        """
        Handles all the plugin manager commands
        :param parser: the infrared parser object.
        :param args: the list of arguments received from cli.
        """
        pargs = parser.parse_args(args)
        subcommand = pargs.command0

        if subcommand == 'create':
            self._create_workspace(pargs.name)
        elif subcommand == 'checkout':
            self._checkout_workspace(pargs.name)
        elif subcommand == 'inventory':
            self._fetch_inventory(pargs.name)
        elif subcommand == 'list':
            workspaces = self.workspace_manager.list()
            headers = ("Name", "Active")
            workspaces = sorted([
                workspace.name for workspace in self.workspace_manager.list()
            ])

            print fancy_table(
                headers,
                *[(workspace, ' ' * (len(headers[-1]) / 2) +
                   "*" if self.workspace_manager.is_active(workspace) else "")
                  for workspace in workspaces])
        elif subcommand == 'delete':
            self.workspace_manager.delete(pargs.name)
            print("Workspace '{}' deleted".format(pargs.name))
        elif subcommand == 'cleanup':
            self.workspace_manager.cleanup(pargs.name)
        elif subcommand == 'export':
            self.workspace_manager.export_workspace(pargs.workspacename,
                                                    pargs.filename,
                                                    pargs.copykeys)
        elif subcommand == 'import':
            self.workspace_manager.import_workspace(pargs.filename,
                                                    pargs.workspacename)
        elif subcommand == 'node-list':
            nodes = self.workspace_manager.node_list(pargs.name)
            print fancy_table(("Name", "Address"),
                              *[node_name for node_name in nodes])
Exemplo n.º 9
0
    def spec_handler(self, parser, args):
        """
        Handles all the plugin manager commands
        :param parser: the infrared parser object.
        :param args: the list of arguments received from cli.
        """
        pargs = parser.parse_args(args)
        subcommand = pargs.command0

        if subcommand == 'create':
            self._create_workspace(pargs.name)
        elif subcommand == 'checkout':
            self._checkout_workspace(pargs.name)
        elif subcommand == 'inventory':
            self._fetch_inventory(pargs.name)
        elif subcommand == 'list':
            workspaces = self.workspace_manager.list()
            headers = ("Name", "Active")
            print fancy_table(
                headers,
                *[(workspace.name, ' ' * (len(headers[-1]) / 2) + "*" if
                    self.workspace_manager.is_active(workspace.name) else "")
                  for workspace in workspaces])
        elif subcommand == 'delete':
            self.workspace_manager.delete(pargs.name)
            print("Workspace '{}' deleted".format(pargs.name))
        elif subcommand == 'cleanup':
            self.workspace_manager.cleanup(pargs.name)
        elif subcommand == 'export':
            self.workspace_manager.export_workspace(
                pargs.workspacename, pargs.filename)
        elif subcommand == 'import':
            self.workspace_manager.import_workspace(
                pargs.filename, pargs.workspacename)
        elif subcommand == 'node-list':
            nodes = self.workspace_manager.node_list(pargs.name)
            print fancy_table(
                ("Name", "Address"), *[node_name for node_name in nodes])