initial import (Boeing r1752, NRL r878)
This commit is contained in:
commit
f8f46d28be
394 changed files with 99738 additions and 0 deletions
26
daemon/examples/myservices/README.txt
Normal file
26
daemon/examples/myservices/README.txt
Normal file
|
@ -0,0 +1,26 @@
|
|||
This directory contains a sample custom service that you can use as a template
|
||||
for creating your own services.
|
||||
|
||||
Follow these steps to add your own services:
|
||||
|
||||
1. Modify the sample service MyService to do what you want. It could generate
|
||||
config/script files, mount per-node directories, start processes/scripts,
|
||||
etc. sample.py is a Python file that defines one or more classes to be
|
||||
imported. You can create multiple Python files that will be imported.
|
||||
Add any new filenames to the __init__.py file.
|
||||
|
||||
2. Put these files in a directory such as /home/username/.core/myservices
|
||||
Note that the last component of this directory name 'myservices' should not
|
||||
be named something like 'services' which conflicts with an existing Python
|
||||
name (the syntax 'from myservices import *' is used).
|
||||
|
||||
3. Add a 'custom_services_dir = /home/username/.core/myservices' entry to the
|
||||
/etc/core/core.conf file.
|
||||
|
||||
4. Restart the CORE daemon (core-daemon). Any import errors (Python syntax)
|
||||
should be displayed in the /var/log/core-daemon.log log file (or on screen).
|
||||
|
||||
5. Start using your custom service on your nodes. You can create a new node
|
||||
type that uses your service, or change the default services for an existing
|
||||
node type, or change individual nodes.
|
||||
|
7
daemon/examples/myservices/__init__.py
Normal file
7
daemon/examples/myservices/__init__.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
"""myservices
|
||||
|
||||
Custom services that you define can be put in this directory. Everything
|
||||
listed in __all__ is automatically loaded when you add this directory to the
|
||||
custom_services_dir = '/full/path/to/here' core.conf file option.
|
||||
"""
|
||||
__all__ = ["sample"]
|
64
daemon/examples/myservices/sample.py
Normal file
64
daemon/examples/myservices/sample.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
#
|
||||
# CORE
|
||||
# Copyright (c)2010-2012 the Boeing Company.
|
||||
# See the LICENSE file included in this distribution.
|
||||
#
|
||||
''' Sample user-defined service.
|
||||
'''
|
||||
|
||||
import os
|
||||
|
||||
from core.service import CoreService, addservice
|
||||
from core.misc.ipaddr import IPv4Prefix, IPv6Prefix
|
||||
|
||||
class MyService(CoreService):
|
||||
''' This is a sample user-defined service.
|
||||
'''
|
||||
# a unique name is required, without spaces
|
||||
_name = "MyService"
|
||||
# you can create your own group here
|
||||
_group = "Utility"
|
||||
# list of other services this service depends on
|
||||
_depends = ()
|
||||
# per-node directories
|
||||
_dirs = ()
|
||||
# generated files (without a full path this file goes in the node's dir,
|
||||
# e.g. /tmp/pycore.12345/n1.conf/)
|
||||
_configs = ('myservice.sh', )
|
||||
# this controls the starting order vs other enabled services
|
||||
_startindex = 50
|
||||
# list of startup commands, also may be generated during startup
|
||||
_startup = ('sh myservice.sh',)
|
||||
# list of shutdown commands
|
||||
_shutdown = ()
|
||||
|
||||
@classmethod
|
||||
def generateconfig(cls, node, filename, services):
|
||||
''' Return a string that will be written to filename, or sent to the
|
||||
GUI for user customization.
|
||||
'''
|
||||
cfg = "#!/bin/sh\n"
|
||||
cfg += "# auto-generated by MyService (sample.py)\n"
|
||||
|
||||
for ifc in node.netifs():
|
||||
cfg += 'echo "Node %s has interface %s"\n' % (node.name, ifc.name)
|
||||
# here we do something interesting
|
||||
cfg += "\n".join(map(cls.subnetentry, ifc.addrlist))
|
||||
break
|
||||
return cfg
|
||||
|
||||
@staticmethod
|
||||
def subnetentry(x):
|
||||
''' Generate a subnet declaration block given an IPv4 prefix string
|
||||
for inclusion in the config file.
|
||||
'''
|
||||
if x.find(":") >= 0:
|
||||
# this is an IPv6 address
|
||||
return ""
|
||||
else:
|
||||
net = IPv4Prefix(x)
|
||||
return 'echo " network %s"' % (net)
|
||||
|
||||
# this line is required to add the above class to the list of available services
|
||||
addservice(MyService)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue