From 01b62973ecc8c929a790206e74a3fa8e2e9796cb Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Mon, 19 Mar 2018 17:03:17 -0700 Subject: [PATCH] [AutoPR] containerinstance/resource-manager 0.4.0 (#2155) * [AutoPR containerinstance/resource-manager] Adding Container Exec Spec (#2114) * Generated from a60b503fd362577f4fab95a5e2518b553ec284e9 fixing small syntax error * Generated from 1ec1e3fd40e63a08d3262affca1203988f7407ef Updating correct examples for async operation * Generated from 24d60116617096cd26598e974ac7e1fa00ec8169 fixing ARM header field * Generated from 9fecbb9feb0b8ea3cbba6a02e84973b2bdf11378 remvoing extra async operations * Generated from 338812373b418f43cc56c9cf152a99475fbe12e1 Update Python version * Update tests and ChangeLog * Generated from 2f0dc17f7d69b23e41058c6aa7eef3946337ffd6 (#2169) Fixing error in naming convention for rows and cols * Adding sanity tests for start container exec * updating the recording file * Final release date --- azure-mgmt-containerinstance/HISTORY.rst | 11 ++ .../container_instance_management_client.py | 5 + .../mgmt/containerinstance/models/__init__.py | 6 + .../models/container_exec_request.py | 33 +++++ .../container_exec_request_terminal_size.py | 32 +++++ .../models/container_exec_response.py | 32 +++++ .../containerinstance/operations/__init__.py | 2 + .../container_group_usage_operations.py | 5 +- .../operations/container_groups_operations.py | 127 +++++++++++++----- .../operations/container_logs_operations.py | 5 +- .../operations/operations.py | 5 +- .../operations/start_container_operations.py | 117 ++++++++++++++++ .../azure/mgmt/containerinstance/version.py | 2 +- ...ainerinstance.test_container_instance.yaml | 123 ++++++++++++++--- .../tests/test_mgmt_containerinstance.py | 11 +- 15 files changed, 456 insertions(+), 60 deletions(-) create mode 100644 azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_request.py create mode 100644 azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_request_terminal_size.py create mode 100644 azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_response.py create mode 100644 azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/start_container_operations.py diff --git a/azure-mgmt-containerinstance/HISTORY.rst b/azure-mgmt-containerinstance/HISTORY.rst index aa1f0f632df3..28f543073f13 100644 --- a/azure-mgmt-containerinstance/HISTORY.rst +++ b/azure-mgmt-containerinstance/HISTORY.rst @@ -3,6 +3,17 @@ Release History =============== +0.4.0 (2018-03-19) +++++++++++++++++++ + +**Breaking changes** + +- container_groups.create_or_update is now a Long Running operation + +**Features** + +- New start_container operation group + 0.3.1 (2018-02-05) ++++++++++++++++++ diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/container_instance_management_client.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/container_instance_management_client.py index 0744af2e4898..6ec5aba00eb2 100644 --- a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/container_instance_management_client.py +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/container_instance_management_client.py @@ -17,6 +17,7 @@ from .operations.operations import Operations from .operations.container_group_usage_operations import ContainerGroupUsageOperations from .operations.container_logs_operations import ContainerLogsOperations +from .operations.start_container_operations import StartContainerOperations from . import models @@ -68,6 +69,8 @@ class ContainerInstanceManagementClient(object): :vartype container_group_usage: azure.mgmt.containerinstance.operations.ContainerGroupUsageOperations :ivar container_logs: ContainerLogs operations :vartype container_logs: azure.mgmt.containerinstance.operations.ContainerLogsOperations + :ivar start_container: StartContainer operations + :vartype start_container: azure.mgmt.containerinstance.operations.StartContainerOperations :param credentials: Credentials needed for the client to connect to Azure. :type credentials: :mod:`A msrestazure Credentials @@ -98,3 +101,5 @@ def __init__( self._client, self.config, self._serialize, self._deserialize) self.container_logs = ContainerLogsOperations( self._client, self.config, self._serialize, self._deserialize) + self.start_container = StartContainerOperations( + self._client, self.config, self._serialize, self._deserialize) diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/__init__.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/__init__.py index 0ae2d1e064b4..4d7d387d8a68 100644 --- a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/__init__.py +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/__init__.py @@ -34,6 +34,9 @@ from .usage import Usage from .usage_list_result import UsageListResult from .logs import Logs +from .container_exec_request_terminal_size import ContainerExecRequestTerminalSize +from .container_exec_request import ContainerExecRequest +from .container_exec_response import ContainerExecResponse from .resource import Resource from .container_group_paged import ContainerGroupPaged from .container_instance_management_client_enums import ( @@ -70,6 +73,9 @@ 'Usage', 'UsageListResult', 'Logs', + 'ContainerExecRequestTerminalSize', + 'ContainerExecRequest', + 'ContainerExecResponse', 'Resource', 'ContainerGroupPaged', 'ContainerNetworkProtocol', diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_request.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_request.py new file mode 100644 index 000000000000..06a3757ef84d --- /dev/null +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_request.py @@ -0,0 +1,33 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ContainerExecRequest(Model): + """The start container exec request. + + :param command: The command to be executed. + :type command: str + :param terminal_size: The size of the terminal. + :type terminal_size: + ~azure.mgmt.containerinstance.models.ContainerExecRequestTerminalSize + """ + + _attribute_map = { + 'command': {'key': 'command', 'type': 'str'}, + 'terminal_size': {'key': 'terminalSize', 'type': 'ContainerExecRequestTerminalSize'}, + } + + def __init__(self, command=None, terminal_size=None): + super(ContainerExecRequest, self).__init__() + self.command = command + self.terminal_size = terminal_size diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_request_terminal_size.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_request_terminal_size.py new file mode 100644 index 000000000000..1b39f9247cc2 --- /dev/null +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_request_terminal_size.py @@ -0,0 +1,32 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ContainerExecRequestTerminalSize(Model): + """The size of the terminal. + + :param rows: The row size of the terminal + :type rows: int + :param cols: The column size of the terminal + :type cols: int + """ + + _attribute_map = { + 'rows': {'key': 'rows', 'type': 'int'}, + 'cols': {'key': 'cols', 'type': 'int'}, + } + + def __init__(self, rows=None, cols=None): + super(ContainerExecRequestTerminalSize, self).__init__() + self.rows = rows + self.cols = cols diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_response.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_response.py new file mode 100644 index 000000000000..33e3557041a5 --- /dev/null +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/models/container_exec_response.py @@ -0,0 +1,32 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ContainerExecResponse(Model): + """The information for the container exec command. + + :param web_socket_uri: The uri for the exec websocket. + :type web_socket_uri: str + :param password: The password to start the exec command. + :type password: str + """ + + _attribute_map = { + 'web_socket_uri': {'key': 'webSocketUri', 'type': 'str'}, + 'password': {'key': 'password', 'type': 'str'}, + } + + def __init__(self, web_socket_uri=None, password=None): + super(ContainerExecResponse, self).__init__() + self.web_socket_uri = web_socket_uri + self.password = password diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/__init__.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/__init__.py index 710e1db45020..1729a0ebb8cb 100644 --- a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/__init__.py +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/__init__.py @@ -13,10 +13,12 @@ from .operations import Operations from .container_group_usage_operations import ContainerGroupUsageOperations from .container_logs_operations import ContainerLogsOperations +from .start_container_operations import StartContainerOperations __all__ = [ 'ContainerGroupsOperations', 'Operations', 'ContainerGroupUsageOperations', 'ContainerLogsOperations', + 'StartContainerOperations', ] diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_group_usage_operations.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_group_usage_operations.py index 41fe07da49fe..7417d09bd637 100644 --- a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_group_usage_operations.py +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_group_usage_operations.py @@ -22,7 +22,7 @@ class ContainerGroupUsageOperations(object): :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. - :param deserializer: An objec model deserializer. + :param deserializer: An object model deserializer. :ivar api_version: Client API version. Constant value: "2018-02-01-preview". """ @@ -54,7 +54,7 @@ def list( :raises: :class:`CloudError` """ # Construct URL - url = '/subscriptions/{subscriptionId}/providers/Microsoft.ContainerInstance/locations/{location}/usages' + url = self.list.metadata['url'] path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'location': self._serialize.url("location", location, 'str') @@ -94,3 +94,4 @@ def list( return client_raw_response return deserialized + list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.ContainerInstance/locations/{location}/usages'} diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_groups_operations.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_groups_operations.py index 2dcacd71fa0f..0f405fa3ebf7 100644 --- a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_groups_operations.py +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_groups_operations.py @@ -12,6 +12,8 @@ import uuid from msrest.pipeline import ClientRawResponse from msrestazure.azure_exceptions import CloudError +from msrest.exceptions import DeserializationError +from msrestazure.azure_operation import AzureOperationPoller from .. import models @@ -22,7 +24,7 @@ class ContainerGroupsOperations(object): :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. - :param deserializer: An objec model deserializer. + :param deserializer: An object model deserializer. :ivar api_version: Client API version. Constant value: "2018-02-01-preview". """ @@ -60,7 +62,7 @@ def internal_paging(next_link=None, raw=False): if not next_link: # Construct URL - url = '/subscriptions/{subscriptionId}/providers/Microsoft.ContainerInstance/containerGroups' + url = self.list.metadata['url'] path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') } @@ -105,6 +107,7 @@ def internal_paging(next_link=None, raw=False): return client_raw_response return deserialized + list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.ContainerInstance/containerGroups'} def list_by_resource_group( self, resource_group_name, custom_headers=None, raw=False, **operation_config): @@ -132,7 +135,7 @@ def internal_paging(next_link=None, raw=False): if not next_link: # Construct URL - url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups' + url = self.list_by_resource_group.metadata['url'] path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str') @@ -178,6 +181,7 @@ def internal_paging(next_link=None, raw=False): return client_raw_response return deserialized + list_by_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups'} def get( self, resource_group_name, container_group_name, custom_headers=None, raw=False, **operation_config): @@ -204,7 +208,7 @@ def get( :raises: :class:`CloudError` """ # Construct URL - url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}' + url = self.get.metadata['url'] path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), @@ -245,33 +249,13 @@ def get( return client_raw_response return deserialized + get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}'} - def create_or_update( - self, resource_group_name, container_group_name, container_group, custom_headers=None, raw=False, **operation_config): - """Create or update container groups. - - Create or update container groups with specified configurations. - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param container_group_name: The name of the container group. - :type container_group_name: str - :param container_group: The properties of the container group to be - created or updated. - :type container_group: - ~azure.mgmt.containerinstance.models.ContainerGroup - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: ContainerGroup or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.containerinstance.models.ContainerGroup or - ~msrest.pipeline.ClientRawResponse - :raises: :class:`CloudError` - """ + def _create_or_update_initial( + self, resource_group_name, container_group_name, container_group, custom_headers=None, raw=False, **operation_config): # Construct URL - url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}' + url = self.create_or_update.metadata['url'] path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), @@ -319,6 +303,78 @@ def create_or_update( return deserialized + def create_or_update( + self, resource_group_name, container_group_name, container_group, custom_headers=None, raw=False, **operation_config): + """Create or update container groups. + + Create or update container groups with specified configurations. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param container_group_name: The name of the container group. + :type container_group_name: str + :param container_group: The properties of the container group to be + created or updated. + :type container_group: + ~azure.mgmt.containerinstance.models.ContainerGroup + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :return: An instance of AzureOperationPoller that returns + ContainerGroup or ClientRawResponse if raw=true + :rtype: + ~msrestazure.azure_operation.AzureOperationPoller[~azure.mgmt.containerinstance.models.ContainerGroup] + or ~msrest.pipeline.ClientRawResponse + :raises: :class:`CloudError` + """ + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + container_group_name=container_group_name, + container_group=container_group, + custom_headers=custom_headers, + raw=True, + **operation_config + ) + if raw: + return raw_result + + # Construct and send request + def long_running_send(): + return raw_result.response + + def get_long_running_status(status_link, headers=None): + + request = self._client.get(status_link) + if headers: + request.headers.update(headers) + header_parameters = {} + header_parameters['x-ms-client-request-id'] = raw_result.response.request.headers['x-ms-client-request-id'] + return self._client.send( + request, header_parameters, stream=False, **operation_config) + + def get_long_running_output(response): + + if response.status_code not in [200, 201]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + deserialized = self._deserialize('ContainerGroup', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + long_running_operation_timeout = operation_config.get( + 'long_running_operation_timeout', + self.config.long_running_operation_timeout) + return AzureOperationPoller( + long_running_send, get_long_running_output, + get_long_running_status, long_running_operation_timeout) + create_or_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}'} + def update( self, resource_group_name, container_group_name, location=None, tags=None, custom_headers=None, raw=False, **operation_config): """Update container groups. @@ -343,12 +399,10 @@ def update( ~msrest.pipeline.ClientRawResponse :raises: :class:`CloudError` """ - resource = None - if location is not None or tags is not None: - resource = models.Resource(location=location, tags=tags) + resource = models.Resource(location=location, tags=tags) # Construct URL - url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}' + url = self.update.metadata['url'] path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), @@ -371,10 +425,7 @@ def update( header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct body - if resource is not None: - body_content = self._serialize.body(resource, 'Resource') - else: - body_content = None + body_content = self._serialize.body(resource, 'Resource') # Construct and send request request = self._client.patch(url, query_parameters) @@ -396,6 +447,7 @@ def update( return client_raw_response return deserialized + update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}'} def delete( self, resource_group_name, container_group_name, custom_headers=None, raw=False, **operation_config): @@ -420,7 +472,7 @@ def delete( :raises: :class:`CloudError` """ # Construct URL - url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}' + url = self.delete.metadata['url'] path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), @@ -461,3 +513,4 @@ def delete( return client_raw_response return deserialized + delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}'} diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_logs_operations.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_logs_operations.py index e5871c4fa945..72513725100e 100644 --- a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_logs_operations.py +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/container_logs_operations.py @@ -22,7 +22,7 @@ class ContainerLogsOperations(object): :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. - :param deserializer: An objec model deserializer. + :param deserializer: An object model deserializer. :ivar api_version: Client API version. Constant value: "2018-02-01-preview". """ @@ -65,7 +65,7 @@ def list( :raises: :class:`CloudError` """ # Construct URL - url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}/containers/{containerName}/logs' + url = self.list.metadata['url'] path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), @@ -109,3 +109,4 @@ def list( return client_raw_response return deserialized + list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}/containers/{containerName}/logs'} diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/operations.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/operations.py index d1c85ca0a159..77b53408cd2f 100644 --- a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/operations.py +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/operations.py @@ -22,7 +22,7 @@ class Operations(object): :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. - :param deserializer: An objec model deserializer. + :param deserializer: An object model deserializer. :ivar api_version: Client API version. Constant value: "2018-02-01-preview". """ @@ -52,7 +52,7 @@ def list( :raises: :class:`CloudError` """ # Construct URL - url = '/providers/Microsoft.ContainerInstance/operations' + url = self.list.metadata['url'] # Construct parameters query_parameters = {} @@ -87,3 +87,4 @@ def list( return client_raw_response return deserialized + list.metadata = {'url': '/providers/Microsoft.ContainerInstance/operations'} diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/start_container_operations.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/start_container_operations.py new file mode 100644 index 000000000000..e3387a6c2586 --- /dev/null +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/operations/start_container_operations.py @@ -0,0 +1,117 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +import uuid +from msrest.pipeline import ClientRawResponse +from msrestazure.azure_exceptions import CloudError + +from .. import models + + +class StartContainerOperations(object): + """StartContainerOperations operations. + + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + :ivar api_version: Client API version. Constant value: "2018-02-01-preview". + """ + + models = models + + def __init__(self, client, config, serializer, deserializer): + + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self.api_version = "2018-02-01-preview" + + self.config = config + + def launch_exec( + self, resource_group_name, container_group_name, container_name, command=None, terminal_size=None, custom_headers=None, raw=False, **operation_config): + """Starts the exec command for a specific container instance. + + Starts the exec command for a specified container instance in a + specified resource group and container group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param container_group_name: The name of the container group. + :type container_group_name: str + :param container_name: The name of the container instance. + :type container_name: str + :param command: The command to be executed. + :type command: str + :param terminal_size: The size of the terminal. + :type terminal_size: + ~azure.mgmt.containerinstance.models.ContainerExecRequestTerminalSize + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: ContainerExecResponse or ClientRawResponse if raw=true + :rtype: ~azure.mgmt.containerinstance.models.ContainerExecResponse or + ~msrest.pipeline.ClientRawResponse + :raises: :class:`CloudError` + """ + container_exec_request = models.ContainerExecRequest(command=command, terminal_size=terminal_size) + + # Construct URL + url = self.launch_exec.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'containerGroupName': self._serialize.url("container_group_name", container_group_name, 'str'), + 'containerName': self._serialize.url("container_name", container_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(container_exec_request, 'ContainerExecRequest') + + # Construct and send request + request = self._client.post(url, query_parameters) + response = self._client.send( + request, header_parameters, body_content, stream=False, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('ContainerExecResponse', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + launch_exec.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroupName}/containers/{containerName}/exec'} diff --git a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/version.py b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/version.py index 54fdd938c10a..85da2c00c1a6 100644 --- a/azure-mgmt-containerinstance/azure/mgmt/containerinstance/version.py +++ b/azure-mgmt-containerinstance/azure/mgmt/containerinstance/version.py @@ -9,5 +9,5 @@ # regenerated. # -------------------------------------------------------------------------- -VERSION = "0.3.1" +VERSION = "0.4.0" diff --git a/azure-mgmt-containerinstance/tests/recordings/test_mgmt_containerinstance.test_container_instance.yaml b/azure-mgmt-containerinstance/tests/recordings/test_mgmt_containerinstance.test_container_instance.yaml index 205059a2d00a..60d407dfa75e 100644 --- a/azure-mgmt-containerinstance/tests/recordings/test_mgmt_containerinstance.test_container_instance.yaml +++ b/azure-mgmt-containerinstance/tests/recordings/test_mgmt_containerinstance.test_container_instance.yaml @@ -11,25 +11,84 @@ interactions: Connection: [keep-alive] Content-Length: ['364'] Content-Type: [application/json; charset=utf-8] - User-Agent: [python/3.6.2 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.26 - msrest_azure/0.4.20 azure-mgmt-containerinstance/0.3.0 Azure-SDK-For-Python] + User-Agent: [python/3.6.2 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.27 + msrest_azure/0.4.22 azure-mgmt-containerinstance/0.4.0 Azure-SDK-For-Python] accept-language: [en-US] method: PUT uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510?api-version=2018-02-01-preview response: body: {string: '{"properties":{"provisioningState":"Creating","containers":[{"name":"pycontainer26441510","properties":{"image":"alpine:latest","ports":[],"environmentVariables":[],"resources":{"requests":{"memoryInGB":1.0,"cpu":1.0}},"volumeMounts":[{"name":"empty-volume","mountPath":"/mnt/mydir"}]}}],"restartPolicy":"OnFailure","osType":"Linux","volumes":[{"name":"empty-volume","emptyDir":{}}],"instanceView":{"events":[],"state":"Pending"}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510","name":"pycontainer26441510","type":"Microsoft.ContainerInstance/containerGroups","location":"westus"}'} headers: + azure-asyncoperation: ['https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerInstance/locations/West + US/operations/5ec11603-ea02-40b4-822e-5856f6518cae?api-version=2018-02-01-preview'] cache-control: [no-cache] content-length: ['741'] content-type: [application/json; charset=utf-8] - date: ['Thu, 01 Feb 2018 18:57:34 GMT'] + date: ['Mon, 19 Mar 2018 23:36:24 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] - x-ms-ratelimit-remaining-subscription-resource-requests-pt1h: ['59'] - x-ms-ratelimit-remaining-subscription-resource-requests-pt5m: ['19'] + x-content-type-options: [nosniff] + x-ms-ratelimit-remaining-subscription-resource-requests-pt1h: ['84'] + x-ms-ratelimit-remaining-subscription-resource-requests-pt5m: ['98'] x-ms-ratelimit-remaining-subscription-writes: ['1199'] status: {code: 201, message: Created} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + User-Agent: [python/3.6.2 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.27 + msrest_azure/0.4.22 azure-mgmt-containerinstance/0.4.0 Azure-SDK-For-Python] + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerInstance/locations/West%20US/operations/5ec11603-ea02-40b4-822e-5856f6518cae?api-version=2018-02-01-preview + response: + body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510","status":"Succeeded","startTime":"2018-03-19T23:36:23.8597884Z","properties":{"events":[{"count":1,"firstTimestamp":"2018-03-19T23:36:32Z","lastTimestamp":"2018-03-19T23:36:32Z","name":"Pulling","message":"pulling + image \"alpine:latest\"","type":"Normal"},{"count":1,"firstTimestamp":"2018-03-19T23:36:34Z","lastTimestamp":"2018-03-19T23:36:34Z","name":"Pulled","message":"Successfully + pulled image \"alpine:latest\"","type":"Normal"},{"count":1,"firstTimestamp":"2018-03-19T23:36:34Z","lastTimestamp":"2018-03-19T23:36:34Z","name":"Created","message":"Created + container with id 8b97d2d01d60e8505ee23d259c04f7193c2d6272f54ea9725f82cfcbfa189f06","type":"Normal"},{"count":1,"firstTimestamp":"2018-03-19T23:36:35Z","lastTimestamp":"2018-03-19T23:36:35Z","name":"Started","message":"Started + container with id 8b97d2d01d60e8505ee23d259c04f7193c2d6272f54ea9725f82cfcbfa189f06","type":"Normal"}]}}'} + headers: + cache-control: [no-cache] + content-length: ['1100'] + content-type: [application/json; charset=utf-8] + date: ['Mon, 19 Mar 2018 23:36:54 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + User-Agent: [python/3.6.2 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.27 + msrest_azure/0.4.22 azure-mgmt-containerinstance/0.4.0 Azure-SDK-For-Python] + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510?api-version=2018-02-01-preview + response: + body: {string: '{"properties":{"provisioningState":"Succeeded","containers":[{"name":"pycontainer26441510","properties":{"image":"alpine:latest","ports":[],"environmentVariables":[],"instanceView":{"restartCount":0,"currentState":{"state":"Terminated","startTime":"2018-03-19T23:36:35Z","exitCode":0,"finishTime":"2018-03-19T23:36:35Z","detailStatus":"Completed"},"events":[{"count":1,"firstTimestamp":"2018-03-19T23:36:32Z","lastTimestamp":"2018-03-19T23:36:32Z","name":"Pulling","message":"pulling + image \"alpine:latest\"","type":"Normal"},{"count":1,"firstTimestamp":"2018-03-19T23:36:34Z","lastTimestamp":"2018-03-19T23:36:34Z","name":"Pulled","message":"Successfully + pulled image \"alpine:latest\"","type":"Normal"},{"count":1,"firstTimestamp":"2018-03-19T23:36:34Z","lastTimestamp":"2018-03-19T23:36:34Z","name":"Created","message":"Created + container with id 8b97d2d01d60e8505ee23d259c04f7193c2d6272f54ea9725f82cfcbfa189f06","type":"Normal"},{"count":1,"firstTimestamp":"2018-03-19T23:36:35Z","lastTimestamp":"2018-03-19T23:36:35Z","name":"Started","message":"Started + container with id 8b97d2d01d60e8505ee23d259c04f7193c2d6272f54ea9725f82cfcbfa189f06","type":"Normal"}]},"resources":{"requests":{"memoryInGB":1.0,"cpu":1.0}},"volumeMounts":[{"name":"empty-volume","mountPath":"/mnt/mydir"}]}}],"restartPolicy":"OnFailure","osType":"Linux","volumes":[{"name":"empty-volume","emptyDir":{}}],"instanceView":{"events":[],"state":"Succeeded"}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510","name":"pycontainer26441510","type":"Microsoft.ContainerInstance/containerGroups","location":"westus"}'} + headers: + cache-control: [no-cache] + content-length: ['1739'] + content-type: [application/json; charset=utf-8] + date: ['Mon, 19 Mar 2018 23:36:55 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} - request: body: null headers: @@ -37,23 +96,28 @@ interactions: Accept-Encoding: ['gzip, deflate'] Connection: [keep-alive] Content-Type: [application/json; charset=utf-8] - User-Agent: [python/3.6.2 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.26 - msrest_azure/0.4.20 azure-mgmt-containerinstance/0.3.0 Azure-SDK-For-Python] + User-Agent: [python/3.6.2 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.27 + msrest_azure/0.4.22 azure-mgmt-containerinstance/0.4.0 Azure-SDK-For-Python] accept-language: [en-US] method: GET uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510?api-version=2018-02-01-preview response: - body: {string: '{"properties":{"provisioningState":"Creating","containers":[{"name":"pycontainer26441510","properties":{"image":"alpine:latest","ports":[],"environmentVariables":[],"resources":{"requests":{"memoryInGB":1.0,"cpu":1.0}},"volumeMounts":[{"name":"empty-volume","mountPath":"/mnt/mydir"}]}}],"restartPolicy":"OnFailure","osType":"Linux","volumes":[{"name":"empty-volume","emptyDir":{}}],"instanceView":{"events":[],"state":"Pending"}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510","name":"pycontainer26441510","type":"Microsoft.ContainerInstance/containerGroups","location":"westus"}'} + body: {string: '{"properties":{"provisioningState":"Succeeded","containers":[{"name":"pycontainer26441510","properties":{"image":"alpine:latest","ports":[],"environmentVariables":[],"instanceView":{"restartCount":0,"currentState":{"state":"Terminated","startTime":"2018-03-19T23:36:35Z","exitCode":0,"finishTime":"2018-03-19T23:36:35Z","detailStatus":"Completed"},"events":[{"count":1,"firstTimestamp":"2018-03-19T23:36:32Z","lastTimestamp":"2018-03-19T23:36:32Z","name":"Pulling","message":"pulling + image \"alpine:latest\"","type":"Normal"},{"count":1,"firstTimestamp":"2018-03-19T23:36:34Z","lastTimestamp":"2018-03-19T23:36:34Z","name":"Pulled","message":"Successfully + pulled image \"alpine:latest\"","type":"Normal"},{"count":1,"firstTimestamp":"2018-03-19T23:36:34Z","lastTimestamp":"2018-03-19T23:36:34Z","name":"Created","message":"Created + container with id 8b97d2d01d60e8505ee23d259c04f7193c2d6272f54ea9725f82cfcbfa189f06","type":"Normal"},{"count":1,"firstTimestamp":"2018-03-19T23:36:35Z","lastTimestamp":"2018-03-19T23:36:35Z","name":"Started","message":"Started + container with id 8b97d2d01d60e8505ee23d259c04f7193c2d6272f54ea9725f82cfcbfa189f06","type":"Normal"}]},"resources":{"requests":{"memoryInGB":1.0,"cpu":1.0}},"volumeMounts":[{"name":"empty-volume","mountPath":"/mnt/mydir"}]}}],"restartPolicy":"OnFailure","osType":"Linux","volumes":[{"name":"empty-volume","emptyDir":{}}],"instanceView":{"events":[],"state":"Succeeded"}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510","name":"pycontainer26441510","type":"Microsoft.ContainerInstance/containerGroups","location":"westus"}'} headers: cache-control: [no-cache] - content-length: ['741'] + content-length: ['1739'] content-type: [application/json; charset=utf-8] - date: ['Thu, 01 Feb 2018 18:57:33 GMT'] + date: ['Mon, 19 Mar 2018 23:36:56 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] transfer-encoding: [chunked] vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] status: {code: 200, message: OK} - request: body: null @@ -62,22 +126,51 @@ interactions: Accept-Encoding: ['gzip, deflate'] Connection: [keep-alive] Content-Type: [application/json; charset=utf-8] - User-Agent: [python/3.6.2 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.26 - msrest_azure/0.4.20 azure-mgmt-containerinstance/0.3.0 Azure-SDK-For-Python] + User-Agent: [python/3.6.2 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.27 + msrest_azure/0.4.22 azure-mgmt-containerinstance/0.4.0 Azure-SDK-For-Python] accept-language: [en-US] method: GET uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups?api-version=2018-02-01-preview response: - body: {string: '{"value":[{"properties":{"provisioningState":"Creating","containers":[{"name":"pycontainer26441510","properties":{"image":"alpine:latest","ports":[],"environmentVariables":[],"resources":{"requests":{"memoryInGB":1.0,"cpu":1.0}},"volumeMounts":[{"name":"empty-volume","mountPath":"/mnt/mydir"}]}}],"restartPolicy":"OnFailure","osType":"Linux","volumes":[{"name":"empty-volume","emptyDir":{}}]},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510","name":"pycontainer26441510","type":"Microsoft.ContainerInstance/containerGroups","location":"westus"}]}'} + body: {string: '{"value":[{"properties":{"provisioningState":"Succeeded","containers":[{"name":"pycontainer26441510","properties":{"image":"alpine:latest","ports":[],"environmentVariables":[],"resources":{"requests":{"memoryInGB":1.0,"cpu":1.0}},"volumeMounts":[{"name":"empty-volume","mountPath":"/mnt/mydir"}]}}],"restartPolicy":"OnFailure","osType":"Linux","volumes":[{"name":"empty-volume","emptyDir":{}}]},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510","name":"pycontainer26441510","type":"Microsoft.ContainerInstance/containerGroups","location":"westus"}]}'} + headers: + cache-control: [no-cache] + content-length: ['707'] + content-type: [application/json; charset=utf-8] + date: ['Mon, 19 Mar 2018 23:36:56 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: '{"command": "/bin/bash", "terminalSize": {"rows": 24, "cols": 80}}' + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + Content-Length: ['66'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.2 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.27 + msrest_azure/0.4.22 azure-mgmt-containerinstance/0.4.0 Azure-SDK-For-Python] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_mgmt_containerinstance_test_container_instance26441510/providers/Microsoft.ContainerInstance/containerGroups/pycontainer26441510/containers/pycontainer26441510/exec?api-version=2018-02-01-preview + response: + body: {string: '{"webSocketUri":"wss://bridge-linux-01.westus.management.azurecontainer.io/exec/caas-17444714c0f443b0b9a8e30467a3308d/bridge-b922f3e57bff7dd4?rows=24&cols=80&api-version=2018-02-01-preview","password":"IKcUC6zOXP68r8MbDrj7Rcbt6RwQHPrrFJA2SYdWAsI"}'} headers: cache-control: [no-cache] - content-length: ['706'] + content-length: ['247'] content-type: [application/json; charset=utf-8] - date: ['Thu, 01 Feb 2018 18:57:34 GMT'] + date: ['Mon, 19 Mar 2018 23:36:57 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] transfer-encoding: [chunked] vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + x-ms-ratelimit-remaining-subscription-writes: ['1198'] status: {code: 200, message: OK} version: 1 diff --git a/azure-mgmt-containerinstance/tests/test_mgmt_containerinstance.py b/azure-mgmt-containerinstance/tests/test_mgmt_containerinstance.py index dd7b52835664..a0f2b8b14cb6 100644 --- a/azure-mgmt-containerinstance/tests/test_mgmt_containerinstance.py +++ b/azure-mgmt-containerinstance/tests/test_mgmt_containerinstance.py @@ -33,7 +33,7 @@ def test_container_instance(self, resource_group, location): empty_volume = Volume(name='empty-volume', empty_dir={}) volume_mount = VolumeMount(name='empty-volume', mount_path='/mnt/mydir') - container_group = self.client.container_groups.create_or_update( + poller = self.client.container_groups.create_or_update( resource_group.name, container_group_name, { @@ -54,6 +54,7 @@ def test_container_instance(self, resource_group, location): 'volumes': [empty_volume] } ) + container_group = poller.result() self.assertEqual(container_group.name, container_group_name) self.assertEqual(container_group.location, location) @@ -89,6 +90,14 @@ def test_container_instance(self, resource_group, location): self.assertEqual(container_groups[0].containers[0].resources.requests.cpu, cpu) self.assertEqual(container_groups[0].volumes[0].name, empty_volume.name) + terminal_size = { + "rows": 24, + "cols": 80 + } + command = "/bin/bash" + containerExecResponse = self.client.start_container.launch_exec(resource_group.name, container_group.name, container_group.containers[0].name, command, terminal_size) + self.assertNotEqual(containerExecResponse.web_socket_uri, None) + self.assertNotEqual(containerExecResponse.password, None) #------------------------------------------------------------------------------ if __name__ == '__main__':