def Check(self, request, context): olds = rpc.deserialize_properties(request.olds, True) news = rpc.deserialize_properties(request.news, True) if news[PROVIDER_KEY] == rpc.UNKNOWN: provider = get_provider(olds) else: provider = get_provider(news) result = provider.check(olds, news) inputs = result.inputs failures = result.failures inputs[PROVIDER_KEY] = news[PROVIDER_KEY] loop = asyncio.new_event_loop() inputs_proto = loop.run_until_complete( rpc.serialize_properties(inputs, {})) loop.close() failures_proto = [ proto.CheckFailure(f.property, f.reason) for f in failures ] fields = {"inputs": inputs_proto, "failures": failures_proto} return proto.CheckResponse(**fields)
def RegisterResource(self, request, context): type_ = request.type name = request.name props = rpc.deserialize_properties(request.object) deps = request.dependencies outs = {} if type_ != "pulumi:pulumi:Stack": outs = self.langhost_test.register_resource( context, self.dryrun, type_, name, props, deps) if outs.get("urn"): urn = outs["urn"] self.registrations[urn] = { "type": type_, "name": name, "props": props } self.reg_count += 1 if "object" in outs: loop = asyncio.new_event_loop() obj_proto = loop.run_until_complete( rpc.serialize_properties(outs["object"], [])) loop.close() else: obj_proto = None return proto.RegisterResourceResponse(urn=outs.get("urn"), id=outs.get("id"), object=obj_proto)
def RegisterResource(self, request, context): type_ = request.type name = request.name props = rpc.deserialize_properties(request.object) deps = sorted(list(request.dependencies)) parent = request.parent custom = request.custom protect = request.protect provider = request.provider delete_before_replace = request.deleteBeforeReplace ignore_changes = sorted(list(request.ignoreChanges)) version = request.version import_ = request.importId property_dependencies = {} for key, value in request.propertyDependencies.items(): property_dependencies[key] = sorted(list(value.urns)) outs = {} if type_ != "pulumi:pulumi:Stack": rrsig = signature(self.langhost_test.register_resource) args = [ context, self.dryrun, type_, name, props, deps, parent, custom, protect, provider, property_dependencies, delete_before_replace, ignore_changes, version, import_ ] outs = self.langhost_test.register_resource( *args[0:len(rrsig.parameters)]) if outs.get("urn"): urn = outs["urn"] self.registrations[urn] = { "type": type_, "name": name, "props": props } self.reg_count += 1 else: # Record the Stack's registration so that it can be the target of register_resource_outputs # later on. urn = self.langhost_test.make_urn(type_, "teststack") self.registrations[urn] = { "type": type_, "name": "somestack", "props": {} } return proto.RegisterResourceResponse(urn=urn, id="teststack", object=None) if "object" in outs: loop = asyncio.new_event_loop() obj_proto = loop.run_until_complete( rpc.serialize_properties(outs["object"], {})) loop.close() else: obj_proto = None return proto.RegisterResourceResponse(urn=outs.get("urn"), id=outs.get("id"), object=obj_proto)
def Invoke(self, request, context): args = rpc.deserialize_properties(request.args) failures, ret = self.langhost_test.invoke(context, request.tok, args, request.provider, request.version) failures_rpc = list(map( lambda fail: provider_pb2.CheckFailure(property=fail["property"], reason=fail["reason"]), failures)) loop = asyncio.new_event_loop() ret_proto = loop.run_until_complete(rpc.serialize_properties(ret, {})) loop.close() fields = {"failures": failures_rpc, "return": ret_proto} return proto.InvokeResponse(**fields)
def Create(self, request, context): props = rpc.deserialize_properties(request.properties) provider = get_provider(props) result = provider.create(props) outs = result.outs outs[PROVIDER_KEY] = props[PROVIDER_KEY] loop = asyncio.new_event_loop() outs_proto = loop.run_until_complete(rpc.serialize_properties(outs, {})) loop.close() fields = {"id": result.id, "properties": outs_proto} return proto.CreateResponse(**fields)
def Read(self, request, context): id_ = request.id props = rpc.deserialize_properties(request.properties) provider = get_provider(props) result = provider.read(id_, props) # pylint: disable=no-member outs = result.outs outs[PROVIDER_KEY] = props[PROVIDER_KEY] loop = asyncio.new_event_loop() outs_proto = loop.run_until_complete(rpc.serialize_properties(outs, {})) loop.close() fields = {"id": result.id, "properties": outs_proto} return proto.ReadResponse(**fields)
def ReadResource(self, request, context): type_ = request.type name = request.name id_ = request.id parent = request.parent state = rpc.deserialize_properties(request.properties) outs = self.langhost_test.read_resource(context, type_, name, id_, parent, state) if "properties" in outs: loop = asyncio.new_event_loop() props_proto = loop.run_until_complete(rpc.serialize_properties(outs["properties"], {})) loop.close() else: props_proto = None return proto.ReadResourceResponse( urn=outs.get("urn"), properties=props_proto)
def Update(self, request, context): olds = rpc.deserialize_properties(request.olds) news = rpc.deserialize_properties(request.news) provider = get_provider(news) result = provider.update(request.id, olds, news) outs = {} if result.outs is not None: outs = result.outs outs[PROVIDER_KEY] = news[PROVIDER_KEY] loop = asyncio.new_event_loop() outs_proto = loop.run_until_complete(rpc.serialize_properties(outs, {})) loop.close() fields = {"properties": outs_proto} return proto.UpdateResponse(**fields)
def RegisterResource(self, request, context): type_ = request.type name = request.name props = rpc.deserialize_properties(request.object) deps = list(request.dependencies) parent = request.parent custom = request.custom protect = request.protect provider = request.provider outs = {} if type_ != "pulumi:pulumi:Stack": outs = self.langhost_test.register_resource( context, self.dryrun, type_, name, props, deps, parent, custom, protect, provider) if outs.get("urn"): urn = outs["urn"] self.registrations[urn] = { "type": type_, "name": name, "props": props } self.reg_count += 1 else: # Record the Stack's registration so that it can be the target of register_resource_outputs # later on. urn = self.langhost_test.make_urn(type_, "teststack") self.registrations[urn] = { "type": type_, "name": "somestack", "props": {} } return proto.RegisterResourceResponse(urn=urn, id="teststack", object=None) if "object" in outs: loop = asyncio.new_event_loop() obj_proto = loop.run_until_complete( rpc.serialize_properties(outs["object"], [])) loop.close() else: obj_proto = None return proto.RegisterResourceResponse(urn=outs.get("urn"), id=outs.get("id"), object=obj_proto)