Skip to content

Instantly share code, notes, and snippets.

View lmazuel's full-sized avatar

Laurent Mazuel lmazuel

View GitHub Profile
@lmazuel
lmazuel / check_profile_to_providers.py
Last active August 16, 2018 22:12
Profile checkers
import json
import sys
def find_rp(provider_name, providers):
for entry in providers:
if entry["namespace"].lower() == provider_name.lower():
return entry
def find_resource_type(provider_object, resource_type_name):
from enum import Enum
import importlib
import inspect
import logging
from pathlib import Path
import pkgutil
import shutil
import sys
import tempfile
import asyncio
import time
from azure.mgmt.compute.v2017_12_01 import ComputeManagementClient
from devtools_testutils.mgmt_settings_real import SUBSCRIPTION_ID, get_credentials
async def test_vm_images_async(client):
result = []
result_list = []
import asyncio
import pytest
@pytest.mark.asyncio
async def test():
iterator = iter([])
return await asyncio.get_event_loop().run_in_executor(
None,
next,
iterator
@lmazuel
lmazuel / __init__.py
Last active February 22, 2018 20:28
Py3 / Py2 compat test
try:
from virtual_machine_py3 import VirtualMachine
except (SyntaxError, ImportError): # Catch SyntaxError if Py2 or ImportError if we decide to build wheel for Py2 without py3 files.
from virtual_machine import VirtualMachine
@lmazuel
lmazuel / package.py
Last active August 1, 2018 18:31
Readme helper super stupid and simple (own usage only, no can find this interesting...)
import os.path
import re
from pathlib import Path
from packaging.version import parse as Version, InvalidVersion
root = Path()
package_list = [p.as_posix() for p in root.iterdir()]
filtered_package_list = [p for p in package_list if p.startswith("azure-mgmt-") and not p.endswith("nspkg")]
def extract_version(package_name):
@lmazuel
lmazuel / req_log.py
Last active February 8, 2018 21:10
Requests debug logging
import logging
import requests
# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
try:
import http.client as http_client
except ImportError:
# Python 2
@lmazuel
lmazuel / lro_usage.py
Last active December 29, 2017 00:57
LRO sandbox
# This starts a poller, and you can call "result" on the poller to get the resource
poller = client.storage_accounts.create(parameters)
assert isinstance(poller, AzureOperationPoller)
account = poller.result()
assert isinstance(account, StorageAccount)
# This starts a poller, and you can call "result" on the poller to get the ClientRawResponse
# THIS IS A BREAKING CHANGE, but diferentiate the resource envelope (raw or not) from the polling
# This makes the return type consistent: whatever the value of "raw", return type is an AzureOperationPoller
poller = client.storage_accounts.create(parameters, raw=True)
@lmazuel
lmazuel / storage_async.py
Last active December 22, 2017 01:54
Async sandbox
async def mymethod():
account_name = self.get_resource_name('pyarmstorage18')
# Normal call, async is just HTTP I/O
result_check = await self.storage_client.storage_accounts.check_name_availability(
account_name
)
self.assertTrue(result_check.name_available)
params_create = models.StorageAccountCreateParameters(
class AsyncMixin:
async def async_get(self, url):
return "Async download: "+url