Example #1
0
 def _set_scaleset(self, resource_group=None, scale_group=None, count=1):
     get_current = self._get_scaleset(
         self._get_resource_group(resource_group), scale_group)
     return azurerm.scale_vmss(self.access_token, self.subscription_id,
                               self._get_resource_group(resource_group),
                               scale_group, get_current['machine_type'],
                               get_current['tier'], count)
Example #2
0
def main():
    '''main routine'''

    # process arguments
    if len(sys.argv) < 4:
        usage()

    rgname = sys.argv[1]
    vmss_name = sys.argv[2]
    capacity = sys.argv[3]

    # Load Azure app defaults
    try:
        with open('azurermconfig.json') as config_file:
            config_data = json.load(config_file)
    except FileNotFoundError:
        print("Error: Expecting azurermconfig.json in current folder")
        sys.exit()

    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)

    scaleoutput = azurerm.scale_vmss(access_token, subscription_id, rgname,
                                     vmss_name, capacity)
    print(scaleoutput.text)
Example #3
0
def scale_event(scaleNum, access_token):
   global vmssProperties
   global rgname
   global vmssname
   global subscription_id
   newCapacity = vmssProperties[1] + scaleNum
   scaleoutput = azurerm.scale_vmss(access_token, subscription_id, rgname, vmssname, 'Standard_A1', 'Standard', newCapacity)
   print(scaleoutput)
    def scale(self, capacity):
        """
        Scale the agent count up or down to the supplied number.
        """
        tenant_id = self.config.get('Subscription', 'tenant_id')
        app_id = self.config.get('Subscription', 'app_id')
        app_secret = self.config.get('Subscription', 'app_secret')
        subscription_id = self.config.get('Subscription', 'subscription_id')
        rg_name = self.config.get('Group', 'name')
        access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)

        # TODO: This assumes only a single VMSS in the resource group, this will not always be the
        # case and will never be the case if when there are multiple Agent Pools
        vmsslist = azurerm.list_vm_scale_sets(access_token, subscription_id, rg_name)['value']
        # self.log.debug("List of VMSS: " + json.dumps(vmsslist, indent=True))
        vmss_name = vmsslist[0]['name']
        self.log.debug("Scaling " + vmss_name + " to " + capacity + " VMs (if this is the wrong VMSS it is because AgentPool.py currently only supports a single VMSS)")

        size = self.config.get("ACS", "AgentVMSize")
        tier = self.config.get("ACS", "AgentVMSize").split('_')[0]

        scale_result = azurerm.scale_vmss(access_token, subscription_id, rg_name, vmss_name, size, tier, capacity)
        self.log.warning("We scaled the cluster, but note that any of the features added will not be present on new machines.")
Example #5
0
 def scale(self, capacity):
     '''set the VMSS to a new capacity'''
     self.model['sku']['capacity'] = capacity
     scaleoutput = azurerm.scale_vmss(self.access_token, self.sub_id, self.rgname, self.name,
                                      capacity)
     self.status = scaleoutput
Example #6
0
def scalevmss():
    newcapacity = capacitytext.get()
    scaleoutput = azurerm.scale_vmss(access_token, subscription_id, selectedrg.get(), vmss_properties['name'],
                                     vmss_properties['vmsize'], vmss_properties['tier'], newcapacity)
    statusmsg(scaleoutput)
    displayvmss()
Example #7
0
 def scale(self, capacity):
     self.model['sku']['capacity'] = capacity
     scaleoutput = azurerm.scale_vmss(self.access_token, self.sub_id, self.rgname, self.name, self.vmsize, 
         self.tier, capacity)
     self.status = scaleoutput
Example #8
0
# To do: change this scale test to not hardcode the sku size
import azurerm
import json

# Load Azure app defaults
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']
rgname = configData['resourceGroup']
vmssname = configData['vmssName']

   
access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)
input()
scaleoutput = azurerm.scale_vmss(access_token, subscription_id, rgname, vmssname, 'Standard_A1', 'Standard', 98)
print(scaleoutput)
Example #9
0
# To do: change this scale test to not hardcode the sku size
import azurerm
import json

# Load Azure app defaults
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']
rgname = configData['resourceGroup']
vmssname = configData['vmssName']

access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)
input()
scaleoutput = azurerm.scale_vmss(access_token, subscription_id, rgname,
                                 vmssname, 'Standard_A1', 'Standard', 98)
