Skip to content

Instantly share code, notes, and snippets.

@glassresistor
Created December 7, 2012 01:45
Show Gist options
  • Save glassresistor/4230058 to your computer and use it in GitHub Desktop.
Save glassresistor/4230058 to your computer and use it in GitHub Desktop.
Fix for SmartDataCenter list_machines tag logic.
from fabric.api import env
def list_machines(*args, **kwargs):
"""
Wrapper for listing machines which match every tag. The current api behavior
is to return a list for any matching tags.
"""
tags = kwargs.get('tags')
lol_machines = [] # list of sets of machines
for key, value in tags.iteritems():
kwargs['tags'] = { key: value, }
lol_machines.append(set(env.sdc.machines(*args, **kwargs)))
if len(lol_machines[-1]) == 0:
break
return list(set.intersection(*lol_machines))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment