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.
reviewable/pr18780/r1
Michael DeHaan 13 years ago
parent 2c5c2f2c58
commit 8f9320aa05

@ -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

@ -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

@ -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

@ -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

Loading…
Cancel
Save