Skip to content
Snippets Groups Projects
Commit 447b7a4e authored by garciadeblas's avatar garciadeblas Committed by Gerrit Code Review
Browse files

Merge "Add a "dig" action"

parents e180c9ba 27aa41dd
No related branches found
No related tags found
No related merge requests found
......@@ -30,3 +30,18 @@ traceroute:
type: string
required:
- destination
dig:
description: "DNS lookup"
params:
nsserver:
description: "The nameserver to lookup against."
type: string
host:
description: "The host to lookup"
type: string
type:
description: "The DNS record type to lookup"
type: string
required:
- host
#!/usr/bin/env python3
import sys
sys.path.append('lib')
from charms.reactive import main
from charms.reactive import set_state
from charmhelpers.core.hookenv import action_fail
"""
`set_state` only works here because it's flushed to disk inside the `main()`
loop. remove_state will need to be called inside the action method.
"""
set_state('actions.dig')
try:
main()
except Exception as e:
action_fail(repr(e))
......@@ -22,6 +22,31 @@ def ready():
status_set('active', 'Ready!')
set_flag('netutils.ready')
@when('actions.dig')
def dig():
err = ''
try:
nsserver = action_get('nsserver')
host = action_get('host')
nstype = action_get('type')
cmd = "dig"
if nsserver:
cmd += " @{}".format(nsserver)
if host:
cmd += " {}".format(host)
else:
action_fail('Hostname required.')
if nstype:
cmd += " -t {}".format(nstype)
result, err = _run(cmd)
except:
action_fail('dig command failed:' + err)
else:
action_set({'outout': result})
finally:
remove_flag('actions.dig')
@when('actions.nmap')
def nmap():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment