Ejemplo n.º 1
0
    def take_action(self, args):
        client = get_client(
            client=args.client,
            endpoint=args.server,
            timeout=args.timeout,
            username=args.username,
            password=args.password,
            verify=False if args.insecure else True,
            run_sql_migrations=False,
        )
        query = {}
        if args.playbook is not None:
            query["playbook"] = args.playbook

        if args.status is not None:
            query["status"] = args.status

        if args.name is not None:
            query["name"] = args.name

        if args.path is not None:
            query["path"] = args.path

        if args.action is not None:
            query["action"] = args.action

        query["order"] = args.order
        query["limit"] = args.limit

        tasks = client.get("/api/v1/tasks", **query)

        for task in tasks["results"]:
            task["results"] = task["items"]["results"]
            if args.resolve:
                playbook = cli_utils.get_playbook(client, task["playbook"])
                # Paths can easily take up too much width real estate
                if not args.long:
                    task["playbook"] = "(%s) %s" % (playbook["id"],
                                                    cli_utils.truncatepath(
                                                        playbook["path"], 50))
                else:
                    task["playbook"] = "(%s) %s" % (playbook["id"],
                                                    playbook["path"])

                if args.long:
                    play = cli_utils.get_play(client, task["play"])
                    task["play"] = "(%s) %s" % (play["id"], play["name"])

        # fmt: off
        if args.long:
            columns = ("id", "status", "results", "action", "name", "tags",
                       "path", "lineno", "handler", "playbook", "play",
                       "started", "duration")
        else:
            columns = ("id", "status", "results", "action", "name", "playbook",
                       "started", "duration")
        # fmt: off
        return (columns, ([task[column] for column in columns]
                          for task in tasks["results"]))
Ejemplo n.º 2
0
    def take_action(self, args):
        client = get_client(
            client=args.client,
            endpoint=args.server,
            timeout=args.timeout,
            username=args.username,
            password=args.password,
            verify=False if args.insecure else True,
            run_sql_migrations=False,
        )
        query = {}
        if args.label is not None:
            query["label"] = args.label

        if args.controller is not None:
            query["controller"] = args.controller

        if args.name is not None:
            query["name"] = args.name

        if args.path is not None:
            query["path"] = args.path

        if args.status is not None:
            query["status"] = args.status

        query["order"] = args.order
        query["limit"] = args.limit

        playbooks = client.get("/api/v1/playbooks", **query)
        for playbook in playbooks["results"]:
            # Send items to columns
            playbook["plays"] = playbook["items"]["plays"]
            playbook["tasks"] = playbook["items"]["tasks"]
            playbook["results"] = playbook["items"]["results"]
            playbook["hosts"] = playbook["items"]["hosts"]
            playbook["files"] = playbook["items"]["files"]
            playbook["records"] = playbook["items"]["records"]
            # Paths can easily take up too much width real estate
            if not args.long:
                playbook["path"] = cli_utils.truncatepath(playbook["path"], 50)

        # fmt: off
        if args.long:
            columns = ("id", "status", "controller", "name", "path", "plays",
                       "tasks", "results", "hosts", "files", "records",
                       "started", "duration")
        else:
            columns = ("id", "status", "controller", "path", "tasks",
                       "results", "hosts", "started", "duration")
        return (columns, ([playbook[column] for column in columns]
                          for playbook in playbooks["results"]))
