[LinchPin] use linchpin in Python code

Clint Savage herlo at redhat.com
Fri Nov 17 00:21:35 UTC 2017


Hi James,

I might suggest the CLI is the reference implementation of the API. Let me
point out a few things there, and then you can probably tinker with it from
there.

Imports:

https://github.com/CentOS-PaaS-SIG/linchpin/blob/develop/linchpin/__init__.py#L8

LinchPinCli (and LinchpinAPI) need a LinchpinContext class:

https://github.com/CentOS-PaaS-SIG/linchpin/blob/develop/linchpin/__init__.py#L8

The LinchpinContext class needs a few functions run to get things ready.
Loading the configurations, up runDB, logging, reading extra_vars, etc.

Instantiate the LinchpinCli class:

https://github.com/CentOS-PaaS-SIG/linchpin/blob/develop/linchpin/__init__.py#L169

>From there, perform actions, up, destroy, fetch, journal. Each of these
items calls into the LinchpinCli (which is subclassing the LinchpinAPI
class), and is prefixed with lp. Each method is named as such:

lp_up, lp_destroy, lp_fetch, lp_journal, etc.

You can read up on those methods on the docs provided. The up/destroy
methods call run_playbook, which calls the proper ansible playgook. The
fetch and journal methods are more for prep or reporting and don't use
ansible.

Hopefully this will get you started.

Cheers,

herlo

PS - The API is about to go through a bit of an overhaul in the next month
or so to handle dynamic PinFiles and topologies. The likeliest change will
be having the API take only dicts of data, and the CLI bits will parse the
files and pass in the information properly.

On Thu, Nov 16, 2017 at 3:26 PM, James Pryor <jpryor at redhat.com> wrote:

> Hello list,
> How can I use linchpin in Python code? I see in the docs the python api
> reference, that at least hints to me that it can be done as python and not
> just sub-process shell-out to the CLI.
>
> Assuming I have a python codebase, and assuming I have linchpin installed
> and working, I guess I would have done
> $ pip install linchpin
>
> maybe then in my code:
>
> import linchpin
>
> but after that, I just don't know.
> I am looking for a "Usage" section for noobs like so: https://github.com/
> openpaperwork/pyocr#usage
>
> Regards,
> James
>
> _______________________________________________
> linchpin mailing list
> linchpin at redhat.com
> https://www.redhat.com/mailman/listinfo/linchpin
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/linchpin/attachments/20171116/fc5cdd6c/attachment.htm>


More information about the linchpin mailing list