Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def filter(self, query, sel, val):
"""Main function for filter command
:param query: query string.
:type query: str.
:param sel: the type selection for the select operation.
:type sel: str.
:param val: value for the property to be modified.
:type val: str.
:returns: returns a list of selected items
"""
if query:
if isinstance(query, list):
if len(query) == 0:
raise InstanceNotFoundError("Unable to locate instance " \
"for '%s'" % query)
else:
query = query[0]
selection = self.get_selection(selector=query, sel=sel, val=val)
if selection and len(selection) > 0:
self.current_client.selector = query
self.current_client.filter_attr = sel
self.current_client.filter_value = val
self.save()
return selection
if selection and len(selection) > 0:
self.current_client.selector = query
if not sel is None and not val is None:
self.current_client.filter_attr = sel
self.current_client.filter_value = val
else:
self.current_client.filter_attr = None
self.current_client.filter_value = None
self.save()
return selection
if not sel is None and not val is None:
raise InstanceNotFoundError("Unable to locate instance for" \
" '%s' and filter '%s=%s'" % (query, sel, val))
else:
raise InstanceNotFoundError("Unable to locate instance for" \
" '%s'" % query)