0
votes

I'm looking for a way to filter virtual machine name which contains string "myvm" using Azure Python SDK. I tried the following way but it seems not to work

for vm in compute_client.virtual_machines.list_by_location(LOCATION):
            print(vm.name)
            if vm.name in "myvm":

the If condition seems not to be able to query in the list of virtual machines.

1
if vm.name == "myvm":? - 4c74356b41
@4c74356b41 sorry for not being clear. I'd like to query all vms whose name contains string "myvm" - EagleDev
i think it should be if 'myvm' in vm.name:. I dont think you can filter when you query, i dont think there is a method for that, at least in the compute sdk - 4c74356b41

1 Answers

1
votes

you need to reverse the in, because you are checking for the existence of myvmname1 in myvm. obviously this wont work, because myvmname1 is not in the string myvm.