Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions rubrik_polaris/compute/vsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,28 @@
Collection of functions that manipulate vSphere compute components
"""


def get_compute_object_ids_vsphere(self, match_all=True, **kwargs):
"""Retrieves all vSphere objects that match query
Arguments:
match_all {bool} -- Set to false to match ANY defined criteria
kwargs {} -- Any top level object from the get_compute_ec2 call
Raises:
RequestException: If the query to Polaris returned an error
"""
try:
return self._get_object_ids_instances(self.get_instances_vsphere(), kwargs, match_all=match_all)
object_ids = []
num_criteria = len(kwargs)
for instance in self.get_compute_vsphere():
num_unmatched_criteria = num_criteria
for key in kwargs:
if key in instance and instance[key] == kwargs[key]:
num_unmatched_criteria -= 1
if match_all and num_unmatched_criteria == 0:
object_ids.append(instance['id'])
elif not match_all and num_criteria > num_unmatched_criteria >= 1:
Copy link
Member

Choose a reason for hiding this comment

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

Is the intent of num_criteria > num_unmatched_criteria >= 1 to return False when we match all criteria? (i.e. if we have match_all = False, num_criteria = 5 and matches them all num_unmatched_criteria = 0) ?

My impression was that it would be enough to match a single criteria to append when match_all = False, i.e. drop the >= 1:

elif not match_all and num_criteria > num_unmatched_criteria:

Copy link
Member Author

Choose a reason for hiding this comment

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

I just ripped all of that out, since we implemented filtering in the resolver now. Take another look. Way simpler.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, indeed, nice!

object_ids.append(instance['id'])
return object_ids
except Exception:
raise

Expand Down
1 change: 1 addition & 0 deletions sample/polaris_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@

### Returns all objectIDs matching arbitrary available inputs. ec2 tags have special treatment
# pp.pprint(rubrik.get_compute_object_ids_ec2(tags = {"Name": "Puppet Master"}))
# pp.pprint(rubrik.get_compute_object_ids_vsphere(name="O365-003"))
# pp.pprint(rubrik.get_compute_object_ids_azure(region = "EastUS2"))
# pp.pprint(rubrik.get_compute_object_ids_gce(region = "us-west1"))

Expand Down