Skip to content
Browse files

lxc: do not trigger state change without a change

  • Loading branch information...
1 parent 6914fcb commit d226ccf4f287f038827b0f92d30c88b6b854d4d0 @kiorky kiorky committed Mar 5, 2014
Showing with 21 additions and 8 deletions.
  1. +11 −3 salt/cloud/clouds/lxc.py
  2. +10 −5 salt/states/cloud.py
View
14 salt/cloud/clouds/lxc.py
@@ -285,6 +285,7 @@ def _checkpoint(ret):
del ret['changes']
raise SaltCloudSystemExit(sret)
log.info(sret)
+ return sret
def destroy(vm_, call=None):
@@ -544,8 +545,8 @@ def wait_for_ip():
# set dns servers
changes['350_dns'] = 'DNS in place'
ret['comment'] = changes['350_dns']
- if dnsservers:
- gid = 'lxc.{0}.initial_dns'.format(name, False)
+ gid = 'lxc.{0}.initial_dns'.format(name, False)
+ if dnsservers and not __grains__.get(gid):
cret = _salt('lxc.set_dns',
name,
dnsservers=dnsservers)
@@ -588,6 +589,8 @@ def testping(*args):
if 'Error' in sret:
ret['result'] = False
changes['400_salt'] = pformat(sret['Error'])
+ else:
+ changed = True
ret['comment'] = changes['400_salt']
_checkpoint(ret)
@@ -599,7 +602,12 @@ def testping(*args):
ret['comment'] = changes['401_salt']
_checkpoint(ret)
- _checkpoint(ret)
+ sret = _checkpoint(ret)
+ if not ret['result']:
+ ret['Error'] = 'Error while creating {0}'.format(vm_['name'])
+ if not changed and ret['result']:
+ ret['changes'] = {}
+ ret['comment'] = '\n{0}'.format(sret)
return ret
View
15 salt/states/cloud.py
@@ -236,12 +236,17 @@ def profile(name, profile, onlyif=None, unless=None, **kwargs):
return ret
info = __salt__['cloud.profile'](profile, name, vm_overrides=kwargs)
if info and not 'Error' in info:
- ret['changes'] = info
+ node_info = info.get(name)
ret['result'] = True
- ret['comment'] = 'Created instance {0} using profile {1}'.format(
- name,
- profile,
- )
+ default_msg = 'Created instance {0} using profile {1}'.format(
+ name, profile,)
+ # some providers support changes
+ if 'changes' in node_info:
+ ret['changes'] = node_info['changes']
+ ret['comment'] = node_info.get('comment', default_msg)
+ else:
+ ret['changes'] = info
+ ret['comment'] = default_msg
elif 'Error' in info:
ret['result'] = False
ret['comment'] = ('Failed to create instance {0}'

0 comments on commit d226ccf

Please sign in to comment.
Something went wrong with that request. Please try again.