Skip to content

Instantly share code, notes, and snippets.

@cluther
Last active September 4, 2015 18:00
Show Gist options
  • Save cluther/9fe6a8e55fb09958e424 to your computer and use it in GitHub Desktop.
Save cluther/9fe6a8e55fb09958e424 to your computer and use it in GitHub Desktop.
Zenoss: Make control center service definitions more appropriate for ZenPack development.
#!/usr/bin/env python
"""devinate-template (a.k.a. developinate-template)
This script can be used to take an existing Zenoss serviced service
definition and modify it to be more appropriate for a slimmed-down
ZenPack development environment. A compiled Zenoss serviced service
definition is expected on STDIN, and the modified service definition
will be written to STDOUT.
Currently the following changes are made to the input template.
* Append ".develop" to app and top level service names.
* Change launch mode from auto to manual for all collector services.
* Reduce Zope minimum and default instances to 1.
Example usage:
serviced template list \
$(serviced template list|grep Zenoss.core|awk '{print $1}') \
| devinate-template \
| serviced template add
"""
__version__ = "1.0"
import json
import sys
collector_services = [
'zencommand',
'zenmodeler',
'zenperfsnmp',
'zenping',
'zenprocess',
'zenpython',
'zenstatus',
'zensyslog',
'zentrap',
'zenmodeletl',
'zeneventetl',
'zenperfetl',
'zenjmx',
'zenjserver',
'zenvsphere',
'zenucsevents',
'zenpropertymonitor',
]
def matching_services(service, names):
"""Recursively generate services in service where "Name" is in names."""
name = service.get('Name')
if name in names:
yield service
for subservice in service.get('Services') or []:
for matching_subservice in matching_services(subservice, names):
yield matching_subservice
def main():
json_lines = []
for line in sys.stdin.readlines():
if line.startswith('This master has been configured to be in pool:'):
continue
json_lines.append(line)
try:
app = json.loads('\n'.join(json_lines))
except KeyboardInterrupt:
sys.exit(1)
top_service = app['Services'][0]
new_name = '{}.develop'.format(app['Name'])
app['Name'] = new_name
top_service['Name'] = new_name
for service in matching_services(app, ['Zope']):
service['Instances']['Min'] = 1
service['Instances']['Default'] = 0
for service in matching_services(app, collector_services):
if 'Launch' in service:
service['Launch'] = 'manual'
print json.dumps(app)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment