|
11 | 11 |
|
12 | 12 | import uuid |
13 | 13 | from msrest.pipeline import ClientRawResponse |
| 14 | +from msrest.polling import LROPoller, NoPolling |
| 15 | +from msrestazure.polling.arm_polling import ARMPolling |
14 | 16 |
|
15 | 17 | from .. import models |
16 | 18 |
|
@@ -781,6 +783,158 @@ def summarize_for_resource( |
781 | 783 | return deserialized |
782 | 784 | summarize_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} |
783 | 785 |
|
| 786 | + |
| 787 | + def _trigger_subscription_evaluation_initial( |
| 788 | + self, subscription_id, custom_headers=None, raw=False, **operation_config): |
| 789 | + # Construct URL |
| 790 | + url = self.trigger_subscription_evaluation.metadata['url'] |
| 791 | + path_format_arguments = { |
| 792 | + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str') |
| 793 | + } |
| 794 | + url = self._client.format_url(url, **path_format_arguments) |
| 795 | + |
| 796 | + # Construct parameters |
| 797 | + query_parameters = {} |
| 798 | + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') |
| 799 | + |
| 800 | + # Construct headers |
| 801 | + header_parameters = {} |
| 802 | + if self.config.generate_client_request_id: |
| 803 | + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) |
| 804 | + if custom_headers: |
| 805 | + header_parameters.update(custom_headers) |
| 806 | + if self.config.accept_language is not None: |
| 807 | + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') |
| 808 | + |
| 809 | + # Construct and send request |
| 810 | + request = self._client.post(url, query_parameters, header_parameters) |
| 811 | + response = self._client.send(request, stream=False, **operation_config) |
| 812 | + |
| 813 | + if response.status_code not in [200, 202]: |
| 814 | + raise models.QueryFailureException(self._deserialize, response) |
| 815 | + |
| 816 | + if raw: |
| 817 | + client_raw_response = ClientRawResponse(None, response) |
| 818 | + return client_raw_response |
| 819 | + |
| 820 | + def trigger_subscription_evaluation( |
| 821 | + self, subscription_id, custom_headers=None, raw=False, polling=True, **operation_config): |
| 822 | + """Triggers a policy evaluation scan for all the resources under the |
| 823 | + subscription. |
| 824 | +
|
| 825 | + :param subscription_id: Microsoft Azure subscription ID. |
| 826 | + :type subscription_id: str |
| 827 | + :param dict custom_headers: headers that will be added to the request |
| 828 | + :param bool raw: The poller return type is ClientRawResponse, the |
| 829 | + direct response alongside the deserialized response |
| 830 | + :param polling: True for ARMPolling, False for no polling, or a |
| 831 | + polling object for personal polling strategy |
| 832 | + :return: An instance of LROPoller that returns None or |
| 833 | + ClientRawResponse<None> if raw==True |
| 834 | + :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or |
| 835 | + ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[None]] |
| 836 | + :raises: |
| 837 | + :class:`QueryFailureException<azure.mgmt.policyinsights.models.QueryFailureException>` |
| 838 | + """ |
| 839 | + raw_result = self._trigger_subscription_evaluation_initial( |
| 840 | + subscription_id=subscription_id, |
| 841 | + custom_headers=custom_headers, |
| 842 | + raw=True, |
| 843 | + **operation_config |
| 844 | + ) |
| 845 | + |
| 846 | + def get_long_running_output(response): |
| 847 | + if raw: |
| 848 | + client_raw_response = ClientRawResponse(None, response) |
| 849 | + return client_raw_response |
| 850 | + |
| 851 | + lro_delay = operation_config.get( |
| 852 | + 'long_running_operation_timeout', |
| 853 | + self.config.long_running_operation_timeout) |
| 854 | + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **operation_config) |
| 855 | + elif polling is False: polling_method = NoPolling() |
| 856 | + else: polling_method = polling |
| 857 | + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) |
| 858 | + trigger_subscription_evaluation.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} |
| 859 | + |
| 860 | + |
| 861 | + def _trigger_resource_group_evaluation_initial( |
| 862 | + self, subscription_id, resource_group_name, custom_headers=None, raw=False, **operation_config): |
| 863 | + # Construct URL |
| 864 | + url = self.trigger_resource_group_evaluation.metadata['url'] |
| 865 | + path_format_arguments = { |
| 866 | + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), |
| 867 | + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str') |
| 868 | + } |
| 869 | + url = self._client.format_url(url, **path_format_arguments) |
| 870 | + |
| 871 | + # Construct parameters |
| 872 | + query_parameters = {} |
| 873 | + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') |
| 874 | + |
| 875 | + # Construct headers |
| 876 | + header_parameters = {} |
| 877 | + if self.config.generate_client_request_id: |
| 878 | + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) |
| 879 | + if custom_headers: |
| 880 | + header_parameters.update(custom_headers) |
| 881 | + if self.config.accept_language is not None: |
| 882 | + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') |
| 883 | + |
| 884 | + # Construct and send request |
| 885 | + request = self._client.post(url, query_parameters, header_parameters) |
| 886 | + response = self._client.send(request, stream=False, **operation_config) |
| 887 | + |
| 888 | + if response.status_code not in [200, 202]: |
| 889 | + raise models.QueryFailureException(self._deserialize, response) |
| 890 | + |
| 891 | + if raw: |
| 892 | + client_raw_response = ClientRawResponse(None, response) |
| 893 | + return client_raw_response |
| 894 | + |
| 895 | + def trigger_resource_group_evaluation( |
| 896 | + self, subscription_id, resource_group_name, custom_headers=None, raw=False, polling=True, **operation_config): |
| 897 | + """Triggers a policy evaluation scan for all the resources under the |
| 898 | + resource group. |
| 899 | +
|
| 900 | + :param subscription_id: Microsoft Azure subscription ID. |
| 901 | + :type subscription_id: str |
| 902 | + :param resource_group_name: Resource group name. |
| 903 | + :type resource_group_name: str |
| 904 | + :param dict custom_headers: headers that will be added to the request |
| 905 | + :param bool raw: The poller return type is ClientRawResponse, the |
| 906 | + direct response alongside the deserialized response |
| 907 | + :param polling: True for ARMPolling, False for no polling, or a |
| 908 | + polling object for personal polling strategy |
| 909 | + :return: An instance of LROPoller that returns None or |
| 910 | + ClientRawResponse<None> if raw==True |
| 911 | + :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or |
| 912 | + ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[None]] |
| 913 | + :raises: |
| 914 | + :class:`QueryFailureException<azure.mgmt.policyinsights.models.QueryFailureException>` |
| 915 | + """ |
| 916 | + raw_result = self._trigger_resource_group_evaluation_initial( |
| 917 | + subscription_id=subscription_id, |
| 918 | + resource_group_name=resource_group_name, |
| 919 | + custom_headers=custom_headers, |
| 920 | + raw=True, |
| 921 | + **operation_config |
| 922 | + ) |
| 923 | + |
| 924 | + def get_long_running_output(response): |
| 925 | + if raw: |
| 926 | + client_raw_response = ClientRawResponse(None, response) |
| 927 | + return client_raw_response |
| 928 | + |
| 929 | + lro_delay = operation_config.get( |
| 930 | + 'long_running_operation_timeout', |
| 931 | + self.config.long_running_operation_timeout) |
| 932 | + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **operation_config) |
| 933 | + elif polling is False: polling_method = NoPolling() |
| 934 | + else: polling_method = polling |
| 935 | + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) |
| 936 | + trigger_resource_group_evaluation.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} |
| 937 | + |
784 | 938 | def list_query_results_for_policy_set_definition( |
785 | 939 | self, policy_states_resource, subscription_id, policy_set_definition_name, query_options=None, custom_headers=None, raw=False, **operation_config): |
786 | 940 | """Queries policy states for the subscription level policy set definition. |
|
0 commit comments