nautobot / nautobot-app-chatops

Extensible ChatOps Framework to enable other chatbots and the Nautobot chat command.
https://docs.nautobot.com/projects/chatops/en/latest/
Other
51 stars 34 forks source link

Initiating Nautobot jobs, next-2.0 rebase #270

Closed MeganerdDev closed 8 months ago

MeganerdDev commented 1 year ago

Closes: #223

224 closed in favor of this rebase

What's Changed

Adds the following nautobot subcommands:

Remaining work

TODO

Screenshots

/nautobot init-job

image

/nautobot init-jobs for job that is not enabled

image

if there is a failed job, we will return the job_result.result message image

/nautobot get-jobs

by default we will get some head items image

/nautobot get-jobs '["id", "name", "installed", "tags"]'

we can specify the header items we want with a JSON formatted list image image

if there is a bad key, eg: /nautobot get-jobs '["id", "name", "invalid key demo"]' image

/nautobot filter-jobs "enabled"

image

Notes

MeganerdDev commented 1 year ago

Got some edge cases left I think, but pretty much everything but making CI happy is left

MeganerdDev commented 1 year ago

I left a few TODO entries, but nothing is a blocker I think

MeganerdDev commented 1 year ago

Not sure if making pylint happy for generator is mandatory for merge or if we can add an ignore for this case # pylint: disable=use-a-generator

MeganerdDev commented 1 year ago

Thanks for the feedback, Ill get this updated!

MeganerdDev commented 1 year ago

My current action/to-do items for this PR:

MeganerdDev commented 1 year ago

status update on TODO item -> "have a job's user-input widgets prompt for chat user input" I have a working concept, will update PR with that soon!

MeganerdDev commented 1 year ago

This now provides a separate nautobot subcommand init-job-form

When /nautobot init-job-form is called without a job name it presents a drop-down dialog Otherwise you can specify the job name, eg: /nautobot init-job-form "demo-job" image image

image

Caveats:

MeganerdDev commented 9 months ago

I removed this helper function, noting in case we want to re-add (eg: enable_job subcommand would use this)

def enable_job(module, name, source="local"):
    """
    Helper function to look up a job by class and job model and enable it.

    Args:
        module (str): Job module name
        name (str): Job class name
        source (str): Job grouping (default: "local")
    """
    job_class = get_job(f"{module}.{name}")
    job_model = Job.objects.get(module_name=module, job_class_name=name) # .restrict() may be preferred if we pass user
    if not job_model.enabled:
        job_model.enabled = True
        job_model.validated_save()
    return 
MeganerdDev commented 9 months ago

Noting some things for the current status of this PR:

Fixed items:

qduk commented 9 months ago

Awesome work @MeganerdDev! The only thing I'd note is the addition of some documentation in the /nautobot commands table.