def run_example(): credentials = get_credentials() config = AzureConfiguration('https://management.azure.com') service_client = ServiceClient(credentials, config) query_parameters = {} query_parameters['api-version'] = API_VERSION header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) operation_config = {} request = service_client.put( "/subscriptions/" + SUBSCRIPTION_ID + "/resourceGroups/" + RESOURCE_GROUP + "/providers/Microsoft.Storage/storageAccounts/" + STORAGE_ACCOUNT_NAME + "/blobServices/" + BLOB_SERVICE_NAME + "/containers/" + CONTAINER_NAME, query_parameters) response = service_client.send(request, header_parameters, BODY, **operation_config) if response.status_code == 202: response = wait_poller(service_client, operation_config, response) print(response.text)
def test_register_failed(self, time_sleep): """Protocol: - We call the provider and get a 409 provider error - Now we POST register provider and get "Registering" - This POST failed """ provider_url = ( "https://management.azure.com/" "subscriptions/12345678-9abc-def0-0000-000000000000/" "resourceGroups/clitest.rg000001/" "providers/Microsoft.Sql/servers/ygserver123?api-version=2014-04-01" ) provider_error = ( '{"error":{"code":"MissingSubscriptionRegistration", ' '"message":"The subscription registration is in \'Unregistered\' state. ' 'The subscription must be registered to use namespace \'Microsoft.Sql\'. ' 'See https://aka.ms/rps-not-found for how to register subscriptions."}}' ) provider_success = '{"success": true}' httpretty.register_uri(httpretty.PUT, provider_url, responses=[ httpretty.Response(body=provider_error, status=409), httpretty.Response(body=provider_success), ], content_type="application/json") register_post_url = ( "https://management.azure.com/" "subscriptions/12345678-9abc-def0-0000-000000000000/" "providers/Microsoft.Sql/register?api-version=2016-02-01") httpretty.register_uri(httpretty.POST, register_post_url, status=409, content_type="application/json") configuration = AzureConfiguration(None) register_rp_hook = configuration.hooks[0] session = requests.Session() def rp_cb(r, *args, **kwargs): kwargs.setdefault("msrest", {})["session"] = session return register_rp_hook(r, *args, **kwargs) session.hooks['response'].append(rp_cb) response = session.put(provider_url) self.assertEqual(409, response.status_code)
def __init__(self, resource, msi_conf=None): self._user_agent = AzureConfiguration(None).user_agent self.identity_type, self.identity_id = None, None if msi_conf: if len(msi_conf.keys()) > 1: raise ValueError('"client_id", "object_id", "msi_res_id" are mutually exclusive') elif len(msi_conf.keys()) == 1: self.identity_type, self.identity_id = next(iter(msi_conf.items())) # default to system assigned identity on an empty configuration object self.cache = {} self.resource = resource
def run_example(): credentials = get_credentials() config = AzureConfiguration('https://management.azure.com') service_client = ServiceClient(credentials, config) query_parameters = {} query_parameters['api-version'] = API_VERSION header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' operation_config = {} request = service_client.put("/subscriptions/" + SUBSCRIPTION_ID + "/resourceGroups/" + RESOURCE_GROUP, query_parameters) response = service_client.send(request, header_parameters, BODY, **operation_config) print(response.text)
def run_example(): credentials = get_credentials() config = AzureConfiguration('https://management.azure.com') service_client = ServiceClient(credentials, config) query_parameters = {} query_parameters['api-version'] = API_VERSION header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' operation_config = {} request = service_client.put("/subscriptions/" + SUBSCRIPTION_ID + "/resourceGroups/" + RESOURCE_GROUP + "/providers/Microsoft.DataFactory/factories/" + FACTORY_NAME + "/pipelines/" + PIPELINE_NAME,query_parameters) # request = service_client.post("/subscriptions/" + SUBSCRIPTION_ID + "/resourceGroups/" + RESOURCE_GROUP + "/providers/Microsoft.DataFactory/factories/" + FACTORY_NAME + "/pipelines/" + PIPELINE_NAME + "/createRun", query_parameters) response = service_client.send(request, header_parameters, BODY, **operation_config) print(response.text)
def run_example(): credentials = get_credentials() config = AzureConfiguration('https://management.azure.com') service_client = ServiceClient(credentials, config) query_parameters = {} query_parameters['api-version'] = API_VERSION header_parameters = {} operation_config = {} request = service_client.get( "/subscriptions/" + SUBSCRIPTION_ID + "/resourceGroups/" + RESOURCE_GROUP + "/providers/Microsoft.DataFactory/factories/" + FACTORY_NAME + "/linkedservices", query_parameters) response = service_client.send(request, header_parameters, **operation_config) print(response.text)
def run_example(): credentials = get_credentials() config = AzureConfiguration('https://management.azure.com') service_client = ServiceClient(credentials, config) query_parameters = {} query_parameters['api-version'] = API_VERSION header_parameters = {} header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) operation_config = {} request = service_client.delete( "/subscriptions/" + SUBSCRIPTION_ID + "/resourceGroups/" + RESOURCE_GROUP + "/providers/Microsoft.Databricks/workspaces/" + WORKSPACE_NAME, query_parameters) response = service_client.send(request, header_parameters, BODY, **operation_config) # if response.status_code == 202: # response = wait_poller(service_client, operation_config, response) print(response.text)
def activate(self): """Parse out all command line options and get ready to process the plugin.""" Plugin.activate(self) # Load config for logging self.load_config() if not msrestazure.tools.is_valid_resource_id(self['resource']): self.parser.error('invalid resource ID') if bool(self['dimension']) != bool(self['dimension-value']): self.parser.error( '--dimension and --dimension-value must be used together') if bool(self['filter']) and bool(self['dimension']): self.parser.error('--dimension and --filter are exclusives') # Set up Azure Resource Management URL if self['host'] is None: self['host'] = self.DEFAULT_AZURE_SERVICE_HOST # Set up timeout if self['timeout'] is not None: try: self['timeout'] = float(self['timeout']) if self['timeout'] < 0: raise ValueError except ValueError as ex: self.parser.error('Invalid timeout') # Authenticate to ARM azure_management_url = 'https://{}'.format(self['host']) try: credentials = ServicePrincipalCredentials(client_id=self['client'], secret=self['secret'], tenant=self['tenant']) self._client = ServiceClient( credentials, AzureConfiguration(azure_management_url)) except ClientException as ex: self.nagios_exit(Plugins.UNKNOWN, str(ex.inner_exception or ex)) try: self._metric_definitions = self._get_metric_definitions() except CloudError as ex: self.nagios_exit(Plugins.UNKNOWN, ex.message) metric_ids = [m['name']['value'] for m in self._metric_definitions] if self['metric'] not in metric_ids: self.parser.error( 'Unknown metric {} for specified resource. ' \ 'Supported metrics are: {}'.format(self['metric'], ', '.join(metric_ids)) ) self._metric_properties = self._get_metric_properties() dimension_ids = [ d['value'] for d in self._metric_properties.get('dimensions', []) ] if self._is_dimension_required() and (self['dimension'] is None and self['filter'] is None): self.parser.error( 'Dimension of Filter required for metric {}. ' \ 'Supported dimensions/filters are: {}'.format(self['metric'], ', '.join(dimension_ids)) ) if self['dimension'] is not None and self[ 'dimension'] not in dimension_ids: self.parser.error( 'Unknown dimension {} for metric {}. ' \ 'Supported dimensions are: {}'.format(self['dimension'], self['metric'], ', '.join(dimension_ids)) ) aggregation_ids = self._metric_properties.get( 'supportedAggregationTypes', []) if self['aggregation'] is not None and self[ 'aggregation'] not in aggregation_ids: self.parser.error( 'Unsupported aggregation {} for metric {}. ' \ 'Supported aggregations are: {}'.format(self['aggregation'], self['metric'], ', '.join(aggregation_ids)) )
def test_config_basic(self): # Do not raise is already something, we don't really need strong tests here. AzureConfiguration('http://management.something.com')
API_VERSION = '2018-06-01' def get_credentials(): credentials = ServicePrincipalCredentials( client_id=os.environ.get('AZURE_CLIENT_ID'), secret=os.environ.get('AZURE_CLIENT_SECRET'), tenant=os.environ.get('AZURE_TENANT_ID') ) return credentials def run_example(): credentials = get_credentials() config = AzureConfiguration('https://management.azure.com') service_client = ServiceClient(credentials, config) query_parameters = {} query_parameters['api-version'] = API_VERSION header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' operation_config = {} # request = service_client.put("/subscriptions/" + SUBSCRIPTION_ID + "/resourceGroups/" + RESOURCE_GROUP + "/providers/Microsoft.DataFactory/factories/" + FACTORY_NAME, query_parameters) request = service_client.post("/subscriptions/"+SUBSCRIPTION_ID+"/resourceGroups/"+RESOURCE_GROUP+"/providers/Microsoft.DataFactory/factories/"+FACTORY_NAME+"/pipelines/"+PIPELINE_NAME+"/createRun" , query_parameters) #request = service_client.put("/subscriptions/"+SUBSCRIPTION_ID+"/resourceGroups/"+RESOURCE_GROUP+"/providers/Microsoft.DataFactory/factories/"+FACTORY_NAME+"/pipelines/"+PIPELINE_NAME , query_parameters) response = service_client.send(request, header_parameters, BODY, **operation_config) print(response.text)