Ejemplo n.º 3
0
    def take_action(self, args):
        client = get_client(
            client=args.client,
            endpoint=args.server,
            timeout=args.timeout,
            username=args.username,
            password=args.password,
            verify=False if args.insecure else True,
            run_sql_migrations=False,
        )
        query = {}
        if args.name is not None:
            query["name"] = args.name

        if args.playbook is not None:
            query["playbook"] = args.playbook

        if args.with_changed:
            query["changed__gt"] = 0
        if args.without_changed:
            query["changed__lt"] = 1
        if args.with_failed:
            query["failed__gt"] = 0
        if args.without_failed:
            query["failed__lt"] = 1
        if args.with_unreachable:
            query["unreachable__gt"] = 0
        if args.without_unreachable:
            query["unreachable__lt"] = 1

        query["order"] = args.order
        query["limit"] = args.limit

        hosts = client.get("/api/v1/hosts", **query)

        if args.resolve:
            for host in hosts["results"]:
                playbook = cli_utils.get_playbook(client, host["playbook"])
                # Paths can easily take up too much width real estate
                if not args.long:
                    host["playbook"] = "(%s) %s" % (playbook["id"],
                                                    cli_utils.truncatepath(
                                                        playbook["path"], 50))
                else:
                    host["playbook"] = "(%s) %s" % (playbook["id"],
                                                    playbook["path"])

        columns = ("id", "name", "playbook", "changed", "failed", "ok",
                   "skipped", "unreachable", "updated")
        # fmt: off
        return (columns, ([host[column] for column in columns]
                          for host in hosts["results"]))
Ejemplo n.º 4
0
    def take_action(self, args):
        client = get_client(
            client=args.client,
            endpoint=args.server,
            timeout=args.timeout,
            username=args.username,
            password=args.password,
            verify=False if args.insecure else True,
            run_sql_migrations=False,
        )
        query = {}
        if args.playbook is not None:
            query["playbook"] = args.playbook

        if args.name is not None:
            query["name"] = args.name

        if args.uuid is not None:
            query["uuid"] = args.uuid

        if args.status is not None:
            query["status"] = args.status

        query["order"] = args.order
        query["limit"] = args.limit

        plays = client.get("/api/v1/plays", **query)
        for play in plays["results"]:
            # Send items to columns
            play["tasks"] = play["items"]["tasks"]
            play["results"] = play["items"]["results"]

            if args.resolve:
                playbook = cli_utils.get_playbook(client, play["playbook"])
                # Paths can easily take up too much width real estate
                if not args.long:
                    play["playbook"] = "(%s) %s" % (playbook["id"], cli_utils.truncatepath(playbook["path"], 50))
                else:
                    play["playbook"] = "(%s) %s" % (playbook["id"], playbook["path"])

        columns = ("id", "status", "name", "playbook", "tasks", "results", "started", "duration")
        # fmt: off
        return (
            columns, (
                [play[column] for column in columns]
                for play in plays["results"]
            )
        )
Ejemplo n.º 5
0
    def take_action(self, args):
        client = get_client(
            client=args.client,
            endpoint=args.server,
            timeout=args.timeout,
            username=args.username,
            password=args.password,
            verify=False if args.insecure else True,
            run_sql_migrations=False,
        )
        query = {}
        if args.playbook is not None:
            query["playbook"] = args.playbook

        if args.key is not None:
            query["key"] = args.key

        query["order"] = args.order
        query["limit"] = args.limit

        records = client.get("/api/v1/records", **query)
        if args.resolve:
            for record in records["results"]:
                playbook = cli_utils.get_playbook(client, record["playbook"])
                # Paths can easily take up too much width real estate
                if not args.long:
                    record["playbook"] = "(%s) %s" % (
                        playbook["id"],
                        cli_utils.truncatepath(playbook["path"], 50))
                else:
                    record["playbook"] = "(%s) %s" % (playbook["id"],
                                                      playbook["path"])

        columns = ("id", "key", "type", "playbook", "updated")
        # fmt: off
        return (columns, ([record[column] for column in columns]
                          for record in records["results"]))
