Skip to content

Commit

Permalink
salt.cloud: allow specific per node profile overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
kiorky committed Mar 6, 2014
1 parent 918d85d commit 9f27fa0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions salt/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,19 @@ def select_query(self, query_type='list_nodes_select'):
mapper = salt.cloud.Map(self._opts_defaults())
return mapper.map_providers_parallel(query_type)

def profile(self, profile, names, **kwargs):
def profile(self, profile, names, vm_opts=None, **kwargs):
'''
Pass in a profile to create, names is a list of vm names to allocate
vm_opts is a spetial dict that will be per node options overrides
'''
if not vm_opts:
vm_opts = {}
mapper = salt.cloud.Map(self._opts_defaults(**kwargs))
if isinstance(names, str):
names = names.split(',')
return salt.utils.cloud.simple_types_filter(
mapper.run_profile(profile, names))
mapper.run_profile(profile, names, vm_opts=vm_opts))

def destroy(self, names):
'''
Expand Down Expand Up @@ -1055,7 +1059,7 @@ def create(self, vm_, local_master=True):
output['ret'] = action_out
return output

def run_profile(self, profile, names):
def run_profile(self, profile, names, vm_opts=None):
'''
Parse over the options passed on the command line and determine how to
handle them
Expand All @@ -1066,6 +1070,8 @@ def run_profile(self, profile, names):
return {'Error': msg}

ret = {}
if not vm_opts:
vm_opts = {}
profile_details = self.opts['profiles'][profile]
alias, driver = profile_details['provider'].split(':')
mapped_providers = self.map_providers_parallel()
Expand All @@ -1082,6 +1088,7 @@ def run_profile(self, profile, names):
continue

vm_ = profile_details.copy()
vm_.update(vm_opts)
vm_['name'] = name
if self.opts['parallel']:
process = multiprocessing.Process(
Expand Down
4 changes: 2 additions & 2 deletions salt/modules/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def select_query(query_type='list_nodes_select'):
return query(query_type='list_nodes_select')


def profile_(profile, names, **kwargs):
def profile_(profile, names, vm_opts=None, **kwargs):
'''
Spin up an instance using Salt Cloud
Expand All @@ -141,7 +141,7 @@ def profile_(profile, names, **kwargs):
salt '*' cloud.profile my-gce-config myinstance
'''
client = _get_client()
info = client.profile(profile, names, **kwargs)
info = client.profile(profile, names, vm_opts=vm_opts, **kwargs)
return info


Expand Down
2 changes: 1 addition & 1 deletion salt/states/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def profile(name, profile, onlyif=None, unless=None, **kwargs):
if __opts__['test']:
ret['comment'] = 'Instance {0} needs to be created'.format(name)
return ret
info = __salt__['cloud.profile'](profile, name, **kwargs)
info = __salt__['cloud.profile'](profile, name, vm_opts=kwargs)
if info and not 'Error' in info:
ret['changes'] = info
ret['result'] = True
Expand Down

0 comments on commit 9f27fa0

Please sign in to comment.