print(scaleoutput)
def scale_event(scaleNum, access_token):
    newCapacity = vmssProperties['capacity'] + scaleNum
    scaleoutput = azurerm.scale_vmss(access_token, subscription_id, rgname,
                                     vmssname, vmssProperties['vmsize'],
                                     vmssProperties['tier'], newCapacity)
Example #11
0
def exec_cmd(window, access_token, cap, cmd):
	global subscription_id, rgname, vmssname, vmsku, tier, vm_selected, window_vm, panel_vm, vm_details, vm_nic, page, insights_flag;

	#Return codes...
	initerror = 2; syntaxerror = 3; capacityerror = 4;
	execsuccess = 0; execerror = 1;

	#Sanity check on capacity...
	if (cap == "999999"):
		return initerror;
	if not (isinstance(cap, int)):
		return initerror;

	#Syntax check...
	if (len(cmd.split()) != 4 and len(cmd.split()) != 3):
		return syntaxerror;

	counter = 0;
	for c in cmd.split():
		if (counter == 0):
			if (c == "add" or c == "del" or c == "rg" or c == "select" or c == "show"):
				op = c;
			else:
				return syntaxerror;
		if (counter == 1 and op == "show" and c != "page"):
				return syntaxerror;
		if (counter == 1 and c != "vm") and (op == "add" or op == "del" or op == "select"):
			return syntaxerror;
		if (counter == 1 and op == "rg"):
			rgname_new = c;
		if (counter == 2) and (op == "add" or op == "del" or op == "select" or op == "show"): 
			try:
				a = int(c) + 1;
				qtd = int(c);
			except:
				return syntaxerror;
		if (counter == 2 and op == "select"):
			z = 0; ifound = 0;
			while (z < instances_deployed.__len__()):
				if (instances_deployed[z] == int(c)):
					ifound = 1;
					break;
				z += 1;
			if (ifound):
				vm = int(c);
			else:
				return execerror;
		if (counter == 2 and op == "rg" and c != "vmss"):
				return syntaxerror;
		if (counter == 2 and op == "show"):
			try:
				a = int(c) + 1;
				if (int(c) == page):
					return execsuccess; 
				if (int(c) > 1):
					b = ((window_vm.__len__() / (int(c) - 1)));
					if (b <= 100 or (int(c)) <= 0):
						return syntaxerror;
					else:
						page_new = int(c);
				elif (int(c) == 1):
						page_new = int(c);
				else:
						return syntaxerror;
			except:
				return syntaxerror;
		if (counter == 3 and op == "rg"):
			vmssname_new = c;
		counter += 1;

	#Execution...
	if (op == "add" or op == "del"):
		if (qtd > 99): 
			return capacityerror;
		#Scale-in or Scale-out...
		if (op == "add"):
   			newCapacity = cap + int(c);
		else:
   			newCapacity = cap - int(c);
		#Ok, everything seems fine, let's do it...
		#Change the VM scale set capacity by 'qtd' (can be positive or negative for scale-out/in)
		scaleoutput = azurerm.scale_vmss(access_token, subscription_id, rgname, vmssname, vmsku, tier, newCapacity);
		if (scaleoutput.status_code == 200):
			return execsuccess;
		else:
			return execerror;
	elif (op == "select"):
		vm_selected[1] = vm_selected[0];
		vm_selected[0] = vm;
		vm_details_old = vm_details; vm_nic_old = vm_nic;
		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]);
		#if (len(vm_details) > 0 and len(vm_nic) > 0):
		if (len(vm_details) > 0):
			return execsuccess;
		else:
			vm_details = vm_details_old;
			vm_nic = vm_nic_old;
			vm_selected[1] = 999998;
			return execerror;
	elif (op == "show"):
		unset_page();
		set_page(window, page_new);
		return execsuccess;
	else:
		#Test to be sure the resource group and vmss provided do exist...
		rgoutput = azurerm.get_vmss(access_token, subscription_id, rgname_new, vmssname_new);
		try:
			test = rgoutput['location'];
			rgname = rgname_new; vmssname = vmssname_new;
			#Just a flag for us to know that we changed the vmss and need to deselect any VM...
			vm_selected[1] = 999998;
			#We need to clear the Insights graph too...
			insights_flag = 1;
			page = 1;
			return execsuccess;
		except:
			return execerror;
Example #12
0
 def scale(self, capacity):
     self.model['sku']['capacity'] = capacity
     scaleoutput = azurerm.scale_vmss(self.access_token, self.sub_id, self.rgname, self.name, self.vmsize, self.tier,
                                      capacity)
     self.status = scaleoutput
