mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Add
This commit is contained in:
parent
7bbbb016ba
commit
eada2f011b
45
salt/states/host.py
Normal file
45
salt/states/host.py
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user