Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix azure terminate to allow for downscaling specific instances #621

Merged
merged 5 commits into from May 19, 2017

Conversation

tmarballi
Copy link
Member

@tmarballi tmarballi commented May 17, 2017

for vm in vm_list:
vm_names.append(vm.name)

if not vm_names:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just check the size of vm_list instead of creating a new array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VM list we get from Azure is a Paged object and we don't have any methods we can use on it to get its size and it can only be iterated over to check the size by creating a new array.

result = compute_client.virtual_machine_scale_set_vms.delete(resource_group,
vmss_name,
instance_id)
resource_name = 'Virtual Machine Instance ' + instance_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Virtual Machine Instance be a constant? I assume it's a fixed construct from Azure?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, so I have a common method for waiting until the resources are created/deleted. So I pass the resource name so that I can print in the logs which is the resource we are waiting on. I don't see any benefit in making it a constant because we would not really use it anywhere else. Unless you see it as neater?

for vmss in vmss_list:
vm_list = compute_client.virtual_machine_scale_set_vms.list(
resource_group, vmss.name)
vm_names = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to just check if there are no elements in an iterable without iterating through the whole thing, you can do:

if not any(True for _ in vm_list):
  [delete_scale_set]

any will stop on the first element, so it would prevent paging through a large scale set.

In cases where you really do need to exhaust the iterable, the list() function can be a nice shortcut.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats awesome, I did not know about that! Thanks, I will make that change :)

thread = threading.Thread(
target=self.delete_virtual_machine_scale_set, args=(
compute_client, resource_group, verbose, vmss.name))
delete_ss_instances.append(vm.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the entire scale set is being deleted, what is this list for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list of instances to delete consists of both the scale set vms and the regular (load balancer) vms. I need this list of scale set vms so that I only give the remaining vms to delete to the delete_virtual_machine method. In this line over here: https://github.com/AppScale/appscale-tools/pull/621/files#diff-6b911255ca065691da775e67ef91b1e2R768

@tmarballi
Copy link
Member Author

@obino obino merged commit 91b56e7 into AppScale:master May 19, 2017
@tmarballi tmarballi deleted the fix-azure-terminate-instances branch August 1, 2017 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants