diff --git a/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/__init__.py b/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/__init__.py index f42e495f0530..ab713f9c6782 100644 --- a/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/__init__.py +++ b/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/__init__.py @@ -15,6 +15,7 @@ from ._models_py3 import EnabledSubscriptionId from ._models_py3 import ErrorResponse, ErrorResponseException from ._models_py3 import Location + from ._models_py3 import ModernCspSubscriptionCreationParameters from ._models_py3 import ModernSubscriptionCreationParameters from ._models_py3 import Operation from ._models_py3 import OperationDisplay @@ -34,6 +35,7 @@ from ._models import EnabledSubscriptionId from ._models import ErrorResponse, ErrorResponseException from ._models import Location + from ._models import ModernCspSubscriptionCreationParameters from ._models import ModernSubscriptionCreationParameters from ._models import Operation from ._models import OperationDisplay @@ -62,6 +64,7 @@ 'EnabledSubscriptionId', 'ErrorResponse', 'ErrorResponseException', 'Location', + 'ModernCspSubscriptionCreationParameters', 'ModernSubscriptionCreationParameters', 'Operation', 'OperationDisplay', diff --git a/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/_models.py b/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/_models.py index 2f0c1370758c..a00e2cc0fa73 100644 --- a/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/_models.py +++ b/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/_models.py @@ -170,6 +170,44 @@ def __init__(self, **kwargs): self.longitude = None +class ModernCspSubscriptionCreationParameters(Model): + """The parameters required to create a new CSP subscription. + + All required parameters must be populated in order to send to Azure. + + :param display_name: Required. The friendly name of the subscription. + :type display_name: str + :param sku_id: Required. The SKU ID of the Azure plan. Azure plan + determines the pricing and service-level agreement of the subscription. + Use 001 for Microsoft Azure Plan and 002 for Microsoft Azure Plan for + DevTest. + :type sku_id: str + :param reseller_id: Reseller ID, basically MPN Id. + :type reseller_id: str + :param service_provider_id: Service provider ID, basically MPN Id. + :type service_provider_id: str + """ + + _validation = { + 'display_name': {'required': True}, + 'sku_id': {'required': True}, + } + + _attribute_map = { + 'display_name': {'key': 'displayName', 'type': 'str'}, + 'sku_id': {'key': 'skuId', 'type': 'str'}, + 'reseller_id': {'key': 'resellerId', 'type': 'str'}, + 'service_provider_id': {'key': 'serviceProviderId', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(ModernCspSubscriptionCreationParameters, self).__init__(**kwargs) + self.display_name = kwargs.get('display_name', None) + self.sku_id = kwargs.get('sku_id', None) + self.reseller_id = kwargs.get('reseller_id', None) + self.service_provider_id = kwargs.get('service_provider_id', None) + + class ModernSubscriptionCreationParameters(Model): """The parameters required to create a new subscription. diff --git a/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/_models_py3.py b/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/_models_py3.py index c813603b0fb3..ed9caff8d991 100644 --- a/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/_models_py3.py +++ b/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/models/_models_py3.py @@ -170,6 +170,44 @@ def __init__(self, **kwargs) -> None: self.longitude = None +class ModernCspSubscriptionCreationParameters(Model): + """The parameters required to create a new CSP subscription. + + All required parameters must be populated in order to send to Azure. + + :param display_name: Required. The friendly name of the subscription. + :type display_name: str + :param sku_id: Required. The SKU ID of the Azure plan. Azure plan + determines the pricing and service-level agreement of the subscription. + Use 001 for Microsoft Azure Plan and 002 for Microsoft Azure Plan for + DevTest. + :type sku_id: str + :param reseller_id: Reseller ID, basically MPN Id. + :type reseller_id: str + :param service_provider_id: Service provider ID, basically MPN Id. + :type service_provider_id: str + """ + + _validation = { + 'display_name': {'required': True}, + 'sku_id': {'required': True}, + } + + _attribute_map = { + 'display_name': {'key': 'displayName', 'type': 'str'}, + 'sku_id': {'key': 'skuId', 'type': 'str'}, + 'reseller_id': {'key': 'resellerId', 'type': 'str'}, + 'service_provider_id': {'key': 'serviceProviderId', 'type': 'str'}, + } + + def __init__(self, *, display_name: str, sku_id: str, reseller_id: str=None, service_provider_id: str=None, **kwargs) -> None: + super(ModernCspSubscriptionCreationParameters, self).__init__(**kwargs) + self.display_name = display_name + self.sku_id = sku_id + self.reseller_id = reseller_id + self.service_provider_id = service_provider_id + + class ModernSubscriptionCreationParameters(Model): """The parameters required to create a new subscription. diff --git a/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/operations/_subscription_factory_operations.py b/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/operations/_subscription_factory_operations.py index a930538e89bf..1bd11910b9da 100644 --- a/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/operations/_subscription_factory_operations.py +++ b/sdk/subscription/azure-mgmt-subscription/azure/mgmt/subscription/operations/_subscription_factory_operations.py @@ -40,13 +40,14 @@ def __init__(self, client, config, serializer, deserializer): def _create_subscription_initial( - self, billing_account_name, invoice_section_name, body, custom_headers=None, raw=False, **operation_config): + self, billing_account_name, billing_profile_name, invoice_section_name, body, custom_headers=None, raw=False, **operation_config): api_version = "2018-11-01-preview" # Construct URL url = self.create_subscription.metadata['url'] path_format_arguments = { 'billingAccountName': self._serialize.url("billing_account_name", billing_account_name, 'str'), + 'billingProfileName': self._serialize.url("billing_profile_name", billing_profile_name, 'str'), 'invoiceSectionName': self._serialize.url("invoice_section_name", invoice_section_name, 'str') } url = self._client.format_url(url, **path_format_arguments) @@ -94,13 +95,16 @@ def _create_subscription_initial( return deserialized def create_subscription( - self, billing_account_name, invoice_section_name, body, custom_headers=None, raw=False, polling=True, **operation_config): - """The operation to create a new Azure subscription. + self, billing_account_name, billing_profile_name, invoice_section_name, body, custom_headers=None, raw=False, polling=True, **operation_config): + """The operation to create a new WebDirect or EA Azure subscription. :param billing_account_name: The name of the Microsoft Customer Agreement billing account for which you want to create the subscription. :type billing_account_name: str + :param billing_profile_name: The name of the billing profile in the + billing account for which you want to create the subscription. + :type billing_profile_name: str :param invoice_section_name: The name of the invoice section in the billing account for which you want to create the subscription. :type invoice_section_name: str @@ -124,6 +128,7 @@ def create_subscription( """ raw_result = self._create_subscription_initial( billing_account_name=billing_account_name, + billing_profile_name=billing_profile_name, invoice_section_name=invoice_section_name, body=body, custom_headers=custom_headers, @@ -152,7 +157,122 @@ def get_long_running_output(response): elif polling is False: polling_method = NoPolling() else: polling_method = polling return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - create_subscription.metadata = {'url': '/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/invoiceSections/{invoiceSectionName}/providers/Microsoft.Subscription/createSubscription'} + create_subscription.metadata = {'url': '/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName}/providers/Microsoft.Subscription/createSubscription'} + + + def _create_csp_subscription_initial( + self, billing_account_name, customer_name, body, custom_headers=None, raw=False, **operation_config): + api_version = "2018-11-01-preview" + + # Construct URL + url = self.create_csp_subscription.metadata['url'] + path_format_arguments = { + 'billingAccountName': self._serialize.url("billing_account_name", billing_account_name, 'str'), + 'customerName': self._serialize.url("customer_name", customer_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + 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(body, 'ModernCspSubscriptionCreationParameters') + + # Construct and send request + request = self._client.post(url, query_parameters, header_parameters, body_content) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200, 202]: + raise models.ErrorResponseException(self._deserialize, response) + + deserialized = None + header_dict = {} + + if response.status_code == 200: + deserialized = self._deserialize('SubscriptionCreationResult', response) + header_dict = { + 'Location': 'str', + 'Retry-After': 'int', + } + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + client_raw_response.add_headers(header_dict) + return client_raw_response + + return deserialized + + def create_csp_subscription( + self, billing_account_name, customer_name, body, custom_headers=None, raw=False, polling=True, **operation_config): + """The operation to create a new CSP subscription. + + :param billing_account_name: The name of the Microsoft Customer + Agreement billing account for which you want to create the + subscription. + :type billing_account_name: str + :param customer_name: The name of the customer. + :type customer_name: str + :param body: The subscription creation parameters. + :type body: + ~azure.mgmt.subscription.models.ModernCspSubscriptionCreationParameters + :param dict custom_headers: headers that will be added to the request + :param bool raw: The poller return type is ClientRawResponse, the + direct response alongside the deserialized response + :param polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :return: An instance of LROPoller that returns + SubscriptionCreationResult or + ClientRawResponse if raw==True + :rtype: + ~msrestazure.azure_operation.AzureOperationPoller[~azure.mgmt.subscription.models.SubscriptionCreationResult] + or + ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[~azure.mgmt.subscription.models.SubscriptionCreationResult]] + :raises: + :class:`ErrorResponseException` + """ + raw_result = self._create_csp_subscription_initial( + billing_account_name=billing_account_name, + customer_name=customer_name, + body=body, + custom_headers=custom_headers, + raw=True, + **operation_config + ) + + def get_long_running_output(response): + header_dict = { + 'Location': 'str', + 'Retry-After': 'int', + } + deserialized = self._deserialize('SubscriptionCreationResult', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + client_raw_response.add_headers(header_dict) + return client_raw_response + + return deserialized + + lro_delay = operation_config.get( + 'long_running_operation_timeout', + self.config.long_running_operation_timeout) + if polling is True: polling_method = ARMPolling(lro_delay, **operation_config) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + create_csp_subscription.metadata = {'url': '/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/customers/{customerName}/providers/Microsoft.Subscription/createSubscription'} def _create_subscription_in_enrollment_account_initial(