Example #13
0
def exec_cmd(window, access_token, cap, cmd):
	global subscription_id, rgname, vmssname, vmsku, tier, vm_selected, window_vm, panel_vm, vm_details, vm_nic, page, insights_flag;

	#Return codes...
	initerror = 2; syntaxerror = 3; capacityerror = 4;
	execsuccess = 0; execerror = 1;

	#Sanity check on capacity...
	if (cap == "999999"):
		return initerror;
	if not (isinstance(cap, int)):
		return initerror;

	#Syntax check...
	if (len(cmd.split()) != 4 and len(cmd.split()) != 3):
		return syntaxerror;

	counter = 0;
	for c in cmd.split():
		if (counter == 0):
			if (c == "add" or c == "del" or c == "rg" or c == "select" or c == "show"):
				op = c;
			else:
				return syntaxerror;
		if (counter == 1 and op == "show" and c != "page"):
				return syntaxerror;
		if (counter == 1 and c != "vm") and (op == "add" or op == "del" or op == "select"):
			return syntaxerror;
		if (counter == 1 and op == "rg"):
			rgname_new = c;
		if (counter == 2) and (op == "add" or op == "del" or op == "select" or op == "show"): 
			try:
				a = int(c) + 1;
				qtd = int(c);
			except:
				return syntaxerror;
		if (counter == 2 and op == "select"):
			z = 0; ifound = 0;
			while (z < instances_deployed.__len__()):
				if (instances_deployed[z] == int(c)):
					ifound = 1;
					break;
				z += 1;
			if (ifound):
				vm = int(c);
			else:
				return execerror;
		if (counter == 2 and op == "rg" and c != "vmss"):
				return syntaxerror;
		if (counter == 2 and op == "show"):
			try:
				a = int(c) + 1;
				if (int(c) == page):
					return execsuccess; 
				if (int(c) > 1):
					b = ((window_vm.__len__() / (int(c) - 1)));
					if (b <= 100 or (int(c)) <= 0):
						return syntaxerror;
					else:
						page_new = int(c);
				elif (int(c) == 1):
						page_new = int(c);
				else:
						return syntaxerror;
			except:
				return syntaxerror;
		if (counter == 3 and op == "rg"):
			vmssname_new = c;
		counter += 1;

	#Execution...
	if (op == "add" or op == "del"):
		if (qtd > 99): 
			return capacityerror;
		#Scale-in or Scale-out...
		if (op == "add"):
   			newCapacity = cap + int(c);
		else:
   			newCapacity = cap - int(c);
		#Ok, everything seems fine, let's do it...
		#Change the VM scale set capacity by 'qtd' (can be positive or negative for scale-out/in)
		#The interface for scale_vmss changed from 7 to just 5 arguments...
		#scaleoutput = azurerm.scale_vmss(access_token, subscription_id, rgname, vmssname, vmsku, tier, newCapacity);
		scaleoutput = azurerm.scale_vmss(access_token, subscription_id, rgname, vmssname, newCapacity);
		if (scaleoutput.status_code == 200):
			return execsuccess;
		else:
			return execerror;
	elif (op == "select"):
		vm_selected[1] = vm_selected[0];
		vm_selected[0] = vm;
		vm_details_old = vm_details; vm_nic_old = vm_nic;
		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]);
		#if (len(vm_details) > 0 and len(vm_nic) > 0):
		if (len(vm_details) > 0):
			return execsuccess;
		else:
			vm_details = vm_details_old;
			vm_nic = vm_nic_old;
			vm_selected[1] = 999998;
			return execerror;
	elif (op == "show"):
		unset_page();
		set_page(window, page_new);
		return execsuccess;
	else:
		#Test to be sure the resource group and vmss provided do exist...
		rgoutput = azurerm.get_vmss(access_token, subscription_id, rgname_new, vmssname_new);
		try:
			test = rgoutput['location'];
			rgname = rgname_new; vmssname = vmssname_new;
			#Just a flag for us to know that we changed the vmss and need to deselect any VM...
			vm_selected[1] = 999998;
			#We need to clear the Insights graph too...
			insights_flag = 1;
			page = 1;
			return execsuccess;
		except:
			return execerror;
Example #14
0
def scale_event(scaleNum, access_token):
    newCapacity = vmssProperties['capacity'] + scaleNum
    scaleoutput = azurerm.scale_vmss(access_token, subscription_id, rgname, vmssname, vmssProperties['vmsize'],
                                     vmssProperties['tier'], newCapacity)