Ejemplo n.º 6
0
    def take_action(self, args):
        client = get_client(
            client=args.client,
            endpoint=args.server,
            timeout=args.timeout,
            username=args.username,
            password=args.password,
            verify=False if args.insecure else True,
            run_sql_migrations=False,
        )
        query = {}
        if args.playbook is not None:
            query["playbook"] = args.playbook

        if args.status is not None:
            query["status"] = args.status

        if args.name is not None:
            query["name"] = args.name

        if args.path is not None:
            query["path"] = args.path

        if args.action is not None:
            query["action"] = args.action

        query["order"] = args.order
        query["limit"] = args.limit

        tasks = client.get("/api/v1/tasks", **query)

        # TODO: This could probably be made more efficient without needing to iterate a second time
        # Group tasks by aggregate
        aggregate = {}
        for task in tasks["results"]:
            item = task[args.aggregate]
            if item not in aggregate:
                aggregate[item] = []
            aggregate[item].append(task)

        data = {}
        for item, tasks in aggregate.items():
            data[item] = {
                "count": len(tasks),
                "results": 0,
                "expired": 0,
                "running": 0,
                "completed": 0,
                "unknown": 0,
                "duration_total": "00:00:00.000000",
            }

            if args.aggregate == "path" and not args.long:
                data[item]["aggregate"] = cli_utils.truncatepath(item, 50)
            else:
                data[item]["aggregate"] = item

            for task in tasks:
                for status in ["running", "completed", "expired", "unknown"]:
                    if task["status"] == status:
                        data[item][status] += 1

                data[item]["results"] += task["items"]["results"]

                if task["duration"] is not None:
                    data[item]["duration_total"] = cli_utils.sum_timedelta(
                        task["duration"], data[item]["duration_total"])

            data[item]["duration_avg"] = cli_utils.avg_timedelta(
                data[item]["duration_total"], data[item]["count"])

        # fmt: off
        if args.long:
            columns = (
                "aggregate",
                "count",
                "results",
                "duration_total",
                "duration_avg",
                "completed",
                "running",
                "expired",
                "unknown",
            )
        else:
            columns = (
                "aggregate",
                "count",
                "results",
                "duration_total",
                "duration_avg",
            )

        return (columns, ([data[action][column] for column in columns]
                          for action in sorted(data.keys())))
Ejemplo n.º 7
0
    def take_action(self, args):
        client = get_client(
            client=args.client,
            endpoint=args.server,
            timeout=args.timeout,
            username=args.username,
            password=args.password,
            verify=False if args.insecure else True,
            run_sql_migrations=False,
        )
        query = {}
        if args.playbook is not None:
            query["playbook"] = args.playbook
        if args.play is not None:
            query["play"] = args.play
        if args.task is not None:
            query["task"] = args.task
        if args.host is not None:
            query["host"] = args.host

        if args.status is not None:
            query["status"] = args.status

        if args.changed:
            query["changed"] = args.changed

        query["ignore_errors"] = args.ignore_errors
        query["order"] = args.order
        query["limit"] = args.limit

        results = client.get("/api/v1/results", **query)

        if args.resolve:
            for result in results["results"]:
                playbook = cli_utils.get_playbook(client, result["playbook"])
                # Paths can easily take up too much width real estate
                if not args.long:
                    result["playbook"] = "(%s) %s" % (
                        playbook["id"],
                        cli_utils.truncatepath(playbook["path"], 50))
                else:
                    result["playbook"] = "(%s) %s" % (playbook["id"],
                                                      playbook["path"])

                task = cli_utils.get_task(client, result["task"])
                result["task"] = "(%s) %s" % (task["id"], task["name"])

                host = cli_utils.get_host(client, result["host"])
                result["host"] = "(%s) %s" % (host["id"], host["name"])

                if args.long:
                    play = cli_utils.get_play(client, result["play"])
                    result["play"] = "(%s) %s" % (play["id"], play["name"])

        # fmt: off
        if args.long:
            columns = (
                "id",
                "status",
                "changed",
                "ignore_errors",
                "playbook",
                "play",
                "task",
                "host",
                "started",
                "duration",
            )
        else:
            columns = (
                "id",
                "status",
                "playbook",
                "task",
                "host",
                "started",
                "duration",
            )

        return (columns, ([result[column] for column in columns]
                          for result in results["results"]))