| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding: utf-8 | 2 # coding: utf-8 |
| 3 | 3 |
| 4 import sys | 4 import sys |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 import subprocess | 7 import subprocess |
| 8 import getopt | 8 import getopt |
| 9 import yaml | 9 import yaml |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 print >>sys.stderr, 'No user name specified' | 49 print >>sys.stderr, 'No user name specified' |
| 50 usage() | 50 usage() |
| 51 sys.exit(1) | 51 sys.exit(1) |
| 52 | 52 |
| 53 return user, mode, args | 53 return user, mode, args |
| 54 | 54 |
| 55 def readMonitoringConfig(): | 55 def readMonitoringConfig(): |
| 56 # Use Puppet's parser to convert monitoringserver.pp into YAML | 56 # Use Puppet's parser to convert monitoringserver.pp into YAML |
| 57 manifest = os.path.join(os.path.dirname(__file__), 'manifests', 'monitoringser ver.pp') | 57 manifest = os.path.join(os.path.dirname(__file__), 'manifests', 'monitoringser ver.pp') |
| 58 parseScript = ''' | 58 parseScript = ''' |
| 59 require 'puppet' | |
| 59 require 'puppet/parser' | 60 require 'puppet/parser' |
| 60 parser = Puppet::Parser::Parser.new(Puppet[:environment]) | 61 parser = Puppet::Parser::Parser.new(Puppet[:environment]) |
| 62 Puppet.settings[:ignoreimport] = true | |
| 61 parser.file = ARGV[0] | 63 parser.file = ARGV[0] |
| 62 print ZAML.dump(parser.parse) | 64 print ZAML.dump(parser.parse) |
| 63 ''' | 65 ''' |
| 64 data, dummy = subprocess.Popen(['ruby', '', manifest], | 66 data, dummy = subprocess.Popen(['ruby', '', manifest], |
| 65 stdin=subprocess.PIPE, | 67 stdin=subprocess.PIPE, |
| 66 stdout=subprocess.PIPE, | 68 stdout=subprocess.PIPE).communicate(parseScript) |
|
Felix Dahlke
2014/03/26 11:19:55
Why ignore stderr now?
Wladimir Palant
2014/03/26 11:27:41
Quite the opposite actually - before this change s
| |
| 67 stderr=subprocess.PIPE).communicate(parseScript) | |
| 68 | 69 |
| 69 # See http://stackoverflow.com/q/8357650/785541 on parsing Puppet's YAML | 70 # See http://stackoverflow.com/q/8357650/785541 on parsing Puppet's YAML |
| 70 yaml.add_multi_constructor(u"!ruby/object:", lambda loader, suffix, node: load er.construct_yaml_map(node)) | 71 yaml.add_multi_constructor(u"!ruby/object:", lambda loader, suffix, node: load er.construct_yaml_map(node)) |
| 71 yaml.add_constructor(u"!ruby/sym", lambda loader, node: loader.construct_yaml_ str(node)) | 72 yaml.add_constructor(u"!ruby/sym", lambda loader, node: loader.construct_yaml_ str(node)) |
| 72 return yaml.load(data) | 73 return yaml.load(data) |
| 73 | 74 |
| 74 def getValidHosts(): | 75 def getValidHosts(): |
| 75 def processNode(node, hosts=None, groups=None): | 76 def processNode(node, hosts=None, groups=None): |
| 76 if hosts == None: | 77 if hosts == None: |
| 77 hosts = set() | 78 hosts = set() |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 if __name__ == "__main__": | 141 if __name__ == "__main__": |
| 141 user, mode, args = parseOptions(sys.argv[1:]) | 142 user, mode, args = parseOptions(sys.argv[1:]) |
| 142 hosts, groups = getValidHosts() | 143 hosts, groups = getValidHosts() |
| 143 needKicking = resolveHostList(args, hosts, groups) | 144 needKicking = resolveHostList(args, hosts, groups) |
| 144 if len(needKicking) == 0: | 145 if len(needKicking) == 0: |
| 145 print >>sys.stderr, 'No valid hosts or groups specified, nothing to do' | 146 print >>sys.stderr, 'No valid hosts or groups specified, nothing to do' |
| 146 sys.exit(0) | 147 sys.exit(0) |
| 147 updateMaster(user) | 148 updateMaster(user) |
| 148 for host in needKicking: | 149 for host in needKicking: |
| 149 updateClient(user, host, mode) | 150 updateClient(user, host, mode) |
| OLD | NEW |