Skip to content

Commit

Permalink
Improve CustomResource for Python SDK
Browse files Browse the repository at this point in the history
- Standardize arg names with the rest of the SDK
- Add typing
- Add .get method
  • Loading branch information
lblackstone committed Aug 8, 2019
1 parent fc7bf17 commit 29b181a
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 34 deletions.
68 changes: 51 additions & 17 deletions pkg/gen/python-templates/CustomResource.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

import warnings
from copy import copy
from typing import Any, Optional

import pulumi
import pulumi.runtime
from pulumi import ResourceOptions

from .. import tables, version

Expand All @@ -15,37 +20,66 @@ class CustomResource(pulumi.CustomResource):
`ServiceMonitor` resource definition as an argument.
"""

def __init__(self, __name__, __opts__=None, api_version=None, kind=None, metadata=None, spec=None):
if not __name__:
def __init__(
self,
resource_name: str,
api_version: pulumi.Input[str],
kind: pulumi.Input[str],
spec: pulumi.Input[Any],
metadata: Optional[pulumi.Input[Any]] = None,
opts: Optional[pulumi.ResourceOptions] = None,
__name__: str = None,
__opts__: pulumi.ResourceOptions = None):
if __name__ is not None:
warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
resource_name = __name__
if __opts__ is not None:
warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
opts = __opts__
if not resource_name:
raise TypeError('Missing resource name argument (for URN creation)')
if not isinstance(__name__, str):
if not isinstance(resource_name, str):
raise TypeError('Expected resource name to be a string')
if __opts__ and not isinstance(__opts__, pulumi.ResourceOptions):
if opts and not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()

if not api_version:
raise TypeError('Missing required property apiVersion')
__props__['apiVersion'] = api_version
if not kind:
raise TypeError('Missing required property kind')
__props__['kind'] = kind
if spec is None:
raise TypeError('Missing required property spec')
__props__['spec'] = spec
__props__['metadata'] = metadata

if __opts__ is None:
__opts__ = pulumi.ResourceOptions()
if __opts__.version is None:
__opts__.version = version.get_version()
if opts is None:
opts = pulumi.ResourceOptions()
if opts.version is None:
opts.version = version.get_version()

super(CustomResource, self).__init__(
"kubernetes:%s:%s" % (api_version, kind),
__name__,
f"kubernetes:{api_version}:{kind}",
resource_name,
__props__,
__opts__)
opts)

@staticmethod
def get(resource_name: str,
api_version: pulumi.Input[str],
kind: pulumi.Input[str],
id: pulumi.Input[str],
opts: Optional[ResourceOptions] = None):
"""
:param pulumi.Input[str] api_version: The API version of the apiExtensions.CustomResource we
wish to select, as specified by the CustomResourceDefinition that defines it on the
API server.
:param pulumi.Input[str] kind: The kind of the apiextensions.CustomResource we wish to select,
as specified by the CustomResourceDefinition that defines it on the API server.
:param pulumi.Input[str] id: An ID for the Kubernetes resource to retrieve.
Takes the form <namespace>/<name> or <name>.
:param Optional[ResourceOptions] opts: A bag of options that control this resource's behavior.
"""
opts_ = copy(opts) if opts is not None else ResourceOptions()
opts_.id = id
return CustomResource(resource_name, api_version, kind, opts)

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down
68 changes: 51 additions & 17 deletions sdk/python/pulumi_kubernetes/apiextensions/CustomResource.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

import warnings
from copy import copy
from typing import Any, Optional

import pulumi
import pulumi.runtime
from pulumi import ResourceOptions

from .. import tables, version

Expand All @@ -15,37 +20,66 @@ class CustomResource(pulumi.CustomResource):
`ServiceMonitor` resource definition as an argument.
"""

def __init__(self, __name__, __opts__=None, api_version=None, kind=None, metadata=None, spec=None):
if not __name__:
def __init__(
self,
resource_name: str,
api_version: pulumi.Input[str],
kind: pulumi.Input[str],
spec: pulumi.Input[Any],
metadata: Optional[pulumi.Input[Any]] = None,
opts: Optional[pulumi.ResourceOptions] = None,
__name__: str = None,
__opts__: pulumi.ResourceOptions = None):
if __name__ is not None:
warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
resource_name = __name__
if __opts__ is not None:
warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
opts = __opts__
if not resource_name:
raise TypeError('Missing resource name argument (for URN creation)')
if not isinstance(__name__, str):
if not isinstance(resource_name, str):
raise TypeError('Expected resource name to be a string')
if __opts__ and not isinstance(__opts__, pulumi.ResourceOptions):
if opts and not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()

if not api_version:
raise TypeError('Missing required property apiVersion')
__props__['apiVersion'] = api_version
if not kind:
raise TypeError('Missing required property kind')
__props__['kind'] = kind
if spec is None:
raise TypeError('Missing required property spec')
__props__['spec'] = spec
__props__['metadata'] = metadata

if __opts__ is None:
__opts__ = pulumi.ResourceOptions()
if __opts__.version is None:
__opts__.version = version.get_version()
if opts is None:
opts = pulumi.ResourceOptions()
if opts.version is None:
opts.version = version.get_version()

super(CustomResource, self).__init__(
"kubernetes:%s:%s" % (api_version, kind),
__name__,
f"kubernetes:{api_version}:{kind}",
resource_name,
__props__,
__opts__)
opts)

@staticmethod
def get(resource_name: str,
api_version: pulumi.Input[str],
kind: pulumi.Input[str],
id: pulumi.Input[str],
opts: Optional[ResourceOptions] = None):
"""
:param pulumi.Input[str] api_version: The API version of the apiExtensions.CustomResource we
wish to select, as specified by the CustomResourceDefinition that defines it on the
API server.
:param pulumi.Input[str] kind: The kind of the apiextensions.CustomResource we wish to select,
as specified by the CustomResourceDefinition that defines it on the API server.
:param pulumi.Input[str] id: An ID for the Kubernetes resource to retrieve.
Takes the form <namespace>/<name> or <name>.
:param Optional[ResourceOptions] opts: A bag of options that control this resource's behavior.
"""
opts_ = copy(opts) if opts is not None else ResourceOptions()
opts_.id = id
return CustomResource(resource_name, api_version, kind, opts)

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down

0 comments on commit 29b181a

Please sign in to comment.