From eada2f011bd0708426c5377130fb59d97867fa7b Mon Sep 17 00:00:00 2001 From: Thomas S Hatch Date: Mon, 23 May 2011 22:24:45 -0600 Subject: [PATCH] Add --- salt/states/host.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 salt/states/host.py diff --git a/salt/states/host.py b/salt/states/host.py new file mode 100644 index 0000000000..54b94f4cc4 --- /dev/null +++ b/salt/states/host.py @@ -0,0 +1,45 @@ +''' +Manage the state of the hosts file +''' + +def present(name, ip): + ''' + Ensures that the named host is present with the given ip + ''' + ret = {'name': name, + 'changes': {}, + 'result': False, + 'comment': ''} + if __salt__['hosts.has_pair'](ip, name): + ret['changes'] = 'Already Present' + ret['result'] = True + return ret + if __salt__['hosts.add_host'](ip, name): + ret['changes'] = {'host': name} + ret['result'] = True + ret['comment'] = 'Added host ' + name + return ret + else: + ret['result'] = False + ret['comment'] = 'Failed to set host' + return ret + +def absent(name, ip): + ''' + Ensure that the the named host is absent + ''' + ret = {'name': name, + 'changes': {}, + 'result': False} + if not __salt__['hosts.has_pair'](ip, name): + ret['changes'] = 'Already Absent' + ret['result'] = True + return ret + if __salt__['hosts.rm_host'](ip, name): + ret['changes'] = {'host': name} + ret['result'] = True + return ret + else: + ret['result'] = False + return ret +