Exemple #1
0
def main():
    '''main routine'''
    # Load Azure app defaults
    try:
        with open('azurermconfig.json') as config_file:
            config_data = json.load(config_file)
    except FileNotFoundError:
        sys.exit('Error: Expecting azurermconfig.json in current folder')

    tenant_id = config_data['tenantId']
    app_id = config_data['appId']
    app_secret = config_data['appSecret']
    subscription_id = config_data['subscriptionId']

    access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)

    vmsslist = azurerm.list_vmss_sub(access_token, subscription_id)
    for vmss in vmsslist['value']:
        name = vmss['name']
        location = vmss['location']
        capacity = vmss['sku']['capacity']
        print(''.join(['Name: ', name, ', location: ',
                       location, ', Capacity: ', str(capacity)]))
        print('VMSS NICs...')
        rgname = get_rg_from_id(vmss['id'])
        vmss_nics = azurerm.get_vmss_nics(
            access_token, subscription_id, rgname, name)
        print(json.dumps(vmss_nics, sort_keys=False,
                         indent=2, separators=(',', ': ')))
        print('VMSS Virtual machines...')
        vms = azurerm.list_vmss_vms(
            access_token, subscription_id, rgname, name)
        #print(json.dumps(vms, sort_keys=False, indent=2, separators=(',', ': ')))
        for vmssvm in vms['value']:
            vm_id = vmssvm['instanceId']
            print(vm_id + ', ' + vmssvm['name'] + '\n')
            print('VMSS VM NICs...')
            vmnics = azurerm.get_vmss_vm_nics(access_token, subscription_id, rgname, name,
                                              vm_id)
            print(json.dumps(vmnics, sort_keys=False,
                             indent=2, separators=(',', ': ')))
Exemple #2
0
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']);
Exemple #3
0
# loop through resource groups
resource_groups = azurerm.list_resource_groups(access_token, subscription_id)
for rg in resource_groups["value"]:
    rgname = rg["name"] 
    vmsslist = azurerm.list_vm_scale_sets(access_token, subscription_id, rgname)
    for vmss in vmsslist['value']:
        name = vmss['name']
        location = vmss['location']
        capacity = vmss['sku']['capacity']
        offer = vmss['properties']['virtualMachineProfile']['storageProfile']['imageReference']['offer']
        sku = vmss['properties']['virtualMachineProfile']['storageProfile']['imageReference']['sku']
        print(''.join(['Name: ', name,
                       ', RG: ', rgname,
                       ', location: ', location,
                       ', Capacity: ', str(capacity),
                       ', OS: ', offer, ' ', sku]))
        print('VMSS NICs...')
        vmssNics = azurerm.get_vmss_nics(access_token, subscription_id, rgname, name)
        print(json.dumps(vmssNics, sort_keys=False, indent=2, separators=(',', ': ')))
        print('VMSS Virtual machines...')
        vms = azurerm.list_vmss_vms(access_token, subscription_id, rgname, name)
        #print(json.dumps(vms, sort_keys=False, indent=2, separators=(',', ': ')))
        for vm in vms['value']:
            vmId = vm['instanceId']
            print(vmId + ', ' + vm['name'] + '\n')
            print('VMSS VM NICs...')
            vmnics = azurerm.get_vmss_vm_nics(access_token, subscription_id, rgname, name, vmId)
            print(json.dumps(vmnics, sort_keys=False, indent=2, separators=(',', ': ')))

Exemple #4
0
        sku = vmss['properties']['virtualMachineProfile']['storageProfile'][
            'imageReference']['sku']
        print(''.join([
            'Name: ', name, ', RG: ', rgname, ', location: ', location,
            ', Capacity: ',
            str(capacity), ', OS: ', offer, ' ', sku
        ]))
        print('VMSS NICs...')
        vmssNics = azurerm.get_vmss_nics(access_token, subscription_id, rgname,
                                         name)
        print(
            json.dumps(vmssNics,
                       sort_keys=False,
                       indent=2,
                       separators=(',', ': ')))
        print('VMSS Virtual machines...')
        vms = azurerm.list_vmss_vms(access_token, subscription_id, rgname,
                                    name)
        # print(json.dumps(vms, sort_keys=False, indent=2, separators=(',', ': ')))
        for vm in vms['value']:
            vmId = vm['instanceId']
            print(vmId + ', ' + vm['name'] + '\n')
            print('VMSS VM NICs...')
            vmnics = azurerm.get_vmss_vm_nics(access_token, subscription_id,
                                              rgname, name, vmId)
            print(
                json.dumps(vmnics,
                           sort_keys=False,
                           indent=2,
                           separators=(',', ': ')))
Exemple #5
0
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']);