Rename 'ensure' to 'state' because I think it's a bit cleaner and doesn't imply

all modules take a common parameter name.  But more or less we still work idempotently
in modules.
This commit is contained in:
Michael DeHaan 2012-02-26 22:31:42 -05:00
parent 2c5c2f2c58
commit 8f9320aa05
4 changed files with 11 additions and 11 deletions

2
copy
View file

@ -10,7 +10,7 @@ except ImportError:
import simplejson as json import simplejson as json
# =========================================== # ===========================================
# convert arguments of form ensure=running name=foo # convert arguments of form a=b c=d
# to a dictionary # to a dictionary
# FIXME: make more idiomatic # FIXME: make more idiomatic

2
git
View file

@ -16,7 +16,7 @@ import shlex
import subprocess import subprocess
# =========================================== # ===========================================
# convert arguments of form ensure=running name=foo # convert arguments of form a=b c=d
# to a dictionary # to a dictionary
# FIXME: make more idiomatic # FIXME: make more idiomatic

16
service
View file

@ -10,7 +10,7 @@ import shlex
import subprocess import subprocess
# =========================================== # ===========================================
# convert arguments of form ensure=running name=foo # convert arguments of form a=b c=d
# to a dictionary # to a dictionary
# FIXME: make more idiomatic # FIXME: make more idiomatic
@ -22,7 +22,7 @@ for x in items:
params[k] = v params[k] = v
name = params['name'] name = params['name']
ensure = params.get('ensure','running') state = params.get('state','running')
# =========================================== # ===========================================
# get service status # get service status
@ -43,11 +43,11 @@ elif name == 'iptables' and status.find("ACCEPT") != -1:
running = True running = True
changed = False changed = False
if not running and ensure == "started": if not running and state == "started":
changed = True changed = True
elif running and ensure == "stopped": elif running and state == "stopped":
changed = True changed = True
elif ensure == "restarted": elif state == "restarted":
changed = True changed = True
# =========================================== # ===========================================
@ -61,11 +61,11 @@ def _run(cmd):
rc = 0 rc = 0
if changed: if changed:
if ensure == 'started': if state == 'started':
rc = _run("/sbin/service %s start" % name) rc = _run("/sbin/service %s start" % name)
elif ensure == 'stopped': elif state == 'stopped':
rc = _run("/sbin/service %s stop" % name) rc = _run("/sbin/service %s stop" % name)
elif ensure == 'restarted': elif state == 'restarted':
rc1 = _run("/sbin/service %s stop" % name) rc1 = _run("/sbin/service %s stop" % name)
rc2 = _run("/sbin/service %s start" % name) rc2 = _run("/sbin/service %s start" % name)
rc = rc1 and rc2 rc = rc1 and rc2

View file

@ -10,7 +10,7 @@ except ImportError:
import simplejson as json import simplejson as json
# =========================================== # ===========================================
# convert arguments of form ensure=running name=foo # convert arguments of form a=b c=d
# to a dictionary # to a dictionary
# FIXME: make more idiomatic # FIXME: make more idiomatic