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
+
--- /dev/null
+#!/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))
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():