def test_compute(self): # create VM vm_size = 'Standard_D1' publisher = 'Canonical' offer = 'UbuntuServer' sku = '16.04.0-LTS' version = 'latest' os_uri = 'http://' + self.saname + '.blob.core.windows.net/vhds/osdisk.vhd' username = '******' password = Haikunator.haikunate(delimiter=',') print('Creating VM: ' + self.vmname) response = azurerm.create_vm(self.access_token, self.subscription_id, self.rgname, \ self.vmname, vm_size, publisher, offer, sku, version, self.saname, os_uri, \ self.nic_id, self.location, username=username, public_key=self.public_key) # print(json.dumps(response.json())) self.assertEqual(response.status_code, 201) self.assertEqual(response.json()['name'], self.vmname) # create VMSS capacity = 3 print('Creating VMSS: ' + self.vmssname + ', capacity = ' + str(capacity)) response = azurerm.create_vmss(self.access_token, self.subscription_id, self.rgname, \ self.vmssname, vm_size, capacity, publisher, offer, sku, version, self.container_list, \ self.subnet_id, self.be_pool_id, self.lb_pool_id, self.location, username=username, \ public_key=self.public_key) # print(json.dumps(response.json())) self.assertEqual(response.status_code, 201) self.assertEqual(response.json()['name'], self.vmssname) # get compute usage print('Getting compute usage') response = azurerm.get_compute_usage(self.access_token, self.subscription_id, self.location) self.assertTrue(len(response['value']) > 0) # get vm instance view print('Getting VM instance view') response = azurerm.get_vm_instance_view(self.access_token, self.subscription_id, \ self.rgname, self.vmname) # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': '))) self.assertEqual(response['statuses'][0]['displayStatus'], 'Creating') # list vm instance views print('Listing VM instance views') response = azurerm.list_vm_instance_view(self.access_token, self.subscription_id, \ self.rgname) # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': '))) self.assertTrue(len(response['value']) > 0) # delete VM print('Deleting VM: ' + self.vmname) response = azurerm.delete_vm(self.access_token, self.subscription_id, self.rgname, \ self.vmname) self.assertEqual(response.status_code, 202) # delete VMSS print('Deleting VMSS: ' + self.vmssname) response = azurerm.delete_vmss(self.access_token, self.subscription_id, self.rgname, \ self.vmssname) self.assertEqual(response.status_code, 202)
def print_region_quota(region): print(region) quota = azurerm.get_compute_usage(access_token, subscription_id, region) print(json.dumps(quota, sort_keys=False, indent=2, separators=(',', ': '))) for resource in quota['value']: if resource['name']['value'] == 'cores': print('Current: ' + str(resource['currentValue']) + ', limit: ' + str(resource['limit'])) break
def print_region_quota(region): print(region + ':') quota = azurerm.get_compute_usage(access_token, subscription_id, region) if Summary == False: print( json.dumps(quota, sort_keys=False, indent=2, separators=(',', ': '))) try: for resource in quota['value']: if resource['name']['value'] == 'cores': print(' Current: ' + str(resource['currentValue']) + ', limit: ' + str(resource['limit'])) break except KeyError: print('Invalid data for region: ' + region)
def test_compute(self): # create VM vm_size = 'Standard_D1' publisher = 'Canonical' offer = 'UbuntuServer' sku = '16.04.0-LTS' version = 'latest' os_uri = 'http://' + self.saname + '.blob.core.windows.net/vhds/osdisk.vhd' username = '******' password = Haikunator.haikunate(delimiter=',') print('Creating VM: ' + self.vmname) response = azurerm.create_vm(self.access_token, self.subscription_id, self.rgname, \ self.vmname, vm_size, publisher, offer, sku, version, self.saname, os_uri, \ username, password, self.nic_id, self.location) self.assertEqual(response.status_code, 201) self.assertEqual(response.json()['name'], self.vmname) # create VMSS capacity = 3 print('Creating VMSS: ' + self.vmssname + ', capacity = ' + str(capacity)) response = azurerm.create_vmss(self.access_token, self.subscription_id, self.rgname, \ self.vmssname, vm_size, capacity, publisher, offer, sku, version, self.container_list, \ username, password, self.subnet_id, self.be_pool_id, self.lb_pool_id, self.location) self.assertEqual(response.status_code, 201) self.assertEqual(response.json()['name'], self.vmssname) # get compute usage print('Getting compute usage') response = azurerm.get_compute_usage(self.access_token, self.subscription_id, self.location) self.assertTrue(len(response['value']) > 0) # delete VM print('Deleting VM: ' + self.vmname) response = azurerm.delete_vm(self.access_token, self.subscription_id, self.rgname, \ self.vmname) self.assertEqual(response.status_code, 202) # delete VMSS print('Deleting VMSS: ' + self.vmssname) response = azurerm.delete_vmss(self.access_token, self.subscription_id, self.rgname, \ self.vmssname) self.assertEqual(response.status_code, 202)
def test_compute(self): # create availability set print('Creating availability set: ' + self.asname + ', update domains = 5, fault domains = 3') response = azurerm.create_as(self.access_token, self.subscription_id, self.rgname, self.asname, 5, 3, self.location) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()['name'], self.asname) # create VM vm_size = 'Standard_B1s' publisher = 'Canonical' offer = 'UbuntuServer' sku = '18.04-LTS' version = 'latest' username = '******' print('Creating VM: ' + self.vmname) response = azurerm.create_vm(self.access_token, self.subscription_id, self.rgname, \ self.vmname, vm_size, publisher, offer, sku, version, \ self.nic_id, self.location, username=username, public_key=self.public_key) # print(json.dumps(response.json())) self.assertEqual(response.status_code, 201) self.assertEqual(response.json()['name'], self.vmname) # create VMSS capacity = 3 print('Creating VMSS: ' + self.vmssname + ', capacity = ' + str(capacity)) response = azurerm.create_vmss(self.access_token, self.subscription_id, self.rgname, \ self.vmssname, vm_size, capacity, publisher, offer, sku, version, \ self.subnet_id, self.location, self.be_pool_id, self.lb_pool_id, username=username, \ public_key=self.public_key) # print(json.dumps(response.json())) self.assertEqual(response.status_code, 201) self.assertEqual(response.json()['name'], self.vmssname) # get compute usage print('Getting compute usage') response = azurerm.get_compute_usage(self.access_token, self.subscription_id, self.location) self.assertTrue(len(response['value']) > 0) # get vm instance view print('Getting VM instance view') response = azurerm.get_vm_instance_view(self.access_token, self.subscription_id, \ self.rgname, self.vmname) # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': '))) self.assertEqual(response['statuses'][0]['displayStatus'], 'Creating') # get availability set details print('Getting availability set details') response = azurerm.get_as(self.access_token, self.subscription_id, self.rgname, self.asname) self.assertEqual(response['name'], self.asname) # list VMSS skus print('Listing VMSS skus') response = azurerm.list_vmss_skus(self.access_token, self.subscription_id, \ self.rgname, self.vmssname) # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': '))) self.assertTrue(len(response['value']) > 0) # list VMSS nics print('Getting VMSS NICs') response = azurerm.get_vmss_nics(self.access_token, self.subscription_id, \ self.rgname, self.vmssname) # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': '))) self.assertTrue(len(response['value']) > 0) # delete VM print('Deleting VM: ' + self.vmname) response = azurerm.delete_vm(self.access_token, self.subscription_id, self.rgname, \ self.vmname) self.assertEqual(response.status_code, 202) # delete VMSS print('Deleting VMSS: ' + self.vmssname) response = azurerm.delete_vmss(self.access_token, self.subscription_id, self.rgname, \ self.vmssname) self.assertEqual(response.status_code, 202) # delete Availability Set print('Deleting Availability Set: ' + self.asname) response = azurerm.delete_as(self.access_token, self.subscription_id, self.rgname, \ self.asname) self.assertEqual(response.status_code, 200)
def test_compute(self): # create availability set print('Creating availability set: ' + self.asname + ', update domains = 5, fault domains = 3') response = azurerm.create_as(self.access_token, self.subscription_id, self.rgname, self.asname, 5, 3, self.location) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()['name'], self.asname) # create VM vm_size = 'Standard_D1' publisher = 'Canonical' offer = 'UbuntuServer' sku = '16.04-LTS' version = 'latest' username = '******' password = self.h.haikunate(',') print('Creating VM: ' + self.vmname) response = azurerm.create_vm(self.access_token, self.subscription_id, self.rgname, \ self.vmname, vm_size, publisher, offer, sku, version, \ self.nic_id, self.location, username=username, public_key=self.public_key) # print(json.dumps(response.json())) self.assertEqual(response.status_code, 201) self.assertEqual(response.json()['name'], self.vmname) # create VMSS capacity = 3 print('Creating VMSS: ' + self.vmssname + ', capacity = ' + str(capacity)) response = azurerm.create_vmss(self.access_token, self.subscription_id, self.rgname, \ self.vmssname, vm_size, capacity, publisher, offer, sku, version, \ self.subnet_id, self.be_pool_id, self.lb_pool_id, self.location, username=username, \ public_key=self.public_key) # print(json.dumps(response.json())) self.assertEqual(response.status_code, 201) self.assertEqual(response.json()['name'], self.vmssname) # get compute usage print('Getting compute usage') response = azurerm.get_compute_usage(self.access_token, self.subscription_id, self.location) self.assertTrue(len(response['value']) > 0) # get vm instance view print('Getting VM instance view') response = azurerm.get_vm_instance_view(self.access_token, self.subscription_id, \ self.rgname, self.vmname) # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': '))) self.assertEqual(response['statuses'][0]['displayStatus'], 'Creating') # get availability set details print('Getting availability set details') response = azurerm.get_as(self.access_token, self.subscription_id, self.rgname, self.asname) self.assertEqual(response['name'], self.asname) # list vm instance views print('Listing VM instance views') response = azurerm.list_vm_instance_view(self.access_token, self.subscription_id, \ self.rgname) # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': '))) self.assertTrue(len(response['value']) > 0) # list VMSS skus print('Listing VMSS skus') response = azurerm.list_vmss_skus(self.access_token, self.subscription_id, \ self.rgname, self.vmssname) # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': '))) self.assertTrue(len(response['value']) > 0) # list VMSS nics print('Getting VMSS NICs') response = azurerm.get_vmss_nics(self.access_token, self.subscription_id, \ self.rgname, self.vmssname) #print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': '))) self.assertTrue(len(response['value']) > 0) # delete VM print('Deleting VM: ' + self.vmname) response = azurerm.delete_vm(self.access_token, self.subscription_id, self.rgname, \ self.vmname) self.assertEqual(response.status_code, 202) # delete VMSS print('Deleting VMSS: ' + self.vmssname) response = azurerm.delete_vmss(self.access_token, self.subscription_id, self.rgname, \ self.vmssname) self.assertEqual(response.status_code, 202) # delete Availability Set print('Deleting Availability Set: ' + self.asname) response = azurerm.delete_as(self.access_token, self.subscription_id, self.rgname, \ self.asname) self.assertEqual(response.status_code, 200)
def get_vmss_properties(access_token, run_event, window_information, panel_information, window_continents, panel_continents): global vmssProperties, vmssVmProperties, countery, capacity, region, tier, vmsku, vm_selected, window_vm, panel_vm, instances_deployed, vm_details, vm_nic, page; ROOM = 5; DEPLOYED = 0; #VM's destination... destx = 22; desty = 4; XS =50; YS = 4; init_coords = (XS, YS); window_dc = 0; #Our window_information arrays... panel_vm = []; window_vm = []; #Our thread loop... while run_event.is_set(): try: #Timestamp... ourtime = time.strftime("%H:%M:%S"); write_str(window_information['status'], 1, 13, ourtime); #Clean Forms... clean_forms(window_information); #Get VMSS details vmssget = azurerm.get_vmss(access_token, subscription_id, rgname, vmssname); # Get public ip address for RG (First IP) - modify this if your RG has multiple ips net = azurerm.list_public_ips(access_token, subscription_id, rgname); #Clean Info and Sys Windows... clean_infoandsys(window_information); #Fill the information... fill_vmss_info(window_information, vmssget, net); #Set VMSS variables... (name, capacity, location, offer, sku, provisioningState, dns, ipaddr) = set_vmss_variables(vmssget, net); #Set the current and old location... old_location = region; if (old_location != ""): continent_old_location = get_continent_dc(old_location); #New region = location; continent_location = get_continent_dc(location); #Quota... quota = azurerm.get_compute_usage(access_token, subscription_id, location); fill_quota_info(window_information, quota); #Mark Datacenter where VMSS is deployed... if (old_location != ""): if (old_location != location): #Now switch the datacenter mark on map... new_window_dc = mark_vmss_dc(continent_old_location, window_continents[continent_old_location], old_location, window_continents[continent_location], location, window_dc); window_dc = new_window_dc; else: new_window_dc = mark_vmss_dc(continent_location, window_continents[continent_location], location, window_continents[continent_location], location, window_dc); window_dc = new_window_dc; #Our arrays... vmssProperties = [name, capacity, location, rgname, offer, sku, provisioningState, dns, ipaddr]; vmssvms = azurerm.list_vmss_vms(access_token, subscription_id, rgname, vmssname); vmssVmProperties = []; #All VMs are created in the following coordinates... qtd = vmssvms['value'].__len__(); factor = (vmssvms['value'].__len__() / 100); write_str(window_information['system'], 3, 22, qtd); step = qtd / 10; if (step < 1): step = 1; #We take more time on our VM effect depending on how many VMs we are talking about... if (qtd < 10): ts = 0.01; elif (qtd < 25): ts = 0.005; elif (qtd < 50): ts = 0.002; elif (qtd < 100): ts = 0.0005; else: ts = 0; counter = 1; counter_page = 0; nr_pages = 1; snap_page = page; page_top = (snap_page * 100); page_base = ((snap_page - 1) * 100); if (vm_selected[1] == 999998): #Clean VM Info... clean_vm(window_information); #Loop each VM... for vm in vmssvms['value']: instanceId = vm['instanceId']; write_str(window_information['monitor'], 1, 30, instanceId); wrefresh(window_information['monitor']); vmsel = 0; vmName = vm['name']; provisioningState = vm['properties']['provisioningState']; vmssVmProperties.append([instanceId, vmName, provisioningState]); if (counter > DEPLOYED): window_vm.append(DEPLOYED); panel_vm.append(DEPLOYED); instances_deployed.append(DEPLOYED); instances_deployed[DEPLOYED] = int(instanceId); #Prepare the place for the VM icon... if countery < 10: countery += 1; else: destx += 3; desty = 4; countery = 1; if (counter_page > 99): destx = 22; counter_page = 0; nr_pages += 1; cur_page = "%02d" % snap_page; tot_pages = "%02d" % nr_pages; update_vm_footer(window_information, cur_page, tot_pages); else: counter_page += 1; window_vm[DEPLOYED] = create_window(3, 5, init_coords[0], init_coords[1]); panel_vm[DEPLOYED] = new_panel(window_vm[DEPLOYED]); #Show only VM's that are on the visible window... if (page_top > DEPLOYED and DEPLOYED >= page_base): show_panel(panel_vm[DEPLOYED]); else: hide_panel(panel_vm[DEPLOYED]); box(window_vm[DEPLOYED]); #Creation of the VM icon, in this flow we never have a VM selected... draw_vm(int(instanceId), window_vm[DEPLOYED], provisioningState, vmsel); vm_animation(panel_vm[DEPLOYED], init_coords, destx, desty, 1, ts); desty += ROOM; DEPLOYED += 1; else: instances_deployed[counter - 1] = int(instanceId); #Remove the old mark... vmsel = deselect_vm(window_vm, panel_information, instanceId, counter); #Show only VM's that are on the visible window... if (page_top > (counter - 1) and (counter - 1) >= page_base): show_panel(panel_vm[counter -1]); else: hide_panel(panel_vm[counter -1]); #Creation of the VM icon... draw_vm(int(instanceId), window_vm[counter - 1], provisioningState, vmsel); #If a VM is selected, fill the details... if (vm_selected[0] == int(instanceId) and vm_selected[1] != 999998): vm_details = azurerm.get_vmss_vm_instance_view(access_token, subscription_id, rgname, vmssname, vm_selected[0]); vm_nic = azurerm.get_vmss_vm_nics(access_token, subscription_id, rgname, vmssname, vm_selected[0]); clean_vm(window_information); if (vm_details != "" and vm_nic != ""): fill_vm_details(window_information, instanceId, vmName, provisioningState); update_panels(); doupdate(); counter += 1; do_update_bar(window_information['status'], step, 0); step += step; #Last mile... write_str(window_information['monitor'], 1, 30, "Done."); do_update_bar(window_information['status'], step, 1); #Remove destroyed VMs... counter_page = 0; if (DEPLOYED >= counter): time.sleep(0.5); write_str_color(window_information['monitor'], 1, 30, "Removing VM's...", 7, 0); wrefresh(window_information['monitor']); time.sleep(1); clean_monitor_form(window_information); while (DEPLOYED >= counter): write_str(window_information['monitor'], 1, 30, DEPLOYED); lastvm = window_vm.__len__() - 1; vm_coords = getbegyx(window_vm[lastvm]); vm_animation(panel_vm[lastvm], vm_coords, init_coords[0], init_coords[1], 0, ts); if (countery > 0): desty -= ROOM; countery -= 1; elif (destx > 22): destx -= 3; desty = 49; countery = 9; if (counter_page > 99): destx = 52; counter_page = 0; nr_pages -= 1; tot_pages = "%02d" % nr_pages; cur_page = "%02d" % page; update_vm_footer(window_information, cur_page, tot_pages); else: counter_page += 1; #Clean VM Info... if (vm_selected[0] == instances_deployed[lastvm]): clean_vm(window_information); #Free up some memory... del_panel(panel_vm[lastvm]); delwin(window_vm[lastvm]); wobj = panel_vm[lastvm]; panel_vm.remove(wobj); wobj = window_vm[lastvm]; window_vm.remove(wobj); wobj = instances_deployed[lastvm]; instances_deployed.remove(wobj); DEPLOYED -= 1; update_panels(); doupdate(); write_str(window_information['monitor'], 1, 30, "Done."); ourtime = time.strftime("%H:%M:%S"); do_update_bar(window_information['status'], step, 1); write_str(window_information['status'], 1, 13, ourtime); write_str_color(window_information['status'], 1, 22, " OK ", 6, 0); update_panels(); doupdate(); # sleep before each loop to avoid throttling... time.sleep(interval); except: logging.exception("Getting VMSS Information...") write_str(window_information['error'], 1, 24, "Let's sleep for 30 seconds and try to refresh the dashboard again..."); show_panel(panel_information['error']); update_panels(); doupdate(); ## break out of loop when an error is encountered #break time.sleep(30); hide_panel(panel_information['error']);
try: with open('azurermconfig.json') as configFile: configData = json.load(configFile) except FileNotFoundError: print("Error: Expecting vmssConfig.json in current folder") sys.exit() tenant_id = configData['tenantId'] app_id = configData['appId'] app_secret = configData['appSecret'] subscription_id = configData['subscriptionId'] access_token = azurerm.get_access_token(tenant_id, app_id, app_secret) # list locations locations = azurerm.list_locations(access_token, subscription_id) # print quota for location in locations['value']: locationStr = location['name'] print(locationStr) quota = azurerm.get_compute_usage(access_token, subscription_id, locationStr) # if locationStr == 'westus' or locationStr == 'southindia' or locationStr == 'centralindia' or locationStr == 'westindia': if locationStr != 'southeastasia': continue print(json.dumps(quota, sort_keys=False, indent=2, separators=(',', ': '))) for resource in quota['value']: if resource['name']['value'] == 'cores': print('Current: ' + str(resource['currentValue']) + ', limit: ' + str(resource['limit'])) break
configData = json.load(configFile) except FileNotFoundError: print("Error: Expecting vmssConfig.json in current folder") sys.exit() tenant_id = configData['tenantId'] app_id = configData['appId'] app_secret = configData['appSecret'] subscription_id = configData['subscriptionId'] access_token = azurerm.get_access_token(tenant_id, app_id, app_secret) # list locations locations = azurerm.list_locations(access_token, subscription_id) # print quota for location in locations['value']: locationStr = location['name'] print(locationStr) quota = azurerm.get_compute_usage(access_token, subscription_id, locationStr) # if locationStr == 'westus' or locationStr == 'southindia' or locationStr == 'centralindia' or locationStr == 'westindia': if locationStr != 'southeastasia': continue print(json.dumps(quota, sort_keys=False, indent=2, separators=(',', ': '))) for resource in quota['value']: if resource['name']['value'] == 'cores': print('Current: ' + str(resource['currentValue']) + ', limit: ' + str(resource['limit'])) break
def get_vmss_properties(access_token, run_event, window_information, panel_information, window_continents, panel_continents): global vmssProperties, vmssVmProperties, countery, capacity, region, tier, vmsku, vm_selected, window_vm, panel_vm, instances_deployed, vm_details, vm_nic, page; ROOM = 5; DEPLOYED = 0; #VM's destination... destx = 22; desty = 4; XS =50; YS = 4; init_coords = (XS, YS); window_dc = 0; #Our window_information arrays... panel_vm = []; window_vm = []; #Our thread loop... while run_event.is_set(): try: #Timestamp... ourtime = time.strftime("%H:%M:%S"); write_str(window_information['status'], 1, 13, ourtime); #Clean Forms... clean_forms(window_information); #Get VMSS details vmssget = azurerm.get_vmss(access_token, subscription_id, rgname, vmssname); # Get public ip address for RG (First IP) - modify this if your RG has multiple ips net = azurerm.list_public_ips(access_token, subscription_id, rgname); #Clean Info and Sys Windows... clean_infoandsys(window_information); #Fill the information... fill_vmss_info(window_information, vmssget, net); #Set VMSS variables... (name, capacity, location, offer, sku, provisioningState, dns, ipaddr) = set_vmss_variables(vmssget, net); #Set the current and old location... old_location = region; if (old_location != ""): continent_old_location = get_continent_dc(old_location); #New region = location; continent_location = get_continent_dc(location); #Quota... quota = azurerm.get_compute_usage(access_token, subscription_id, location); fill_quota_info(window_information, quota); #Mark Datacenter where VMSS is deployed... if (old_location != ""): if (old_location != location): #Now switch the datacenter mark on map... new_window_dc = mark_vmss_dc(continent_old_location, window_continents[continent_old_location], old_location, window_continents[continent_location], location, window_dc); window_dc = new_window_dc; else: new_window_dc = mark_vmss_dc(continent_location, window_continents[continent_location], location, window_continents[continent_location], location, window_dc); window_dc = new_window_dc; #Our arrays... vmssProperties = [name, capacity, location, rgname, offer, sku, provisioningState, dns, ipaddr]; vmssvms = azurerm.list_vmss_vms(access_token, subscription_id, rgname, vmssname); vmssVmProperties = []; #All VMs are created in the following coordinates... qtd = vmssvms['value'].__len__(); factor = (vmssvms['value'].__len__() / 100); write_str(window_information['system'], 3, 22, qtd); step = qtd / 10; if (step < 1): step = 1; #We take more time on our VM effects depending on how many VMs we are talking about... if (qtd < 10): ts = 0.01; elif (qtd < 25): ts = 0.004; elif (qtd < 50): ts = 0.0008; elif (qtd < 100): ts = 0.0004; else: ts = 0; counter = 1; counter_page = 0; nr_pages = 1; snap_page = page; page_top = (snap_page * 100); page_base = ((snap_page - 1) * 100); if (vm_selected[1] == 999998): #Clean VM Info... clean_vm(window_information); #Loop each VM... for vm in vmssvms['value']: instanceId = vm['instanceId']; write_str(window_information['monitor'], 1, 30, instanceId); wrefresh(window_information['monitor']); vmsel = 0; vmName = vm['name']; provisioningState = vm['properties']['provisioningState']; vmssVmProperties.append([instanceId, vmName, provisioningState]); if (counter > DEPLOYED): window_vm.append(DEPLOYED); panel_vm.append(DEPLOYED); instances_deployed.append(DEPLOYED); instances_deployed[DEPLOYED] = int(instanceId); #Prepare the place for the VM icon... if countery < 10: countery += 1; else: destx += 3; desty = 4; countery = 1; if (counter_page > 99): destx = 22; counter_page = 0; nr_pages += 1; cur_page = "%02d" % snap_page; tot_pages = "%02d" % nr_pages; update_vm_footer(window_information, cur_page, tot_pages); else: counter_page += 1; window_vm[DEPLOYED] = create_window(3, 5, init_coords[0], init_coords[1]); panel_vm[DEPLOYED] = new_panel(window_vm[DEPLOYED]); #Show only VM's that are on the visible window... if (page_top > DEPLOYED and DEPLOYED >= page_base): show_panel(panel_vm[DEPLOYED]); else: hide_panel(panel_vm[DEPLOYED]); box(window_vm[DEPLOYED]); #Creation of the VM icon, in this flow we never have a VM selected... draw_vm(int(instanceId), window_vm[DEPLOYED], provisioningState, vmsel); vm_animation(panel_vm[DEPLOYED], init_coords, destx, desty, 1, ts); desty += ROOM; DEPLOYED += 1; else: instances_deployed[counter - 1] = int(instanceId); #Remove the old mark... vmsel = deselect_vm(window_vm, panel_information, instanceId, counter); #Show only VM's that are on the visible window... if (page_top > (counter - 1) and (counter - 1) >= page_base): show_panel(panel_vm[counter -1]); else: hide_panel(panel_vm[counter -1]); #Creation of the VM icon... draw_vm(int(instanceId), window_vm[counter - 1], provisioningState, vmsel); #If a VM is selected, fill the details... if (vm_selected[0] == int(instanceId) and vm_selected[1] != 999998): vm_details = azurerm.get_vmss_vm_instance_view(access_token, subscription_id, rgname, vmssname, vm_selected[0]); vm_nic = azurerm.get_vmss_vm_nics(access_token, subscription_id, rgname, vmssname, vm_selected[0]); clean_vm(window_information); if (vm_details != "" and vm_nic != ""): fill_vm_details(window_information, instanceId, vmName, provisioningState); update_panels(); doupdate(); counter += 1; do_update_bar(window_information['status'], step, 0); step += step; #Last mile... write_str(window_information['monitor'], 1, 30, "Done."); do_update_bar(window_information['status'], step, 1); #Remove destroyed VMs... counter_page = 0; if (DEPLOYED >= counter): time.sleep(0.5); write_str_color(window_information['monitor'], 1, 30, "Removing VM's...", 7, 0); wrefresh(window_information['monitor']); time.sleep(1); clean_monitor_form(window_information); while (DEPLOYED >= counter): write_str(window_information['monitor'], 1, 30, DEPLOYED); lastvm = window_vm.__len__() - 1; vm_coords = getbegyx(window_vm[lastvm]); vm_animation(panel_vm[lastvm], vm_coords, init_coords[0], init_coords[1], 0, ts); if (countery > 0): desty -= ROOM; countery -= 1; elif (destx > 22): destx -= 3; desty = 49; countery = 9; if (counter_page > 99): destx = 52; counter_page = 0; nr_pages -= 1; tot_pages = "%02d" % nr_pages; cur_page = "%02d" % page; update_vm_footer(window_information, cur_page, tot_pages); else: counter_page += 1; #Clean VM Info... if (vm_selected[0] == instances_deployed[lastvm]): clean_vm(window_information); #Free up some memory... del_panel(panel_vm[lastvm]); delwin(window_vm[lastvm]); wobj = panel_vm[lastvm]; panel_vm.remove(wobj); wobj = window_vm[lastvm]; window_vm.remove(wobj); wobj = instances_deployed[lastvm]; instances_deployed.remove(wobj); DEPLOYED -= 1; update_panels(); doupdate(); write_str(window_information['monitor'], 1, 30, "Done."); ourtime = time.strftime("%H:%M:%S"); do_update_bar(window_information['status'], step, 1); write_str(window_information['status'], 1, 13, ourtime); write_str_color(window_information['status'], 1, 22, " OK ", 6, 0); update_panels(); doupdate(); # sleep before each loop to avoid throttling... time.sleep(interval); except: logging.exception("Getting VMSS Information...") write_str(window_information['error'], 1, 24, "Let's sleep for 30 seconds and try to refresh the dashboard again..."); show_panel(panel_information['error']); update_panels(); doupdate(); ## break out of loop when an error is encountered #break time.sleep(30); hide_panel(panel_information['error']);
"Quota warning for cloud provider " + provider_name + ": " + msg, 'FullQuota', 'Warning', api_core) elif cloud == "azr": azOSP = json.loads( dc(secret_data['osServicePrincipal.json'])) access_token = azurerm.get_access_token( azOSP['tenantId'], azOSP['clientId'], azOSP['clientSecret']) for region in [ 'centralus', 'eastus', 'eastus2', 'westus', 'westus2', 'southcentralus' ]: compute_usage = azurerm.get_compute_usage( access_token, azOSP['subscriptionId'], region)['value'] compute_usage = compute_usage + azurerm.get_network_usage( access_token, azOSP['subscriptionId'], region)['value'] compute_usage = compute_usage + azurerm.get_storage_usage( access_token, azOSP['subscriptionId'], region)['value'] print("Azure: Processing Cloud Provider: " + provider_name + " in region: " + region) for quota in compute_usage: if quota['limit'] != 0 and quota[ 'currentValue'] / quota[ 'limit'] > CM_THRESHOLD and quota[ 'name'][