sagemaker.core.tools.resources_codegen#

Generates the resource classes for the service model.

Classes

ResourcesCodeGen(service_json)

A class for generating resources based on a service JSON file.

class sagemaker.core.tools.resources_codegen.ResourcesCodeGen(service_json: dict)[source]#

Bases: object

A class for generating resources based on a service JSON file.

Parameters:

service_json (dict) – The Botocore service.json containing the shape definitions.

service_json#

The Botocore service.json containing the shape definitions.

Type:

dict

version#

The API version of the service.

Type:

str

protocol#

The protocol used by the service.

Type:

str

service#

The full name of the service.

Type:

str

service_id#

The ID of the service.

Type:

str

uid#

The unique identifier of the service.

Type:

str

operations#

The operations supported by the service.

Type:

dict

shapes#

The shapes used by the service.

Type:

dict

resources_extractor#

An instance of the ResourcesExtractor class.

Type:

ResourcesExtractor

resources_plan#

The resource plan in dataframe format.

Type:

DataFrame

shapes_extractor#

An instance of the ShapesExtractor class.

Type:

ShapesExtractor

Raises:

Exception – If the service ID is not supported or the protocol is not supported.

generate_additional_get_all_method(method: Method, resource_attributes: list)[source]#

Auto-Generate methods that return a list of objects.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted method code.

Return type:

str

generate_base_class() str[source]#

Generate the base class for the resources.

Returns:

The base class.

Return type:

str

generate_config_schema()[source]#

Generates the Config Schema that is used by json Schema to validate config jsons . This function creates a python file with a variable that is consumed in the scripts to further fetch configs.

Input for generating the Schema is the service JSON that is already loaded in the class

generate_create_method(resource_name: str, **kwargs) str[source]#

Auto-generate the CREATE method for a resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted Create Method template.

Return type:

str

static generate_defaults_decorator(config_schema_for_resource: dict, resource_name: str, class_attributes: dict) str[source]#
generate_delete_method(resource_name: str, **kwargs) str[source]#

Auto-Generate ‘delete’ object Method [delete API] for a resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted delete Method template.

Return type:

str

generate_get_all_method(resource_name: str) str[source]#

Auto-Generate ‘get_all’ class Method [list API] for a resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted get_all Method template.

Return type:

str

generate_get_method(resource_name: str) str[source]#

Auto-generate the GET method (describe API) for a resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted Get Method template.

Return type:

str

generate_get_name_method(resource_lower: str) str[source]#

Autogenerate the method that would return the identifier of the object :param resource_name: Name of Resource

Returns:

Formatted Get Name Method

Return type:

str

generate_import_method(resource_name: str) str[source]#

Auto-generate the IMPORT method for a resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted Import Method template.

Return type:

str

generate_imports() str[source]#

Generate the import statements for the generated resources file.

Returns:

The import statements.

Return type:

str

generate_license() str[source]#

Generate the license for the generated resources file.

Returns:

The license.

Return type:

str

generate_logging() str[source]#

Generate the logging statements for the generated resources file.

Returns:

The logging statements.

Return type:

str

generate_method(method: Method, resource_attributes: list)[source]#
generate_refresh_method(resource_name: str, **kwargs) str[source]#

Auto-Generate ‘refresh’ object Method [describe API] for a resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted refresh Method template.

Return type:

str

generate_resource_class(resource_name: str, class_methods: list, object_methods: list, additional_methods: list, raw_actions: list, resource_status_chain: list, resource_states: list) str[source]#

Generate the resource class for a resource.

Parameters:
  • resource_name (str) – The name of the resource.

  • class_methods (list) – The class methods.

  • object_methods (list) – The object methods.

  • additional_methods (list) – The additional methods.

  • raw_actions (list) – The raw actions.

Returns:

The formatted resource class.

Return type:

str

generate_resources(output_folder: str = '/home/docs/checkouts/readthedocs.org/user_builds/sagemaker/checkouts/5737/docs/src/sagemaker/core', file_name: str = 'resources.py') None[source]#

Generate the resources file.

Parameters:
  • output_folder (str, optional) – The output folder path. Defaults to “GENERATED_CLASSES_LOCATION”.

  • file_name (str, optional) – The output file name. Defaults to “RESOURCES_CODEGEN_FILE_NAME”.

generate_start_method(resource_name: str, **kwargs) str[source]#

Auto-Generate ‘start’ object Method [delete API] for a resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted stop Method template.

Return type:

str

generate_stop_method(resource_name: str) str[source]#

Auto-Generate ‘stop’ object Method [delete API] for a resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted stop Method template.

Return type:

str

generate_update_method(resource_name: str, **kwargs) str[source]#

Auto-generate the UPDATE method for a resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted Update Method template.

Return type:

str

generate_wait_for_delete_method(resource_name: str) str[source]#

Auto-Generate WAIT_FOR_DELETE Method for a resource with deleting status.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted wait_for_delete Method template.

Return type:

str

generate_wait_for_status_method(resource_name: str) str[source]#

Auto-Generate WAIT_FOR_STATUS Method for a waitable resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted wait_for_status Method template.

Return type:

str

generate_wait_method(resource_name: str) str[source]#

Auto-Generate WAIT Method for a waitable resource.

Parameters:

resource_name (str) – The resource name.

Returns:

The formatted Wait Method template.

Return type:

str