How to use the msrestazure.tools function in msrestazure

To help you get started, we’ve selected a few msrestazure examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudmarker / cloudmarker / cloudmarker / clouds / azkv.py View on Github external
tenant = self._tenant
            creds = self._credentials
            subscription_id = sub.get('subscription_id')
            key_vault_mgmt_client = KeyVaultManagementClient(creds,
                                                             subscription_id)
            key_vault_list = key_vault_mgmt_client.vaults.list()

            for key_vault_index, key_vault in enumerate(key_vault_list):
                key_vault = key_vault.as_dict()
                key_vault_name = key_vault.get('name')
                key_vault_id = key_vault.get('id')
                _log.info('Found key_vault #%d: %s; %s',
                          key_vault_index, key_vault_name,
                          util.outline_az_sub(sub_index, sub, tenant))
                rg_name = \
                    tools.parse_resource_id(key_vault_id)['resource_group']

                yield (key_vault_index, key_vault_name,
                       rg_name, sub_index, sub)

                # Break after pulling data for self._max_recs number
                # of Key Vault for a subscriber. Note that if
                # self._max_recs is 0 or less, then the following
                # condition never evaluates to True.
                if key_vault_index + 1 == self._max_recs:
                    _log.info('Stopping Key Vault fetch due '
                              'to _max_recs: %d; %s', self._max_recs,
                              util.outline_az_sub(sub_index, sub,
                                                  self._tenant))
                    break
        except CloudError as e:
            _log.error('Failed to fetch Key Vault; %s; error: %s: %s',
github Azure / azure-batch-maya / azure_batch_maya / scripts / tools / job_watcher.py View on Github external
convert_utc_expireson_to_local_timezone_naive(batch_auth_token)

        if need_to_refresh_auth_tokens([mgmt_auth_token, batch_auth_token]):
            mgmt_auth_token, batch_auth_token = refresh_auth_tokens(mgmt_auth_token, batch_auth_token, environment_provider, aad_environment_id)

        mgmtCredentials = AADTokenCredentials(mgmt_auth_token,  
            cloud_environment= environment_provider.getEnvironmentForId(aad_environment_id),
            tenant=aadTenant)

        batchCredentials = AADTokenCredentials(batch_auth_token, 
            cloud_environment= environment_provider.getEnvironmentForId(aad_environment_id),
            tenant=aadTenant)

        storage_account_resource_id = cfg.get('AzureBatch', 'storage_account_resource_id')

        parsedStorageAccountId = msrestazuretools.parse_resource_id(storage_account_resource_id)
        storage_account = parsedStorageAccountId['name']

        storage_mgmt_client = StorageManagementClient(mgmtCredentials, subscription_id,  base_url=resource_url)

        storage_key = call(storage_mgmt_client.storage_accounts.list_keys, parsedStorageAccountId['resource_group'], storage_account).keys[0].value

        storage_client = storage.BlockBlobService(
            storage_account,
            storage_key)

        batch_client = batch.BatchExtensionsClient(batchCredentials, 
            base_url=batch_url,
            storage_client=storage_client)
        try:
            batch_client.threads = cfg.get("AzureBatch", "threads")
        except ConfigParser.NoOptionError:
github Azure / azure-batch-maya / azure_batch_maya / scripts / config.py View on Github external
def init_from_config(self):
        parsedStorageAccountId = msrestazuretools.parse_resource_id(self.storage_account_resource_id)
        self.storage_account = parsedStorageAccountId['name']

        self.storage_mgmt_client = StorageManagementClient(self.mgmtCredentials, str(self.subscription_id),
            base_url=self.aad_environment_provider.getResourceManager(self.aad_environment_id))

        self.storage_key = self._call(self.storage_mgmt_client.storage_accounts.list_keys, parsedStorageAccountId['resource_group'], self.storage_account).keys[0].value
        
        self._storage = storage.BlockBlobService(
            self.storage_account,
            self.storage_key)
        self._storage.MAX_SINGLE_PUT_SIZE = 2 * 1024 * 1024

        #TODO refactor move the below shared block into def configureClient(client)
        self._client = batch.BatchExtensionsClient(self.batchCredentials, 
            base_url=self.batch_url,
            storage_client=self._storage)
github cloudmarker / cloudmarker / cloudmarker / clouds / azwebapp.py View on Github external
sub_index (int): Subscription index (for logging only).
            sub (Subscription): Azure subscription object.

        Yields:
            dict: An Azure web app record with config details.

        """
        app_name = app.get('name')
        _log.info('Working on web app #%d: %s; %s', app_index, app_name,
                  util.outline_az_sub(sub_index, sub, self._tenant))
        try:
            creds = self._credentials
            sub_id = sub.get('subscription_id')
            web_client = WebSiteManagementClient(creds, sub_id)
            app_id = app.get('id')
            rg_name = tools.parse_resource_id(app_id)['resource_group']
            app_config = web_client.web_apps.get_configuration(rg_name,
                                                               app_name)
            app_config = app_config.as_dict()
            yield _process_app_config(app_index, app, app_config,
                                      sub_index, sub, self._tenant)
        except Exception as e:
            _log.error('Failed to fetch app_config for web app #%d: '
                       '%s; %s; error: %s: %s', app_index, app_name,
                       util.outline_az_sub(sub_index, sub, self._tenant),
                       type(e).__name__, e)
github cloudmarker / cloudmarker / cloudmarker / clouds / azvm.py View on Github external
sub_index (int): Subscription index (for logging only).
            sub (Subscription): Azure subscription object.

        Yields:
            dict: An Azure virtual machine record with instance view details.

        """
        vm_name = vm.get('name')
        _log.info('Working on VM #%d: %s; %s', vm_index, vm_name,
                  util.outline_az_sub(sub_index, sub, self._tenant))
        try:
            creds = self._credentials
            sub_id = sub.get('subscription_id')
            compute_client = ComputeManagementClient(creds, sub_id)
            vm_id = vm.get('id')
            rg_name = tools.parse_resource_id(vm_id)['resource_group']
            vm_iv = compute_client.virtual_machines.instance_view(rg_name,
                                                                  vm_name)
            vm_iv = vm_iv.as_dict()
            yield _process_vm_instance_view(vm_index, vm, vm_iv,
                                            sub_index, sub, self._tenant)
        except Exception as e:
            _log.error('Failed to fetch vm_instance_view for VM #%d: '
                       '%s; %s; error: %s: %s', vm_index, vm_name,
                       util.outline_az_sub(sub_index, sub, self._tenant),
                       type(e).__name__, e)
github cloudmarker / cloudmarker / cloudmarker / clouds / azstorageaccount.py View on Github external
Yields:
            dict: An Azure storage account record with property details.

        """
        act_name = storage_account.get('name')
        _log.info('Working on storage account #%d: %s; %s',
                  storage_account_index,
                  act_name,
                  util.outline_az_sub(sub_index, sub, self._tenant))
        try:
            creds = self._credentials
            sub_id = sub.get('subscription_id')
            client = StorageManagementClient(creds, sub_id)
            account_id = storage_account.get('id')
            rg_name = tools.parse_resource_id(account_id)['resource_group']

            properties = client.storage_accounts.get_properties(rg_name,
                                                                act_name)
            properties = properties.as_dict()
            yield _process_storage_account_properties(storage_account_index,
                                                      storage_account,
                                                      properties,
                                                      sub_index,
                                                      sub,
                                                      self._tenant)
        except Exception as e:
            _log.error('Failed to fetch properties for storage accounts'
                       '#%d:%s; %s; error: %s: %s', storage_account_index,
                       act_name,
                       util.outline_az_sub(sub_index, sub, self._tenant),
                       type(e).__name__, e)
github cloudmarker / cloudmarker / cloudmarker / clouds / azsql.py View on Github external
try:
            tenant = self._tenant
            creds = self._credentials
            sub_id = sub.get('subscription_id')
            sql_client = SqlManagementClient(creds, sub_id)
            db_server_list = sql_client.servers.list()

            for server_index, sql_server in enumerate(db_server_list):
                sql_server = sql_server.as_dict()
                server_id = sql_server.get('id')
                server_name = sql_server.get('name')
                _log.info('Found SQL Server #%d: %s; %s',
                          server_index, server_name,
                          util.outline_az_sub(sub_index, sub, tenant))
                rg_name = \
                    tools.parse_resource_id(server_id)['resource_group']
                yield (server_index, server_name, rg_name, sub_index, sub)

                # Break after pulling data for self._max_recs number
                # of SQL servers for a subscriber. Note that if
                # self._max_recs is 0 or less, then the following
                # condition never evaluates to True.
                if server_index + 1 == self._max_recs:
                    _log.info('Stopping SQL server fetch due '
                              'to _max_recs: %d; %s', self._max_recs,
                              util.outline_az_sub(sub_index, sub,
                                                  self._tenant))
                    break
        except Exception as e:
            _log.error('Failed to fetch SQL servers; %s; error: %s: %s',
                       util.outline_az_sub(sub_index, sub, tenant),
                       type(e).__name__, e)