run_scripting cmd can't mute the pinger effectively
Closed this issue · 4 comments
wcpettus commented
When we run the routine script, we should generically mute the pinger on the esr for the next one hour via something like:
- action: cmd
cmds:
- endpoint: pinger
method_name: silence_ping
value: [datetime.datetime.utcnow()+datetime.timedelta(0,3600)).strftime(constants.TIME_FORMAT)]
timeout: 100
Fixing this is a two part-issue:
- run_scripting's
action_cmd
doesn't try asteval logic, so this would fail.- asteval string processing should probably be generically implemented as a separate method, rather than specifically implemented separately in
action_set
, etc.
- asteval string processing should probably be generically implemented as a separate method, rather than specifically implemented separately in
- asteval explicitly blocks
import
and doesn't import datetime, so the generic asteval can't accomplish this anyway- we could fork our own version of asteval to add the datetime functions
laroque commented
The second point is solved by adding datetime to the asteval Interpretor's symtable
laroque commented
For point 1, it should probably be a different function, not just a method. The calibration decorator should also use it.
wcpettus commented
and for point 2, the solution Ben demonstrated interactively is:
In [1]: import asteval
In [2]: i = asteval.Interpreter()
In [3]: import datetime
In [4]: i.symtable['datetime'] = datetime
In [5]: i("datetime.datetime.now()")
Out[5]: datetime.datetime(2017, 12, 7, 18, 26, 47, 440703)
In [6]: i("(datetime.datetime.utcnow()+datetime.timedelta(1)).strftime('%Y-%m-%dT%H:%M:%SZ')")
Out[6]: '2017-12-08T18:27:40Z'
wcpettus commented
Specific problem fixed in v1.9.4, a generic implementation of astral should be discussed in a separate issue.