Skip to content

Commit

Permalink
Merge pull request #114 from nutanix/task/runbook-watch-for-non-itera…
Browse files Browse the repository at this point in the history
…ctive-command

Task/runbook watch for non interactive command
  • Loading branch information
abhijeetkaurav1st authored Aug 26, 2020
2 parents e430e8b + 435d3a4 commit 9879969
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
38 changes: 24 additions & 14 deletions calm/dsl/cli/runlog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys

from asciimatics.widgets import (
Expand Down Expand Up @@ -202,7 +203,7 @@ def displayRunLogTree(screen, root, completed_tasks, total_tasks, msg=None):

screen.print_at(
runlog_state,
screen.width - len(runlog_state) - 5,
screen.width - len(runlog_state) - 5 if hasattr(screen, "width") else 0,
0,
colour=colour,
attr=Screen.A_UNDERLINE,
Expand Down Expand Up @@ -298,7 +299,8 @@ def displayRunLog(screen, obj, pre, fill, line):
colour = 4 # blue for running state
elif state == RUNLOG.STATUS.INPUT:
colour = 6 # cyan for input state
screen.print_at("{}".format(state), len(prefix) + 1, idx(), colour=colour)
if os.isatty(sys.stdout.fileno()):
screen.print_at("{}".format(state), len(prefix) + 1, idx(), colour=colour)

if obj.children:
fill = fill + u"\u2502"
Expand Down Expand Up @@ -361,7 +363,9 @@ def is_action_complete(
if len(entities):

# catching interrupt for pause and play
interrupt = screen.get_event()
interrupt = None
if hasattr(screen, "get_event"):
interrupt = screen.get_event()

# Sort entities based on creation time
sorted_entities = sorted(
Expand Down Expand Up @@ -571,23 +575,29 @@ def is_action_complete(
state = runlog["status"]["state"]
if state in RUNLOG.FAILURE_STATES:
sleep(2)
msg = "Action failed. Exit screen? (y)"
screen.play([Scene([RerunFrame(state, screen)], -1)])
if rerun.get("rerun", False):
client.runbook.rerun(runlog_uuid)
msg = "Triggered rerun for the Runbook Runlog"
msg = "Action failed."
if os.isatty(sys.stdout.fileno()):
msg += " Exit screen?"
screen.play([Scene([RerunFrame(state, screen)], -1)])
if rerun.get("rerun", False):
client.runbook.rerun(runlog_uuid)
msg = "Triggered rerun for the Runbook Runlog"
displayRunLogTree(
screen, root, completed_tasks, total_tasks, msg=msg
)
return (False, "")
displayRunLogTree(
screen, root, completed_tasks, total_tasks, msg=msg
)
return (False, "")
displayRunLogTree(
screen, root, completed_tasks, total_tasks, msg=msg
)
return (True, msg)
return (True, msg)
else:
return (True, msg)
if state not in RUNLOG.TERMINAL_STATES:
return (False, "")

msg = "Action ran successfully. Exit screen? (y)"
msg = "Action ran successfully."
if os.isatty(sys.stdout.fileno()):
msg += " Exit screen?"
screen.print_at(msg, 0, line, colour=6)
screen.refresh()

Expand Down
2 changes: 1 addition & 1 deletion calm/dsl/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def refresh(self):
def wait_for_input(self, *args):
pass

def print_at(self, text, x, *args):
def print_at(self, text, x, *args, **kwargs):
click.echo("{}{}".format((" " * x), text))


Expand Down

0 comments on commit 9879969

Please sign in to comment.