python - How to verify that you have enough resources at Azure -
background
if seems question incomplete information, is. that's because has large project uses azure automatically provision , scale , downscale large amount of vms, handed on third party, , we're having trouble understanding issues. i'll try best explain
we using python's azure sdk launch azure vms, kill them etc. see code used in method launches azure vms:
#get vms info. via minimum calls speed things started_on = time.time() while true: try: time.sleep(5) vm = compute_client.virtual_machines.get(self.resource_group, vm_name) break
problem
sometimes when run command, error:
aioc.logic.connectors.azure:2017-08-17 08:39:45,709 | error | stop waiting vm auto-acfinh-25 finish traceback (most recent call last): file "/home/aioc/aioc/aioc/logic/connectors/azure.py", line 126, in start vm = compute_client.virtual_machines.get(self.resource_group, vm_name) file "/home/aioc/venv/lib/python3.4/site-packages/azure/mgmt/compute/compute/v2016_04_30_preview/operations/virtual_machines_operations.py", line 369, in raise exp msrestazure.azure_exceptions.clouderror: azure error: resourcenotfound message: resource 'microsoft.compute/virtualmachines/auto-acfinh-25' under resource group 'aiocbot' not found. aioc.logic.main_controller_logic:2017-08-17 08:39:45,978 | error | error occurred while checking vm id '599553cdc1462e3a828c66da' machine id '328' traceback (most recent call last): file "/home/aioc/aioc/aioc/logic/main_controller_logic.py", line 41, in run_vm_controller started_vms = vmc.start(vm.machine_type, 1) file "/home/aioc/aioc/aioc/logic/connectors/azure.py", line 135, in start vm_net_interface = network_client.network_interfaces.get(self.resource_group, vm_name) file "/home/aioc/venv/lib/python3.4/site-packages/azure/mgmt/network/v2017_03_01/operations/network_interfaces_operations.py", line 171, in raise exp msrestazure.azure_exceptions.clouderror: azure error: resourcenotfound
upon investigation, turns out happening b/c our resources @ azure have maxed out (?). way solve problem purging said resources using method:
def cleanup_all(self): """ clean auto-created resources """ compute_client = computemanagementclient(self.credentials, self.subscription_id) network_client = networkmanagementclient(self.credentials, self.subscription_id) resource_client = resourcemanagementclient(self.credentials, self.subscription_id) l = resource_client.resources.list() r in [r r in l if r.name.startswith('auto-')]: try: if 'publicipaddresses' in r.type: rs = network_client.public_ip_addresses.delete(self.resource_group, r.name) rs.wait() elif 'microsoft.network' in r.type: rs = network_client.network_interfaces.delete(self.resource_group, r.name) rs.wait() elif 'microsoft.compute/virtualmachines' in r.type: rs = compute_client.virtual_machines.delete(self.resource_group, r.name) rs.wait() except: log.warn("failed stop resource: %s type: %s", r.name, r.type, exc_info=1)
which awesome. however, business reasons cannot - create cron job runs commands on regular interval - cannot run in automated fashion b/c affects many different environments @ once (ie prod/demo/stage/dev) big side affect fathomable.
which means must run command periodically, every once in while once have agreement envs clear , ready.
question
i take @ resources section inside azure console
and have a way find out how of allowed resources have consumed. need have idea example that: oh way have consumed 45% percent of allowed public ips etc, , way know if i'm safe or if need run purge command again.
ideas?
update
this page discussees in detail available limits, example:
but doesn't talk how gauge how of these resources in use or how left.. that's i'm trying find out
can explain what's going on?
part answer question. manual, can find information on azure portal itself. click on "subscription", select subscription subscriptions list , "usage + quota".
Comments
Post a Comment