root/tags/v1.0/modipy.py

Revision 27, 1.2 KB (checked in by daedalus, 4 years ago)

* Added 'authoritarian' mode, which allows you permit/deny each and every command

that will be issued to a remote device. Designed for testing new change scripts.

* Added a 'command_timeout' parameter to Command Provisioners, so you can override

the default command timeout of 300 seconds by setting an attribute in the config
file

* Added proper handling of the 'onfail: continue' idea. You can now specify that

if a change fails, and it is a pre-requisite for some other change, processing
will continue despite the failure.

* Added the onfail: retry feature. If a change fails, you can specify that it should

be retried. You can also set a max number of retries. The default is 3.

  • Property svn:executable set to *
Line 
1#!/usr/bin/python
2#
3# Apply changes defined in a configuration file
4
5import sys
6import traceback
7
8from options import ChangeOptions
9from confloader import ConfigLoader, ChangeController
10from twisted.internet import reactor
11
12import logging
13log = logging.getLogger('modipy')
14
15optparser = ChangeOptions()
16optparser.parseOptions()
17
18try:
19    cfgldr = ConfigLoader(optparser.options, optparser.args)
20except Exception, e:
21    log.error("Cannot load configuration: %s", e)
22    traceback.print_exc(e)
23   
24    sys.exit(1)
25    pass
26
27log.debug("changes to apply: %s", cfgldr.changes)
28log.debug("total devices: %s", cfgldr.devices)
29
30controller = ChangeController(cfgldr)
31
32def mystop(ignored):
33    log.debug("finished!")
34    reactor.stop()
35    pass
36
37def errstop(failure):
38    log.error("Changes not implemented ok!")
39    tlog.err(failure)
40    reactor.stop()
41
42def go():
43    d = controller.do_changes()       
44    d.addCallbacks(mystop, errstop)
45
46# Use callLater(0) syntax to trigger running of changes once
47# the reactor has actually started, so it can be stopped cleanly.
48
49if getattr(optparser.options, 'loadonly', False):
50    log.info("Load only specified")
51    reactor.callLater(0, mystop, None)
52else:
53    reactor.callLater(0, go)
54    pass
55
56reactor.run()
57
58
Note: See TracBrowser for help on using the browser.