Skip to content

Instantly share code, notes, and snippets.

@Snergster
Created May 4, 2015 14:02
Show Gist options
  • Save Snergster/c6f376f4b14698b8d25c to your computer and use it in GitHub Desktop.
Save Snergster/c6f376f4b14698b8d25c to your computer and use it in GitHub Desktop.
before and after
was
def project_present(name, **kwargs):
"""Ensure that there's a UWM project with the specified properties.
:returns: dict with keys ('project', 'main-user', 'comment')
"""
props = {'name': name}
for key in ('description', 'expires', 'enabled', 'user_password',
'user_os_password', 'networks', 'quota_instances', 'quota_ram',
'quota_vcpus'):
if key in kwargs:
json_key = key.replace('_', '-')
props[json_key] = kwargs[key]
data = simplejson.dumps({'projects': [props],
'users': []})
results = __uwm_client('project-import',
args=('--update',),
kwargs={'--data': data})
result = results['results'][0]
if 'exception' in result:
raise CommandExecutionError(result['exception'])
return result
and now
def project_present(name, description=None, expires=None, quota_vcpus=200, quota_ram=512000, quota_instances=100, **kwargs):
"""Ensure that there's a UWM project with the specified properties.
:returns: dict with keys ('project', 'main-user', 'comment')
"""
props = {'name': name,'description':description,'expires':expires,'quota-vcpus': quota_vcpus, 'quota-ram': quota_ram, 'quota-instances': quota_instances}
for key in ('description', 'expires', 'enabled', 'user_password',
'user_os_password', 'networks', 'quota_instances', 'quota_ram',
'quota_vcpus'):
if key in kwargs:
json_key = key.replace('_', '-')
props[json_key] = kwargs[key]
data = simplejson.dumps({'projects': [props],
'users': []})
results = __uwm_client('project-import',
args=('--update',),
kwargs={'--data': data})
result = results['results'][0]
if 'exception' in result:
raise CommandExecutionError(result['exception'])
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment