fix cloud profile creation event

This commit is contained in:
Thomas S Hatch 2013-11-15 14:34:22 -07:00
parent 9d2466a723
commit 8aa4a68836

View File

@ -54,15 +54,16 @@ class CloudClient(object):
self.opts = opts
else:
self.opts = salt.cloud.config.cloud_config(path)
self.mapper = salt.cloud.Map(self.opts)
def _opts_defaults(self, **kwargs):
'''
Set the opts dict to defaults and allow for opts to be overridden in
the kwargs
'''
self.mapper.opts['parallel'] = False
self.mapper.opts.update(kwargs)
self.opts['parallel'] = False
self.opts['keep_tmp'] = False
self.opts.update(kwargs)
return self.opts
def low(self, fun, low):
'''
@ -76,59 +77,66 @@ class CloudClient(object):
'''
List all available sizes in configured cloud systems
'''
mapper = salt.cloud.Map(self._opts_defaults())
return salt.cloud.utils.simple_types_filter(
self.mapper.size_list(provider))
mapper.size_list(provider))
def list_images(self, provider=None):
'''
List all available images in configured cloud systems
'''
mapper = salt.cloud.Map(self._opts_defaults())
return salt.cloud.utils.simple_types_filter(
self.mapper.image_list(provider))
mapper.image_list(provider))
def list_locations(self, provider=None):
'''
List all available locations in configured cloud systems
'''
mapper = salt.cloud.Map(self._opts_defaults())
return salt.cloud.utils.simple_types_filter(
self.mapper.location_list(provider))
mapper.location_list(provider))
def query(self, query_type='list_nodes'):
'''
Query basic instance information
'''
return self.mapper.map_providers_parallel(query_type)
mapper = salt.cloud.Map(self._opts_defaults())
return mapper.map_providers_parallel(query_type)
def full_query(self, query_type='list_nodes_full'):
'''
Query all instance information
'''
return self.mapper.map_providers_parallel(query_type)
mapper = salt.cloud.Map(self._opts_defaults())
return mapper.map_providers_parallel(query_type)
def select_query(self, query_type='list_nodes_select'):
'''
Query select instance information
'''
return self.mapper.map_providers_parallel(query_type)
mapper = salt.cloud.Map(self._opts_defaults())
return mapper.map_providers_parallel(query_type)
def profile(self, profile, names, **kwargs):
'''
Pass in a profile to create, names is a list of vm names to allocate
'''
self._opts_defaults(**kwargs)
mapper = salt.cloud.Map(self._opts_defaults(**kwargs))
if isinstance(names, str):
names = names.split(',')
return salt.cloud.utils.simple_types_filter(
self.mapper.run_profile(profile, names))
mapper.run_profile(profile, names))
def destroy(self, names):
'''
Destroy the named vms
'''
mapper = salt.cloud.Map(self._opts_defaults())
if isinstance(names, str):
names = names.split(',')
return salt.cloud.utils.simple_types_filter(
self.mapper.destroy(names))
mapper.destroy(names))
def action(self, fun=None, cloudmap=None, names=None, provider=None,
instance=None, kwargs=None):
@ -140,11 +148,12 @@ class CloudClient(object):
client.action(fun='show_instance', names=['myinstance'])
client.action(fun='show_image', provider='my-ec2-config', kwargs={'image': 'ami-10314d79'})
'''
mapper = salt.cloud.Map(self._opts_defaults(action=fun))
if names and not provider:
self.opts['action'] = fun
return self.mapper.do_action(names, kwargs)
return mapper.do_action(names, kwargs)
if provider:
return self.mapper.do_function(provider, fun, kwargs)
return mapper.do_function(provider, fun, kwargs)
else:
# This should not be called without either an instance or a
# provider.
@ -153,7 +162,7 @@ class CloudClient(object):
)
return salt.cloud.utils.simple_types_filter(
self.mapper.run_profile(fun, names))
mapper.run_profile(fun, names))
# map
# create