pulumi/scripts
Luke Hoban 3768e5c690
Python Dynamic Providers (#2900)
Dynamic providers in Python.

This PR uses [dill](https://pypi.org/project/dill/) for code serialization, along with a customization to help ensure deterministic serialization results.

One notable limitation - which I believe is a general requirement of Python - is that any serialization of Python functions must serialize byte code, and byte code is not safely versioned across Python versions.  So any resource created with Python `3.x.y` can only be updated by exactly the same version of Python.  This is very constraining, but it's not clear there is any other option within the realm of what "dynamic providers" are as a feature.  It is plausible that we could ensure that updates which only update the serialized provider can avoid calling the dynamic provider operations, so that version updates could still be accomplished.  We can explore this separately.

```py
from pulumi import ComponentResource, export, Input, Output
from pulumi.dynamic import Resource, ResourceProvider, CreateResult, UpdateResult
from typing import Optional
from github import Github, GithubObject

auth = "<auth token>"
g = Github(auth)

class GithubLabelArgs(object):
    owner: Input[str]
    repo: Input[str]
    name: Input[str]
    color: Input[str]
    description: Optional[Input[str]]
    def __init__(self, owner, repo, name, color, description=None):
        self.owner = owner
        self.repo = repo
        self.name = name
        self.color = color
        self.description = description

class GithubLabelProvider(ResourceProvider):
    def create(self, props):
        l = g.get_user(props["owner"]).get_repo(props["repo"]).create_label(
            name=props["name"],
            color=props["color"],
            description=props.get("description", GithubObject.NotSet))
        return CreateResult(l.name, {**props, **l.raw_data}) 
    def update(self, id, _olds, props):
        l = g.get_user(props["owner"]).get_repo(props["repo"]).get_label(id)
        l.edit(name=props["name"],
               color=props["color"],
               description=props.get("description", GithubObject.NotSet))
        return UpdateResult({**props, **l.raw_data})
    def delete(self, id, props):
        l = g.get_user(props["owner"]).get_repo(props["repo"]).get_label(id)
        l.delete()

class GithubLabel(Resource):
    name: Output[str]
    color: Output[str]
    url: Output[str]
    description: Output[str]
    def __init__(self, name, args: GithubLabelArgs, opts = None):
        full_args = {'url':None, 'description':None, 'name':None, 'color':None, **vars(args)}
        super().__init__(GithubLabelProvider(), name, full_args, opts)

label = GithubLabel("foo", GithubLabelArgs("lukehoban", "todo", "mylabel", "d94f0b"))

export("label_color", label.color)
export("label_url", label.url)
```


Fixes https://github.com/pulumi/pulumi/issues/2902.
2019-07-19 10:18:25 -07:00
..
build-and-publish-docker Build/Push pulumi/actions container with new SDK releases (#2646) 2019-04-18 15:32:19 -07:00
build-sdk.cmd Use newer versions of the build-sdk.sh scripts 2018-04-30 20:44:01 -07:00
build-sdk.ps1 Publish SDK binaries with same filename format as NPM packages 2018-11-21 14:38:24 -08:00
build-sdk.sh Remove references to Pulumi private clouds (#2095) 2018-10-24 13:50:35 -07:00
get-py-version Fix python package versions 2018-05-07 12:38:08 -07:00
get-py-version.go Fix python package versions 2018-05-07 12:38:08 -07:00
get-version Rework get-version scripts 2018-11-16 20:11:04 -08:00
get-version.cmd Add get-version.cmd and use it 2018-03-16 16:36:27 -07:00
get-version.ps1 Fix +dirty tag on Windows for tagged versions 2018-12-05 11:11:43 -08:00
gocover.sh Pass -count=1 to disable result caching on go 1.10 and above 2018-11-08 14:11:52 -08:00
make_release.ps1 Python Dynamic Providers (#2900) 2019-07-19 10:18:25 -07:00
make_release.sh Python Dynamic Providers (#2900) 2019-07-19 10:18:25 -07:00
publish.cmd Build, integration tests and publishing on Windows 2017-10-02 13:40:58 -07:00
publish.ps1 Fix Windows publishing 2018-06-17 23:16:58 -07:00
publish_packages.sh Don't clobber dev tag from PR builds 2019-01-31 14:55:01 -08:00
publish_tgz.sh Only publish some artifacts from a single Linux leg 2019-01-15 10:42:28 -08:00
reversion.js Substitute ${VERSION} on Windows builds too 2018-02-20 14:37:28 -08:00