1 from charmhelpers
.core
.hookenv
import (
8 from charms
.reactive
import (
11 set_state
as set_flag
,
12 remove_state
as remove_flag
,
14 import charms
.sshproxy
17 @when_not('netutils.ready')
19 status_set('active', 'Ready!')
20 set_flag('netutils.ready')
27 nsserver
= action_get('nsserver')
28 host
= action_get('host')
29 nstype
= action_get('type')
33 cmd
+= " @{}".format(nsserver
)
35 cmd
+= " {}".format(host
)
37 action_fail('Hostname required.')
39 cmd
+= " -t {}".format(nstype
)
41 result
, err
= charms
.sshproxy
._run
(cmd
)
43 action_fail('dig command failed:' + err
)
45 action_set({'outout': result
})
47 remove_flag('actions.dig')
54 result
, err
= charms
.sshproxy
._run
(
55 'nmap {}'.format(action_get('destination'))
58 action_fail('nmap command failed:' + err
)
60 action_set({'outout': result
})
62 remove_flag('actions.nmap')
69 result
, err
= charms
.sshproxy
._run
('ping -qc {} {}'.format(
70 action_get('count'), action_get('destination'))
74 action_fail('ping command failed:' + err
)
76 # Here you can send results back from ping, if you had time to parse it
77 action_set({'output': result
})
79 remove_flag('actions.ping')
82 @when('actions.traceroute')
85 result
, err
= charms
.sshproxy
._run
(
86 'traceroute -m {} {}'.format(
88 action_get('destination')
92 action_fail('traceroute command failed')
94 # Here you can send results back from ping, if you had time to parse it
95 action_set({'output': result
})
97 remove_flag('actions.traceroute')